unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11773: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents
@ 2012-06-24 17:43 Gergely Risko
  2012-08-14  5:09 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Gergely Risko @ 2012-06-24 17:43 UTC (permalink / raw)
  To: 11773

Tags: patch

I've run into the following problem the other day:
-=-
(defun common ()
  (save-buffer)
  (setq buffer-undo-list nil))

(defun insert-bad ()
  (interactive)
  (common)
  (insert-file-contents "/etc/fstab"))

(defun insert-good ()
  (interactive)
  (common)
  (insert "foobar"))
-=-

If I open a file and run insert-good and then I undo, the file goes back
to unmodified state.

If I open a file and run insert-bad and then I undo, the file doesn't
go back to unmodified state.

Investigating, it turned out that if insert-file-contents is ran for
an unmodified buffer, the first change marker of (t HIGH . LOW) is not
inserted although it should've been.

This is because of a bug in decode_string at coding.c, where by the time
the record_insert is ran at the end, MODIFF is already too high.
MODIFF gets increased in insert_from_gap (used by produce_chars).  But
at the point of increase there is a record_insert before:
-=-
  record_insert (GPT, nchars);
  MODIFF++;
-=-

So why it's not having the effect of recording first change?  Because
decode_coding disables undo list handling at the beginning of the
function.  Therefore, my solution is to record the first change (if
MODIFF <= SAVE_MODIFF) before the undo list handling gets disabled.

I attached the patch, please consider applying it.

Thanks,
Gergely Risko

diff --git a/src/coding.c b/src/coding.c
index eb89563..212e73e 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7083,6 +7083,15 @@ decode_coding (struct coding_system *coding)
        set_buffer_internal (XBUFFER (coding->dst_object));
       if (GPT != PT)
        move_gap_both (PT, PT_BYTE);
+
+      /* We have to disable undo_list, so we can record the whole
+        insert transaction via record_insert at the end.
+        Unfortunately, disabling the undo recording also disables the
+        recording of the first change in the undo_list.  Therefore
+        we check for first change here and record it via
+        record_first_change if needed.  */
+      if (MODIFF <= SAVE_MODIFF)
+       record_first_change ();
       undo_list = BVAR (current_buffer, undo_list);
       BVAR (current_buffer, undo_list) = Qt;
     }





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#11773: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents
  2012-06-24 17:43 bug#11773: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents Gergely Risko
@ 2012-08-14  5:09 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2012-08-14  5:09 UTC (permalink / raw)
  To: Gergely Risko; +Cc: 11773

Gergely Risko <gergely@risko.hu> writes:

> decode_coding disables undo list handling at the beginning of the
> function.  Therefore, my solution is to record the first change (if
> MODIFF <= SAVE_MODIFF) before the undo list handling gets disabled.
>
> I attached the patch, please consider applying it.

Thanks, I've committed your patch to trunk.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-14  5:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-24 17:43 bug#11773: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents Gergely Risko
2012-08-14  5:09 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).