tags:

views:

101

answers:

4

How can I make an emacs command to copy text (to the kill ring) by appending? (Why is there no such built-in command?)

Appending Kills mentions C-M-w (`append-next-kill') which allows me to append with kill commands such as C-d or C-k. But it's for killing texts instead of copying them.

+1  A: 

Can append-to-register meet your needs?

pc1500
+1  A: 

Play with a variation of this in your .emacs file...

(defun append-kill-line (&optional arg)
  "Append kill-line to current kill buffer, prefix arg kills from beginning of line."
  (interactive "P")
  (append-next-kill)
  (kill-line arg)
)

(define-key global-map "\C-x\C-m" 'append-kill-line)
Don
+4  A: 

Actually, there is such a built in command. C-M-w will append a subsequent copy as well as a kill. So you would mark the region you desire to copy, then type C-M-w followed by M-w and the next C-y will yank the joined kills.

pajato0
A: 

The various kill commands use a little trick to decide whether or not to append. If the previous command is the same as the current command, it will append; if not, it doesn't. The functions use the value of last-command to do this, and manipulating this value is key to getting what you want.

(defun copy-region-as-kill-append (beg end)
  (interactive "r")
  (let ((last-command 'kill-region))
    (copy-region-as-kill beg end)))
Joe Casadonte