Emacs Lisp: Cut Copy Paste, kill-ring
Emacs kill-ring stores users copy/paste data.
This page shows you how to use te kill ring.
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 Emacs Lisp: 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
;; 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 (yank)
Mark a Region
To mark a region, do
(push-mark positon nil t)(make the region active)
The current cursor positon to positon will become the new region.
[see Emacs Lisp: Region, Active Region]
(defun my-select-text-in-quote () "Select text between the nearest left and right quotes." (interactive) (let ((xskipChars "^\"")) (skip-chars-backward xskipChars) (push-mark (point) t t) (skip-chars-forward xskipChars)))
The Kill Ring (ELISP Manual)