The Lumber Room

"Consign them to dust and damp by way of preserving them"

Editing TEXTAREAs in an external editor

with 2 comments

For many people today, much more text editing happens in TEXTAREA forms than elsewhere, as observed here. But textareas have many problems — they don’t have all of the features your favourite editor has; it’s easy to lose text permanently (browser crash, or some confusion with undo operations, etc.); can’t save what you type for safekeeping, ….
The solution, of course, is to use your own external editor for entering text into textareas. Typing it somewhere and pasting it into the textarea is clumsy (and what happens when you decide to edit some more?). Fortunately, there are solutions which (promise to) work seamlessly:

  1. The ViewSourceWith firefox extension. This is what I use was using, and it works well. Despite its name (and all the things it can do), I suspect that this extension is primarily used for editing textareas :-)
  2. The It’s all text firefox extension. Haven’t used this myself.
  3. The MozEx firefox extension. Actually, this works only with Firefox 0.7–0.9; try the one at its homepage. I had tried this a while ago, and I vaguely remember there were some problems. It may have been fixed now, though.
  4. The Editus Externus firefox extension. Never heard of it before today. Doesn’t work on Firefox 2.
  5. The EmbeddedEditor extension. Experimental, works with Linux only.
  6. There’s also the Xinha here firefox extension, which starts a particular editor (“Xinha”) each time, but I think it’s pointless to learn one more entirely new editor, with probably its own set of limitations.

To use Emacs with any of these, simply set the external editor to use Emacs as a server, i.e. EmacsClient. (You could also set it to use emacs instead of emacsclient, but that would start a new instance of Emacs each time.)

There’s also an amazingly clumsy clever hack, which might work far better than anything else if you’re on X: a script called external-edit. (The Windows version external.exe is here.) This promises much, much more: being able to call an external editor from anywhere, not just Firefox. It works by getting the ID of the window with focus, simulating keypresses that correspond to those for Select All and Copy (so that the contents of the textarea get pasted into clipboard), creating a file with the contents of the clipboard, invoking your editor on the file and waiting for it to exit, moving file’s contents to clipboard, and generating the keystroke for Paste. Clever. Hack.
I haven’t tried the Windows version of course, but the Linux version is buggy (at least, I couldn’t get it to work directly). After much effort and a long time (that’s because I’m an idiot, not because there was much to change), I think I’ve fixed it. I’ve tested it on {GNOME,KDE}×{Firefox,Konqueror,Opera}×{emacs,emacsclient,gvim -f,gedit,kate}. You can get it here.
Simply set up a keystroke to invoke (say) “external-edit emacsclient”, and no matter where you’re typing something, if you suddenly decide you want to do it in Emacs, just hit the key. Nothing could be better :-)

About these ads

Written by S

Fri, 2006-12-29 at 02:09:10 +05:30

Posted in compknow

2 Responses

Subscribe to comments with RSS.

  1. Hi,
    thanks for patching this program! It works well, but only with window managers that support EWMH because wmctrl otherwise won’t work. This happens e.g. with ctwm that I’m using. But you can use the program “xwit” instead of wmctrl, although this won’t warp between workspaces (at least not in ctwm). But as long as your browser and your editor are in the same workspare, you can use external-edit with xwit and ctwm.

    cu,
    Frank

    Frank Steiner

    Wed, 2008-04-30 at 08:25:41 +05:30

  2. Hi Frank,
    Thanks for the note. xwit looks useful… but I’m currently using a Mac :-) So I might try it when I’m using X for long periods again.

    Shreevatsa

    Wed, 2008-04-30 at 21:38:23 +05:30


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 68 other followers