prodissues

Get The Current File's Path in Emacs

Mon 04 January 2016 by yaniv

Here's a small function I borrowed from this question on stack-overflow. It returns the full path of the file I currently edit in the buffer:

(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name))
  (kill-new (file-truename buffer-file-name))
)
(global-set-key "\C-cz" 'show-file-name)

You'll note that this function is bind to C-c z. So when typing it, you should see the path showing in the minibuffer. As a bonus, it stores the path in the kill ring, so C-y (CMD-v works as well on my mac) will paste the value.