Add: Convert bare strings to (regexp) predicates
This commit is contained in:
parent
7c4297b667
commit
70176d9c5f
3 changed files with 60 additions and 3 deletions
18
org-ql.el
18
org-ql.el
|
|
@ -150,6 +150,7 @@ non-nil."
|
|||
;; a buffer if the filename doesn't exist.
|
||||
(find-file-noselect it))
|
||||
(user-error "Can't open file: %s" it)))))))
|
||||
(query (org-ql--pre-process-query query))
|
||||
((query preamble-re) (org-ql--query-preamble query))
|
||||
(predicate (org-ql--query-predicate query))
|
||||
(action (pcase action
|
||||
|
|
@ -221,6 +222,23 @@ should be an `org-ql' query sexp."
|
|||
(org-ql-select from where
|
||||
:action select))
|
||||
|
||||
(defun org-ql--pre-process-query (query)
|
||||
"Return QUERY having been pre-processed.
|
||||
Replaces bare strings with (regexp) selectors."
|
||||
;; This is unsophisticated, but it works.
|
||||
(cl-labels ((rec (element)
|
||||
(pcase element
|
||||
(`(or . ,clauses) `(or ,@(mapcar #'rec clauses)))
|
||||
(`(and . ,clauses) `(and ,@(mapcar #'rec clauses)))
|
||||
(`(when ,condition . ,clauses) `(when ,(rec condition)
|
||||
,@(mapcar #'rec clauses)))
|
||||
(`(unless ,condition . ,clauses) `(unless ,(rec condition)
|
||||
,@(mapcar #'rec clauses)))
|
||||
;; TODO: Combine (regexp) when appropriate (i.e. inside an OR, not an AND).
|
||||
((pred stringp) `(regexp ,element))
|
||||
(_ element))))
|
||||
(rec query)))
|
||||
|
||||
(defun org-ql--query-predicate (query)
|
||||
"Return predicate function for QUERY."
|
||||
(byte-compile `(lambda ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue