unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Markus Triska <triska@metalevel.at>
To: 35177@debbugs.gnu.org
Subject: bug#35177: 27.0.50; Binding deactivate-mark to nil unexpectedly deactivates the mark
Date: Sun, 07 Apr 2019 02:11:02 +0200	[thread overview]
Message-ID: <m2tvfa3ca1.fsf@metalevel.at> (raw)


Please start Emacs with "emacs -Q" and insert the following form in the
*scratch* buffer:

    (progn
      (let (deactivate-mark)
        (switch-to-buffer (get-buffer-create "t"))
        (erase-buffer)
        (insert "hello"))
      (let (deactivate-mark)
        (set-mark-command nil)
        (move-beginning-of-line nil)))

then place point at the end of the form and evaluate it with C-x C-e.

You will see a new buffer ("t"), where "hello" is inserted and nothing
is highlighted because the mark is inactive.

However, I expect the mark to be active and the region highlighted,
because the form binds deactivate-mark to nil. This is the way that is
recommended in the Elisp manual, see for Example 31.7 "The Mark":

     To write Lisp code that modifies the buffer without causing
     deactivation of the mark at the end of the command, bind
     ‘deactivate-mark’ to ‘nil’ around the code that does the
     modification.  For example:

          (let (deactivate-mark)
            (insert " "))


When I remove the second let-binding in the snippet, then the mark is in
fact active after the form is evaluated. For example, when I evaluate:

    (let (deactivate-mark)
      (switch-to-buffer (get-buffer-create "t"))
      (erase-buffer)
      (insert "hello")
      (set-mark-command nil)
      (move-beginning-of-line nil))

then "hello" is highlighted.

Hence, if I bind deactivate-mark to nil, then the mark is in some cases
unexpectedly deactivated.

As another test case, here is the first form bound to F4:

    (global-set-key [f4]
                    (lambda ()
                      (interactive)
                      (progn
                        (let (deactivate-mark)
                          (switch-to-buffer (get-buffer-create "t"))
                          (erase-buffer)
                          (insert "hello"))
                        (let (deactivate-mark)
                          (set-mark-command nil)
                          (move-beginning-of-line nil)))))

with this binding in place, when I press F4, I also expect "hello" to be
highlighted, since this form binds deactivate-mark to nil. However,
"hello" is unexpectedly not highlighted when I then press F4.

In contrast, when I evaluate the first form with C-M-x, then the region
is highlighted. Could you please make C-x C-e and F4 (with this binding
in place) give the same result as using C-M-x on the form?

Thank you and all the best!
Markus


In GNU Emacs 27.0.50 (build 1, x86_64-apple-darwin18.0.0, X toolkit, Xaw scroll bars)
 of 2018-11-15 built on mt-computer
Repository revision: b4eb908f858284a7962851fd99c94598f76afa6f
Windowing system distributor 'The X.Org Foundation', version 11.0.11804000
System Description:  Mac OS X 10.14.2






             reply	other threads:[~2019-04-07  0:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-07  0:11 Markus Triska [this message]
2019-04-07 15:42 ` bug#35177: 27.0.50; Binding deactivate-mark to nil unexpectedly deactivates the mark Eli Zaretskii
2019-04-07 22:39   ` Markus Triska
2019-04-08  2:35     ` Eli Zaretskii
2019-04-08 10:03       ` Markus Triska
2019-04-08 15:09         ` Eli Zaretskii
2019-04-08 15:50           ` Markus Triska
2019-04-08 16:00             ` Eli Zaretskii
2019-04-09  0:04             ` Noam Postavsky
2019-04-09 15:26               ` Markus Triska
2019-04-09 23:46                 ` Noam Postavsky

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=m2tvfa3ca1.fsf@metalevel.at \
    --to=triska@metalevel.at \
    --cc=35177@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).