At the office about 95% of all work I do is on unix machines,
inside of emacs. Inside of emacs, I do most of my command-line work,
SQL connections to sybase, I do my IRCing, I send email, and of course
I edit and compile code in emacs as well. Typically I have between
twenty to fifty buffers open at any given time.
But I sit by a windows machine. I have to use putty to connect to
my primary development machine, where I commence with starting emacs
which opens a window on my local machine under Hummingbird's X
server.
The problem with this is that after a couple of days (or hours!) I
forget which putty session spawned the emacs I'm sitting
with. Inevitably I end up hitting ctrl-d to close the window, and it
then... just hangs there, waiting for all daughter processes to
die. And emacs proudly floats there on my screen, with all my open
files, notes, running programs and sql sessions.
And I don't want to close it. But the hanging putty window is
there, in my taskbar, taunting me. What to do?
I realized that I wanted to be able to start emacs on a remote
machine without first opening a putty session. I wanted the windows
equivalent of
ssh -XY remotemachine.foo.com "emacs --eval \(server-start\)"
.
Here's what I did.
- First I made sure that pageant was running, and that it had my
private key loaded. I made sure that it was auto-started by windos
when I logged in.
- Next I created a putty session which contained the configurations
necessary for X11 tunnelling etc, gave it a name 'remoteSession'.
- Now I created a .bat script which contained the following:
REM Startup emacs on remote machine
plink -X -A -agent -load remoteSession -l my_username ". .bash_profile ; emacs --eval \(server-start\)"
This script will, when run, connect to the remote machine and start up emacs as a server. I source .bash_profile since I have some environment settings there, yhou might not need it.
- The thing is, the previous step works, but it leaves an ugly windows commandprompt window which just... well hangs there. If there's something that bugs me more than a useless putty session window, its the worlds ugliest shell. So I wrote a VBscript which starts the .bat script, but without a window.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "c:\mattias_progs\devapp_emacs_server.bat" &
Chr(34), 0
Set WshShell = Nothing
- Finally I made a shortcut to the vb script into my start menu, so that I could fire it up at will.
Its a very small improvement, but it makes everything a little easier.