region-bindings-mode
region-bindings-mode copied to clipboard
bindings get unexpectedly enabled without any manual region activation
Something is fundamentally broken, because the bindings sometimes get enabled even without manually activating the region.
I suspect this is due to activate-mark-hook
being overloaded:
Documentation:
Hook run when the mark becomes active.
It is also run at the end of a command, if the mark is active and
it is possible that the region may have changed.
Further investigation required, but for now this is a show-stopper for me, because it randomly breaks FAR too often.
I noticed that when using winner-mode
's undo, region-bindings
mode gets enabled in all visible buffers.
I think I fixed this too but I'm not sure. Try my fork and report if you have a way to reproduce (I don't, I just occasionally suffer from it).
Hum, I just had this refactoring idea which should solve this problem: always have the binding active, with a wrapper binding that does the right thing according to (region-active-p)
instead of relying on activate-mark-hook
.
@Silex I've tried you modification, It works pretty but have tested it extensively. However (i'm not sure), I think it introduces the issue that the region-bindings
bindings are still active when in the minibuffer.
Example:
- select a region
-
M-x ev|al-buffer
-> I'm unable to typea
as not region is active in the minibuffer.
Ill try to look into it but I m not that familiar with Elisp
@Lompik: yeah, I also have this problem. I'll think for this mode to work reliably it needs to function differently, namely to have the keymap always active but each keymap has a wrapper that checks wether the region is active or not. I'll see what I can do.
I just tested emacs25 for the first time yesterday and region bindings mode did not work at all.. Did not get disabled on keyboard-quit and also missed deactivation when repeatedly selecting regions with the mouse.
I use the cursor color to inform me if region bindings mode is active, works great for me on emacs24:
(defvar my-normal-cursor-type 'bar)
(defun cursor-style-update-action ()
(when (bound-and-true-p cua-normal-cursor-color)
(let* ((current-cursor-color (cdr (assq 'cursor-color (frame-parameters))))
(cursor-style (cond
((bound-and-true-p region-bindings-mode) (list "#d33682" '(bar . 8) t))
((bound-and-true-p god-local-mode) (list "#268bd2" 'box nil))
((bound-and-true-p buffer-read-only) (list "#859900" 'box nil))
(t (list cua-normal-cursor-color my-normal-cursor-type t)))))
(unless (equal (nth 0 cursor-style) current-cursor-color)
(set-cursor-color (nth 0 cursor-style)))
(unless (equal (nth 1 cursor-style) cursor-type)
(setq cursor-type (nth 1 cursor-style)))
(unless (equal (nth 2 cursor-style) blink-cursor-mode)
(blink-cursor-mode (or (nth 2 cursor-style) -1))))))
(defvar cursor-style-timer nil)
(defun cursor-style-update ()
(when cursor-style-timer
(cancel-timer cursor-style-timer))
(setq cursor-style-timer
(run-with-idle-timer 0.2 nil 'cursor-style-update-action)))
(defadvice hardhat-local-hook (after cursor-style-update activate)
(cursor-style-update))
;;;; Modes and mode groupings
(defmacro hook-into-modes (func modes)
"Add hook `FUNC' to multiple `MODES'."
`(dolist (mode-hook ,modes)
(add-hook mode-hook ,func)))
(hook-into-modes 'cursor-style-update
'(activate-mark-hook
deactivate-mark-hook
region-bindings-mode-hook
window-configuration-change-hook
minibuffer-setup-hook
minibuffer-exit-hook
god-mode-enabled-hook
god-mode-disabled-hook
god-local-mode-hook
read-only-mode-hook
after-change-major-mode-hook
focus-in-hook
focus-out-hook
))
(add-hook mode-hook 'cursor-style-update))
I just switched to the emacs-25 branch again due to bugs elsewhere and now deactivation stopped working properly again.. Maybe I should create a separate issue..
The biggest problem seems to be that when region-bindings-mode fails to deactive once it's not deactivet until I manually run the region-bindings-mode-off function.
The problem actually seems to be that the region gets deactivated without deactivate-mark-hook
being executed. The emacs NEWS file says "deactivate-mark is now buffer-local." .,. I will investigate if its related in a bit.
It seems like cua-mode might be the cause of the region not being deactivated even though I only have the cua rectangle mode active and have not used it..