Skip to content

Commit b3696f4

Browse files
committed
Handle defpred-alias with arguments
1 parent 94f9e6f commit b3696f4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

org-ql.el

+22
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,28 @@ It would be expanded to:
11501150
(org-ql--define-query-preamble-fn (reverse org-ql-predicates))
11511151
(org-ql--def-query-string-to-sexp-fn (reverse org-ql-predicates))))))
11521152

1153+
(defmacro org-ql-defpred-alias (name args docstring query)
1154+
"Define an `org-ql' predicate alias to complex `org-ql' query.
1155+
NAME may be a symbol or a list of symbols: if a list, the first
1156+
is used as NAME and the rest are aliases.
1157+
1158+
ARGS is an argument list. DOCSTRING is the function's docstring.
1159+
1160+
QUERY is a valid `org-ql' query."
1161+
(declare (debug ([&or symbolp listp] listp stringp
1162+
&rest (sexp query)))
1163+
(indent defun))
1164+
`(org-ql-defpred ,name ,args
1165+
,docstring
1166+
:normalizers ((`(,predicate-names . ,arg-values)
1167+
(cl-progv ',args arg-values
1168+
(-tree-map
1169+
(lambda (el)
1170+
(if (cl-member el ',args)
1171+
(symbol-value el)
1172+
el))
1173+
',query))))))
1174+
11531175
(defmacro org-ql--normalize-from-to-on (&rest body)
11541176
"For internal use.
11551177
Expands into a form that processes arguments to timestamp-related

0 commit comments

Comments
 (0)