Emacs command to add to ring

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

Adding Kill mentions CMw (`append-next-kill '), which allows me to add kill commands such as Cd or Ck. But this is for killing texts instead of copying them.

+5
source share
4 answers

Actually, there is such a built-in command. C-M-wwill add a subsequent copy as well as kill. Thus, you mark the region you want to copy, then enter C-M-w, and then M-w, and the next C-ywill destroy the combined killings.

+6

.emacs...

(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)
+3

?

+2

Various kill commands use a little trick to decide whether to add or not to add. If the previous command matches the current command, it will add; if not, it is not. Functions use a value for this last-command, and manipulating that value is the 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)))
+1
source

All Articles