unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 31042@debbugs.gnu.org
Subject: bug#31042: Emacs 27. Inserting a character doesn't always "deactivate" the mark.
Date: Tue, 3 Apr 2018 13:42:46 +0000	[thread overview]
Message-ID: <20180403134246.GA5363@ACM> (raw)

Hello, Emacs.

In master, evaluate the following definition:

    (defun no-deactivate-mark-bug (arg)
      (interactive "P")
      (transient-mark-mode 1)
      (set-mark (point))
      (forward-char)
      (let ((inhibit-modification-hooks arg))
        (insert "a"))
      (message "deactivate-mark is %s" deactivate-mark))

.  In a non-empty buffer, with point not at end of buffer, do

    M-x no-deactivate-mark-bug

.  The character "a" will have been inserted, the region will not be
"active", and the message in the message area will confirm that
deactivate-mark had been set to t.  This is as it should be.

Now do

    C-u M-x no-deactivate-mark-bug

.  This time, after the insertion of "a", the region WILL spuriously be
"active", and the message will indicate that deactivate-mark was still
nil.  This is a bug.

I found this bug whilst integrating the new combine-change-calls macro
into Emacs.

What triggers this bug is inhibit-modification-hooks being non-nil.

The place where the bug is is in prepare_to_modify_buffer_1 in
.../src/insdel.c.  The test there of inhibit_modification_hooks rudely
exits before setting deactivate-mark to t.  A patch which fixes this
(still not tidied up; it's left as simple as possible to read) is:


diff --git a/src/insdel.c b/src/insdel.c
index 173c243834..1f45ccd28a 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -1951,9 +1951,10 @@ prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end,
   else
     base_buffer = current_buffer;
 
-  if (inhibit_modification_hooks)
-    return;
-
+  /* if (inhibit_modification_hooks) */
+  /*   return; */
+  if (!inhibit_modification_hooks)
+    {
   if (!NILP (BVAR (base_buffer, file_truename))
       /* Make binding buffer-file-name to nil effective.  */
       && !NILP (BVAR (base_buffer, filename))
@@ -1973,6 +1974,7 @@ prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end,
       = call1 (Fsymbol_value (Qregion_extract_function), Qnil);
 
   signal_before_change (start, end, preserve_ptr);
+    }
   Fset (Qdeactivate_mark, Qt);
 }
 

On a related note, it appears that in the same function, the file
locking is done for the first change in a buffer.  This locking would
appear not to be done if that first change to the buffer happens when
inhibit-modification-hooks is non-nil.  I haven't tested this, but it
would appear to be part of the same bug.

-- 
Alan Mackenzie (Nuremberg, Germany).
 





             reply	other threads:[~2018-04-03 13:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03 13:42 Alan Mackenzie [this message]
2018-04-03 14:08 ` bug#31042: Emacs 27. Inserting a character doesn't always "deactivate" the mark Eli Zaretskii
2018-04-03 14:39   ` Alan Mackenzie
2018-04-03 15:12     ` Eli Zaretskii

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=20180403134246.GA5363@ACM \
    --to=acm@muc.de \
    --cc=31042@debbugs.gnu.org \
    /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).