How to integrate Firefox and Emacs

Sometimes, when you edit a textarea on a web page (for example, to write a new post on your blog), you would really like to use an external text editor for that.

I personally love Emacs, I’m addicted to its shortcuts and key bindings and I would love to use it, for example, for searching and replacing or for applying macros on the text of a textarea.

Well, it seems someone already thought about this. A Firefox plugin to bind an external editor to your browser is available here. In the following lines, I’ll refer to a Linux environment, but the same procedure, by applying some variants, is possible on Mac, too.

Once installed the plugin and restarted Firefox, you might want to edit some preferences.

First of all, specify the following command to be executed:

/usr/bin/emacsclient

The reason we don’t simply trigger the emacs command, but we use emacsclient instead is that, if we have an Emacs session open, we would like to attach to that one, so we could easily move between Emacs buffers (thanks to Magnus for this suggestion).

Before this can actually work, though, we need to start a daemon on Emacs. To do so, just open Emacs and do the following:

M-x customize-option

Variable name: server-mode

Click on toggle

Save for future sessions

Finish

Optionally (and I would strongly advise you to do so), you can bind the trigger of the external editor to a shortcut. I personally use the following: