Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org-ql-defpred-alias: Simplified custom predicates #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions org-ql.el
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,28 @@ It would be expanded to:
(org-ql--define-query-preamble-fn (reverse org-ql-predicates))
(org-ql--def-query-string-to-sexp-fn (reverse org-ql-predicates))))))

(defmacro org-ql-defpred-alias (name args docstring query)
"Define an `org-ql' predicate alias to complex `org-ql' query.
NAME may be a symbol or a list of symbols: if a list, the first
is used as NAME and the rest are aliases.

ARGS is an argument list. DOCSTRING is the function's docstring.

QUERY is a valid `org-ql' query."
(declare (debug ([&or symbolp listp] listp stringp
&rest (sexp query)))
(indent defun))
`(org-ql-defpred ,name ,args
,docstring
:normalizers ((`(,predicate-names . ,arg-values)
(cl-progv ',args arg-values
(-tree-map
(lambda (el)
(if (cl-member el ',args)
(symbol-value el)
el))
',query))))))

(defmacro org-ql--normalize-from-to-on (&rest body)
"For internal use.
Expands into a form that processes arguments to timestamp-related
Expand Down