Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert something into kill ring in Emacs

I want to write a function that will insert the file name of the current buffer into the kill ring so I can yank it to the terminal in another window. How can I programmatically insert a string into the kill ring?

(<SOME FUNCTION> (buffer-file-name))

Is there a (built-in) function for that or do I need to insert the string I want into a buffer and then kill it?

I tried something like this:

(defun path ()
  (interactive)
  (save-excursion
    (let ((begin (mark)))
      (insert (buffer-file-name))
      (kill-region begin (mark)))))

but it doesn't work.

like image 904
jcubic Avatar asked Mar 17 '14 12:03

jcubic


1 Answers

There's a function for that:

(defun copy-buffer-name ()
  (interactive)
  (kill-new (buffer-file-name)))
like image 112
abo-abo Avatar answered Oct 23 '22 07:10

abo-abo