is it possible to replace Insert state with Emacs state?

Leo Alekseyev dnquark at gmail.com
Fri Feb 10 07:54:04 CET 2012


I wrote some helper code to do this.  I'm not sure if it's a good
idea, since it makes me want to stick to my old Emacs habits instead
of learning Evil commands, but I'm using it anyhow.  I also provide a
function to toggle this behavior on and off (per buffer), for when
insert state is really needed (e.g. when inserting rectangular
blocks).  Here's the code:

#+begin_src emacs-lisp
  ;; switch to emacs mode instead of insert mode
  (defadvice evil-append
    (after evil-append/emacs-state activate)
    (evil-backward-char)
    (evil-emacs-state)
    (forward-char))
  (defadvice evil-append-line
    (after evil-append-line/emacs-state activate)
    (evil-emacs-state)
    (end-of-line))
  (defadvice evil-insert
    (after evil-insert/emacs-state activate)
    (let ((old-point (point)))
    (evil-emacs-state)
    (unless (eq old-point (point)) ; that is, if switching to emacs
state moved cursor back
      (forward-char))))
  (defadvice evil-insert-line
    (after evil-insert-line/emacs-state activate)
    (evil-emacs-state))
  (defadvice evil-open-below
    (after evil-open-below/emacs-state activate)
    (evil-emacs-state))
  (defadvice evil-open-above
    (after evil-open-above/emacs-state activate)
    (evil-emacs-state))


  (defvar lva-emacs-state-toggle 1  "Keeps the state of how the buffer
was last toggled.")
  (make-variable-buffer-local 'lva-emacs-state-toggle)
  (defun lva-toggle-emacs-state-advice ()
    (interactive)
    (let ((evil-insert-advice-regexp "evil-.+/emacs-state"))
      (if lva-emacs-state-toggle
          (ad-disable-regexp evil-insert-advice-regexp)
        (ad-enable-regexp evil-insert-advice-regexp))
      (setq lva-emacs-state-toggle (not lva-emacs-state-toggle))
      (ad-activate-regexp evil-insert-advice-regexp)
      (if lva-emacs-state-toggle ; V->E
          (evil-emacs-state) ;; else E->V
        (evil-insert-state))))

#+end_src


On Thu, Feb 9, 2012 at 10:00 PM, Eric Luo <eric.wenbl at gmail.com> wrote:
>
> Hi,
>
> When in Insert state, some Emacs-state key bindings are shadowed in evil, it
> is annoyed as I used to emacs edit command.
>
> Is it possible to enter the emacs state when I press "O","o","i","I" etc
> in Normal state.
>
> Thanks
>
>
> _______________________________________________
> implementations-list mailing list
> implementations-list at lists.ourproject.org
> https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list



More information about the implementations-list mailing list