diff --git a/README.org b/README.org index 85a89e3..7cb32d0 100644 --- a/README.org +++ b/README.org @@ -521,6 +521,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like: *Changed* + Helm support (including the command =helm-org-ql=) has been moved to a separate package, =helm-org-ql=. ++ Predicates ~outline-path~ and ~outline-path-segment~, when called with multiple arguments, optimize to a query like ~(and (heading LAST-OLP-ARG) (olp OTHER-OLP-ARGS))~, which is much faster. *Internal* + Predicates are now defined more cleanly with a macro (=org-ql-defpred=) that consolidates functionality related to each predicate. This will also allow users to more easily define custom predicates. diff --git a/org-ql.el b/org-ql.el index 36e69a5..b02ab7c 100644 --- a/org-ql.el +++ b/org-ql.el @@ -1170,9 +1170,17 @@ the following queries: (olp \"Food\" \"Fruits\") (olp \"Fruits\" \"Grapes\") (olp \"Food\" \"Grapes\")" - :normalizers ((`(,predicate-names . ,strings) - ;; Regexp quote headings. - `(outline-path ,@(mapcar #'regexp-quote strings)))) + ;; FIXME: Stop regexp quoting when the (heading) predicate is changed to take a non-regexp string. + :normalizers ((`(,predicate-names ,string) + ;; Equivalent to (heading string), which is much faster. + `(heading ,(regexp-quote string))) + (`(,predicate-names . ,strings) + ;; Rewrite query to use (heading) with the last string + ;; and (olp) for the rest, which is much faster. + (let ((last (car (last strings))) + (rest (butlast strings))) + `(and (heading ,(regexp-quote last)) + (outline-path ,@(mapcar #'regexp-quote rest)))))) :body (let ((entry-olp (org-ql--value-at (point) #'org-ql--outline-path))) (cl-loop for h in regexps always (cl-member h entry-olp :test #'string-match)))) @@ -1195,9 +1203,17 @@ contiguous segment of the outline path: (olp \"Food\" \"Grape\")" ;; MAYBE: Allow anchored matching. - :normalizers ((`(,(or 'outline-path-segment 'olps) . ,strings) - ;; Regexp quote headings. - `(outline-path-segment ,@(mapcar #'regexp-quote strings)))) + ;; FIXME: Stop regexp quoting when the (heading) predicate is changed to take a non-regexp string. + :normalizers ((`(,predicate-names ,string) + ;; Equivalent to (heading string), which is much faster. + `(heading ,(regexp-quote string))) + (`(,predicate-names . ,strings) + ;; Rewrite query to use (heading) with the last string + ;; and (olp) for the rest, which is much faster. + (let ((last (car (last strings))) + (rest (butlast strings))) + `(and (heading ,(regexp-quote last)) + (outline-path-segment ,@(mapcar #'regexp-quote rest)))))) :body (org-ql--infix-p regexps (org-ql--value-at (point) #'org-ql--outline-path))) (org-ql-defpred path (&rest regexps) diff --git a/org-ql.info b/org-ql.info index ae676fb..c5d7a1e 100644 --- a/org-ql.info +++ b/org-ql.info @@ -966,6 +966,9 @@ File: README.info, Node: 06-pre, Next: 05, Up: Changelog *Changed* • Helm support (including the command helm-org-ql) has been moved to a separate package, helm-org-ql. + • Predicates ‘outline-path’ and ‘outline-path-segment’, when called + with multiple arguments, optimize to a query like ‘(and (heading + LAST-OLP-ARG) (olp OTHER-OLP-ARGS))’, which is much faster. *Internal* • Predicates are now defined more cleanly with a macro @@ -1488,29 +1491,29 @@ Node: Links33872 Node: Tips34559 Node: Changelog34877 Node: 06-pre35573 -Node: 0536196 -Node: 04937673 -Node: 04837947 -Node: 04738294 -Node: 04638689 -Node: 04539089 -Node: 04439448 -Node: 04339805 -Node: 04240000 -Node: 04140161 -Node: 0440402 -Node: 03244335 -Node: 03144714 -Node: 0344911 -Node: 02347886 -Node: 02248114 -Node: 02148382 -Node: 0248581 -Node: 0152616 -Node: Notes52717 -Node: Comparison with Org Agenda searches52879 -Node: org-sidebar53751 -Node: License54030 +Node: 0536416 +Node: 04937893 +Node: 04838167 +Node: 04738514 +Node: 04638909 +Node: 04539309 +Node: 04439668 +Node: 04340025 +Node: 04240220 +Node: 04140381 +Node: 0440622 +Node: 03244555 +Node: 03144934 +Node: 0345131 +Node: 02348106 +Node: 02248334 +Node: 02148602 +Node: 0248801 +Node: 0152836 +Node: Notes52937 +Node: Comparison with Org Agenda searches53099 +Node: org-sidebar53971 +Node: License54250  End Tag Table