Search code examples
emacskey-bindings

How to extend Neotree to open a file using hexl?


I'm trying to extend Neotree to open a file using hexl-mode with the shortcut C-c C-x. How would one do this?

I've tried to evaluate a key definition after the Neotree load where it uses my/neotree-hex to open a file path using neo-buffer--get-filename-current-line.

(defun my/neotree-hex
    (hexl-find-file neo-buffer--get-filename-current-line))
(with-eval-after-load 'neotree
  (define-key neotree-mode-map (kbd "C-c C-x")
    'my/neotree-hex))

Solution

  • At the very least, you are missing the (empty) argument list in the function:

    (defun my/neotree-hex ()
        (hexl-find-file neo-buffer--get-filename-current-line))
    

    I don't know what neo-buffer--get-filename-current-line is: if it is a function, then you are not calling it correctly - in lisp, you call a function by enclosing the (name of the) function and its arguments in parens: (func arg1 arg2 ...)[1]; so if it is a function and it takes no arguments, then your function should probably look like this:

    (defun my/neotree-hex ()
        (interactive)
        (hexl-find-file (neo-buffer--get-filename-current-line)))
    

    In order to be able to bind it to a key, you have to make your function a command, which means that you need to add the (interactive) form.

    Disclaimer: I know nothing about neotree.

    [1] You might want to read an introduction to lisp. One (specifically tailored to Emasc Lisp) is included with the emacs documentation, but is also available online. Eventually, you will want to read the Emacs Lisp Reference Manual. Calling a function is covered in the Introduction and is covered in detail in the Reference.