Emacs: Copy Append Text

By Xah Lee. Date: . Last updated: .

This command lets you copy text and append it to register 1.

Everytime this command is called, current line (or selected text) is appended to register 1.

Then, you can paste the collected text in another place.

To paste the collected text, Alt+x insert-register

(defun xah-append-to-register-1 ()
  "Append current line or text selection to register 1.
When no selection, append current line, with newline char.
See also: `xah-paste-from-register-1', `copy-to-register'.

URL `http://ergoemacs.org/emacs/emacs_copy_append.html'
Version 2015-12-08 2020-09-08"
  (interactive)
  (let ($p1 $p2)
    (if (use-region-p)
         (setq $p1 (region-beginning) $p2 (region-end))
      (setq $p1 (line-beginning-position) $p2 (line-end-position)))
    (append-to-register ?1 $p1 $p2)
    (with-temp-buffer (insert "\n")
                      (append-to-register ?1 (point-min) (point-max)))
    (message "Appended to register 1: 「%s」." (buffer-substring-no-properties $p1 $p2))))

This command need to have a easy key to be useful. I recommend Alt+2. [see Emacs: How to Define Keys]

See also: Emacs: 1 Key to Copy/Paste from Register

Clear Register 1

With append to register 1, sometimes you need to clear it first.

Here's command to clear register 1.

(defun xah-clear-register-1 ()
  "Clear register 1.
See also: `xah-paste-from-register-1', `copy-to-register'.

URL `http://ergoemacs.org/emacs/elisp_copy-paste_register_1.html'
Version 2015-12-08"
  (interactive)
  (progn
    (copy-to-register ?1 (point-min) (point-min))
    (message "Cleared register 1.")))

This command need to have a easy key to be useful. I recommend Alt+1. [see Emacs: How to Define Keys]

Emacs Copy/Paste

Put $5 at https://www.patreon.com/xahlee , or goto paypal.com and pay to Xah@XahLee.org . Message me on XahLee discord, say so, ask me questions.
Or Buy Xah Emacs Tutorial

Xah Emacs Commands

buffer

file

edit

edit brackets

copy paste

whitespace

reformat

misc