Emacs: Copy/Paste from/to Register 1 🚀
Here's a command that lets you copy/paste text to register 1.
put this in your Emacs Init File:
(defun xah-copy-to-register-1 () "Copy current line or selection to 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: 2012-07-17 2022-10-03 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))) (copy-to-register ?1 xp1 xp2) (message "Copied to register 1: [%s]." (buffer-substring-no-properties xp1 xp2))))
Here's paste from register 1:
(defun xah-paste-from-register-1 () "Paste text from 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) (when (region-active-p) (delete-region (region-beginning) (region-end))) (insert-register ?1 t))
You should give them a easy key, such as Alt + 3 Alt + 4. [see Emacs: How to Define Keybinding]
Why the commands?
When you call
{copy-to-register
,
insert-register
},
each time you have to tell it which register to use.
Rather annoying.
[see Emacs: Copy to Register]
Most of the time all you need is one register.
The single key commands
xah-copy-to-register-1
and
xah-paste-from-register-1
by-pass the asking and just use register 1.
This saves you 2 key strokes and a brain cycle.