emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
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: Sun, 12 Jun 2022 10:53:16 +0200	[thread overview]
Message-ID: <AM4PR0601MB20811847F0EEFFF515F7E160C6A89@AM4PR0601MB2081.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <875yl7d52o.fsf@localhost>

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


> buffer-modified-p is not the only parameter affected by juggling around
> the local variables. There will be undo history,
> buffer-chars-modified-tick, before/after-change-hooks triggered by
> `org-preserve-local-variables', etc.
>
> However, I do not see any obvious way how your proposed change can
> negatively affect all the above. Feel free to propose a patch.

I've written a patch proposal. It deals with buffer-modified-p and undo
history, but not the other two points you mention. I have tested it and
it works, but I had never dealt before with `buffer-undo-list' so maybe
there are some cases that I have not considered and for which this patch
could be problematic. Let me know what you think:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1839 bytes --]

From 14506bea13bf6278d95825257d90bbc3390ae8f1 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 | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 19e5f42e9..64beeff53 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -163,16 +163,24 @@
 	  (org-with-wide-buffer
 	   (goto-char (point-max))
 	   (let ((case-fold-search t))
-	     (and (re-search-backward "^[ \t]*# +Local Variables:"
+	     (when (re-search-backward "^[ \t]*# +Local Variables:"
 				      (max (- (point) 3000) 1)
 				      t)
-		  (delete-and-extract-region (point) (point-max)))))))
+               (undo-boundary)
+	       (delete-and-extract-region (point) (point-max))))))
+         (tick-counter (buffer-modified-tick))
+         modified)
      (unwind-protect (progn ,@body)
        (when local-variables
+         (setq modified (< tick-counter (buffer-modified-tick)))
 	 (org-with-wide-buffer
 	  (goto-char (point-max))
 	  (unless (bolp) (insert "\n"))
-	  (insert local-variables))))))
+	  (insert local-variables))
+         (unless modified
+           (set-buffer-modified-p nil)
+           (setq buffer-undo-list
+                 (seq-drop-while 'identity buffer-undo-list)))))))
 
 (defmacro org-no-popups (&rest body)
   "Suppress popup windows and evaluate BODY."
-- 
2.25.1


  reply	other threads:[~2022-06-12  9:10 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 [this message]
2022-06-14  4:17     ` Ihor Radchenko
2022-06-14  7:21       ` Ignacio Casso
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=AM4PR0601MB20811847F0EEFFF515F7E160C6A89@AM4PR0601MB2081.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).