emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Liu Hui <liuhui1610@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode@gnu.org, visuweshm@gmail.com
Subject: Re: [PATCH] Re: [BUG] org-agenda-remove-restriction-lock does not remove file lock [9.5.2 (release_9.5.2-17-gea6b74 @ /nix/store/iqqk7iqfwmfc6r78xg2knyq7hww2mhs4-emacs-git-20220225.0/share/emacs/29.0.50/lisp/org/)]
Date: Sun, 09 Oct 2022 15:14:25 +0800	[thread overview]
Message-ID: <87czb1qxim.fsf@gmail.com> (raw)

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


Hi Ihor,

> Ihor Radchenko <yantar92@gmail.com> writes:
>
> > Visuwesh <visuweshm@gmail.com> writes:
> >
> >> C-u C-c C-x < followed by C-c C-x > does not remove the file restriction
> >> lock.
> >>
> >> `org-agenda-remove-restriction-lock' checks for non-nil value of
> >> `org-agenda-restriction' but `org-agenda-set-restriction-lock' explicitly
> >> sets it to nil when TYPE is 'file.  Setting `org-agenda-restriction' to
> >> a dummy value like 'dummy gets the job done.
> >
> > Confirmed.
> >
> > The fix is attached.
> > Setting org-agenda-restriction to non-nil appears to be risky since
> > org-agenda-set-restriction-lock explicitly sets it to nil. So, I use
> > different approach.
>
> Fixed.
> Applied onto main via df0e96ba4.

File restriction can be also temporarily set by pressing '<' in the
agenda dispatcher, e.g. pressing 'C-c a < a' in an org-mode file.
`org-agenda-remove-restriction-lock' still cannot remove the temporary
file restriction with the fix.

Setting `org-agenda-restrict' to a non-nil value is a straightforward
way to fixing both cases. The variable is only tested in several
places and I don't find any problem with the change. Therefore I
suggest the attached patch, where the value of `org-agenda-restrict'
is changed from nil to t during temporary and extended file
restriction.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-agenda-Make-sure-file-restriction-can-be-removed.patch --]
[-- Type: text/x-diff, Size: 4360 bytes --]

From f4e46051fbb13adadbbafeebab343383e1bca35a Mon Sep 17 00:00:00 2001
From: Liu Hui <liuhui1610@gmail.com>
Date: Sun, 9 Oct 2022 15:00:50 +0800
Subject: [PATCH] org-agenda: Make sure file restriction can be removed

* lisp/org-agenda.el: (org-agenda):
(org-agenda-set-restriction-lock): Set `org-agenda-restrict' non-nil
during both temporary and extended file restriction.
(org-agenda-remove-restriction-lock): Revert commit df0e96ba4.
* testing/lisp/test-org-agenda.el (test-org-agenda/file-restriction):
Add a test.
---
 lisp/org-agenda.el              | 19 ++++++++-----------
 testing/lisp/test-org-agenda.el | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 86ed6a5f5..a4f766cd9 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2962,12 +2962,12 @@ Pressing `<' twice means to restrict to the current subtree or region
 	    (move-marker org-agenda-restrict-begin (point))
 	    (move-marker org-agenda-restrict-end
 			 (progn (org-end-of-subtree t)))))
-	 ((and (eq restriction 'buffer)
-	       (or (< 1 (point-min))
-		   (< (point-max) (1+ (buffer-size)))))
-	  (setq org-agenda-restrict (current-buffer))
-	  (move-marker org-agenda-restrict-begin (point-min))
-	  (move-marker org-agenda-restrict-end (point-max)))))
+	 ((eq restriction 'buffer)
+          (if (not (buffer-narrowed-p))
+              (setq org-agenda-restrict t)
+            (setq org-agenda-restrict (current-buffer))
+	    (move-marker org-agenda-restrict-begin (point-min))
+	    (move-marker org-agenda-restrict-end (point-max))))))

       ;; For example the todo list should not need it (but does...)
       (cond
@@ -7958,7 +7958,7 @@ subtree."
 	  (message "Locking agenda restriction to subtree"))
       (put 'org-agenda-files 'org-restrict
 	   (list (buffer-file-name (buffer-base-buffer))))
-      (setq org-agenda-restrict nil)
+      (setq org-agenda-restrict t)
       (setq org-agenda-overriding-restriction 'file)
       (move-marker org-agenda-restrict-begin nil)
       (move-marker org-agenda-restrict-end nil)
@@ -7969,14 +7969,11 @@ subtree."
 (defun org-agenda-remove-restriction-lock (&optional noupdate)
   "Remove agenda restriction lock."
   (interactive "P")
-  (if (not (or org-agenda-restrict org-agenda-overriding-restriction))
+  (if (not org-agenda-restrict)
       (message "No agenda restriction to remove.")
     (delete-overlay org-agenda-restriction-lock-overlay)
     (delete-overlay org-speedbar-restriction-lock-overlay)
     (setq org-agenda-overriding-restriction nil)
-    (unless org-agenda-keep-restricted-file-list
-      ;; There is a request to keep the file list in place
-      (put 'org-agenda-files 'org-restrict nil))
     (setq org-agenda-restrict nil)
     (put 'org-agenda-files 'org-restrict nil)
     (move-marker org-agenda-restrict-begin nil)
diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el
index 256f701df..bd96163e9 100644
--- a/testing/lisp/test-org-agenda.el
+++ b/testing/lisp/test-org-agenda.el
@@ -255,6 +255,34 @@ See https://list.orgmode.org/06d301d83d9e$f8b44340$ea1cc9c0$@tomdavey.com"
           (get-text-property (point) 'day))))
     (org-test-agenda--kill-all-agendas)))

+(ert-deftest test-org-agenda/file-restriction ()
+  "Test file restriction for org agenda."
+  (org-test-with-temp-text-in-file "* TODO Foo"
+    (org-agenda-set-restriction-lock t)
+    (org-agenda nil "t")
+    (should (search-forward "Foo"))
+    (should (org-agenda-files))
+    (should-not (org-agenda-files t))
+    (org-agenda-remove-restriction-lock)
+    (goto-char (point-min))
+    (should-not (search-forward "Foo" nil t))
+    (should-not (org-agenda-files)))
+  (org-test-with-temp-text-in-file "* TODO Bar"
+    (org-agenda nil "t" 'buffer)
+    (should (search-forward "Bar"))
+    (should (org-agenda-files))
+    (should-not (org-agenda-files t))
+    (org-agenda-remove-restriction-lock)
+    (goto-char (point-min))
+    (should-not (search-forward "Bar" nil t))
+    (should-not (org-agenda-files)))
+  (org-test-with-temp-text-in-file "* TODO Bar"
+    (org-agenda nil "t" 'buffer)
+    (org-agenda nil "t")
+    (should-not (search-forward "Bar" nil t))
+    (should-not (org-agenda-files)))
+  (org-test-agenda--kill-all-agendas))
+
 \f
 ;; agenda redo

--
2.25.1


             reply	other threads:[~2022-10-09  7:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-09  7:14 Liu Hui [this message]
2022-10-11  2:33 ` [PATCH] Re: [BUG] org-agenda-remove-restriction-lock does not remove file lock [9.5.2 (release_9.5.2-17-gea6b74 @ /nix/store/iqqk7iqfwmfc6r78xg2knyq7hww2mhs4-emacs-git-20220225.0/share/emacs/29.0.50/lisp/org/)] Ihor Radchenko
2022-10-12  6:11   ` Liu Hui
2022-10-12  7:44     ` Ihor Radchenko
  -- strict thread matches above, loose matches on Subject: below --
2022-03-25 15:05 Visuwesh
2022-03-26  9:04 ` [PATCH] " Ihor Radchenko
2022-07-17 12:09   ` 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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87czb1qxim.fsf@gmail.com \
    --to=liuhui1610@gmail.com \
    --cc=87pmi46ivt.fsf@localhost \
    --cc=emacs-orgmode@gnu.org \
    --cc=visuweshm@gmail.com \
    --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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).