unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Benjamin Rutt <rutt.4@osu.edu>
Subject: Re: automatic selection of emacsclient/emacs?
Date: Sun, 12 Jun 2005 20:28:23 GMT	[thread overview]
Message-ID: <87oeabz5eg.fsf@penguin.brutt.org> (raw)
In-Reply-To: 2cydneqEPbdzxTvfRVn-uw@speakeasy.net

Hattuari <susudata@setidava.kushan.aa> 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

      parent reply	other threads:[~2005-06-12 20:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-08  2:32 automatic selection of emacsclient/emacs? Hattuari
     [not found] ` <2cydneqEPbdzxTvfRVn-uw-zY4eFNvK5D9If6P1QZMOBw@public.gmane.org>
2005-06-08  7:56   ` Jochen Küpper
2005-06-08  8:00 ` Thorsten Bonow
2005-06-08  9:17 ` David Kastrup
2005-06-12 14:29 ` Dan Elliott
2005-06-12 18:19   ` Floyd L. Davidson
2005-06-13 15:29   ` Drew Adams
2005-06-13 18:27   ` kgold
2005-06-12 20:28 ` Benjamin Rutt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oeabz5eg.fsf@penguin.brutt.org \
    --to=rutt.4@osu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).