A few years ago I mentioned that I use Textern so that I can easily edit input boxes and text areas in Emacs. While I still use it, it seems less and less great. More and more web apps do crazy JavaScript things with their input
s and textarea
s, and they sometimes interfere with Textern in unpredictable ways.
Recently, I found something similar but possibly better: Emacs everywhere. One of its advantages is that it works, well, everywhere in X.org, not only in Firefox. (I’m not sure how, but it supposedly also works on Macs. Maybe they use X.org, too? I don’t know.) At first it seemed to me that it doesn’t matter much – I hardly ever use anything but Emacs and Firefox. Then it dawned on me: Emacs everywhere works in the terminal, too! (You may be surprised that I don’t use Eshell or at least M-x term
. Well, I don’t. Old habits die slowly, plus I am a tad paranoid and I’m slightly afraid of my Emacs (or more probably, some rogue package) doing something unpleasant like saving sessions or my keypresses to the disk. Since I often type various passwords in the terminal, I’d prefer this not to happen.
The way Emacs everywhere does its job is (at least conceptually) pretty simple. It spawns an Emacs frame, creates an empty buffer, inserts the primary selection into it if it exists, and lets me edit the buffer. When I’m done, I can press C-c C-c
and Emacs everywhere pastes what I’ve written into the program that was running before I started it. (In fact, there is a bit more to that. You can also press C-c C-k
to cancel, and DEL
(that is, backspace
) as the first keypress deletes everything.)
I made a few quick experiments with various nasty apps like Jira and Discord, and Emacs everywhere seems to work very well! I also wrote a short script to launch it, emacs-everywhere.sh
:
#!/bin/bash emacsclient --eval "(emacs-everywhere)"
and bound it to s-e
(that is, Super-e
) in my window manager of choice:
globalkeys = gears.table.join( -- Emacs everywhere awful.key({ modkey, }, "e", function() awful.util.spawn("emacs-everywhere.sh") end), -- Emacs everywhere ends here -- ... )
Now, the only thing left is that I need to remember to press s-e
to edit anything in Emacs – unlike Textern, Emacs everywhere does not (and cannot) put the “current” content of whatever I’m editing in the Emacs buffer it creates. (Technically, it could simulate pressing C-a C-x
which in many applications means “mark everything and kill” (or “select all and paste”, as the youth of today calls it), but that would break e.g. in a terminal.) In fact, even if I forget about it, I can for example select everything with C-a
(in Firefox at least), and then the selected text will get copied to the Emacs everywhere buffer – and when it gets pasted again, the selection will still be active (unless I deactivated it manually), so what I wrote in Emacs will effectively replace what I had earlier. Very nice!
That’s it for today, see you next week!