Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active July 4, 2024 23:15
Show Gist options
  • Save jdtsmith/a169362879388bc1bdf2bbb977782d4f to your computer and use it in GitHub Desktop.
Save jdtsmith/a169362879388bc1bdf2bbb977782d4f to your computer and use it in GitHub Desktop.
Emacs: change cursor color during active repeat-mode commands
(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)))
@jdtsmith
Copy link
Author

jdtsmith commented Sep 15, 2023

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.

@jdtsmith
Copy link
Author

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