Add heading-regexp predicate. Fix #64
This commit is contained in:
parent
b9dfd7d93b
commit
486778e9fa
3 changed files with 48 additions and 12 deletions
23
org-ql.el
23
org-ql.el
|
|
@ -696,6 +696,23 @@ replace the clause with a preamble."
|
|||
'no-group))
|
||||
element)
|
||||
|
||||
;; Heading regexp.
|
||||
;; MAYBE: Adjust regexp to avoid matching in tag list.
|
||||
(`(heading-regexp ,regexp)
|
||||
;; Only one regexp: match with preamble, then let predicate confirm (because
|
||||
;; the match could be in e.g. the tags rather than the heading text).
|
||||
(setq org-ql-preamble (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
|
||||
(regexp ,regexp))
|
||||
'no-group))
|
||||
element)
|
||||
(`(heading-regexp . ,regexps)
|
||||
;; Multiple regexps: use preamble to match against first
|
||||
;; regexp, then let the predicate match the rest.
|
||||
(setq org-ql-preamble (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
|
||||
(regexp ,(car regexps)))
|
||||
'no-group))
|
||||
element)
|
||||
|
||||
;; Heading levels.
|
||||
(`(level ,comparator-or-num ,num)
|
||||
(let ((repeat (pcase comparator-or-num
|
||||
|
|
@ -1149,6 +1166,12 @@ priority B)."
|
|||
(let ((heading (org-get-heading 'no-tags 'no-todo)))
|
||||
(--all? (string-match it heading) regexps)))
|
||||
|
||||
(org-ql--defpred heading-regexp (&rest regexps)
|
||||
"Return non-nil if current entry's heading matches all REGEXPS (regexp strings)."
|
||||
;; TODO: In Org 9.2+, `org-get-heading' takes 2 more arguments.
|
||||
(let ((heading (org-get-heading 'no-tags 'no-todo)))
|
||||
(--all? (string-match it heading) regexps)))
|
||||
|
||||
(org-ql--defpred property (property &optional value)
|
||||
"Return non-nil if current entry has PROPERTY (a string), and optionally VALUE (a string)."
|
||||
(pcase property
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue