Categories

Author

Emacs-friendly Firefox

February 23, 2007 — jao

When i use Firefox, there’s nothing more annoying than editing a textarea. On a Mac, one has at least some Emacs-like shortcuts. Incomprehensibly, on GTK+ 2.0 Emacs shortcuts are no longer the default, and one has to put something like

include "/usr/share/themes/Emacs/gtk-2.0-key/gtkrc"

in ~/.gtkrc-2.0 to restore a minimum of sanity.

But still, what i really want is to edit those textareas using the real thing. I just stumbled upon the answer to my prayers: It’s All Text! is a Firefox add-on that provides an edit button on any text box. You click on it and, the first time, you’re asked for your editor of choice. As you’ll notice, the default option is wrong. Change it by /usr/bin/emacsclient (Emacs 21 users may use gnuclient instead), and don’t forget to start the Emacs server with (server-start) somewhere in your initialisation file.

Better, no?

Update: Well, things can be even better, as pointed out by Victor below. The Mozex extension lets you not only edit textareas, but also assign shortcuts, view sources or choose the editor for mailto URLs. For some reason, using just emacsclient -e '(compose-mail "%a" "%s")' didn’t work for me, so i’ve created a simple shell script, gnumail:

#!/bin/sh
exec emacsclient -e "(compose-mail \"$1\" \"$2\")"

and told Mozex to use it. Don’t forget to set the variable mail-user-agent to something reasonable (for instance, since i use Gnus, i’ve got (setq mail-user-agent 'gnus-user-agent) in my configuration files).

You might find mozex more convenient, since you can configure it t o use Emacs not just to edit text areas, but also to view sources. Moreover, you can configure a shortcut to activate it, so as soon as you are confronted with a text area, hit your shortcut and listo! you in Emacs.

[…] This Firefox extension called “It’s All Text!” might be the best thing since sliced bread: it adds an “Edit” button to any textarea component which, when clicked, opens your favourite text editor. […]

You should also look at the FireFox “View Source With” extension. You can set it to launch Emacs whenever you Ctrl-U. If you’re in a textbox, it will bring Emacs up with the box text. Otherwise, you get the page source. A nice thing about that when you’re working on something locally is that it brings up the actual source file for the page and you can change it, save then reload in FireFox.

Good tip. The mozex extension didn’t seem to work for me on OS X, and the mozex faq claims it’s just an “ugly hack” that needs to go away. I stuck with the All Text extension. I use Carbon Emacs. The extension prefs didn’t allow me to dive into the Emacs.app package to find emacsclient and the text field was read-only, so I performed the following:

1) Open about:config in Firefox
2) Find the “extensions.itsalltext.editor” key
3) Manually set it to “/Applications/Emacs.app/Contents/MacOS/bin/emacsclient”
4) Make sure (server-start) is in emacs init (of course).

mozev doesn’t escape command strings and appears to have problems with quotes around more than one substitution sequence. here’s another possible gnus command w/o a script, but probably can’t handle more than the subject substitution:

emacsclient -e “(compose-mail (symbol-name ‘%a) “%s”)”

p.s. the ‘debugging messages’ feature under mozex’s preference ‘General’ helps much when composing these incantations

[…] Just noticed this emacs blog. Now as any fool knows, emacs is the one true editor, vi being better suited for editing passwd files or similar, and should never be allowed near code (my colleague Hampus strongly agrees on this point). This is an interesting post too: Emacs-friendly Firefox. […]