From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Benjamin Rutt Newsgroups: gmane.emacs.help Subject: Re: automatic selection of emacsclient/emacs? Date: Sun, 12 Jun 2005 20:28:23 GMT Organization: Road Runner High Speed Online http://www.rr.com Message-ID: <87oeabz5eg.fsf@penguin.brutt.org> References: <2cydneqEPbdzxTvfRVn-uw@speakeasy.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1118607960 18074 80.91.229.2 (12 Jun 2005 20:26:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 12 Jun 2005 20:26:00 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 12 22:25:52 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DhZ1N-00033t-87 for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Jun 2005 22:25:29 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DhZ61-0004NE-7S for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Jun 2005 16:30:17 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news3.google.com!news.glorb.com!hwmnpeer01.lga!hwmedia!news-server.columbus.rr.com!tornado.ohiordc.rr.com.POSTED!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help Mail-Copies-To: nobody User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/22.0.50 (gnu/linux) Cancel-Lock: sha1:ORA+nRMH4mAKtlQdOfRtQHZ7eFs= Original-Lines: 55 Original-NNTP-Posting-Host: 65.25.157.254 Original-X-Complaints-To: abuse@rr.com Original-X-Trace: tornado.ohiordc.rr.com 1118608103 65.25.157.254 (Sun, 12 Jun 2005 16:28:23 EDT) Original-NNTP-Posting-Date: Sun, 12 Jun 2005 16:28:23 EDT Original-Xref: shelby.stanford.edu gnu.emacs.help:131965 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:27435 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:27435 Hattuari 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