all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Problem with multi-occur search when restricted to region
@ 2022-12-27 13:10 Alain.Cochard
  2022-12-27 13:43 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Alain.Cochard @ 2022-12-27 13:10 UTC (permalink / raw)
  To: emacs-orgmode


Tested with

   Org mode version 9.6 (release_9.6-149-g554935.dirty @
   /home/cochard/Org/Coch-git/org-mode/lisp/)

I have the file debug.org containing

   * h1
   foo
   * h2
   foo bar

I make the 1st two lines the region.  Then I do

   M-x org-agenda << / foo

and I see

   2 matches for "foo" in buffer: debug.org
	 2:foo
	 4:foo bar

(By contrast, 'M-x org-agenda << s foo' only shows 'debug: h1' as I
expect.)

-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.cochard@unistra.fr
5 rue René Descartes   [bureau 110]  | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France     | [ slot available for rent ]



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with multi-occur search when restricted to region
  2022-12-27 13:10 Problem with multi-occur search when restricted to region Alain.Cochard
@ 2022-12-27 13:43 ` Ihor Radchenko
  2022-12-27 20:36   ` Alain.Cochard
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2022-12-27 13:43 UTC (permalink / raw)
  To: alain.cochard; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

Alain.Cochard@unistra.fr writes:

>    * h1
>    foo
>    * h2
>    foo bar
>
> I make the 1st two lines the region.  Then I do
>
>    M-x org-agenda << / foo
>
> and I see
>
>    2 matches for "foo" in buffer: debug.org
> 	 2:foo
> 	 4:foo bar

Thanks for reporting!
Can you try the attached patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-occur-in-agenda-files-Respect-agenda-restriction.patch --]
[-- Type: text/x-patch, Size: 2734 bytes --]

From e0e18a6e98fb2faafcc9a43a55321206e8b3f9ed Mon Sep 17 00:00:00 2001
Message-Id: <e0e18a6e98fb2faafcc9a43a55321206e8b3f9ed.1672148559.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Tue, 27 Dec 2022 16:41:57 +0300
Subject: [PATCH] org-occur-in-agenda-files: Respect agenda restriction

* lisp/org.el (org-occur-in-agenda-files): Respect agenda restriction
when searching.

Reported-by: Alain.Cochard@unistra.fr
Link: https://orgmode.org/list/25514.61148.396137.347019@gargle.gargle.HOWL
---
 lisp/org.el | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 26a4c8b1c..2ab7c0ccf 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18551,24 +18551,40 @@ (defun org-occur-in-agenda-files (regexp &optional _nlines)
   (interactive "sOrg-files matching: ")
   (let* ((files (org-agenda-files))
 	 (tnames (mapcar #'file-truename files))
-	 (extra org-agenda-text-search-extra-files))
-    (when (eq (car extra) 'agenda-archives)
+	 (extra org-agenda-text-search-extra-files)
+         (narrows nil))
+    (when (and (eq (car extra) 'agenda-archives)
+               (not org-agenda-restrict))
       (setq extra (cdr extra))
       (setq files (org-add-archive-files files)))
-    (dolist (f extra)
-      (unless (member (file-truename f) tnames)
-	(unless (member f files) (setq files (append files (list f))))
-	(setq tnames (append tnames (list (file-truename f))))))
+    (unless org-agenda-restrict
+      (dolist (f extra)
+        (unless (member (file-truename f) tnames)
+	  (unless (member f files) (setq files (append files (list f))))
+	  (setq tnames (append tnames (list (file-truename f)))))))
     (multi-occur
      (mapcar (lambda (x)
 	       (with-current-buffer
 		   ;; FIXME: Why not just (find-file-noselect x)?
 		   ;; Is it to avoid the "revert buffer" prompt?
 		   (or (get-file-buffer x) (find-file-noselect x))
-		 (widen)
+                 (if (eq (current-buffer) org-agenda-restrict)
+		     (progn
+                       ;; Save the narrowing state.
+                       (push (list (current-buffer) (point-min) (point-max))
+                             narrows)
+                       (widen)
+                       (narrow-to-region org-agenda-restrict-begin
+				         org-agenda-restrict-end))
+		   (widen))
 		 (current-buffer)))
 	     files)
-     regexp)))
+     regexp)
+    ;; Restore the narrowing.
+    (dolist (narrow narrows)
+      (with-current-buffer (car narrow)
+        (widen)
+        (narrow-to-region (nth 1 narrow) (nth 2 narrow))))))
 
 (add-hook 'occur-mode-find-occurrence-hook
 	  (lambda () (when (derived-mode-p 'org-mode) (org-fold-reveal))))
-- 
2.38.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Problem with multi-occur search when restricted to region
  2022-12-27 13:43 ` Ihor Radchenko
@ 2022-12-27 20:36   ` Alain.Cochard
  2022-12-29  9:57     ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Alain.Cochard @ 2022-12-27 20:36 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: alain.cochard, emacs-orgmode

Ihor Radchenko writes on Tue 27 Dec 2022 13:43:

 > Can you try the attached patch?

It did not work with the version I initially used:

   release_9.6-149-g554935.dirty

but it works OK with

   release_9.6-149-g554935


Thanks





-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.cochard@unistra.fr
5 rue René Descartes   [bureau 110]  | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France     | [ slot available for rent ]



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with multi-occur search when restricted to region
  2022-12-27 20:36   ` Alain.Cochard
@ 2022-12-29  9:57     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2022-12-29  9:57 UTC (permalink / raw)
  To: Alain.Cochard; +Cc: emacs-orgmode

Alain.Cochard@unistra.fr writes:

> Ihor Radchenko writes on Tue 27 Dec 2022 13:43:
>
>  > Can you try the attached patch?
>
> It did not work with the version I initially used:
>
>    release_9.6-149-g554935.dirty
>
> but it works OK with
>
>    release_9.6-149-g554935

Fixed on main then. For the next release.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=a9c0d4cde

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-29  9:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-27 13:10 Problem with multi-occur search when restricted to region Alain.Cochard
2022-12-27 13:43 ` Ihor Radchenko
2022-12-27 20:36   ` Alain.Cochard
2022-12-29  9:57     ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.