reddit / emacs

Changing cursor color depending if you are on god mode or not

nz0k · 2022-04-17 14:34
I've spent a lot of time on this because the most popular solution didn't work, and now that I figured it out, I want to post it so that, maybe, I help someone with the same problem as I had. To change the cursor color on emacs depending if you are or not in god mode you put the following code into your init.el file. (defun hook-update-cursor () (cond ((or (bound-and-true-p god-mode) (bound-and-true-p god-global-mode)) (set-cursor-color "lime green")) (t (set-cursor-color "cornflower blue")))) (add-hook 'buffer-list-update-hook 'hook-update-cursor) If that doesn't work, try this other one. (defun my-god-mode-update-cursor () (cond (god-local-mode (set-cursor-color "lime green")) (t (set-cursor-color "cornflower blue")))) (add-hook 'post-command-hook 'my-god-mode-update-cursor) The latter works for me, while the first doesn't. I hope I helped!!!!
ieure · 2022-04-17 16:03
Hooking into `buffer-list-update-hook` and `post-command-hook` is going to run your stuff much more often than it needs to. You should use `god-mode-enabled-hook` and `god-mode-disabled-hook`, since those only run when the state you care about changes. Note also that `god-global-mode` should change point's face globally, and `god-local-mode` only for the current buffer. This seems like a good addition to that package, especially if you can define `god-mode-enabled-point-face` and figure a way to avoid making unwanted changes -- like maintaining the default point color if it isn't "cornflower blue."
divinedominion · 2022-04-18 10:49
TIL that `set-cursor-color` exists, that's useful for modal input in general! Thanks