theclapp

Search theclapp.blog-city.com

 

Emacsclient / gnuclient for Lispworks

posted Monday, 18-Jun-2007
Emacsclient / gnuclient allow you to run a shell command and make an existing Emacs session read the file (or files?) listed on the command line.

Lispworks, of course, allows multiple "green" threads, and they have a convenient function already written that forks a listener running on a socket. I leveraged this to implement what I call "lwclient".

Put this in your $HOME/.lispworks:

;; Arrange for LW to start a Listener server once multiprocessing gets going.
;; Used by lwclient.
(push (list "start-lwserver"
nil
(lambda ()
(comm:start-up-server :service 65000
:address "localhost"
:process-name "lwserver")))
mp:*initial-processes*)

And put this in $HOME/bin/lwclient:

#!/usr/bin/zsh

(
echo "lwclient$RANDOM"
echo "(progn "
for f in "$@" ; do
if [[ $f = /* ]] ; then
echo "(editor:find-file-command nil #p\"$f\")"
else
echo "(editor:find-file-command nil #p\"$PWD/$f\")"
fi
done
echo ")"
) \
| nc -q 1 localhost 65000 \
> /dev/null

(Later I'll rewrite lwclient in actual Lisp, using the lw-console command I mentioned here.)

I even aliased "vi" to call "lwclient" instead:

function vi {
lwclient "$@"
}
Usage example:
lwclient some_file

# or using my above alias
vi some_file

To use this, the Lispworks IDE has to be running, of course, and (at the moment) you need netcat (the "nc" command).

To invoke the real "vi", use "vim" (or whatever editor you used to use).

Caveat: If you ssh to your machine (and LW is already running there), use "vim" to run the real vim, otherwise Lispworks will happily pop up a window on your remote machine and your shell will look like this:

% vi some_file
%
and you'll smack yourself on the forehead and get a concussion.

And, in case you're a total neophyte, I'll also point out Caveat 2: This allows anyone with an account on your machine to run arbitrary code under your ID. Use with caution.

Update 6/20/07: See here for an updated version of lwclient.

tags:          

links: digg this    del.icio.us    technorati    reddit




1. Stéphane Perrot left...
Tuesday, 19-Jun-2007 7:34 am

Great, works fine (linux, lw 5.0.2)

I had always wanted a hack like this, never took the time to implement it... thanks !