Issue #172 resolved

Insert-mode in org-add-note buffers doesn't work (the first time)

created an issue

Steps to reproduce:

  1. open an org-mode buffer

  2. navigate to an existing headline or add a new one. E.g "* Test"

  3. Invoke `org-add-note', possibly by pressing "C-c C-z". This will open a new buffer where you are supposed to type your notes. Evil comes up in normal mode.

  4. Press 'i'

What should happen:

Evil should switch to insert mode.

What actually happens:

Evil indeed prints --INSERT-- in the minibuffer, but stays in normal mode. Pressing 'i' again finally turns on insert mode.

emacs version: GNU Emacs 24.1.1 (i686-pc-linux-gnu, GTK+ Version 3.2.4) of 2012-06-11 org-version: Org-mode version 7.8.11 evil version: 3fa0ad440309db978874643d0575bd7b428b6baf

Comments (4)

  1. hpdeifel reporter

    I just noticed that pressing any key (for example C-g) in the newly created note buffer makes the problem go away.

    This means that insert mode just doesn't work if 'i' is the very first key I press in the buffer.

  2. Frank Fischer repo owner
    • changed status to open

    Hm, maybe this is related to some initialization bug mentioned somewhere else. Sometimes an evil command (or so) has to be executed in order to trigger some hooks. But I don't know, have to investigate this.

  3. Frank Fischer repo owner

    Set initial state in `evil-initialize'.

    The function evil-initialize' is called bydefine-globalized-minor-mode' whenever evil should be started in a new buffer or if the major mode in a buffer has been changed. In particular, `define-globalized-minor-mode' calls this function exactly once in each buffer unless the major-mode has been changed. This is ensured using major-mode-hooks as well as post-command-hooks.

    Thus evil-initialize' is the perfect candidate for setting the initial evil in a buffer. The old implementation advicedevil-mode-check-buffers', which is defined by define-globalized-minor-mode', to setup the initial state. Unfortunately this advice did not check whether the initialization for the current major-mode has already been performed. In some cases this caused a double-initialization of this state when the first command in a buffer is executed. The reason is thatevil-mode-check-buffers' is called from a post-command-hook which may not be called before the first command is being executed. But if this command changed the state (e.g. "i" changing to insert state), the double-initialization caused evil to switch back to the initial state immediately.

    This fixes #172.

    → <<cset bfbb9457e898>>

  4. Log in to comment