From ba49d0e3c7ed38e0603707bb7d23f6ce12b0813d Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Mon, 26 Aug 2024 07:14:31 -0500 Subject: [PATCH 1/2] Change: Respect narrowing in org-ql-find This allows searching within a narrowed buffer with org-ql-find. Using "C-u" searches the widened buffer, while "C-u C-u" prompts to select the buffers to search (which previously worked with just "C-u"). --- org-ql-completing-read.el | 5 ++++- org-ql-find.el | 40 ++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/org-ql-completing-read.el b/org-ql-completing-read.el index 18cfd7f9..03f3db12 100644 --- a/org-ql-completing-read.el +++ b/org-ql-completing-read.el @@ -134,7 +134,7 @@ value, or nil." ;;;###autoload (cl-defun org-ql-completing-read - (buffers-files &key query-prefix query-filter + (buffers-files &key query-prefix query-filter narrowp (action #'org-ql-completing-read-action) ;; FIXME: Unused argument. ;; (annotate #'org-ql-completing-read-snippet) @@ -145,6 +145,8 @@ value, or nil." "Return marker at entry in BUFFERS-FILES selected with `org-ql'. PROMPT is shown to the user. +NARROWP is passed to `org-ql-select', which see. + QUERY-PREFIX may be a string to prepend to the query entered by the user (e.g. use \"heading:\" to only search headings, easily creating a custom command that saves the user from having to type @@ -323,6 +325,7 @@ single predicate)." bow (or ,@query-tokens) (0+ (not space)) (optional (repeat 1 3 (0+ space) (repeat 1 15 (not space)))))))) (org-ql-select buffers-files (org-ql--query-string-to-sexp input) + :narrow narrowp :action #'action)))) (unless (listp buffers-files) ;; Since we map across this argument, we ensure it's a list. diff --git a/org-ql-find.el b/org-ql-find.el index 820d2dd2..ed6d21dd 100644 --- a/org-ql-find.el +++ b/org-ql-find.el @@ -54,14 +54,18 @@ See function `display-buffer'." ;;;; Commands ;;;###autoload -(cl-defun org-ql-find (buffers-files &key query-prefix query-filter +(cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen (prompt "Find entry: ")) "Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'. Interactively, search the buffers and files relevant to the current buffer (i.e. in `org-agenda-mode', the value of `org-ql-view-buffers-files' or `org-agenda-contributing-files'; -in `org-mode', that buffer). With universal prefix, select -multiple buffers to search with completion and PROMPT. +in `org-mode', that buffer). + +With one or more universal prefix arguments, WIDEN buffers before +searching (otherwise, respect any narrowing). With two universal +prefix arguments, select multiple buffers to search with +completion and PROMPT. QUERY-PREFIX may be a string to prepend to the query (e.g. use \"heading:\" to only search headings, easily creating a custom @@ -72,11 +76,17 @@ types is filtered before execution (e.g. it could replace spaces with commas to turn multiple tokens, which would normally be treated as multiple predicates, into multiple arguments to a single predicate)." - (interactive (list (org-ql-find--buffers))) - (let ((marker (org-ql-completing-read buffers-files - :query-prefix query-prefix - :query-filter query-filter - :prompt prompt))) + (interactive (list (org-ql-find--buffers + :read-buffer-p (equal '(16) current-prefix-arg)) + :widen current-prefix-arg)) + (let ((marker (save-restriction + (when (and widen (equal (current-buffer) buffers-files)) + (widen)) + (org-ql-completing-read buffers-files + :narrowp (not widen) + :query-prefix query-prefix + :query-filter query-filter + :prompt prompt)))) (set-buffer (or (buffer-base-buffer (marker-buffer marker)) (marker-buffer marker))) (pop-to-buffer (current-buffer) org-ql-find-display-buffer-action) @@ -195,15 +205,15 @@ multiple buffers to search with completion and PROMPT." ;;;; Functions -(defun org-ql-find--buffers () - "Return list of buffers to search in. +(cl-defun org-ql-find--buffers (&key read-buffer-p) + "Return buffer or list of buffers to search in. In a mode derived from `org-agenda-mode', return the value of `org-ql-view-buffers-files' or `org-agenda-contributing-files'. -In a mode derived from `org-mode', return the current buffer. -When `current-prefix-arg', read a list of buffers in `org-mode' -with completion. To be used in `org-ql-find' commands' -interactive forms." - (if current-prefix-arg +In a mode derived from `org-mode', return the current buffer. If +READ-BUFFER-P, read a list of buffers in `org-mode' with +completion. To be used in `org-ql-find' commands' interactive +forms." + (if read-buffer-p (mapcar #'get-buffer (completing-read-multiple "Buffers: " From cfe5300987dcec095ccbced0ae2c77a847bca681 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Mon, 26 Aug 2024 07:19:09 -0500 Subject: [PATCH 2/2] Docs: Update changelog --- README.org | 4 +++ org-ql.info | 100 ++++++++++++++++++++++++++++------------------------ 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/README.org b/README.org index 61995fba..3382496f 100644 --- a/README.org +++ b/README.org @@ -556,6 +556,10 @@ Simple links may also be written manually in either sexp or non-sexp form, like: ** 0.9-pre +*Changes* ++ Command ~org-ql-find~ respects narrowing of the current buffer by default, allowing searching within the narrowed region. (Using one ~C-u~ argument widens the current buffer, and using two ~C-u~ arguments prompts for the buffers to search.) ++ Function ~org-ql-completing-read~ accepts a new ~NARROWP~ argument, which is passed to ~org-ql-select~. + *Compatibility* + Fix compilation error on Emacs 30. ([[https://github.com/alphapapa/org-ql/issues/433][#433]]. Thanks to [[https://github.com/akirak][Akira Komamura]] and [[https://github.com/monnier][Stefan Monnier]].) diff --git a/org-ql.info b/org-ql.info index c2641b7b..edf994a9 100644 --- a/org-ql.info +++ b/org-ql.info @@ -1091,7 +1091,15 @@ File: README.info, Node: 09-pre, Next: 087, Up: Changelog 5.1 0.9-pre =========== -*Compatibility* +*Changes* + • Command ‘org-ql-find’ respects narrowing of the current buffer by + default, allowing searching within the narrowed region. (Using one + ‘C-u’ argument widens the current buffer, and using two ‘C-u’ + arguments prompts for the buffers to search.) + • Function ‘org-ql-completing-read’ accepts a new ‘NARROWP’ argument, + which is passed to ‘org-ql-select’. + + *Compatibility* • Fix compilation error on Emacs 30. (#433 (https://github.com/alphapapa/org-ql/issues/433). Thanks to Akira Komamura (https://github.com/akirak) and Stefan Monnier @@ -2092,51 +2100,51 @@ Node: Links39023 Node: Tips39710 Node: Changelog40034 Node: 09-pre40973 -Node: helm-org-ql (1)41339 -Node: 08741480 -Node: 08642711 -Node: 08542945 -Node: 08443601 -Node: 08344053 -Node: 08244394 -Node: 08144787 -Node: 0845208 -Node: 07447932 -Node: 07348157 -Node: 07248891 -Node: 07149812 -Node: 0750623 -Node: 06353489 -Node: 06254022 -Node: 06154329 -Node: 0654899 -Node: 05257955 -Node: 05158257 -Node: 0558682 -Node: 04960213 -Node: 04860495 -Node: 04760844 -Node: 04661253 -Node: 04561661 -Node: 04462022 -Node: 04362381 -Node: 04262584 -Node: 04162745 -Node: 0462992 -Node: 03267093 -Node: 03167496 -Node: 0367693 -Node: 02370993 -Node: 02271227 -Node: 02171507 -Node: 0271712 -Node: 0175790 -Node: Development75891 -Node: Copyright assignment76124 -Node: Notes76714 -Node: Comparison with Org Agenda searches76878 -Node: org-sidebar77767 -Node: License78046 +Node: helm-org-ql (1)41757 +Node: 08741898 +Node: 08643129 +Node: 08543363 +Node: 08444019 +Node: 08344471 +Node: 08244812 +Node: 08145205 +Node: 0845626 +Node: 07448350 +Node: 07348575 +Node: 07249309 +Node: 07150230 +Node: 0751041 +Node: 06353907 +Node: 06254440 +Node: 06154747 +Node: 0655317 +Node: 05258373 +Node: 05158675 +Node: 0559100 +Node: 04960631 +Node: 04860913 +Node: 04761262 +Node: 04661671 +Node: 04562079 +Node: 04462440 +Node: 04362799 +Node: 04263002 +Node: 04163163 +Node: 0463410 +Node: 03267511 +Node: 03167914 +Node: 0368111 +Node: 02371411 +Node: 02271645 +Node: 02171925 +Node: 0272130 +Node: 0176208 +Node: Development76309 +Node: Copyright assignment76542 +Node: Notes77132 +Node: Comparison with Org Agenda searches77296 +Node: org-sidebar78185 +Node: License78464  End Tag Table