help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filename of buffer into kill-ring functionality


From: Kevin Rodgers
Subject: Re: Filename of buffer into kill-ring functionality
Date: Thu, 31 Aug 2006 09:43:52 -0600
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

Reiner Steib wrote:
On Thu, Aug 31 2006, Marco Wahl wrote:

is there already a function in emacs that puts the
absolute filename belonging to a buffer into the
kill-ring?

I'm not aware of any predefined function for this.  You might use this
one:

(defun rs-kill-ring-save-buffer-file-name ()
  "Add `buffer-file-name' in the kill ring."
  (interactive)
  (if (not (stringp buffer-file-name))
      (error "Not visiting a file.")
    (kill-new buffer-file-name)
    ;; Give some visual feedback:
    (message "String \"%s\" saved to kill ring." buffer-file-name)
    buffer-file-name))

That can be easily generalized:

(defun kill-new-string-variable (variable)
  "Make the string value of VARIABLE the latest kill in the kill ring."
  (interactive (let ((current-buffer (current-buffer)))
                 (intern (completing-read "Variable: " obarray
                                          (lambda (symbol)
                                            (with-current-buffer current-buffer
                                              (and (boundp symbol)
                                                   (stringp
                                                    (symbol-value symbol)))))
                                          t))))
  ;; Let symbol-value and kill-new signal errors for unbound variables
  ;; and non-string values, respectively:
  (kill-new (symbol-value variable)))

(defun kill-new-buffer-file-name ()
  (kill-new-string-variable 'buffer-file-name))

--
Kevin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]