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

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