From 8f51fe9a122743fe107d0b4d919d58091f278621 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 4 Dec 2020 10:48:42 +0800 Subject: [PATCH 1/4] Revert "Change: (olp, olps) Optimize multiple args with heading query" This reverts commit 2d07cb082263061420c5a28a23bbd1d7f9008a25. --- README.org | 1 - org-ql.el | 28 ++++++---------------------- org-ql.info | 49 +++++++++++++++++++++++-------------------------- 3 files changed, 29 insertions(+), 49 deletions(-) diff --git a/README.org b/README.org index 7cb32d0..85a89e3 100644 --- a/README.org +++ b/README.org @@ -521,7 +521,6 @@ 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 b02ab7c..36e69a5 100644 --- a/org-ql.el +++ b/org-ql.el @@ -1170,17 +1170,9 @@ the following queries: (olp \"Food\" \"Fruits\") (olp \"Fruits\" \"Grapes\") (olp \"Food\" \"Grapes\")" - ;; 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)))))) + :normalizers ((`(,predicate-names . ,strings) + ;; Regexp quote headings. + `(outline-path ,@(mapcar #'regexp-quote strings)))) :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)))) @@ -1203,17 +1195,9 @@ contiguous segment of the outline path: (olp \"Food\" \"Grape\")" ;; MAYBE: Allow anchored matching. - ;; 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)))))) + :normalizers ((`(,(or 'outline-path-segment 'olps) . ,strings) + ;; Regexp quote headings. + `(outline-path-segment ,@(mapcar #'regexp-quote strings)))) :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 c5d7a1e..ae676fb 100644 --- a/org-ql.info +++ b/org-ql.info @@ -966,9 +966,6 @@ 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 @@ -1491,29 +1488,29 @@ Node: Links33872 Node: Tips34559 Node: Changelog34877 Node: 06-pre35573 -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 +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  End Tag Table From 7ecb80fca9e719bb5f358b561d1f6cbc9ccee248 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Mon, 7 Dec 2020 13:55:18 +0800 Subject: [PATCH 2/4] Run `helm-org-ql--heading' as :filtered-candidate-transformer --- helm-org-ql.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/helm-org-ql.el b/helm-org-ql.el index 54d6566..b634d30 100644 --- a/helm-org-ql.el +++ b/helm-org-ql.el @@ -178,21 +178,27 @@ Is transformed into this query: "Return Helm source named NAME that searches BUFFERS-FILES with `helm-org-ql'." ;; Expansion of `helm-build-sync-source' macro. (helm-make-source name 'helm-source-sync + :filtered-candidate-transformer (lambda (candidates _) + (let ((window-width (window-width (helm-window)))) + (mapcar (lambda (marker) + (unless (markerp marker) (user-error "Unexpected candidate for `helm-org-ql-source'")) + (org-with-point-at marker + (helm-org-ql--heading window-width))) + candidates))) :candidates (lambda () - (let* ((query (org-ql--query-string-to-sexp helm-pattern)) - (window-width (window-width (helm-window)))) + (let* ((query (org-ql--query-string-to-sexp helm-pattern))) (when query (with-current-buffer (helm-buffer-get) (setq helm-org-ql-buffers-files buffers-files)) (ignore-errors ;; Ignore errors that might be caused by partially typed queries. (org-ql-select buffers-files query - :action `(helm-org-ql--heading ,window-width)))))) + :action `(point-marker)))))) :match #'identity :fuzzy-match nil :multimatch nil :nohighlight t - :volatile t + :match-dynamic t :keymap helm-org-ql-map :action helm-org-ql-actions)) From 555ae98eb8b8795d03ff4efa479376bbaa5cb9f3 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Mon, 7 Dec 2020 14:49:43 +0800 Subject: [PATCH 3/4] Use spaces for indentation --- helm-org-ql.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helm-org-ql.el b/helm-org-ql.el index b634d30..980f68f 100644 --- a/helm-org-ql.el +++ b/helm-org-ql.el @@ -179,12 +179,12 @@ Is transformed into this query: ;; Expansion of `helm-build-sync-source' macro. (helm-make-source name 'helm-source-sync :filtered-candidate-transformer (lambda (candidates _) - (let ((window-width (window-width (helm-window)))) - (mapcar (lambda (marker) - (unless (markerp marker) (user-error "Unexpected candidate for `helm-org-ql-source'")) - (org-with-point-at marker + (let ((window-width (window-width (helm-window)))) + (mapcar (lambda (marker) + (unless (markerp marker) (user-error "Unexpected candidate for `helm-org-ql-source'")) + (org-with-point-at marker (helm-org-ql--heading window-width))) - candidates))) + candidates))) :candidates (lambda () (let* ((query (org-ql--query-string-to-sexp helm-pattern))) (when query From 8ba81a44412095b3a58397a0d8521c94d0a37416 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Mon, 7 Dec 2020 15:07:23 +0800 Subject: [PATCH 4/4] Scope window-width lexically and do not check for candidate type --- helm-org-ql.el | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/helm-org-ql.el b/helm-org-ql.el index 980f68f..44a4ecd 100644 --- a/helm-org-ql.el +++ b/helm-org-ql.el @@ -177,30 +177,29 @@ Is transformed into this query: (cl-defun helm-org-ql-source (buffers-files &key (name "helm-org-ql")) "Return Helm source named NAME that searches BUFFERS-FILES with `helm-org-ql'." ;; Expansion of `helm-build-sync-source' macro. - (helm-make-source name 'helm-source-sync - :filtered-candidate-transformer (lambda (candidates _) - (let ((window-width (window-width (helm-window)))) - (mapcar (lambda (marker) - (unless (markerp marker) (user-error "Unexpected candidate for `helm-org-ql-source'")) - (org-with-point-at marker + (let ((window-width (window-width (helm-window)))) + (helm-make-source name 'helm-source-sync + :filtered-candidate-transformer (lambda (candidate-markers _) + (mapcar (lambda (candidate-marker) + (org-with-point-at candidate-marker (helm-org-ql--heading window-width))) - candidates))) - :candidates (lambda () - (let* ((query (org-ql--query-string-to-sexp helm-pattern))) - (when query - (with-current-buffer (helm-buffer-get) - (setq helm-org-ql-buffers-files buffers-files)) - (ignore-errors - ;; Ignore errors that might be caused by partially typed queries. - (org-ql-select buffers-files query - :action `(point-marker)))))) - :match #'identity - :fuzzy-match nil - :multimatch nil - :nohighlight t - :match-dynamic t - :keymap helm-org-ql-map - :action helm-org-ql-actions)) + candidate-markers)) + :candidates (lambda () + (let* ((query (org-ql--query-string-to-sexp helm-pattern))) + (when query + (with-current-buffer (helm-buffer-get) + (setq helm-org-ql-buffers-files buffers-files)) + (ignore-errors + ;; Ignore errors that might be caused by partially typed queries. + (org-ql-select buffers-files query + :action `(point-marker)))))) + :match #'identity + :fuzzy-match nil + :multimatch nil + :nohighlight t + :match-dynamic t + :keymap helm-org-ql-map + :action helm-org-ql-actions))) (defun helm-org-ql--heading (window-width) "Return string for Helm for heading at point.