ELisp: Cut Copy Paste, kill-ring

By Xah Lee. Date: . Last updated: .

Emacs kill-ring stores users copy/paste data.

Normally, you should not modify the kill-ring, unless your command is designed to put something in there for user. If you want to store some text, store them in a local variable [see ELisp: Variable]

Copy Region to Kill Ring

;; push text between buffer positions to kill-ring
(copy-region-as-kill 1 100)

Kill Region to Kill Ring

;; delete text between buffer positions and push to kill-ring
(kill-region 247 528)

String to Kill Ring

If you already have a string, use kill-new

;; push a string into kill-ring
(kill-new "cute cat")

Append String to Kill Ring

;; append string to the latest in kill-ring
(kill-append "cute cat" nil)
;; if second arg is t, do prepend

Paste from Kill Ring

;; paste from kill-ring

Mark a Region

To mark a region, do

The current cursor positon to positon will become the new region.

[see ELisp: Mark, Region, Active Region]

(defun my-select-text-in-quote ()
  "Select text between the nearest left and right quotes."
  (let ((xskipChars "^\""))
    (skip-chars-backward xskipChars)
    (push-mark (point) t t)
    (skip-chars-forward xskipChars)))