From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#24074: bug#24094: 25.1.50; revert-buffer error in CC mode Date: Fri, 29 Jul 2016 21:18:24 +0000 Message-ID: <20160729211824.GB3300@acm.fritz.box> References: <20160729175924.11811.qmail@mail.muc.de> <87r3ac2t7m.fsf@wanadoo.es> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1469827237 7379 80.91.229.3 (29 Jul 2016 21:20:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 29 Jul 2016 21:20:37 +0000 (UTC) Cc: =?UTF-8?Q?=C3=93scar?= Fuentes , 24094@debbugs.gnu.org, 24074@debbugs.gnu.org To: Richard Copley Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 29 23:20:26 2016 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 1bTFCj-00036I-Hc for geb-bug-gnu-emacs@m.gmane.org; Fri, 29 Jul 2016 23:20:25 +0200 Original-Received: from localhost ([::1]:33306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTFCd-0003Co-JQ for geb-bug-gnu-emacs@m.gmane.org; Fri, 29 Jul 2016 17:20:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTFCT-00038p-Qx for bug-gnu-emacs@gnu.org; Fri, 29 Jul 2016 17:20:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTFCR-0001B9-Lc for bug-gnu-emacs@gnu.org; Fri, 29 Jul 2016 17:20:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTFCM-00017b-RS; Fri, 29 Jul 2016 17:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bTFCM-0005eN-IR; Fri, 29 Jul 2016 17:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 29 Jul 2016 21:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24074 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 24074-submit@debbugs.gnu.org id=B24074.146982714921645 (code B ref 24074); Fri, 29 Jul 2016 21:20:02 +0000 Original-Received: (at 24074) by debbugs.gnu.org; 29 Jul 2016 21:19:09 +0000 Original-Received: from localhost ([127.0.0.1]:50980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTFBU-0005d1-Sg for submit@debbugs.gnu.org; Fri, 29 Jul 2016 17:19:09 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:35714) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTFBS-0005cn-Sn for 24074@debbugs.gnu.org; Fri, 29 Jul 2016 17:19:07 -0400 Original-Received: (qmail 59381 invoked by uid 3782); 29 Jul 2016 21:19:05 -0000 Original-Received: from acm.muc.de (p548C6EF4.dip0.t-ipconnect.de [84.140.110.244]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 29 Jul 2016 23:19:02 +0200 Original-Received: (qmail 5154 invoked by uid 1000); 29 Jul 2016 21:18:24 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:121697 Archived-At: Hello, Richard and Óscar. I've cracked it! On Fri, Jul 29, 2016 at 07:41:39PM +0100, Richard Copley wrote: > Here is a recipe. > Prepare a file "test0.cpp" as follows: (< int main () { > int a = 0; > int b = 1; > int c = 2; > int d = 3; > } > END > In a shell: cp test0.cpp test.cpp > In Emacs: visit test.cpp, transpose "line b" and "line c", save the > buffer, and put point between the transposed lines (i.e., at the > beginning of "line b"). > In the shell: cp test0.cpp test.cpp > In Emacs: revisit test.cpp (C-x C-f M-n RET). > I hope that helps. Very much indeed. What is happening in that sequence is that the C-x C-f calls the hook after-change-functions without having first called before-change-functions. This screws up CC Mode. The function doing this, insert-file-contents, is called as follows: (insert-file-contents "test.cpp" t nil nil t) | | | | | | | replace | | end | beg visit The section of Finsert_file_contents which calls before-change-functions (through prepare_to_modify_buffer) looks like this: if (NILP (visit) && total > 0) { if (!NILP (BVAR (current_buffer, file_truename)) /* Make binding buffer-file-name to nil effective. */ && !NILP (BVAR (current_buffer, filename)) && SAVE_MODIFF >= MODIFF) we_locked_file = true; prepare_to_modify_buffer (PT, PT, NULL); <====================== } The brace block will not be executed since `visit' is t. The section of code which calls after-change-functions looks like this: if (inserted > 0 && total > 0 && (NILP (visit) || !NILP (replace))) { signal_after_change (PT, 0, inserted); <===================== update_compositions (PT, PT, CHECK_BORDER); } The brace block here _will_ get called, since `replace' is non-nil. There are thus two different, conflicting, conditions governing whether to call the change hooks. At a guess, the `if' condition around the after-change-functions call was modified at some stage, without the same change being made to the condition around the before-change-functions call. I'll look into this further over the weekend. -- Alan Mackenzie (Nuremberg, Germany).