Changing Cursor Shape to Indicate Emacs Minor Modes

As it turns out, Emacs actually allows for different cursor shapes. We can use this feature to change the cursor based on the current minor mode.

Overwrite Mode

The following snippet changes the cursor to a “bar” shape when the overwrite mode is enabled, and back to the usual “box” shape when overwrite mode is disabled again.

(add-hook 'overwrite-mode-hook
          (lambda ()
            (setq cursor-type
                  (if overwrite-mode 'bar 'box))))

Note that this is an improvement and slight variant of the accepted answer on StackExchange, which does not, in fact, seem to work properly.

Update: I have since learned that there is a package, bar-cursor, available from Melpa, that does something very similar.

Input Method

Emacs allows for various “input methods”, in which keystrokes may be interpreted differently. One is the “TeX” input method, which makes it possible to enter TeX-like key sequences (such as \lambda) and have them be converted to the appropriate Unicode glyph: λ.

The following snippet changes the cursor to a hollow box outline, when the TeX input method is active. Mostly for convenience, it defines a new minor mode tex-input-method-mode, so that the actual switching of the cursor shape can be done via a mode-hook.

Toggling the mode is bound to C-\, which is the default key for activating an input method.

(setq default-input-method "TeX")

(define-minor-mode tex-input-method-mode
  "TeX input method, with Frame cursor"
  :lighter "/"
  (toggle-input-method)
  )

(add-hook 'tex-input-method-mode-hook
          (lambda ()
            (setq cursor-type
                  (if current-input-method 'hollow 'box))))

(global-set-key (kbd "C-\") 'tex-input-method-mode)