Friday, December 23, 2022

CLCL Customization for Emacs

Way back in 2017 I wrote an introduction to CLCL1, the clipboard manager that I prefer.  That post described how to add the supplementary Edit tool.  Today I’ll describe how to make CLCL work with Emacs.

By default, CLCL is set up to “listen” to the keystrokes Ctrl-x and Ctrl-c for pushing a selection to its stack of clipboard items, and Ctrl-v for popping the latest item into the focused application.  But Emacs’ standard keystrokes are Ctrl-w for “cutting,” Alt-w for “copying,” and Ctrl-y for “pasting.”  The terms “cutting,” “copying,” and “pasting” are in quotations because Emacs uses “killing” for “cutting” and “yanking” for “pasting.”2   And the keystrokes are described in Emacs-speak as C-w and C-y respectively.  The Emacs function “kill-ring-save” is like copy; it’s bound to M-w on my system.3

Anyway, to get a CLCL item yanked into the Emacs buffer, I add the Ctrl-y keystroke to CLCL.  You can do this on the Key tab of the Options dialog while Emacs is open.  Here's how.

Click the Add... button and scroll the Present Window List until you find a row whose title matches the text in the title bar of your Emacs application.  For me, that’s “GNU Emacs 25.2.1: *scratch*”, which is shown highlighted below.  Select that line and then click the down arrow button (or just double-click the line) to transfer the settings into the edit portion of the dialog box.


The Emacs title bar may include the name of the buffer.  In my example, that’s “*scratch*.”  But since the buffer name will vary, we need to replace it with the asterisk wildcard.

Click in the textbox below Copy and press Ctrl-w.4  Likewise, click in the textbox below Paste and click Ctrl-y.  The dialog should look similar to the one below.  Note that CLCL shows uppercase versions of W and Y in the Copy and Paste boxes; if you had pressed Ctrl-Shift-W it would display Ctrl + Shift + W instead.  OK your way out.


Now when you choose an item from CLCL while visiting a buffer in Emacs, it will be yanked into the buffer as expected.

Do you have a CLCL tip that you’d like to share?  Please let me know.  Add a comment below or email me.


1 https://ludditegeek.blogspot.com/2017/11/introduction-to-clcl-tools.html

2 And to further confuse the issue, Emacs maintains it own “clipboard” which is called the “kill ring.”  Somehow, Emacs on Windows will yank from the Windows clipboard or yank from its kill ring depending on which was modified last.

3 Please see https://www.emacswiki.org/emacs/CopyAndPaste for more details.

4 Actually, configuring Copy not not be necessary.  Emacs on Windows seems to kill to the Windows clipboard, and CLCL adds each new clipboard item to its stack.

No comments: