emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: No Wayman <iarchivedmywholelife@gmail.com>
To: marcel@hsdev.com
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] org-save-all-org-buffers reapplies startup visibility [9.5 (release_9.5 @ /usr/local/share/emacs/29.0.50/lisp/org/)]
Date: Tue, 05 Oct 2021 22:08:43 -0400	[thread overview]
Message-ID: <87zgrmc2rg.fsf@gmail.com> (raw)
In-Reply-To: <87ilybmvvf.fsf@hsdev.com>

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

Confirmed with the following, simpler, test case:

Yodel[1] Report 2021-10-05 22:07:33
===================================

--8<---------------cut here---------------start------------->8---
(yodel
  :user-dir "org-save-all-org-buffers"
  :packages* org
  :formatter yodel-format-as-mailing-list-message
  :post*
  (yodel-file "./test.org"
    :with*
    "#+startup: overview
* A
** B"
    :then*
    (require 'org-element)
    (defun +org-visible nil
      (org-element-interpret-data
       (org-element-parse-buffer nil 'visible-only)))
    (message "%s
%s" "Before `org-save-all-org-buffers':"
(+org-visible))
    (set-buffer-modified-p t)
    (org-save-all-org-buffers)
    (message "%s
%s" "After `org-save-all-org-buffers':"
(+org-visible))))
--8<---------------cut here---------------end--------------->8---

STDOUT
======

> Loading 
> /tmp/org-save-all-org-buffers/straight-bootstrap-snippet.el 
> (source)...
> Before `org-save-all-org-buffers':

> #+startup: overview
> * A
> ** B

> Saving all Org buffers...

> Saving all Org buffers... done
> After `org-save-all-org-buffers':

> #+startup: overview
> * A

Environment
===========

- emacs version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, 
  X toolkit, cairo version 1.17.4, Xaw3d scroll bars)
 of 2021-09-29
- system type: gnu/linux

Packages
========

- org 
  https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=cc2490a7061955395c4f5a1a23a088044554a2f7

The behavior of `save-some-buffers' PRED argument changed 
recently:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=a9ad3d477441feefa3bf6107d58281cb64e0e78a

If the PRED returns a function, that function is called.
Since `derived-mode-p' returns the symbol `org-mode', Org is being 
reloaded in modified buffers.
That's what is causing the visibility change. 
This could also have other undesirable behavior such as running 
the mode hook, resetting buffer-local variables, etc.

The attached patch ensures we're returning a boolean from the PRED 
function.
Tested with:

Yodel[1] Report 2021-10-05 22:07:33
===================================

--8<---------------cut here---------------start------------->8---
(yodel
  :user-dir "org-save-all-org-buffers.patch"
  :packages*
  (org :host github :repo "progfolio/org-mode" :branch 
  "fix/org-save-all-org-buffers")
  :formatter yodel-format-as-mailing-list-message
  :post*
  (yodel-file "./test.org"
    :with*
    "#+startup: overview
* A
** B"
    :then*
    (require 'org-element)
    (defun +org-visible nil
      (org-element-interpret-data
       (org-element-parse-buffer nil 'visible-only)))
    (message "%s
%s" "Before `org-save-all-org-buffers':"
(+org-visible))
    (set-buffer-modified-p t)
    (org-save-all-org-buffers)
    (message "%s
%s" "After `org-save-all-org-buffers':"
(+org-visible))))
--8<---------------cut here---------------end--------------->8---

STDOUT
======

> Loading 
> /tmp/org-save-all-org-buffers.patch/straight-bootstrap-snippet.el 
> (source)...
> Bootstrapping straight.el...
> Bootstrapping straight.el...done
> Rebuilding all packages due to build cache schema change
> Looking for gnu-elpa-mirror recipe → Cloning melpa...
> Looking for gnu-elpa-mirror recipe → Cloning melpa...done
> Looking for emacsmirror-mirror recipe → Cloning 
> gnu-elpa-mirror...
> Looking for emacsmirror-mirror recipe → Cloning 
> gnu-elpa-mirror...done
> Looking for emacsmirror-mirror recipe → Cloning el-get...
> Looking for emacsmirror-mirror recipe → Cloning el-get...done
> Looking for straight recipe → Cloning emacsmirror-mirror...
> Looking for straight recipe → Cloning emacsmirror-mirror...done
> Building straight...
> Building straight...done
> Cloning org...
> Cloning org...done
> Building org...
> Building org...done

> Before `org-save-all-org-buffers':

> #+startup: overview
> * A
> ** B

> Saving all Org buffers...

> Saving all Org buffers... done
> After `org-save-all-org-buffers':

> #+startup: overview
> * A
> ** B

Environment
===========

- emacs version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, 
  X toolkit, cairo version 1.17.4, Xaw3d scroll bars)
 of 2021-09-29
- system type: gnu/linux

Packages
========

- org 
  https://github.com/progfolio/org-mode/commit/f1fc22f861ca9610ad4f1e1227660712b46337e4


[1] https://www.github.com/progfolio/yodel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org.el-org-save-all-org-buffers-Prevent-org-mod.patch --]
[-- Type: text/x-patch, Size: 1470 bytes --]

From f1fc22f861ca9610ad4f1e1227660712b46337e4 Mon Sep 17 00:00:00 2001
From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
Date: Tue, 5 Oct 2021 21:07:01 -0400
Subject: [PATCH] lisp/org.el: (org-save-all-org-buffers): Prevent `org-mode'
 reload

* lisp/org.el: (org-save-all-org-buffers): Ensure `save-some-buffers' PRED returns boolean.

As of this upstream commit:

https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=a9ad3d477441feefa3bf6107d58281cb64e0e78a

`save-some-buffers' will call its PRED argument if it returns a function.
Since (derived-mode-p 'org-mode) returns the symbol org-mode,
and org-mode is a function, org-mode is reloaded in modified Org
buffers when calling `org-save-all-org-buffers'. Among other
undesirable behavior, this will cause the buffer's visibility to be
reset to its initial visibility.
---
 lisp/org.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 18cb53af6..6ddcc6af7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15366,7 +15366,7 @@ The value is a list, with zero or more of the symbols `effort', `appt',
   "Save all Org buffers without user confirmation."
   (interactive)
   (message "Saving all Org buffers...")
-  (save-some-buffers t (lambda () (derived-mode-p 'org-mode)))
+  (save-some-buffers t (lambda () (and (derived-mode-p 'org-mode) t)))
   (when (featurep 'org-id) (org-id-locations-save))
   (message "Saving all Org buffers... done"))
 
-- 
2.33.0


  parent reply	other threads:[~2021-10-06  2:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05 13:14 Marcel van der Boom
2021-10-05 17:53 ` Bhavin Gandhi
2021-10-06  2:08 ` No Wayman [this message]
2021-10-09 19:33   ` Kyle Meyer
     [not found] <cdd5fdae-5c61-916b-9e6e-9e9d51a0a834@ctpowe.net>
2021-10-05 19:51 ` Fwd: " Michael Powe
2021-10-08 11:55   ` Lennart C. Karssen
2021-10-08 22:00     ` Mark Barton
2021-10-08 22:30       ` Mark Barton
2021-10-09 16:38         ` No Wayman
2021-10-09 18:43           ` Mark Barton

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=87zgrmc2rg.fsf@gmail.com \
    --to=iarchivedmywholelife@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=marcel@hsdev.com \
    --subject='Re: [BUG] org-save-all-org-buffers reapplies startup visibility [9.5 (release_9.5 @ /usr/local/share/emacs/29.0.50/lisp/org/)]' \
    /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

Code repositories for project(s) associated with this 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).