Skip to content

Commit b0cb761

Browse files
committed
Merge: Respect narrowing in org-ql-find
2 parents b7d4856 + cfe5300 commit b0cb761

File tree

4 files changed

+87
-62
lines changed

4 files changed

+87
-62
lines changed

README.org

+4
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
556556

557557
** 0.9-pre
558558

559+
*Changes*
560+
+ 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.)
561+
+ Function ~org-ql-completing-read~ accepts a new ~NARROWP~ argument, which is passed to ~org-ql-select~.
562+
559563
*Compatibility*
560564
+ 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]].)
561565

org-ql-completing-read.el

+4-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ value, or nil."
134134

135135
;;;###autoload
136136
(cl-defun org-ql-completing-read
137-
(buffers-files &key query-prefix query-filter
137+
(buffers-files &key query-prefix query-filter narrowp
138138
(action #'org-ql-completing-read-action)
139139
;; FIXME: Unused argument.
140140
;; (annotate #'org-ql-completing-read-snippet)
@@ -145,6 +145,8 @@ value, or nil."
145145
"Return marker at entry in BUFFERS-FILES selected with `org-ql'.
146146
PROMPT is shown to the user.
147147
148+
NARROWP is passed to `org-ql-select', which see.
149+
148150
QUERY-PREFIX may be a string to prepend to the query entered by
149151
the user (e.g. use \"heading:\" to only search headings, easily
150152
creating a custom command that saves the user from having to type
@@ -323,6 +325,7 @@ single predicate)."
323325
bow (or ,@query-tokens) (0+ (not space))
324326
(optional (repeat 1 3 (0+ space) (repeat 1 15 (not space))))))))
325327
(org-ql-select buffers-files (org-ql--query-string-to-sexp input)
328+
:narrow narrowp
326329
:action #'action))))
327330
(unless (listp buffers-files)
328331
;; Since we map across this argument, we ensure it's a list.

org-ql-find.el

+25-15
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ See function `display-buffer'."
5454
;;;; Commands
5555

5656
;;;###autoload
57-
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter
57+
(cl-defun org-ql-find (buffers-files &key query-prefix query-filter widen
5858
(prompt "Find entry: "))
5959
"Go to an Org entry in BUFFERS-FILES selected by searching entries with `org-ql'.
6060
Interactively, search the buffers and files relevant to the
6161
current buffer (i.e. in `org-agenda-mode', the value of
6262
`org-ql-view-buffers-files' or `org-agenda-contributing-files';
63-
in `org-mode', that buffer). With universal prefix, select
64-
multiple buffers to search with completion and PROMPT.
63+
in `org-mode', that buffer).
64+
65+
With one or more universal prefix arguments, WIDEN buffers before
66+
searching (otherwise, respect any narrowing). With two universal
67+
prefix arguments, select multiple buffers to search with
68+
completion and PROMPT.
6569
6670
QUERY-PREFIX may be a string to prepend to the query (e.g. use
6771
\"heading:\" to only search headings, easily creating a custom
@@ -72,11 +76,17 @@ types is filtered before execution (e.g. it could replace spaces
7276
with commas to turn multiple tokens, which would normally be
7377
treated as multiple predicates, into multiple arguments to a
7478
single predicate)."
75-
(interactive (list (org-ql-find--buffers)))
76-
(let ((marker (org-ql-completing-read buffers-files
77-
:query-prefix query-prefix
78-
:query-filter query-filter
79-
:prompt prompt)))
79+
(interactive (list (org-ql-find--buffers
80+
:read-buffer-p (equal '(16) current-prefix-arg))
81+
:widen current-prefix-arg))
82+
(let ((marker (save-restriction
83+
(when (and widen (equal (current-buffer) buffers-files))
84+
(widen))
85+
(org-ql-completing-read buffers-files
86+
:narrowp (not widen)
87+
:query-prefix query-prefix
88+
:query-filter query-filter
89+
:prompt prompt))))
8090
(set-buffer (or (buffer-base-buffer (marker-buffer marker))
8191
(marker-buffer marker)))
8292
(pop-to-buffer (current-buffer) org-ql-find-display-buffer-action)
@@ -195,15 +205,15 @@ multiple buffers to search with completion and PROMPT."
195205

196206
;;;; Functions
197207

198-
(defun org-ql-find--buffers ()
199-
"Return list of buffers to search in.
208+
(cl-defun org-ql-find--buffers (&key read-buffer-p)
209+
"Return buffer or list of buffers to search in.
200210
In a mode derived from `org-agenda-mode', return the value of
201211
`org-ql-view-buffers-files' or `org-agenda-contributing-files'.
202-
In a mode derived from `org-mode', return the current buffer.
203-
When `current-prefix-arg', read a list of buffers in `org-mode'
204-
with completion. To be used in `org-ql-find' commands'
205-
interactive forms."
206-
(if current-prefix-arg
212+
In a mode derived from `org-mode', return the current buffer. If
213+
READ-BUFFER-P, read a list of buffers in `org-mode' with
214+
completion. To be used in `org-ql-find' commands' interactive
215+
forms."
216+
(if read-buffer-p
207217
(mapcar #'get-buffer
208218
(completing-read-multiple
209219
"Buffers: "

org-ql.info

+54-46
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,15 @@ File: README.info, Node: 09-pre, Next: 087, Up: Changelog
10911091
5.1 0.9-pre
10921092
===========
10931093

1094-
*Compatibility*
1094+
*Changes*
1095+
• Command ‘org-ql-find’ respects narrowing of the current buffer by
1096+
default, allowing searching within the narrowed region. (Using one
1097+
‘C-u’ argument widens the current buffer, and using two ‘C-u’
1098+
arguments prompts for the buffers to search.)
1099+
• Function ‘org-ql-completing-read’ accepts a new ‘NARROWP’ argument,
1100+
which is passed to ‘org-ql-select’.
1101+
1102+
*Compatibility*
10951103
• Fix compilation error on Emacs 30. (#433
10961104
(https://github.com/alphapapa/org-ql/issues/433). Thanks to Akira
10971105
Komamura (https://github.com/akirak) and Stefan Monnier
@@ -2092,51 +2100,51 @@ Node: Links39023
20922100
Node: Tips39710
20932101
Node: Changelog40034
20942102
Node: 09-pre40973
2095-
Node: helm-org-ql (1)41339
2096-
Node: 08741480
2097-
Node: 08642711
2098-
Node: 08542945
2099-
Node: 08443601
2100-
Node: 08344053
2101-
Node: 08244394
2102-
Node: 08144787
2103-
Node: 0845208
2104-
Node: 07447932
2105-
Node: 07348157
2106-
Node: 07248891
2107-
Node: 07149812
2108-
Node: 0750623
2109-
Node: 06353489
2110-
Node: 06254022
2111-
Node: 06154329
2112-
Node: 0654899
2113-
Node: 05257955
2114-
Node: 05158257
2115-
Node: 0558682
2116-
Node: 04960213
2117-
Node: 04860495
2118-
Node: 04760844
2119-
Node: 04661253
2120-
Node: 04561661
2121-
Node: 04462022
2122-
Node: 04362381
2123-
Node: 04262584
2124-
Node: 04162745
2125-
Node: 0462992
2126-
Node: 03267093
2127-
Node: 03167496
2128-
Node: 0367693
2129-
Node: 02370993
2130-
Node: 02271227
2131-
Node: 02171507
2132-
Node: 0271712
2133-
Node: 0175790
2134-
Node: Development75891
2135-
Node: Copyright assignment76124
2136-
Node: Notes76714
2137-
Node: Comparison with Org Agenda searches76878
2138-
Node: org-sidebar77767
2139-
Node: License78046
2103+
Node: helm-org-ql (1)41757
2104+
Node: 08741898
2105+
Node: 08643129
2106+
Node: 08543363
2107+
Node: 08444019
2108+
Node: 08344471
2109+
Node: 08244812
2110+
Node: 08145205
2111+
Node: 0845626
2112+
Node: 07448350
2113+
Node: 07348575
2114+
Node: 07249309
2115+
Node: 07150230
2116+
Node: 0751041
2117+
Node: 06353907
2118+
Node: 06254440
2119+
Node: 06154747
2120+
Node: 0655317
2121+
Node: 05258373
2122+
Node: 05158675
2123+
Node: 0559100
2124+
Node: 04960631
2125+
Node: 04860913
2126+
Node: 04761262
2127+
Node: 04661671
2128+
Node: 04562079
2129+
Node: 04462440
2130+
Node: 04362799
2131+
Node: 04263002
2132+
Node: 04163163
2133+
Node: 0463410
2134+
Node: 03267511
2135+
Node: 03167914
2136+
Node: 0368111
2137+
Node: 02371411
2138+
Node: 02271645
2139+
Node: 02171925
2140+
Node: 0272130
2141+
Node: 0176208
2142+
Node: Development76309
2143+
Node: Copyright assignment76542
2144+
Node: Notes77132
2145+
Node: Comparison with Org Agenda searches77296
2146+
Node: org-sidebar78185
2147+
Node: License78464
21402148

21412149
End Tag Table
21422150

0 commit comments

Comments
 (0)