Emacs: Append/Clear Register 1 🚀

By Xah Lee. Date: . Last updated: .

This command lets you append text to register 1 and clear text in register 1.

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

put this in your Emacs Init File:

(defun xah-append-to-register-1 ()
  "Append current line or selection to register 1.
When no selection, append current line, with newline char.

See also:
`xah-copy-to-register-1'
`xah-append-to-register-1'
`xah-paste-from-register-1'
`xah-clear-register-1'

URL `http://xahlee.info/emacs/emacs/emacs_copy_append.html'
Version: 2015-12-08 2020-09-08 2023-04-07"
  (interactive)
  (let (xp1 xp2)
    (if (region-active-p)
         (setq xp1 (region-beginning) xp2 (region-end))
      (setq xp1 (line-beginning-position) xp2 (line-end-position)))
    (append-to-register ?1 xp1 xp2)
    (with-temp-buffer (insert "\n")
                      (append-to-register ?1 (point-min) (point-max)))
    (message "Appended to register 1: [%s]." (buffer-substring-no-properties xp1 xp2))))

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

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-copy-to-register-1'
`xah-append-to-register-1'
`xah-paste-from-register-1'
`xah-clear-register-1'

URL `http://xahlee.info/emacs/emacs/elisp_copy-paste_register_1.html'
Version: 2015-12-08 2023-04-07"
  (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 Keys: Define Key]

Emacs Copy/Paste