Skip to content

org-query-select and last headline. #6

@elraymond

Description

@elraymond

Hi

I'm currently testing your code and example setup, and the very first issue I came across was "false positives" on the last headline in a file. Example:

* TODO
** NEXT

Here, NEXT will show up under "Next tasks in active projects" section in the agenda, which is obviously wrong. Similar problem with backlog section.

The reason seems to be org-query-next-when, which returns nil when there are no more headlines/trees in the buffer. Which makes the agenda code assume, by skipping logic, that this line should be included in the corresponding section.

I'm not elisp expert at all, but I tried

(cl-defsubst org-query-next-when (pred &key (next-fn #'outline-next-heading))
  "Return position of next item if PRED is non-nil for current entry.
NEXT-FN is called to find the next item,
e.g. `outline-next-heading' or `org-end-of-subtree'."
  (save-excursion
    (save-restriction
      ;; NOTE: Possibly unnecessary to widen.  Tests pass without it,
      ;; and it should be faster without it:
      ;; (widen)
      (when (funcall pred)
        (or (funcall next-fn) (point-max))))))

to make the skipping functions return end-of-file instead of nil. Which appears to work, as far as I can tell.

Kind of surprised I'm the first one running into this. It's the very first thing I came across after a minute of testing with an old org file of mine.

Emacs is 25.1.1 and Org 9.1.13.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions