unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Richard Copley <rcopley@gmail.com>
Cc: "Óscar Fuentes" <ofv@wanadoo.es>,
	24094@debbugs.gnu.org, 24074@debbugs.gnu.org
Subject: bug#24074: bug#24094: 25.1.50; revert-buffer error in CC mode
Date: Fri, 29 Jul 2016 21:18:24 +0000	[thread overview]
Message-ID: <20160729211824.GB3300@acm.fritz.box> (raw)
In-Reply-To: <CAPM58oh254BLonxsScwgJL748eEHGte41yvS-YOZ2-txyokqxA@mail.gmail.com>

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: (<<END)
> 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).





  parent reply	other threads:[~2016-07-29 21:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-28 13:50 bug#24094: 25.1.50; revert-buffer error in CC mode Richard Copley
     [not found] ` <handler.24094.B.146971385325079.ack@debbugs.gnu.org>
2016-07-28 13:54   ` bug#24094: Acknowledgement (25.1.50; revert-buffer error in CC mode) Richard Copley
     [not found] ` <mailman.2189.1469713866.26859.bug-gnu-emacs@gnu.org>
2016-07-29 17:59   ` bug#24094: 25.1.50; revert-buffer error in CC mode Alan Mackenzie
2016-07-29 18:16     ` Richard Copley
2016-07-29 18:43       ` bug#24074: " Óscar Fuentes
2016-07-29 18:29     ` Óscar Fuentes
2016-07-29 18:41       ` Richard Copley
2016-07-29 19:01         ` Óscar Fuentes
2016-07-29 21:18         ` Alan Mackenzie [this message]
2016-07-29 21:34           ` Richard Copley
2016-08-09 16:21             ` Alan Mackenzie
2016-07-29 21:59           ` bug#24074: " Óscar Fuentes

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.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160729211824.GB3300@acm.fritz.box \
    --to=acm@muc.de \
    --cc=24074@debbugs.gnu.org \
    --cc=24094@debbugs.gnu.org \
    --cc=ofv@wanadoo.es \
    --cc=rcopley@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.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).