From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id UBerC4VeRmP1fQAAbAwnHQ (envelope-from ) for ; Wed, 12 Oct 2022 08:28:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id sDa4C4VeRmMXuwAAauVa8A (envelope-from ) for ; Wed, 12 Oct 2022 08:28:21 +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 D49433EA64 for ; Wed, 12 Oct 2022 08:28:20 +0200 (CEST) Received: from localhost ([::1]:38636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiVE3-0000rv-TT for larch@yhetil.org; Wed, 12 Oct 2022 02:28:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiUy3-00038u-Si for emacs-orgmode@gnu.org; Wed, 12 Oct 2022 02:11:49 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:37557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiUy1-0008S2-T4 for emacs-orgmode@gnu.org; Wed, 12 Oct 2022 02:11:47 -0400 Received: by mail-pg1-x52c.google.com with SMTP id bh13so14740381pgb.4 for ; Tue, 11 Oct 2022 23:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :references:from:to:cc:subject:date:message-id:reply-to; bh=EQI0ALbqReWPJb+IzSYrExSMzAxgp/WGF0mxztbyK9I=; b=m3+t5KThlGPGdYg9wlQrYsI0L8QP4RFNkb+Ujcd5wUwi3X5XBmKV++SQValXOBe9Ev PUS1gI1Vv9Pv5FT3lr7eEOaLFg1eJcZpBLt9X9G06RXfHrDg8i1cp2v9YEBciy6YAiNZ ORKPGmye2NFvGzNEMZe2r/SNVmDxLmDs+fLh1EgUUManz6hpACGAbXXiW59Hn6BMteKq m5oCKb33E67seOtywEr+ZcfiFF1CRjjLo4VtkS5lfbbjVM/jI3qTnL97m3jfynSSofZY 78h9Le1b/M9VMo3hSan9RUe1Wy4nbyyUeRV3a+b+DUZ64bbXbZvgQ3SxYNPe9047pAYF k3iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :references:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EQI0ALbqReWPJb+IzSYrExSMzAxgp/WGF0mxztbyK9I=; b=iq14CMrRV7FT/uIyKVtq9bqRDpbclxbjt3SOMTYyFTaVDcJdfBV69Dj7h3rhw3cEZl vxqaIg1Lde4IA2X0mCdgIwG11A/Ek5tpT00sd0/ZnIVwcFzewrLWIixo3matk17hgXcn EWuYtvWEXv/82trnx9pPMAx+UfhF0aASAmgBbk/WjK1Fwsns+5bOA82seKaatjZFNF0y xfqh81Z/7nR5Qt8ohLsLoP8X8AST0KxFZ0PCXLfYJQcOG40EDs69aVoUmI6FC3h8p6Bf 8yinbMfa3QOe6mon2hbj9BWPYxS4eGBQQA4Wo73fCAF+bVemqJwVRhJTe+PV4169g5oY QlHQ== X-Gm-Message-State: ACrzQf18p6u4l6EEGCAsdGABH0wDr1hZc/RkVujMPs2M/fgbvXMuTATC Fku9hCRpZbtUjvRZetvLepw= X-Google-Smtp-Source: AMsMyM7ok2d7G81EI8jivvPqLIAWt6oA17X5ZBh+q17ExFqUNzpbWPZB8+Kig5MMcl59CElYOU4npA== X-Received: by 2002:a63:8341:0:b0:46a:cf98:493f with SMTP id h62-20020a638341000000b0046acf98493fmr582383pge.120.1665555104177; Tue, 11 Oct 2022 23:11:44 -0700 (PDT) Received: from HP-Z6-G4 ([112.38.217.10]) by smtp.gmail.com with ESMTPSA id h2-20020a17090a130200b0020ad26fa65dsm580477pja.56.2022.10.11.23.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 23:11:43 -0700 (PDT) References: <87czb1qxim.fsf@gmail.com> <87wn97um15.fsf@localhost> 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/)] In-reply-to: <87wn97um15.fsf@localhost> Date: Wed, 12 Oct 2022 14:11:32 +0800 Message-ID: <87edvdinaj.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=liuhui1610@gmail.com; helo=mail-pg1-x52c.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: , 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=1665556101; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Jok84ca4SBdfk+hKz5kf4xFnbR+6DYGhDg047jxjKlE=; b=IA/X+cOkuvIv+oebj6dhAolVf8Xmd0tTiIb+dMIWiGi0wQFVu+sKpdUwavyDUuxmasEmhG jVyjGUNOi3T90Qvub2Hb9e0cG7elXKclJORTzKYmLFiRgoomJgps8DWn6msR8AuzqJ2BEW 3P6FgD5Mxb1/iD3NuFaqePG7cSNsQ1xEf/+R5y18/keJWlo1gJuf9R65qC9IQ5TOuVeBc4 3oPO4gVYPUI52+PSs3Kl0O76HJYXeBJ1rDVgivtJ5JOWouXijhFAZCrohTob72lCljyPnl JuyF8DqnBzUnvXWPXQLEgbi9vZAgj+EGJ9TIUfwF5VDWXQLnJSQzo4jlAyOX/Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665556101; a=rsa-sha256; cv=none; b=dRg6xP8U0jBEAOR6etqoTlwPXszTA9xOPH2/4DlpfQK5+vaX3f6oCA5v1H1vW1Q/w0d4VD KazmVx5BCtH99mIqgP/gBTcFgBo8AlU9JCDs9kbhsu9MZ3C3F9RJkFe0QHrrmO2ydfpc/6 d4Y3tcxhW4OCh33hO7E1zM9OjWVybo1DUXs9GJOJcAQpsIHQtaS4bAqP/aFfIt1R2Bpz/d 6wsHV3d9EzmtVBZk7R1lqIC4KrRjt+h520gGE0xIgM6EeCqRCiQhr2vPyoVK5ExQ5PXupb eKIjHSOJkbzOvSUgS9yQhDVerS8WUhi4V+TilzXkOS4sLW5dWisIIHsacyazIg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=m3+t5KTh; 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: 7.98 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b=m3+t5KTh; 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: D49433EA64 X-Spam-Score: 7.98 X-Migadu-Scanner: scn1.migadu.com X-TUID: GZ7WKA+41nj2 --=-=-= Content-Type: text/plain Hi Ihor, Ihor Radchenko writes: > Could you please add docstrings and possibly code comments for > `org-agenda-restrict', `org-agenda-restrict-begin', > `org-agenda-restrict-end', `org-agenda-last-dispatch-buffer', and > possibly other elated variables? I have added docstrings for related variables except `org-agenda-last-dispatch-buffer', which is actually not used by any other org-mode code. Please see the patch below. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-agenda-Make-sure-file-restriction-can-be-removed.patch >From 907499f16769e5a5353170c13f09595584530139 Mon Sep 17 00:00:00 2001 From: Liu Hui Date: Wed, 12 Oct 2022 14:02:05 +0800 Subject: [PATCH] org-agenda: Make sure file restriction can be removed * lisp/org-agenda.el: (org-agenda-restrict): (org-agenda-restrict-begin): (org-agenda-restrict-end): (org-agenda-overriding-restriction): add docstrings. (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 | 43 +++++++++++++++++++++------------ testing/lisp/test-org-agenda.el | 28 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 86ed6a5f5..82ca2913a 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -2202,7 +2202,17 @@ string that it returns." (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line) (defvar org-agenda-menu) ; defined later in this file. -(defvar org-agenda-restrict nil) +(defvar org-agenda-restrict nil + "Non-nil means agenda restriction is active. +This is an internal flag indicating either temporary or extended +agenda restriction. Specifically, it is set to t if the agenda +is restricted to an entire file, and is set to the corresponding +buffer if the agenda is restricted to a part of a file, e.g. a +region or a substree. In the latter case, +`org-agenda-restrict-begin' and `org-agenda-restrict-end' are set +to the beginning and the end of the part. + +See also `org-agenda-set-restriction-lock'.") (defvar org-agenda-follow-mode nil) (defvar org-agenda-entry-text-mode nil) (defvar org-agenda-clockreport-mode nil) @@ -2734,10 +2744,16 @@ that have been changed along." ;;; Agenda dispatch -(defvar org-agenda-restrict-begin (make-marker)) -(defvar org-agenda-restrict-end (make-marker)) +(defvar org-agenda-restrict-begin (make-marker) + "Internal variable used to mark the restriction beginning. +It is only relevant when `org-agenda-restrict' is a buffer.") +(defvar org-agenda-restrict-end (make-marker) + "Internal variable used to mark the restriction end. +It is only relevant when `org-agenda-restrict' is a buffer.") (defvar org-agenda-last-dispatch-buffer nil) -(defvar org-agenda-overriding-restriction nil) +(defvar org-agenda-overriding-restriction nil + "Non-nil means extended agenda restriction is active. +This is an internal flag set by `org-agenda-set-restriction-lock'.") (defcustom org-agenda-custom-commands-contexts nil "Alist of custom agenda keys and contextual rules. @@ -2962,12 +2978,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 +7974,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 +7985,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 --=-=-=--