3

I would like to have NeoTree automatically toggle-open upon Emacs start up. I have tried adding:

(neotree-mode t)

under my:

(require 'neotree)

line in ~/.spacemacs (and yes, I am using Spacemacs too, if that is somehow relevant) in order to get NeoTree to automatically toggle open upon startup, but it failed. It gives an error such that Spacemacs is not even loaded, see this screenshot for further details, if relevant (here is the ~/.spacemacs file I was using when I got this error). I know that adding:

(global-set-key [f8] 'neotree-toggle)

to my ~/.spacemacs file, after the require line will cause it so that if I press F8 after Emacs startup it will toggle the NeoTree open, but I would like to rewrite my ~/.spacemacs file such that it toggles the NeoTree open automatically on startup, is this possible?

1
  • 1
    Well I'll be, adding (neotree-toggle) to my ~/.spacemacs file worked. If you write this up as an answer I will accept it.
    – Josh Pinto
    Mar 11, 2016 at 7:04

1 Answer 1

10

neotree-mode is a major mode for the neotree buffer, and major mode functions do not take any arguments, so calling (neotree-mode t) is an error.

You wouldn't want to invoke that mode yourself, though -- it's only intended to be called from neotree's own buffer.

(Unlike minor modes -- it's very common to call a global minor mode directly from your init file, so you want to establish what sort of a mode any given *-mode is before trying to use it. You can invariably do so by invoking describe-function: C-hf neotree-mode RET -- at minimum you will learn whether or not the function accepts any arguments.)

What you actually wanted to do here is call the command you were already calling via your keybinding, which is neotree-toggle

Like so:

(neotree-toggle)

Although I can see that there's actually a better function to call:

(neotree-show)

(which is the function called by the 'toggle' command when neotree is not currently visible.)

Occasionally you might need to use call-interactively to mimic a key binding more directly -- e.g.: (call-interactively 'neotree-show) -- but that's not the case here.


FYI, the different kinds of mode functions you'll encounter in Emacs are:

  • Major modes: Every buffer is running a single major mode. If you call a different major mode in a buffer, it replaces the previous one.

  • Buffer-local minor modes: These are enabled or disabled on a per-buffer basis. They are typically invoked via the mode hook of another mode (often a major mode).

  • Global minor modes: These have a global state and so are either on or off for Emacs globally, and hence might be called directly in your init file.

  • 'Globalized' minor modes: These are global minor modes which control a separate buffer-local minor mode. When the globalized mode is enabled, it causes the buffer-local mode to be enabled en-masse in multiple buffers, and also arranges for it to be enabled in subsequent new buffers as appropriate. When the globalized mode is disabled, the buffer-local mode is also disabled en-masse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.