[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [h-e-w] Want a hybrid of traditional Emacs and EmacsW32

From: Mark Ludwig
Subject: Re: [h-e-w] Want a hybrid of traditional Emacs and EmacsW32
Date: Sun, 13 Apr 2008 14:46:44 -0500
User-agent: Thunderbird (Windows/20080213)

Jason Rumney wrote:
Mark Ludwig wrote:
I can get emacsclient/emacsserver to work for "Edit with Emacs" once Emacs is running, but can't get it to start the first time. How do I do this? Can EmacsW32 be configured to leave the keyboard alone? I know it's confusing -- and even occasionally find myself scrolling forward when I want to paste -- but I use Emacs on UNIX for work, too, so my fingers mostly know the original key bindings.

(The solution to starting Emacs the first time using emacsclient/emacsserver on UNIX leverages the ALTERNATE_EDITOR environmental variable, a concept that does not exist on Windows, as far as I know.)

ALTERNATE_EDITOR works on Windows. Set it to runemacs.exe to avoid the console window popping up when emacs is started.
Right, and I felt like a complete idiot the instant I got a response about how to set an environmental variable on Windows (which I know how to do all too well). I'd obviously not been thinking clearly, because I somehow got the wrong impression about the support for an alternate editor; I thought it was limited to UNIX, because it was in a shell script, and of course it works on all platforms, because it's part of the EmacsClient program distributed with Emacs 22.

To wrap this up, here's what I ended up doing. I kept my original minimalist installation of Emacs 22.1 (not EmacsW32), and hacked the Registry to add an "Edit with Emacs" option on the context menu that uses something like the following command:

C:\...\emacs-22.1\bin\emacsclientw.exe -n -a C:\...\emacs-22.1\bin\runemacs.exe "%1"

(Hopefully obvious, but "C:\..." is not really the installation directory where I installed Emacs 22.1.)

In other words, I used the "-a" option instead of the ALTERNATE_EDITOR environmental variable.

Another detail: The emacsclientw program throws up an error dialog box when it can't make contact with EmacsServer. The error complains "connect: Result too large" and is apparently from a network error. One must click "OK" before it invokes the alternate editor -- very annoying. I worked around this by using emacsclient (instead of emacsclientw), and further worked around the necessary console window by using NirCmd ( to invoke "emacsclient" without showing a console window. Thanks to someone who anonymously documented his/her use of NirCmd in the EmacsWiki (

In addition to the "Edit with Emacs" entry, I further hacked the Registry to associate this with the .txt (Text) file type. This being Windows Vista, I did it in two steps: first lying to the GUI by telling it to use emacsclientw.exe directly, then finding "emacsclientw.exe" in the Registry and substituting my much more complicated command line. The way the file type association is represented in the Registry has a level of indirection to an "open" command for "emacsclientw.exe" (which I also cloned under an "edit" command for "emacsclientw.exe" modeled on edit for "notepad.exe"), so this works well to let me associate any number of other file types with Emacs and they all get the same treatment.

All together this is the form of the command:

"C:\...\NirCmd\nircmd.exe" exec hide "C:\...\emacs-22.1\bin\emacsclient.exe" -n -a C:\...\emacs-22.1\bin\runemacs.exe "%1"



"I didn't care where Hemingway drank or Alice B. Toklas had her moustache trimmed."
-- David Sedaris, touring Paris

reply via email to

[Prev in Thread] Current Thread [Next in Thread]