Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling evil-mode for Nav in Emacs? Or any read-only buffers?

I'm trying to get something like Nerd Tree in Emacs and found Nav, which is like the basic emacs file navigator, and it suits me.

The problem is, when I open Nav and switch to its buffer, evil-mode is still on and I have to press C-z if I want to use any Nav specific commands (e.g. . for nav-toggle-hidden-files). And it annoys me.

It's been a few hours I'm trying to fix that issue, by pasting

(require 'evil)
    (evil-mode 0)

everywhere in the Nav files, but obviously I'm doing it wrong.. And I'm pretty sure it will happen again while using other plugins.. How do I do that?

like image 609
Felix D. Avatar asked May 22 '14 04:05

Felix D.


People also ask

What is Emacs evil mode?

Emacs Evil mode is an extensible Vi layer for Emacs. It adds a set of Vi(m) key bindings and features to Emacs to give it a more modal feel, and lets you rely less on the pinky-accessed CTRL key when manipulating text.


3 Answers

As described on the evil wiki here you might want to check out evil-set-initial-state.

Here's the relevant part of my emacs config:

(evil-set-initial-state 'ibuffer-mode 'normal)
(evil-set-initial-state 'bookmark-bmenu-mode 'normal)
(evil-set-initial-state 'dired-mode 'emacs)
(evil-set-initial-state 'sunrise-mode 'emacs)

Doesn't alleviate the fact that I sure would like to have vim key bindings in these modes someday however...

like image 95
joefromct Avatar answered Oct 13 '22 15:10

joefromct


You want nav-mode buffers to open in Emacs state rather than in Evil's normal state. I don't know what nav-mode is actually called, but do the following, adjusting the name of the mode accordingly:

(add-to-list 'evil-emacs-state-modes 'nav-mode)

like image 33
Dan Avatar answered Oct 13 '22 15:10

Dan


What you need is "hook", which will tell Emacs under which conditions you want a particular mode to be active or not.

I don't use evil or nav modes, but you want something very similar to the following line in your .emacs:

(add-hook 'nav-mode-hook 'turn-off-evil-mode)

This command tells Emacs that when the mode (whose hooks are listed in nav-mode-hook) is active, run the function turn-off-evil-mode. You will likely have to modify either the hook list name, or the callback function name according to how nav-mode and evil-mode are implemented.

nav-mode-hook is my guess at what nav-mode will call its hook list. If it doesn't work, check the nav-mode documentation, look for how to add hooks.

like image 21
Spacemoose Avatar answered Oct 13 '22 14:10

Spacemoose