From: Ignacio Casso <ignaciocasso@hotmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] org-copy-subtree in a file with local variables marks buffer as modified [9.5.3 (release_9.5.3-6-gef41f3 @ /home/ignacio/repos/emacs/lisp/org/)]
Date: Tue, 14 Jun 2022 09:21:50 +0200 [thread overview]
Message-ID: <DB6PR0601MB20875A68B9CAF23CB3F8CEA9C6AA9@DB6PR0601MB2087.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <87mtefq3nx.fsf@localhost>
[-- Attachment #1: Type: text/plain, Size: 846 bytes --]
>> - (delete-and-extract-region (point) (point-max)))))))
>> + (undo-boundary)
>
>> + (setq buffer-undo-list
>> + (seq-drop-while 'identity buffer-undo-list)))))))
>
> This looks fragile and can be disasterous when buffer-undo-list is
> large.
I agree that it is very fragile, but could you explain why is it also
problematic with a large `buffer-undo-list'? I guess you mean
efficiency-wise, but it would only iterate through the few items added
since the call to (undo-boundary). Is there something else I'm not seeing?
> Maybe just use with-silent-modifications or some ideas from there (for
> example, wrapping modifications inside let-bound (buffer-undo-list t))?
> We should not inhibit modification hooks though. Otherwise, it will mess
> up with caching code.
Done. I attach the new patch:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: New patch using (let ((buffer-undo-list t)) ...) --]
[-- Type: text/x-diff, Size: 1650 bytes --]
From 54e05dc54fe7091f2d1c7e0c44e01cf5abeb4907 Mon Sep 17 00:00:00 2001
From: Ignacio Casso <ignaciocasso@hotmail.com>
Date: Sun, 12 Jun 2022 10:38:53 +0200
Subject: [PATCH] Do not mark buffer as modified with
org-preserve-local-variables
* lisp/org-macs.el (org-preserve-local-variables): Do not mark buffer
as modified or alter `buffer-undo-list' when body does not actually
modify the buffer.
This commit fixes a bug with `org-copy-subtree', which marked the
buffer as modified and added an entry to the undo list when the visited
file had local variables.
---
lisp/org-macs.el | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 19e5f42e9..c34ff3ab7 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -166,13 +166,19 @@
(and (re-search-backward "^[ \t]*# +Local Variables:"
(max (- (point) 3000) 1)
t)
- (delete-and-extract-region (point) (point-max)))))))
+ (let ((buffer-undo-list t))
+ (delete-and-extract-region (point) (point-max)))))))
+ (tick-counter-before (buffer-modified-tick)))
(unwind-protect (progn ,@body)
(when local-variables
(org-with-wide-buffer
(goto-char (point-max))
(unless (bolp) (insert "\n"))
- (insert local-variables))))))
+ (let ((modified (< tick-counter-before (buffer-modified-tick)))
+ (buffer-undo-list t))
+ (insert local-variables)
+ (unless modified
+ (restore-buffer-modified-p nil))))))))
(defmacro org-no-popups (&rest body)
"Suppress popup windows and evaluate BODY."
--
2.25.1
next prev parent reply other threads:[~2022-06-14 7:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-22 7:08 [BUG] org-copy-subtree in a file with local variables marks buffer as modified [9.5.3 (release_9.5.3-6-gef41f3 @ /home/ignacio/repos/emacs/lisp/org/)] Ignacio Casso
2022-06-11 7:36 ` Ihor Radchenko
2022-06-12 8:53 ` Ignacio Casso
2022-06-14 4:17 ` Ihor Radchenko
2022-06-14 7:21 ` Ignacio Casso [this message]
2022-06-14 14:05 ` 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=DB6PR0601MB20875A68B9CAF23CB3F8CEA9C6AA9@DB6PR0601MB2087.eurprd06.prod.outlook.com \
--to=ignaciocasso@hotmail.com \
--cc=emacs-orgmode@gnu.org \
--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).