copy text and name of the buffer
glynn.clements at virgin.net
Thu Feb 5 17:53:15 EST 2004
Uwe Brauer wrote:
> > AFAICT, the main problem with what you are proposing is that killing
> > or copying text (C-w, M-w etc) doesn't keep any record of where the
> > text came from.
> Ups ok, then my attempts do not make sense.
> > Determining the name of a given buffer is trivial, as is determining
> > its associated filename (if it has one). The tricky part is
> > determining exactly *which* buffer you are interested in.
> Ok then in order to get the desired generalisation for the remember
> function, the following kludge may work.
> Since the remember function will be executed in a buffer in which I
> am, I have to pass this name to the remember function.
Actually, I've figured out that kill-hooks could be used for this.
Here's an attempt at the functionality which you're after. It attaches
add-filename-extent to kill-hooks to record the buffer's filename on
an extent which is applied to the killed text, and advises the "yank"
function to retrieve the filename from the extent and insert it into
Use add-filename-activate to activate the behaviour, and
add-filename-deactivate to deactivate it.
(defun add-filename-extent (str)
(let ((ext (make-extent 0 (length str) str)))
(list 'filename buffer-file-name
(defadvice yank (around yank-advice)
(let* ((point (point))
(setq filename (plist-get (extent-properties-at point) 'filename))
(and filename (stringp filename)
(insert-string (format "\n[%s]\n\n" filename))))))
(defun add-filename-activate ()
(add-hook 'kill-hooks 'add-filename-extent)
(defun add-filename-deactivate ()
(remove-hook 'kill-hooks 'add-filename-extent)
Glynn Clements <glynn.clements at virgin.net>
More information about the XEmacs-Beta