evil
evil copied to clipboard
evil-insert-state-cursor not always respected in org-mode src blocks
Issue type
- Bug report
Environment
Emacs version: 27.1
Operating System: EndeavourOS Linux
Evil version: evil-git-cc9d688
Evil installation type: manual
Graphical/Terminal: graphical
Tested in a make emacs
session (see CONTRIBUTING.md): Yes
Reproduction steps
- Have a recent org-mode (at least 9.4.4, not the one included with Emacs)
- Run
make emacs
from cloned evil git repository - Paste the following into a scratch buffer, and add the path to your org install:
(add-to-list 'load-path "[path to org-mode install]")
(require 'org)
(setq evil-insert-state-cursor '(box "green")
evil-normal-state-cursor '(box "red")
evil-visual-state-cursor '(box "orange")
evil-motion-state-cursor '(box "white")
evil-replace-state-cursor '(box "pink")
evil-operator-state-cursor '(box "yellow")
evil-default-state 'normal)
(evil-mode 1)
- M-x eval-buffer
- Switch between modes a few times to confirm the settings worked and the cursor changes color as expected.
- Create an org-mode buffer and add a source code block for elisp to it:
#+begin_src emacs-lisp
#+end_src
- Position the cursor anywhere on the
#+begin_src emacs-lisp
line. - Press "o"
- Cursor is still red, as if we were still in normal-state, but pressing some keys, we find that we're actually in insert-state.
Expected behavior
- Cursor's color should change from red to green, as specified by the evil-insert-state-cursor that was set above.
Actual behavior
- Cursor stays red. But if we press additional characters, we realize that we're still in insert state.
- We can make it green by switching to normal-state and then back to insert-state again, but something prevents the cursor from changing color as it enters the src block.
- This only happens when entering the src block by use of either the "o" or "O" command.
Further notes
Causes confusion, because the user thinks they're still in normal-state after they've switched to insert-state.
Sometimes the cursor flashes green very quickly before moving to the new line, but it changes back to red immediately.
Curiously, the behavior depends on which language was specified on the begin_src line.
All the identifiers listed below are valid language identifiers (listed here). But the problem only occurs when specifying one of the identifiers listed as bad.
bad: latex C emacs-lisp lisp awk css js perl java makefile ruby scheme shell good: ledger asymptote D ocaml plantuml oz arduino php lua haskell
FWIW this bug also reproduces for me in Fundamental mode and python mode.
So get this - evidently if you switch the order of the items in the lists used as the arguments to set the cursor states it works.
That is to say:
(setq evil-insert-state-cursor '("#824BB9" box)) ;; color first, then shape
(setq evil-normal-state-cursor '("#41903F" box))
This no longer switches the cursor color incorrectly after saving in org mode or any other mode as far as I can tell. @mmarshall540 not sure if this is still an issue for you but this fixed it for me.
Hi @amodelbello , I'm no longer using evil-mode. However, for the sake of trying to resolve the issue, I attempted to reproduce it again.
Unfortunately, I'm still able to successfully reproduce the problem. I started Emacs with emacs -Q
and followed the same instructions I'd posted a year ago.
Even if I copy your cursor settings in place of my own, when I enter an org src-block using either "o" (with point on the opening line) or "O" (with point on the closing line), the cursor still fails to change* color with the transition from normal-state to insert-state.
(Or maybe it does change but changes back to the wrong color very quickly. I described seeing that behavior above.)
Are you sure we're talking about the same thing? For me, it's specific to entering org-mode src-blocks. But strangely, it depends on the language argument in the header of the src-block. I notice that when the language argument is python, the problem still occurs. But when it's ledger or ocaml, for example, we get the expected behavior. However, I don't believe there is a Fundamental-mode language argument for org-src blocks, since it's just mode and not a language.
Given that the issue depends on which language is given as an argument to the src-block, maybe this issue has something to do with how each language is implemented in org-babel? If that's the case, maybe an issue should be opened with the org project instead.
I'm still willing to assist anyone who'd like to reproduce and try to solve this issue.
(FWIW, I'm currently using a recent build of the Emacs master branch, which is git commit d8a47823103da803b8274d790527f48d85a3f9b4. That includes org version 9.5.3. And the evil version I used was the latest commit from here: 5a9cfbc443219c4063b17853b7828ec0a00d2736.)