Last active
July 4, 2024 23:15
-
-
Save jdtsmith/a169362879388bc1bdf2bbb977782d4f to your computer and use it in GitHub Desktop.
Emacs: change cursor color during active repeat-mode commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let ((orig (default-value 'repeat-echo-function)) | |
rcol ccol in-repeat) | |
(setq | |
repeat-echo-function | |
(lambda (map) | |
(if orig (funcall orig map)) | |
(unless rcol (setq rcol (face-foreground 'error))) | |
(if map | |
(unless in-repeat ; new repeat sequence | |
(setq in-repeat t | |
ccol (face-background 'cursor)) | |
(set-frame-parameter nil 'my/repeat-cursor ccol)) | |
(setq in-repeat nil) | |
(set-frame-parameter nil 'my/repeat-cursor nil)) | |
(set-cursor-color (if map rcol ccol)))) | |
(add-function | |
:after after-focus-change-function | |
(let ((sym 'my/remove-repeat-cursor-color-on-focus-change)) | |
(defalias sym | |
(lambda () | |
(when in-repeat | |
(dolist (frame (frame-list)) | |
(when-let ((col (frame-parameter frame 'my/repeat-cursor))) | |
(with-selected-frame frame | |
(set-cursor-color col))))))) | |
sym))) |
Updated to avoid using a post-command-hook (setting the repeat-echo-function
instead), and handle the case of commands which change window focus.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After reading u/karthink's great post on simplified home-spun structural editing UIs, I've been playing with repeat-mode. It's trivial to configure a repeat map with a bunch of disparate commands all joined together by some entry binding(s).
The problem, as mentioned in the article, is that you can't tell when repeat mode is active. You just have to remember, unless you notice the message way down in the minibuffer. This contrasts with something like lispy, where you have visual confirmation at point that it's active (i.e. whether point is on a () boundary).
So I whipped this simple fix up: turn the cursor error-red while repeat mode is active. Working well so far.