Mon, 11 Feb 2008

« That was cold | MAIN | Moving mountains »

Copy the current buffer name

At least once a day in emacs I need to get the name of the file visited by the current buffer and paste it somewhere. This bit of code puts the current buffer's filename at the top of the kill ring, ready for yanking:

(defun copy-current-buffer-name ()
  "Copy the name of the current buffer into the kill ring, ready
for yanking."
  (interactive)
  (let ((name (buffer-name (current-buffer))))
    (kill-new name)
    (message "%s" name)))

(global-set-key "\C-ch" 'copy-current-buffer-name)

I'm using the less-than-obvious C-c h since my C-c keymap is just about full.

A facility for quotation covers the absence of original thought.—Lord Peter Wimsey

Left column Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.