From unknown Fri Jun 20 07:23:10 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#11773 <11773@debbugs.gnu.org> To: bug#11773 <11773@debbugs.gnu.org> Subject: Status: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents Reply-To: bug#11773 <11773@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:23:10 +0000 retitle 11773 24.1; [PATCH] Handle first change undo marker correctly in ca= se of insert-file-contents reassign 11773 emacs submitter 11773 Gergely Risko severity 11773 normal tag 11773 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 24 14:06:35 2012 Received: (at submit) by debbugs.gnu.org; 24 Jun 2012 18:06:35 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 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 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 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 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 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 From: Gergely Risko To: bug-gnu-emacs@gnu.org Subject: 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> User-Agent: GNU Emacs with Gnus MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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-Received-From: 208.118.235.17 X-Spam-Score: -6.9 (------) X-Debbugs-Envelope-To: submit 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 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) 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; } From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 14 01:18:31 2012 Received: (at 11773) by debbugs.gnu.org; 14 Aug 2012 05:18:31 +0000 Received: from localhost ([127.0.0.1]:54725 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T19WR-00048C-5x for submit@debbugs.gnu.org; Tue, 14 Aug 2012 01:18:31 -0400 Received: from mail-yw0-f44.google.com ([209.85.213.44]:65063) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T19WP-000484-HH for 11773@debbugs.gnu.org; Tue, 14 Aug 2012 01:18:30 -0400 Received: by yhq56 with SMTP id 56so4488449yhq.3 for <11773@debbugs.gnu.org>; Mon, 13 Aug 2012 22:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=9g3wbNpbSuAlFaXjyBxYLvyDLzNRlGf9FKfNehchXp4=; b=YSJn/O6XkuNMwMRK5qsLEDSyvFDgDilE4ADKxfcKACm5jokaKPAob92u0Iv3hE84Fb 0pnlrDwzach5Ce2yTNCwh6PWYEkJcFTMZtSShDe2lcylYvIetz7CEb1k3n57LDh/gap2 RjRWefPTHbTyZa//V9+uoaXdTsxZGfUn/gvAsGPDuIAwzdlWOUVzp6GPL5ldaRHnrgNV 4kTJgJEeK9E4cBoUgom9LeOoBD+C4OG+7sVJckDGtvUNdB84tOVh6YpwZUhTTdxtLE+T Wl/Fy7/mX4FQQRSa583Vq02h8+BYwWfStI/GxPkdue0lMGZ7GsixyRk9B4y3Q/qOHeju 2XvQ== Received: by 10.50.194.130 with SMTP id hw2mr9313598igc.57.1344920992740; Mon, 13 Aug 2012 22:09:52 -0700 (PDT) Received: from ulysses ([155.69.19.125]) by mx.google.com with ESMTPS id or5sm8765259igc.10.2012.08.13.22.09.50 (version=SSLv3 cipher=OTHER); Mon, 13 Aug 2012 22:09:51 -0700 (PDT) From: Chong Yidong To: Gergely Risko Subject: Re: bug#11773: 24.1; [PATCH] Handle first change undo marker correctly in case of insert-file-contents References: <87pq8od2rv.fsf@gergely.risko.hu> Date: Tue, 14 Aug 2012 13:09:47 +0800 In-Reply-To: <87pq8od2rv.fsf@gergely.risko.hu> (Gergely Risko's message of "Sun, 24 Jun 2012 19:43:16 +0200") Message-ID: <874no6ys84.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 11773 Cc: 11773@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) Gergely Risko 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. From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 14 01:18:40 2012 Received: (at control) by debbugs.gnu.org; 14 Aug 2012 05:18:40 +0000 Received: from localhost ([127.0.0.1]:54728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T19WZ-00048W-Fm for submit@debbugs.gnu.org; Tue, 14 Aug 2012 01:18:40 -0400 Received: from mail-yx0-f172.google.com ([209.85.213.172]:39071) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T19WX-00048P-MV for control@debbugs.gnu.org; Tue, 14 Aug 2012 01:18:38 -0400 Received: by yenm5 with SMTP id m5so4497618yen.3 for ; Mon, 13 Aug 2012 22:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version:content-type; bh=BATziZ1EOKam21EG4SDGbAvfVVR09sikL+xrqNNlYZ8=; b=VgRtsI6xnpymavrD1/nivrp1tX3XhmDNyOhPuEHlMKJIJoy+WBwg73D0SgDF3/pxtp iE68YJbVe+ogOFVt81iGQo9lrlKnXgs7Ps/EYzgN+u+tDh3vrj86czXA0x6yt3bhd1ZH XHsHkC8Sa3a3Nf9dyqHgTVS3qjBBZxcppseO8FL1SXos9/CVJzzmbXDGepJQ4XipvkoX eMcvdzLWTJXJKstO9jbkTe3JV6/dLrtv5OupFxk+2bmR19fkYdDlFZB3oMd2k8wBQPkR KhkSEF7Dtvz8aP2KHlXt0yiQRJfDXieIPv4xasTMXw2cpCg4Ot//E+vAViq5mCpq0502 FREw== Received: by 10.50.159.135 with SMTP id xc7mr9533890igb.9.1344921001139; Mon, 13 Aug 2012 22:10:01 -0700 (PDT) Received: from ulysses ([155.69.19.125]) by mx.google.com with ESMTPS id uq6sm9778538igb.14.2012.08.13.22.09.58 (version=SSLv3 cipher=OTHER); Mon, 13 Aug 2012 22:10:00 -0700 (PDT) From: Chong Yidong To: control@debbugs.gnu.org Subject: close 11773 Date: Tue, 14 Aug 2012 13:09:56 +0800 Message-ID: <87mx1yjbyz.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) close 11773 thanks From unknown Fri Jun 20 07:23:10 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 11 Sep 2012 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator