سؤال

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)))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top