From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Gergely Risko Newsgroups: gmane.emacs.bugs Subject: bug#11773: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents Date: Sun, 24 Jun 2012 19:43:16 +0200 Message-ID: <87pq8od2rv.fsf@gergely.risko.hu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1340561000 25243 80.91.229.3 (24 Jun 2012 18:03:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 24 Jun 2012 18:03:20 +0000 (UTC) To: 11773@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 24 20:03:19 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sir9Y-0004FC-LW for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Jun 2012 20:03:16 +0200 Original-Received: from localhost ([::1]:38479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sir9Y-00087x-MB for geb-bug-gnu-emacs@m.gmane.org; Sun, 24 Jun 2012 14:03:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sir9V-00087h-Ri for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 14:03:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sir9U-0006I4-0K for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 14:03:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sir9T-0006Hy-Sc for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 14:03:11 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SirDC-0003TG-4p for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 14:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gergely Risko Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Jun 2012 18:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 11773 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.134056119513308 (code B ref -1); Sun, 24 Jun 2012 18:07:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 Jun 2012 18:06:35 +0000 Original-Received: from localhost ([127.0.0.1]:55407 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SirCk-0003Sa-Mi for submit@debbugs.gnu.org; Sun, 24 Jun 2012 14:06:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52798) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Siqu6-00032B-HR for submit@debbugs.gnu.org; Sun, 24 Jun 2012 13:47:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SiqqM-00027f-EO for submit@debbugs.gnu.org; Sun, 24 Jun 2012 13:43:27 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:41692) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiqqM-00027T-BA for submit@debbugs.gnu.org; Sun, 24 Jun 2012 13:43:26 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiqqJ-00043R-W9 for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 13:43:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SiqqI-00026T-2R for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 13:43:23 -0400 Original-Received: from jenson.atom.hu ([62.112.193.66]:38840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiqqH-00026F-Re for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 13:43:21 -0400 Original-Received: from risko@atom.hu by jenson.atom.hu with esmtpsa (Exim v4) (envelope-from ) id 1SiqqE-00073e-SV for bug-gnu-emacs@gnu.org; Sun, 24 Jun 2012 19:43:19 +0200 User-Agent: GNU Emacs with Gnus X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Sun, 24 Jun 2012 14:06:33 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:61255 Archived-At: 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; }