3

Suppose I'm using neotree in emacs, and suppose point lies above a node representing a file or a directory.

how can I yank the full path of said node to the kill ring so that I can C-y this path afterwards?

ninrod
  • 523
  • 6
  • 25

2 Answers2

5

How about using neo-buffer--get-filename-current-line to get the filename or directory at point (which is a STRING), and then using kill-new to make STRING the latest kill in the kill ring?

The solution, when combined, looks like this:

(kill-new (neo-buffer--get-filename-current-line))
lawlist
  • 13,099
  • 3
  • 49
  • 158
  • hi lawlist, thank you. How should I use your solution? I'm really new in elisp. Do I define an interactive function that uses the neo-buffer function? Will I have access to that private function from my init.el? – ninrod Nov 12 '16 at 17:45
  • 1
    One idea would be to place the following function named `ninrod` inside your `init.el` file, save the file and reboot Emacs: `(defun ninrod () (interactive) (kill-new (neo-buffer--get-filename-current-line)))`. You can use `M-x ninrod` to copy your filename or directory at point, and then paste/yank your kill wherever you want. The method of pasting/yanking remains the same as it has ever been. – lawlist Nov 12 '16 at 17:50
0

You can open the file, and then find the location via M-: 'buffer-file-name'. Since you wish to Yank it you can follow some of the approaches listed here: File path to clipboard in Emacs

Community
  • 1
  • 1
jmercouris
  • 348
  • 5
  • 17
  • 2
    The reason why this answer is less than ideal is because it is not necessary to actually open the file to get the filename or directory at point. Neotree is a library that generates a tree-view of files and directories. The filenames and directory names must be known by neotree in order to accurately depict a tree-view of the directories/files. Neotree is not opening every file that is listed in order to extract the `buffer-file-name`. Therefore, it is just a matter of examining the code of neotree to see what is already available to extract the filename or directory at point. – lawlist Nov 12 '16 at 17:26