Search code examples
emacsmode

Changing cursor color based on a minor mode


I have written a minor-mode, it defines some key bindings and does some initialization. The mode properly sets up Navi-mode and Navi-mode-map.

How do I enhance this minor-mode to change the color of the cursor when Navi-mode is enabled, and change it back whenever the mode is disabled? Can I use the hook Navi-mode-hook?


Solution

  • Try this:

    (define-minor-mode foo-mode "doodad" :lighter ""
      (if foo-mode
          (setq cursor-type 'bar)
        (setq cursor-type (default-value 'cursor-type))))
    

    Or, if you anticipate cursor-type to already have a non-default value, you can save it when the mode is enabled and restore the saved value when it's disabled.