简体   繁体   中英

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.

There's a function for that:

(defun copy-buffer-name ()
  (interactive)
  (kill-new (buffer-file-name)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM