unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#31042: Emacs 27. Inserting a character doesn't always "deactivate" the mark.
@ 2018-04-03 13:42 Alan Mackenzie
  2018-04-03 14:08 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2018-04-03 13:42 UTC (permalink / raw)
  To: 31042

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).
 





^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-03 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-03 13:42 bug#31042: Emacs 27. Inserting a character doesn't always "deactivate" the mark Alan Mackenzie
2018-04-03 14:08 ` Eli Zaretskii
2018-04-03 14:39   ` Alan Mackenzie
2018-04-03 15:12     ` Eli Zaretskii

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).