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"
  (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"
    (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

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode

ELisp Examples

Xah Commands

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples