From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 kA/WOf7DxmKQXAAAbAwnHQ (envelope-from ) for ; Thu, 07 Jul 2022 13:31:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id wCl9Of7DxmI0fgAAauVa8A (envelope-from ) for ; Thu, 07 Jul 2022 13:31:10 +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 874682AE47 for ; Thu, 7 Jul 2022 13:31:05 +0200 (CEST) Received: from localhost ([::1]:35706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9Piq-0001iB-8w for larch@yhetil.org; Thu, 07 Jul 2022 07:31:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Phw-0001f9-FZ for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 07:30:08 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:44792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9Phu-0001KO-CU for emacs-orgmode@gnu.org; Thu, 07 Jul 2022 07:30:08 -0400 Received: by mail-wr1-x42f.google.com with SMTP id bk26so10800721wrb.11 for ; Thu, 07 Jul 2022 04:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=X7tFo+JcUeijXhO2OOrBQNfKVUUX6Vb2psmOiegnBm0=; b=H/Efgvb2dNWJT0GwMrhuggnqzKJ08cMl/fO7hdUU0uruhEBSneNvhlUmDhHJL+Qihm 2zd+vo2a5CwwR5BWCrg3x5g3RKmQfvm4WUTFj+b2XpUhkZyKsR4gZFKCyzmBkbPSu2Ul tkwsCWI4rH+BjNB1O+2sa8ePQoe8oqmriUIEgUmPf+U12Rdv/4w/V+t+bmfgENqQGGkO 4E0nG+5I8nWZjLE+UBgxWhgBWQoVR4fu4tiUmsSav4Ezgbj3XQRsbZaawbqkoKlJIaxx p6pQ2cxB1DD0TzY6LiyIf2HZkdYjsJHhw4FqZ9pKFH3EbvqZheilP2tIRkzNH1XjWFbn KWpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=X7tFo+JcUeijXhO2OOrBQNfKVUUX6Vb2psmOiegnBm0=; b=GxdA5lCRQ8sRRrsUoG5+y1uQK7BLAYv1I7AACBQDMoSETgKFAoaHqCXC1DE8B7ODnZ /pg4alXWLDLi1ERT99Q5KE4DfOKbyu3yLRynJEUQ4PDa5NTO35FFEZkHrgKSj9rNV5NK lpEWSflWqQWDS1cBiACg7sTVOtDXyvnzBPbG1hR4TmZdIfr5Z0lzhB5nFuzfn8zCtJYA u8L4AHiXPd32VwSBMNxjNiiglDgusAqBe+FauWTtERpjPYwtkAADAegZp00ni2p6IZWB r7thY3kmg/cxLbiYBIiNlBv+rqzIkimdgicJK5KZakjvobuNspjUNUko6bUEGWbLCaHw TOJA== X-Gm-Message-State: AJIora8QgsbdPr0kuNmduodwGRQxOb8hNIXKnVvFuWMp2iU5Rx6v7tX/ QjHdYP+4GKPOWy6UCSpCaY2+cJgcxn4= X-Google-Smtp-Source: AGRyM1u+0+ItQkszhUGoKUQS6zPcX6QWmBbTpCJvEN9RKAn3/aeGRu2YM6DBxw0N/PFYOxo4/TlaLw== X-Received: by 2002:adf:d206:0:b0:21d:6434:a158 with SMTP id j6-20020adfd206000000b0021d6434a158mr24960887wrh.37.1657193402837; Thu, 07 Jul 2022 04:30:02 -0700 (PDT) Received: from localhost (vpn-fn-224.net.ed.ac.uk. [192.41.114.224]) by smtp.gmail.com with ESMTPSA id bn24-20020a056000061800b0020fe35aec4bsm37431263wrb.70.2022.07.07.04.30.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 04:30:02 -0700 (PDT) From: Al Haji-Ali To: emacs-orgmode@gnu.org Subject: [BUG] org-agenda-prepare-buffers does not save restrictions Date: Thu, 07 Jul 2022 12:25:11 +0100 Message-ID: <87y1x588rs.fsf@thinkpad.mail-host-address-is-not-set> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=abdo.haji.ali@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1657193465; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=X7tFo+JcUeijXhO2OOrBQNfKVUUX6Vb2psmOiegnBm0=; b=WCkwUrVPXdkrXmQ3KDK+xUUIguQGX66GRIL+gOdapNmdhu4ZQFFIvTR5q12dNDuRJty+DR 6fVrJHpo5JgEwV4cg0Q5gGUm4EBAuRq/M9Qu5cLcibGxr2ky2YMuTzap0bpgMJsjLBY52c FtehL2MVl+ni9FXuOD2oSYt2jQILrK+uIm+pLZAL/SYLJwhHqWLrX8coGxUcFl7ksBbYee fbYu4qR2xmi9qaoCLogL1WF68zZUBNG048jI/kMY4+7v7CLjE4SZRq8cok3cTN6tifsRIP MC3hUKU/oT9mobKHF5hn45+zujF/zjLTikCBGQvUGcw/OKiH04hn1cVdAMTQwQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1657193465; a=rsa-sha256; cv=none; b=mfRWwvfqcS7097p3hUbqilT2m5w0BI2/ej0SM+xyomgcehtb6rmSbJP6yhLYBIyPloE75T B9hvdd23hZNXgBZ8PlEB/DREW7QSIMRp0701LfD1VGnOrqAhnkMq4RAQJlnsT5CWU4coDW Wa0KfZk3S+tZ7JMTGH3INN03xcFAvQBeJbBIJdLuzW8BX/fyclHM1Kx6sHXUIQRZrHCoX+ JBsoGLTQ0BFPNtBCk1kJehLT1a2Yff5F2/hCsqLVu8tyuq46N2RnDJ7MedtfYdrLUIZh5t 6Nk8oPw5ie0KV3Vau9y3Tfp/lcSLCkwfwQOBz0ESC+k4JxLxZr86FV54mKgoQA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="H/Efgvb2"; dmarc=pass (policy=none) header.from=gmail.com; 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: -9.45 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="H/Efgvb2"; dmarc=pass (policy=none) header.from=gmail.com; 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: 874682AE47 X-Spam-Score: -9.45 X-Migadu-Scanner: scn0.migadu.com X-TUID: R9pKupd1BUl/ --=-=-= Content-Type: text/plain I am not sure if this has been reported before, of if the behaviour is intended. But to reproduce this "bug": - Open an org file from the agenda. - Restrict to some headline - Execute the following command: (with-temp-buffer (org-agenda-prepare-buffers (org-agenda-files t))) - The restriction is removed. Note that executing `(org-agenda-prepare-buffers (org-agenda-files t))` in the buffer (without `with-temp-buffer`) restores the restriction upon completion. The reason is that `save-restriction` (and `save-excursion`) are called in `org-agenda-prepare-buffers` before switching to the buffer of the org file so the restriction is not saved (the point is manually restored but not the restriction). This has implications on running `org-map-entries` where all org buffers in the agenda (beside the current one) lose their restrictions. Attached is a possible patch to fix this. Emacs : GNU Emacs 28.1 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-04-08 Package: Org mode version 9.5.3 (9.5.3-g428076 @ /home/abdo/Work/Projects/dotfiles/emacs-radian/.emacs.d/.elocal/straight/build-28.1/org/) --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=org-agenda-prepare-buffers.patch diff --git a/lisp/org.el b/lisp/org.el index 661efeb9c..e75b7c93c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -15031,49 +15031,48 @@ 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 + (if (bufferp file) + (set-buffer file) + (org-check-agenda-file file) + (set-buffer (org-get-agenda-file-buffer file))) + (save-excursion + (save-restriction + (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)))))))))) (setq org-todo-keywords-for-agenda (org-uniquify org-todo-keywords-for-agenda)) (setq org-todo-keyword-alist-for-agenda --=-=-=--