In evil-mode, the cursor shape and colour for each state is controlled by the series of variables
evil-*-state-cursor. The documentation for these variables states:
May be a cursor type as per
cursor-type, a color string as passed to
set-cursor-color, a zero-argument function for changing the cursor, or a list of the above.
However, when I attempt to use such a nullary function to make the shape of
evil-insert-state-cursor dependent on the value of
overwrite-mode, it doesn't work:
(setq evil-insert-state-cursor (lambda() (cond (overwrite-mode '("chartreuse3" (hbar . 2))) (t '("chartreuse3" (bar . 2))))))
The result of this is that the insert cursor changes to a hollow box in the same colour as the normal state cursor (Darkgoldenrod2 on my system). If I use a named function instead, I get a solid box (ie. identical to the normal state cursor).
I've also attempted to use a function that actually sets the value of
evil-insert-state-cursor, rather than simply returning it. The result was the same. In general, setting the variable to any function results in a solid cursor, while setting it to any symbol/quoted sexp or lambda results in a hollow cursor.
How can I set a state-cursor variable to a function effectively?
(I've found the answer to this before posting, but since I've already written the question, I might as well post it with the answer in case anyone else is searching for it.)