[Bug] cursor-type not set on state entry for buffers not yet attached to a window
- Dominant language
- Emacs Lisp
- Stars
- 3.9k
- Forks
- 307
- PR merge metrics
- No merged PRs in 30d
Description
# Describe the bug
When a buffer is opened in insert state via a hook (e.g. COMMIT_EDITMSG via Magit's `git-commit-setup-hook`), the cursor displays as a block until the user starts typing, then it'll correctly switch to `(bar . 1)`.
# Steps to reproduce
- Use magit with evil and evil-collection
- Press `c c` to start a commit
- Observe the cursor briefly appears as a block even though evil-state is insert
# Investigation result and theory
My theory is: when a buffer is set up via a hook before being attached to a window, `(window-buffer)` returns a different buffer, so `evil-refresh-cursor` is skipped entirely. `cursor-type` is never set during state entry and remains `t` (the default block cursor) until `evil--sw-refresh-cursor` fires via the `select-window` advice (or some other trigger?) during the first redisplay.
# Temporary fix
I can add the following to my local .emacs.d/init.el as a temporary fix. Confirmed to work on my Emacs 30.2.
```elisp
(with-eval-after-load 'magit
;; Entering Magit COMMIT_EDITMSG does not correctly set evil cursor to (bar . 1)
;; Temporary workaround until evil fixes the cursor refresh and display timing upstream.
(add-hook 'git-commit-setup-hook
(lambda ()
(setq-local cursor-type (evil-state-property evil-state :cursor t)))
t))
```
Contributor guide
Assessment
This issue has not been assessed yet.