emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org a9c0d4cde2 9/9: org-occur-in-agenda-files: Respect


From: ELPA Syncer
Subject: [elpa] externals/org a9c0d4cde2 9/9: org-occur-in-agenda-files: Respect agenda restriction
Date: Thu, 29 Dec 2022 04:58:05 -0500 (EST)

branch: externals/org
commit a9c0d4cde2ce039d00c0168a31868b9bb74b2814
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    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 6906881608..db32ec562c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18551,24 +18551,40 @@ block from point."
   (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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]