unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: emacs-devel@gnu.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH] Use deactivate-mark from cua-cancel
Date: Sun,  7 Jun 2020 09:20:19 +0100	[thread overview]
Message-ID: <20200607082019.255681-1-andrew.burgess@embecosm.com> (raw)

Create a config file ~/tmp/setup.el containing:

  (defun cursor-activate-mark ()
     (setq cursor-type 'bar))
  (add-hook 'activate-mark-hook 'cursor-activate-mark)

  (defun cursor-deactivate-mark ()
     (setq cursor-type 'box))
  (add-hook 'deactivate-mark-hook 'cursor-deactivate-mark)

Start emacs like this:

  emacs -Q -l ~/tmp/setup.el ~/tmp/setup.el

Now do the following:

  M-x set-mark-command
  M-x forward-paragraph
  C-g

You should see that after `set-mark-command` the cursor changes from
box to bar, then after the C-g (`keyboard-quit`) the cursor changes
back to box.

Now do:

  M-x cua-selection-mode
  M-x set-mark-command
  M-x forward-paragraph
  C-g

In this case the cursor should still change from box to bar when the
mark is set, but after the C-g the cursor will be left as a bar.

The reason is that with `cua-selection-mode` enabled, C-g now calls
`cua-cancel` instead of `keyboard-quit`.  Currently `cua-cancel` looks
like this:

  (defun cua-cancel ()
    "Cancel the active region, rectangle, or global mark."
    (interactive)
    (setq mark-active nil)
    (if (fboundp 'cua--cancel-rectangle)
        (cua--cancel-rectangle)))

It is the line:

    (setq mark-active nil)

that is problematic, setting `mark-active` directly avoids the
`deactivate-mark-hook`.  I think that instead we should be calling
`deactivate-mark`, and this is what this patch does.

* lisp/emulation/cua-base.el (cua-cancel): Use deactivate-mark
instead of setting mark-active directly.
---
 lisp/emulation/cua-base.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emulation/cua-base.el b/lisp/emulation/cua-base.el
index 26a1a8955f..c4dcb76446 100644
--- a/lisp/emulation/cua-base.el
+++ b/lisp/emulation/cua-base.el
@@ -860,7 +860,7 @@ With numeric prefix arg, copy to register 0-9 instead."
 (defun cua-cancel ()
   "Cancel the active region, rectangle, or global mark."
   (interactive)
-  (setq mark-active nil)
+  (deactivate-mark)
   (if (fboundp 'cua--cancel-rectangle)
       (cua--cancel-rectangle)))
 
-- 
2.25.4




             reply	other threads:[~2020-06-07  8:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-07  8:20 Andrew Burgess [this message]
2020-06-20  7:45 ` [PATCH] Use deactivate-mark from cua-cancel 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=20200607082019.255681-1-andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=emacs-devel@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).