2
votes

Hi I am trying to define an interactive menu when using 'm' in neotree to give me similar options to what I used in Nerdtree.

I binded this key:

  (evil-define-key
    'normal neotree-mode-map
... More keybindings ...
    (kbd "m") 'neotree-modify-mode-menu)

and my function is:

(defun neotree-modify-mode-menu (option)
  "Asks for a mode and execute associated Neotree command"
  (interactive "c(a)dd node | (d)elete node | (r)ename node")
  (cond
    ((eq option ?a) (neotree-create-node))
    ((eq option ?d) (neotree-delete-node))
    ((eq option ?c) (neotree-copy-node))
    ((eq option ?r) (neotree-rename-node))
    (:else (message (format "Invalid option %c" option)))))

it works for every option but not create-node. The reason is because create-node takes one argument as I can see here: https://github.com/jaypei/emacs-neotree/blob/dev/neotree.el#L1921 and the rest take no arguments.

So I get this error when calling the function from the keybinding:

Wrong number of arguments: #[(filename) "Å2w^@Æ^X GÇU\203^R^@ÈÅÆ\"\210  ÉÆOÊ\232?^PË  !\203*^@ÌÍ  \"\210ÈÅÆ\"\210^H\203[^@                                                                     
ÎÏ  \"!\203[^@Ð ÇÑÒ ÓÔ$TOÔ\"\210ÕÖÆ #\210×  !\210ØÆ!\210^K\203[^@Ù  !\210^H?\205u^@^LÎÚ \"!\205u^@Ð Ô\"\210×  !\210ØÆ!)0\207" [is-file filename neo-confirm-create-file neo-create-file-auto-o\
pen neo-confirm-create-directory rlt nil 0 throw -1 ...] 8 ("/home/panavtec/.emacs.d/elpa/neotree-20170522.758/neotree.elc" . 64641) (let* ((current-dir (neo-buffer--get-filename-current-lin\
e neo-buffer--start-node)) (current-dir (neo-path--match-path-directory current-dir)) (filename (read-file-name "Filename:" current-dir))) (if (file-directory-p filename) (setq filename (con\
cat filename "/"))) (list filename))], 0   

If i bind the key to neotree-create-node function it works:

  (evil-define-key normal neotree-mode-map
    (kbd "m") 'neotree-create-node)

How I can fix it?

2

2 Answers

2
votes

Clearly you need to provide an argument for create node. What argument do you want to provide it? How do you expect to get that argument?

If you always want to use the same argument value then just hard-code it in your call to neotree-create-node.

Otherwise, have your interactive spec read it.

Your interactive spec is anyway wrong - see the Elisp manual, node Using Interactive.

2
votes

I found the answer, when you are in a function that is called interactivly the argument of that function is automagically populated with the answer of the user. as I used "option" in my question:

(defun neotree-modify-mode-menu (option)
  (interactive "c(a)dd node | (d)elete node | (r)ename node")

But if you need to call another function that need interactive you have to call it with call-interactively

Full code: https://github.com/PaNaVTEC/dotfiles/commit/f69c855cb2d31d79ab81331a5ee53cb9cd8e2f38#diff-e68ea0da4891dbc0f47897e9562e9daeR29

Thanks.