Add: Outline level predicate

Fixes #3.  Thanks to @akirak.
This commit is contained in:
Adam Porter 2018-08-04 23:09:21 -05:00
parent 69083fb17b
commit 465767e7cc

View file

@ -135,6 +135,7 @@ first."
(tags #'org-ql--tags-p) (tags #'org-ql--tags-p)
(property #'org-ql--property-p) (property #'org-ql--property-p)
(regexp #'org-ql--regexp-p) (regexp #'org-ql--regexp-p)
(level #'org-ql--level-p)
(org-back-to-heading #'outline-back-to-heading)) (org-back-to-heading #'outline-back-to-heading))
(save-excursion (save-excursion
(save-restriction (save-restriction
@ -178,6 +179,26 @@ With KEYWORDS, return non-nil if its keyword is one of KEYWORDS."
(null t) (null t)
(otherwise (seq-intersection tags tags-at))))) (otherwise (seq-intersection tags tags-at)))))
(defun org-ql--level-p (level-or-comparator &optional level)
"Return non-nil if current heading's outline level matches LEVEL with COMPARATOR.
If LEVEL is nil, LEVEL-OR-COMPARATOR should be a level, which
will be tested for equality to the heading's outline level. If
LEVEL is non-nil, LEVEL-OR-COMPARATOR should be a comparator
function.
Outline levels should be integers."
;; NOTE: It might be necessary to take into account `org-odd-levels'; see docstring for
;; `org-outline-level'.
;; NOTE: `org-outline-level' accounts for inline tasks, which might be slower than the naive
;; `org-current-level'.
(when-let ((outline-level (org-outline-level)))
(pcase level
;; Check for equality
((pred null) (= outline-level level-or-comparator))
;; Check with comparator
(_ (funcall level-or-comparator outline-level level)))))
(defun org-ql--date-p (type &optional comparator target-date) (defun org-ql--date-p (type &optional comparator target-date)
"Return non-nil if current heading has a date property of TYPE. "Return non-nil if current heading has a date property of TYPE.
TYPE should be a keyword symbol, like :scheduled or :deadline. TYPE should be a keyword symbol, like :scheduled or :deadline.