> Of course, if you want, you can have a simple shell script that tests to
> see if there is an already running emacs, and either start a new one, or
> attach to an existing one:
> #!/bin/csh -f
> gnudoit "(make-frame)"
> if ( ! ( $status == 0 ) ) then
> xemacs &
> The script for what would be $EDITOR would be a little more complex, but
> still doable. Of course, just never shut down emacs.
gnuclient to be a little heavy and awkward, given that
I just wanted to open another xemacs frame. I wrote this
shell script a little while ago, and find it much more
convenient (although YMMV). I called the script "x" for
convenience, and include it (with a simple test) in my
.profile. (Note: this was written for ksh, but should be
easy to convert).
The script works like this:
If you run "x" with no arguments, it will do one of
- If no server is currently running, it will start
one iconified (perhaps not mapping the frame
would be better).
- If a server *is* running, a new frame will be
created displaying the current buffer.
If you provide arguments to "x", it will first
start a server if one doesn't exist. It will then
treat each of the arguments as a filespec and open
them in reverse order, so that the first one presented
is the first one specified on the command line, etc.
You must explicitly kill buffers. Also, the C-x C-c
sequence has been re-mapped to delete-frame, so that
using "x" is similar to using a lightweight editor.
The "vi" oriented people here appreciate this, since
they aren't used to leaving an editor running.
The script contains a reference to "do-gnuserv", a simple
function that I placed in site-start.el:
;; Start Xemacs server
(defun do-gnuserv ()
"Perform operations to establish Xemacs server"
(global-set-key '[(control x) (control c)]
I'm not the most proficient shell programmer, so my
apologies to those who are!
# x - shell script to use server functionality of Xemacs
gnuclient -q 2>/dev/null
ServerStarted=$? # get rc of last command
# Start xemacs server if not done already
if [ ServerStarted -eq 0 ] ; then
# server has already been started
if [ Args -eq 0 ] ; then
# no arguments, so open new frame
echo "New Frame"
gnudoit -q "(new-frame)"
# start the server and wait for it to accept requests
echo "Starting XEmacs server\c"
xemacs -iconic -f "do-gnuserv" >/dev/null&
until gnuclient -q 2>/dev/null; do
echo "XEmacs server started"
if [ Args -ne 0 ] ; then
# invoke client application to edit file(s)
echo "xemacs "$*" &"
# Get file names in reverse order
while [ $1 ]; do
if [ "$2" = "" ]; then
# Open the last file in another frame
gnudoit "(find-file-other-frame \"$PWD/$1\")" >/dev/null
# Find the rest of files
for i in $reverse
# Open all remaining files in reverse order
gnudoit "(find-file \"$PWD/$i\")" >/dev/null