I change my cursor based on state in evil. However I notice that when I type in the minibuffer I'm in normal mode.
I'm trying to make code that change the state from whatever it's in to insert state while I type in the minibuffer and switch back when I exit the minibuffer. Note, I use ivy for minibuffer completion (though I don't think it makes a difference).
(setq evil-insert-state-cursor '((bar . 3) "chartreuse3"))
(defun void-ivy-insert-state (orig-func &rest args)
"Wrapper around ivy, so it goes into insert state."
;; minibuffer is different so I have to manually change the state
(let ((saved-evil-state evil-state))
(evil-insert-state)
(setq cursor-type (elt evil-insert-state-cursor 0))
(set-cursor-color (elt evil-insert-state-cursor 1))
(apply orig-func args)
(evil-change-state saved-evil-state)))
(advice-add 'ivy-read :around #'void-ivy-insert-state)
I expect the cursor to be the right color and the write shape while typing something into the minibuffer. And to return to the appropriate shape of the state I was in before entering the minibuffer.
What actually happens is that the cursor is the right color, but it's the wrong shape. And if I exit the minibuffer with C-g
insert state persists. It never returns to the original state. I think C-g
aborts the execution of my advice.
evil
orivy
, but I am aware that there is aminibuffer-exit-hook
and aminibuffer-setup-hook
that may be helpful. I have set up custom functions that change appearances if I want to move into or out of the minibuffer (leaving it open with something still happening, such as waiting for the user to type additional information or press the return key). I also set a timer function that fires just before I send a quit signal so that it doesn't get canceled -- i.e., about three different custom keyboard-quit functions that all launch my timer function. – lawlist