help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting if the Emacs server is running


From: PJ Weisberg
Subject: Re: Detecting if the Emacs server is running
Date: Fri, 18 Mar 2011 00:38:29 -0700

On Thu, Mar 17, 2011 at 11:47 PM, Deniz Dogan <address@hidden> wrote:
> 2011/3/18 PJ Weisberg <address@hidden>:
>> Is there a way, in GNU/Linux, to detect whether Emacs is running in
>> server mode from a shell script?
>>
>> I'd like to write a script that creates a new frame with emacsclient
>> if the user is already running an emacs server, but just starts up a
>> regular Emacs instance if he isn't.
>>
>
> See e.g. (info "(emacs) emacsclient Options").
>
>   The other optional arguments recognized by `emacsclient' are listed
> below:
>
> `-a COMMAND'
> `--alternate-editor=COMMAND'
>     Specify a command to run if `emacsclient' fails to contact Emacs.
>     This is useful when running `emacsclient' in a script.  For
>     example, the following setting for the `EDITOR' environment
>     variable will always give you an editor, even if no Emacs server is
>     running:
>
>          EDITOR="emacsclient --alternate-editor emacs +%d %s"
>
>     As a special exception, if COMMAND is the empty string, then
>     `emacsclient' starts Emacs in daemon mode and then tries
>     connecting again.
>
>     The environment variable `ALTERNATE_EDITOR' has the same effect as
>     the `-a' option.  If both are present, the latter takes precedence.
>
> --
> Deniz Dogan
>

Ok, I guess I wasn't clear.  I actually want to do MORE than just make
a new frame. :-)  Say I run this command:

emacsclient -a emacs -e "(progn (select-frame (make-frame-on-display
\"$DISPLAY\")) (insert \"Hello, world!\"))"

If emacs is running in server mode it does what I wanted (make a
frame, select it, run some elisp), but if emacs isn't running in
server mode, I find myself editing a new file named '(progn
(select-frame (make-frame-on-display ":0.0")) (insert "Hello,
world!"))'

Any thoughts on a better way I could go about this?

Thanks,
PJ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]