[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Use deactivate-mark from cua-cancel
From: |
Andrew Burgess |
Subject: |
[PATCH] Use deactivate-mark from cua-cancel |
Date: |
Sun, 7 Jun 2020 09:20:19 +0100 |
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
- [PATCH] Use deactivate-mark from cua-cancel,
Andrew Burgess <=