Change/Fix: Preambles for predicates that expect arguments

Closes #285.  Thanks to Caleb Chase (@chasecaleb) for reporting.
This commit is contained in:
Adam Porter 2022-12-09 19:41:30 -06:00
parent ecde3a0420
commit 91908186fc

View file

@ -1415,7 +1415,15 @@ Matching is done case-insensitively."
;; "h" alias. ;; "h" alias.
`(heading ,@args))) `(heading ,@args)))
;; TODO: Adjust regexp to avoid matching in tag list. ;; TODO: Adjust regexp to avoid matching in tag list.
:preambles ((`(,predicate-names ,string) :preambles ((`(,predicate-names)
;; This clause protects against the case in which the
;; arguments are nil, which would cause an error in
;; `rx-to-string' in other clauses. This can happen
;; with `org-ql-completing-read', e.g. when the input
;; is "h:" while the user is typing.
(list :regexp (rx bol (1+ "*") (1+ blank) (0+ nonl))
:case-fold t :query query))
(`(,predicate-names ,string)
;; Only one string: match with preamble, then let predicate confirm (because ;; Only one string: match with preamble, then let predicate confirm (because
;; the match could be in e.g. the tags rather than the heading text). ;; the match could be in e.g. the tags rather than the heading text).
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl) (list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
@ -1442,7 +1450,15 @@ Matching is done case-insensitively."
;; "h" alias. ;; "h" alias.
`(heading-regexp ,@args))) `(heading-regexp ,@args)))
;; MAYBE: Adjust regexp to avoid matching in tag list. ;; MAYBE: Adjust regexp to avoid matching in tag list.
:preambles ((`(,predicate-names ,regexp) :preambles ((`(,predicate-names)
;; This clause protects against the case in which the
;; arguments are nil, which would cause an error in
;; `rx-to-string' in other clauses. This can happen
;; with `org-ql-completing-read', e.g. when the input
;; is "h:" while the user is typing.
(list :regexp (rx bol (1+ "*") (1+ blank) (0+ nonl))
:case-fold t :query query))
(`(,predicate-names ,regexp)
;; Only one regexp: match with preamble, then let predicate confirm (because ;; 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). ;; the match could be in e.g. the tags rather than the heading text).
(list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl) (list :regexp (rx-to-string `(seq bol (1+ "*") (1+ blank) (0+ nonl)
@ -1478,7 +1494,15 @@ COMPARATOR may be `<', `<=', `>', or `>='."
((pred stringp) (string-to-number it)) ((pred stringp) (string-to-number it))
(_ it)) (_ it))
args)))) args))))
:preambles ((`(,predicate-names ,comparator-or-num ,num) :preambles ((`(,predicate-names)
;; This clause protects against the case in which the
;; arguments are nil, which would cause an error in
;; `rx-to-string' in other clauses. This can happen
;; with `org-ql-completing-read', e.g. when the input
;; is "h:" while the user is typing.
(list :regexp (rx bol (1+ "*") " ")
:case-fold t))
(`(,predicate-names ,comparator-or-num ,num)
(let ((repeat (pcase comparator-or-num (let ((repeat (pcase comparator-or-num
('< `(repeat 1 ,(1- num) "*")) ('< `(repeat 1 ,(1- num) "*"))
('<= `(repeat 1 ,num "*")) ('<= `(repeat 1 ,num "*"))
@ -1736,7 +1760,18 @@ entry; if t, also match entries with inheritance. If INHERIT is
not specified, use the Boolean value of not specified, use the Boolean value of
`org-use-property-inheritance', which see (i.e. it is only `org-use-property-inheritance', which see (i.e. it is only
interpreted as nil or non-nil)." interpreted as nil or non-nil)."
:normalizers ((`(,predicate-names ,property ,value . ,plist) :normalizers ((`(,predicate-names)
;; HACK: This clause protects against the case in
;; which the arguments are nil, which would cause an
;; error in `rx-to-string' in other clauses. This
;; can happen with `org-ql-completing-read',
;; e.g. when the input is "property:" while the user
;; is typing.
;; FIXME: Instead of this being moot, make this
;; predicate test for whether an entry has local
;; properties when no arguments are given.
(list 'property ""))
(`(,predicate-names ,property ,value . ,plist)
;; Convert keyword property arguments to strings. Non-sexp ;; Convert keyword property arguments to strings. Non-sexp
;; queries result in keyword property arguments (because to do ;; queries result in keyword property arguments (because to do
;; otherwise would require ugly special-casing in the parsing). ;; otherwise would require ugly special-casing in the parsing).