Hattuari <[EMAIL PROTECTED]> writes:
> Is there a clean way to get Emacs to start as a client when there is an
> available server? I find it moderately annoying to have to look around to
> see if there is already an instance of Emacs started in order to determine
> if I should enter `emacs' or `emacsclient'. I much prefer running
> emacsclient when I already have one instance of Emacs running. One option
> is to try and sniff for emacs with ps and filter out the current processes
> such as grep emacs, and (assuming the script I'm running is also called
> emacs) the launch script. It would seem more correct to directly check to
> see if the service is available. Is there such a capability?
I use the following, which I call '$HOME/bin/e'. I use it as follows:
$ e # opens a window
$ e foo.sh # opens an old or new file
$ e foo.sh:23 # opens foo.sh at line 23
I never have to think if emacs is already loaded or not. Hope it
helps.
#!/bin/sh
EMACS=emacs
if [ -z "$DISPLAY" ]
then
$EMACS ${1+"$@"}
else
if emacsclient --eval "(setenv \"DISPLAY\" \"$DISPLAY\")" >/dev/null 2>&1;
then
if [ $# -eq 0 ]; then
emacsclient --eval "(make-frame-on-display \"$DISPLAY\")"
elif [ $# -lt 10 ]; then
for f in $@; do
# handle file.h:234 paths
echo $f | egrep ".*:[0-9]+$" >/dev/null
if [ $? -eq 0 ]; then
emacsclient -n `echo $f | sed 's/\(.*\):\([0-9]\+\)$/+\2/'`
`echo $f | sed 's/\(.*\):\([0-9]\+\)$/\1/'`
else
emacsclient -n $f
fi
done
else
echo "`basename $0`: ERROR, opening $# files would take too long"
fi
else
emacs ${1+"$@"} &
fi
fi
--
Benjamin Rutt
_______________________________________________
Help-gnu-emacs mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs