Emacs: Copy Append Text

By Xah Lee. Date: .

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/elisp_copy-paste_register_1.html'
Version 2015-12-08"
  (interactive)
  (let ($p1 $p2)
    (if (region-active-p)
        (progn (setq $p1 (region-beginning))
               (setq $p2 (region-end)))
      (progn (setq $p1 (line-beginning-position))
             (setq $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

Copy/Paste Topic

  1. Emacs: Copy/Paste and kill-ring History
  2. Emacs: Copy/Cut Current Line If No Selection
  3. Emacs: Copy/Cut All or Selection
  4. Emacs: Paste or Paste Previous
  5. Emacs: Show kill-ring
  6. Emacs: Copy to Register
  7. Emacs: 1 Key to Copy/Paste from Register
  8. Emacs: Copy Append
  9. Emacs: Copy Rectangle Region to kill-ring
  10. Emacs: Sync Copy/Paste Clipboards with Linux X11
Liket it? Put $5 at patreon. Or Buy Xah Emacs Tutorial. Thanks.