all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Al Haji-Ali <abdo.haji.ali@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] org-agenda-prepare-buffers does not save restrictions
Date: Fri, 08 Jul 2022 10:45:11 +0100	[thread overview]
Message-ID: <x1o5yk8rl94.fsf@lxstaff02.mail-host-address-is-not-set> (raw)
In-Reply-To: <87a69k44kr.fsf@localhost>

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


On 08/07/2022, Ihor Radchenko wrote:
> Could you please create a proper patch

See attached. I made a further change to use `with-current-buffer` instead of
`set-buffer+save-excursion`.

Best regards,
-- Al

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: save-restrictions-agenda-buf.patch --]
[-- Type: text/x-patch, Size: 4556 bytes --]

From 398fee0c235c53399cd8cc481f9e732f64ae88cb Mon Sep 17 00:00:00 2001
From: Al Haji-Ali <abdo.haji.ali@gmail.com>
Date: Fri, 8 Jul 2022 10:24:08 +0100
Subject: [PATCH] lisp/org.el: Save restrictions in all agenda file buffers.

* lisp/org.el (org-agenda-prepare-buffers): Call
`save-restriction'/`save-excursion' for every buffer in the agenda
instead of just once for the current buffer. Use `with-current-buffer'
instead of `set-buffer'/`save-excursion'.

TINYCHANGE
---
 lisp/org.el | 80 ++++++++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 41 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 661efeb9c..ef3e4b950 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15031,49 +15031,47 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
   "Create buffers for all agenda files, protect archived trees and comments."
   (interactive)
   (let ((inhibit-read-only t)
-	(org-inhibit-startup org-agenda-inhibit-startup)
-	pos)
+	(org-inhibit-startup org-agenda-inhibit-startup))
     (setq org-tag-alist-for-agenda nil
 	  org-tag-groups-alist-for-agenda nil)
-    (save-excursion
-      (save-restriction
-	(dolist (file files)
-	  (catch 'nextfile
-	    (if (bufferp file)
-		(set-buffer file)
-	      (org-check-agenda-file file)
-	      (set-buffer (org-get-agenda-file-buffer file)))
-	    (widen)
-	    (org-set-regexps-and-options 'tags-only)
-	    (setq pos (point))
-	    (or (memq 'category org-agenda-ignore-properties)
-		(org-refresh-category-properties))
-	    (or (memq 'stats org-agenda-ignore-properties)
-		(org-refresh-stats-properties))
-	    (or (memq 'effort org-agenda-ignore-properties)
-                (unless org-element-use-cache
-		  (org-refresh-effort-properties)))
-	    (or (memq 'appt org-agenda-ignore-properties)
-		(org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime))
-	    (setq org-todo-keywords-for-agenda
-		  (append org-todo-keywords-for-agenda org-todo-keywords-1))
-	    (setq org-done-keywords-for-agenda
-		  (append org-done-keywords-for-agenda org-done-keywords))
-	    (setq org-todo-keyword-alist-for-agenda
-		  (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
-	    (setq org-tag-alist-for-agenda
-		  (org--tag-add-to-alist
-		   org-tag-alist-for-agenda
-		   org-current-tag-alist))
-	    ;; Merge current file's tag groups into global
-	    ;; `org-tag-groups-alist-for-agenda'.
-	    (when org-group-tags
-	      (dolist (alist org-tag-groups-alist)
-		(let ((old (assoc (car alist) org-tag-groups-alist-for-agenda)))
-		  (if old
-		      (setcdr old (org-uniquify (append (cdr old) (cdr alist))))
-		    (push alist org-tag-groups-alist-for-agenda)))))
-	    (goto-char pos)))))
+    (dolist (file files)
+      (catch 'nextfile
+        (with-current-buffer
+            (if (bufferp file)
+                file
+              (org-check-agenda-file file)
+              (org-get-agenda-file-buffer file))
+          (save-excursion
+            (save-restriction
+              (widen)
+	      (org-set-regexps-and-options 'tags-only)
+	      (or (memq 'category org-agenda-ignore-properties)
+		  (org-refresh-category-properties))
+	      (or (memq 'stats org-agenda-ignore-properties)
+		  (org-refresh-stats-properties))
+	      (or (memq 'effort org-agenda-ignore-properties)
+                  (unless org-element-use-cache
+		    (org-refresh-effort-properties)))
+	      (or (memq 'appt org-agenda-ignore-properties)
+		  (org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime))
+	      (setq org-todo-keywords-for-agenda
+		    (append org-todo-keywords-for-agenda org-todo-keywords-1))
+	      (setq org-done-keywords-for-agenda
+		    (append org-done-keywords-for-agenda org-done-keywords))
+	      (setq org-todo-keyword-alist-for-agenda
+		    (append org-todo-keyword-alist-for-agenda org-todo-key-alist))
+	      (setq org-tag-alist-for-agenda
+		    (org--tag-add-to-alist
+		     org-tag-alist-for-agenda
+		     org-current-tag-alist))
+	      ;; Merge current file's tag groups into global
+	      ;; `org-tag-groups-alist-for-agenda'.
+	      (when org-group-tags
+	        (dolist (alist org-tag-groups-alist)
+		  (let ((old (assoc (car alist) org-tag-groups-alist-for-agenda)))
+		    (if old
+		        (setcdr old (org-uniquify (append (cdr old) (cdr alist))))
+		      (push alist org-tag-groups-alist-for-agenda))))))))))
     (setq org-todo-keywords-for-agenda
           (org-uniquify org-todo-keywords-for-agenda))
     (setq org-todo-keyword-alist-for-agenda
--
2.24.4

  reply	other threads:[~2022-07-08  9:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 11:25 [BUG] org-agenda-prepare-buffers does not save restrictions Al Haji-Ali
2022-07-08  4:21 ` Ihor Radchenko
2022-07-08  9:45   ` Al Haji-Ali [this message]
2022-07-09  3:57     ` Ihor Radchenko
2022-07-10  8:58       ` Al Haji-Ali
2022-07-10 10:06         ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x1o5yk8rl94.fsf@lxstaff02.mail-host-address-is-not-set \
    --to=abdo.haji.ali@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.