From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id WGssLhd1QmMFPQEAbAwnHQ (envelope-from ) for ; Sun, 09 Oct 2022 09:15:35 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id oGo/Lhd1QmP2VwEA9RJhRA (envelope-from ) for ; Sun, 09 Oct 2022 09:15:35 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 468A5206EF for ; Sun, 9 Oct 2022 09:15:35 +0200 (CEST) Received: from localhost ([::1]:57124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohQX8-0005vm-29 for larch@yhetil.org; Sun, 09 Oct 2022 03:15:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohQWD-0005uj-Mv for emacs-orgmode@gnu.org; Sun, 09 Oct 2022 03:14:37 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:37756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohQWB-0001WX-M7 for emacs-orgmode@gnu.org; Sun, 09 Oct 2022 03:14:37 -0400 Received: by mail-pg1-x531.google.com with SMTP id bh13so8006393pgb.4 for ; Sun, 09 Oct 2022 00:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to; bh=8/kl5lOR265R96e8R+uy1vlQ76bqtAMZum+8QtG0zss=; b=HR82WAWEgcpZGYxhP8jg4Eomfxu28SwaWFrEat3fKV6j/q+pyiYhLrap5z6otnyVky El4KP94mMtyqahLM7owkmHxtSPzwuSkZDC/eAAT8Tb3IZ11p1koz3MQbN7JdqpBI/3bX CB97o6dvYc2HZAHZyBYZCPa57VIt7D1722yU+UtRF/QzoDE7N6DgU79m3cp/PrxbZjUg OLjEJKSaIZ5skmveEtbi/vKSqr/rssYrrnBnWKi6UDOaYLvUJxA2jN60ClWkkT4Ej9u5 KSfgdT++7Vt5WD7V7OglsfW8t64IXJEQQrCY0cj4YqlZBPW5XAjz7g5yjOv+25BZIps0 o+ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:reply-to:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8/kl5lOR265R96e8R+uy1vlQ76bqtAMZum+8QtG0zss=; b=TORk1tqYXeXI92hA5OrRUnW1AbV30MipQJn6PGwPXrcA1sHP0Z4zBblgdSM7Nsx8at QXxraVvABJOSDScswpXFUGIpq9ja/eIvUArYTGw8+MjcpbBvGfXL9bpvFimDLGxbYJhe eKcBvz7T92aRHA/ZvWM0WdVLdWLCYp9bspE9lSs1Q+z0lx1vpt7aQLRXHsUB6fcrT95E JlIMAxYIRBAD2XYJL63vpx+PIbIq1a0FvWj4KjxiveRH4UITH0Xmphq3+ZKfj8AGtrCd 0TErzjiEclRt5goiDvaCTPz2tpP9kZeyTJhl8SCTP+7MU8xV1Y/pujjlCRCVXIzY7dgV UnCQ== X-Gm-Message-State: ACrzQf1GsJ3GtKRngXE3gcmLsb8Gsiy5lhgOuaR+Ptn+kEFs9vnG2Qis g4G8DaITrng8N5vft4E8eBE= X-Google-Smtp-Source: AMsMyM7deMKEt3bvpDYK19Pyh9/WJjapMuAxW6L6kE7NNKLBSAxTMf/fMMbXtuHJW/8++U9xF84CQQ== X-Received: by 2002:a63:f057:0:b0:438:5c6c:de26 with SMTP id s23-20020a63f057000000b004385c6cde26mr11268328pgj.509.1665299673888; Sun, 09 Oct 2022 00:14:33 -0700 (PDT) Received: from LH-K42 ([112.36.174.61]) by smtp.gmail.com with ESMTPSA id g18-20020a625212000000b00562e4adcd5fsm2660646pfb.81.2022.10.09.00.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Oct 2022 00:14:32 -0700 (PDT) From: Liu Hui To: Ihor Radchenko 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 Message-ID: <87czb1qxim.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=liuhui1610@gmail.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: 87pmi46ivt.fsf@localhost Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1665299735; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=omJS8Y53T3boHCkKKpESQjOZNVR4eYfWlhzYbR71/bw=; b=Ch7oC0iQhlNLXIczv58eUllqIZtVAvw5jcH5k7yTUCmI8fb/Ta+R7EA3fTQmpnCvARKcSR 9y1DmnOmPMUXHrZUAUGDxnWtvkda1QqaBJ1JNh8BhrQkz5UhfFYv3VczVMaJvidkq61f9k cjmFoC9NbsrdEOoSPB+/f7Da0/SKxrHQuh74KxYwV7xWGs55FDf2LfBMhDmBoHuN7W+o6K CmtuA/uzWJ6carbI7rSVLknTnO5KZeBALrnmBBB1RRWzqObFmjwTM7B984VvFzHU3UITra Ys9YumTvYUsKJqCUhjmota0PZ8DR9Rfy63twPeuZfvSO9STx1En3wfSYAbwd8Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665299735; a=rsa-sha256; cv=none; b=GMZYRqt7WlsuIsHuy1SZhNWqqdaOtEmsngP9siC5appIOpmHuQ2mDiHOZA/TzukfN7IsJK IC+RScvcj6y0TMwIcGDWvQ2i5++heXW87HqGbBapOFqVlkOpoIbAjGAi8I8mWZVAcFOWEo ZjxXvGmfZ1Xdym+xtKRIMFzz4A5fqHfqlK7ePTCBXYgxdrqUmMT6XgdwNTcqFUjYbC7Ss/ 9i2jFZc1KIGWLjfLpWuYL2v0JvAbFrEUUHuRVltmD0yMgnV1nUkYyG7wxh7Pc/rB89GhqR 96qvFYmG46l0leY9CiL6CL1keITVyZyi5DDXHMAd9qB2AR1JkVw5zii27krMfw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=HR82WAWE; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 10.49 X-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=HR82WAWE; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 468A5206EF X-Spam-Score: 10.49 X-Migadu-Spam: Yes X-Migadu-Scanner: scn1.migadu.com X-TUID: Nq29fFVozlxL --=-=-= Content-Type: text/plain Hi Ihor, > Ihor Radchenko writes: > > > Visuwesh 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-agenda-Make-sure-file-restriction-can-be-removed.patch >From f4e46051fbb13adadbbafeebab343383e1bca35a Mon Sep 17 00:00:00 2001 From: Liu Hui 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)) + ;; agenda redo -- 2.25.1 --=-=-=--