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.
There's a function for that:
(defun copy-buffer-name ()
  (interactive)
  (kill-new (buffer-file-name)))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With