#!/bin/sh
# This script launches emacs using the emacsclient program.
# If necessary, emacs is started

. `dirname $0`/Config

echo USE_CLIENT=$USE_CLIENT

if [ -z "$USE_CLIENT" ] ; then
    emacs "$@"
else
    if [ -n "$USE_GNUCLIENT" ]; then
	start_server="-eval '(gnuserv-start)'"
	client="gnuclient -q"
        else
	    start_server="-eval '(server-start)'"
	    client="emacsclient -n"
        fi

	if [ -z "$1" ] || ! $client "$@" 2>/dev/null ; then
	    eval emacs $start_server "$@"
	fi
fi
