Emacs: Show Buffer File Name

I share my Emacs configuration on GitHub, but the truth is that most of the fun stuff happens in my experimental.el file (mentioned previously), which I don’t share. It’s growing rather large and some of the contents are fairly mature so I’m going to going to work on moving more things into my stable config and I may as well share them along the way.

One little utility I’ve grown quite fond of is my show-buffer-file-name utility:

(defun camdez/show-buffer-file-name ()
  "Show the full path to the current file in the minibuffer."
  (interactive)
  (let ((file-name (buffer-file-name)))
    (if file-name
        (progn
          (message file-name)
          (kill-new file-name))
      (error "Buffer not visiting a file"))))

…which I keep on C-x C-p, overriding the fairly useless mark-page command:

(global-set-key (kbd "C-x C-p") 'camdez/show-buffer-file-name)

It’s fairly self-explanatory but notice that it not only shows you the path to the current file but also leaves it on the kill-ring. I find this to be pretty useful when switching to the shell to operate on a file (though obviously there are lots of ways to do such things within Emacs), and for pasting filenames into GitHub discussions, emails, or the company chat room.