Emacs as Word Processor: Copy and Paste

A word processor is distinct from an editor. Editors are for coders. Word processors are for (prose) writers. In either case, plain text is best and formatting is to be kept to a bare minimum, so that e.g. copy and paste across programs would work as expected.

Paste environment

Each program has its own paste environment which affects the results of a paste command. For example, Emacs has a GUI, but can also run in a terminal. The results of pasting in a GUI are vastly different from pasting in a terminal. Moreover, Emacs’ GUI does not quite work as the average Notepad and requires some getting used to.

Anyway, the paste keybind in Emacs is C-y, while M-y can be used many times to cycle through more pastes from the copied history.

Clipboard versus Kill Ring

Emacs has its own isolated (internal) history of copied stuff, which is called kill-ring. To combine the desktop environment clipboard with Emacs’ kill-ring, Emacs’ config file needs the following piece of code:

(setq select-enable-clipboard t)

If you want to see the full history, then Emacs manual recommends C-h v kill-ring which is simply the help function of the kill-ring, including the history of copies.

A more convenient solution for re-pasting is an additional config file called browse-kill-ring.el. To use it as intended:

  1. Download it to your personal emacs config directory (in my case ~/.emacs.d/lisp)
  2. Add the following to the main config file (in my case ~/.emacs.el)

(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'browse-kill-ring)

If the line with add-to-list is already there, do not re-use this line.

When browse-kill-ring function is installed along with (browse-kill-ring-default-keybindings), it gets invoked by M-y, unless the preceding command was C-y. As previously described, C-y stands for paste (“yank” in Emacs’ terminology), which can be followed by M-y to cycle through earlier cut or copied items. But when M-y is not in the yank cycle, it now triggers browse-kill-ring, which is an additional pane with the list of kill ring contents, similar to search occurrences when occur is triggered.

The single setting in =browse-kill-ring.el= file that in my opinion needed changing after installation was browse-kill-ring-show-preview to nil. Otherwise the kill ring item under point gets automatically pre-filled into the buffer, which can be very distracting.

Leave a Reply

Your email address will not be published. Required fields are marked *