remyhonig / org-query

Create complex but readable skip-functions for org-agenda
57 stars 4 forks source link

org-query-select and last headline. #6

Open elraymond opened 6 years ago

elraymond commented 6 years ago

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!

alphapapa commented 4 years ago

Somehow I stumbled back in here a year and a half later. :)

@elraymond Thanks for noticing that, and my apologies for introducing the bug in my patch.

I don't want to minimize org-query, but allow me to mention https://github.com/alphapapa/org-ql, which provides an alternative that you may find useful.