diff --git a/README.org b/README.org index 32dada2..38a79e2 100644 --- a/README.org +++ b/README.org @@ -385,6 +385,7 @@ Expands into a call to ~org-ql-select~ with the same arguments. For convenience *Fixed* + Handle date ranges in date-based selectors. (Thanks to [[https://github.com/codygman][Cody Goodman]], [[https://github.com/swflint][Samuel W. Flint]], and [[https://github.com/vikasrawal][Vikas Rawal]].) + Don't overwrite bindings in =org-agenda-mode-map=. ++ Don't search buffers without headings, and show a message if the user attempts it. *Compatibility* + Fixes for compatibility with Org 9.2. (Thanks to [[https://github.com/ataias][Ataias Pereira Reis]] and [[https://github.com/dakra][Daniel Kraus]].) diff --git a/org-ql.el b/org-ql.el index 377db58..ca38445 100644 --- a/org-ql.el +++ b/org-ql.el @@ -487,15 +487,23 @@ If NARROW is non-nil, buffer will not be widened." (goto-char (point-min)) (when (org-before-first-heading-p) (outline-next-heading)) - ;; `cl-loop' makes this double-while much clearer than the expanded form. - (cond (preamble-re (cl-loop while (re-search-forward preamble-re nil t) - do (outline-back-to-heading 'invisible-ok) - when (funcall predicate) - collect (funcall action) - do (outline-next-heading))) - (t (cl-loop when (funcall predicate) - collect (funcall action) - while (outline-next-heading))))))) + (if (not (org-at-heading-p)) + (progn + ;; No headings in buffer: return nil. + (unless (string-prefix-p " " (buffer-name)) + ;; Not a special, hidden buffer: show message, because if a user accidentally + ;; searches a buffer without headings, he might be confused. + (message "org-ql: No headings in buffer: %s" (current-buffer))) + nil) + ;; `cl-loop' makes this double-while much clearer than the expanded form. + (cond (preamble-re (cl-loop while (re-search-forward preamble-re nil t) + do (outline-back-to-heading 'invisible-ok) + when (funcall predicate) + collect (funcall action) + do (outline-next-heading))) + (t (cl-loop when (funcall predicate) + collect (funcall action) + while (outline-next-heading)))))))) (--each orig-fns ;; Restore original function mappings. (fset (plist-get it :name) (plist-get it :fn))))))