unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Daemon and client: Only open new frame if there isn't one already?
@ 2009-03-12 22:52 Hugo Heden
  2009-03-12 23:10 ` Peter Dyballa
  0 siblings, 1 reply; 18+ messages in thread
From: Hugo Heden @ 2009-03-12 22:52 UTC (permalink / raw)
  To: help-gnu-emacs

Good day all,

Is there a way for emacsclient to ask the daemon to make a new frame
(as in window-manager-managed X GUI frame, not a terminal one) only if
there isn't one already running? Presumably by using "--eval" on the
commandline I guess, perhaps something like  ( unless selected-frame
(make-frame) ) ( find-file "myfile.txt" ) ..?

When I am about to open a file (from the bash command line) I often
don't remember whether I have a frame open or not..  If there is one,
I would want the file to be automatically opened there, and otherwise
I would want a new frame to be automatically created.

Any hints appreciated.

Best regards

Hugo Heden

--

I am using a snapshot built for Ubuntu 8.10 20090207 --
https://launchpad.net/~ubuntu-elisp/+archive/ppa
$ emacs-snapshot --version
GNU Emacs 23.0.90.1




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-12 22:52 Daemon and client: Only open new frame if there isn't one already? Hugo Heden
@ 2009-03-12 23:10 ` Peter Dyballa
  2009-03-12 23:44   ` Hugo Heden
  0 siblings, 1 reply; 18+ messages in thread
From: Peter Dyballa @ 2009-03-12 23:10 UTC (permalink / raw)
  To: Hugo Heden; +Cc: help-gnu-emacs


Am 12.03.2009 um 23:52 schrieb Hugo Heden:

> Is there a way for emacsclient to ask the daemon to make a new frame

Have you invoked

	emacsclient --help

Yes, in GNU Emacs 23.0.91 it can!

--
Greetings

   Pete

Experience is what you get when you don't get what you want.






^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one  already?
  2009-03-12 23:10 ` Peter Dyballa
@ 2009-03-12 23:44   ` Hugo Heden
  2009-03-13  5:55     ` thierry.volpiatto
                       ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Hugo Heden @ 2009-03-12 23:44 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: help-gnu-emacs

>> Is there a way for emacsclient to ask the daemon to make a new frame
>
> Have you invoked
>
>        emacsclient --help
>
> Yes, in GNU Emacs 23.0.91 it can!
>

Yes, thanks Peter, I have, but this is not what I want to do:
  "-c, --create-frame Create a new frame instead of trying to use the
current Emacs frame"

What I want is a command line option (or some hacky script ) to
automatically create a new frame only if there is no frame currently
open. If there is a frame already, that frame should automatically be
reused.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-12 23:44   ` Hugo Heden
@ 2009-03-13  5:55     ` thierry.volpiatto
  2009-03-13  9:35     ` Peter Dyballa
  2009-03-13  9:35     ` Eli Zaretskii
  2 siblings, 0 replies; 18+ messages in thread
From: thierry.volpiatto @ 2009-03-13  5:55 UTC (permalink / raw)
  To: help-gnu-emacs

Hugo Heden <hugoheden@gmail.com> writes:

>>> Is there a way for emacsclient to ask the daemon to make a new frame
>>
>> Have you invoked
>>
>>        emacsclient --help
>>
>> Yes, in GNU Emacs 23.0.91 it can!
>>
>
> Yes, thanks Peter, I have, but this is not what I want to do:
>   "-c, --create-frame Create a new frame instead of trying to use the
> current Emacs frame"
>
> What I want is a command line option (or some hacky script ) to
> automatically create a new frame only if there is no frame currently
> open. If there is a frame already, that frame should automatically be
> reused.
Do you mean a frame or an emacs session?
If it's an emacs session, last emacs allow the -a option of emacsclient
empty:
If no emacs process is found, start emacs --daemon and open an
emacsclient frame.

,----
| emacsclient -a "" "$@"
`----


-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-12 23:44   ` Hugo Heden
  2009-03-13  5:55     ` thierry.volpiatto
@ 2009-03-13  9:35     ` Peter Dyballa
  2009-03-13  9:35     ` Eli Zaretskii
  2 siblings, 0 replies; 18+ messages in thread
From: Peter Dyballa @ 2009-03-13  9:35 UTC (permalink / raw)
  To: Hugo Heden; +Cc: help-gnu-emacs


Am 13.03.2009 um 00:44 schrieb Hugo Heden:

> What I want is a command line option (or some hacky script ) to
> automatically create a new frame only if there is no frame currently
> open.

I think this is done via the DISPLAY environment variable in the  
shell where you launch GNU Emacs as daemon. Without $DISPLAY set GNU  
Emacs assumes that it will run as the "client" of some terminal  
emulation (inside of it). When it's set, then it's clear advise to  
launch as an X client. I presume that X11 is running when you log in.  
So DISPLAY is available and set.

--
Greetings

   Pete

Bake pizza not war!







^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-12 23:44   ` Hugo Heden
  2009-03-13  5:55     ` thierry.volpiatto
  2009-03-13  9:35     ` Peter Dyballa
@ 2009-03-13  9:35     ` Eli Zaretskii
  2009-03-13 11:08       ` Hugo Heden
  2 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2009-03-13  9:35 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 13 Mar 2009 00:44:25 +0100
> From: Hugo Heden <hugoheden@gmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
> >> Is there a way for emacsclient to ask the daemon to make a new frame
> >
> > Have you invoked
> >
> >        emacsclient --help
> >
> > Yes, in GNU Emacs 23.0.91 it can!
> >
> 
> Yes, thanks Peter, I have, but this is not what I want to do:
>   "-c, --create-frame Create a new frame instead of trying to use the
> current Emacs frame"
> 
> What I want is a command line option (or some hacky script ) to
> automatically create a new frame only if there is no frame currently
> open. If there is a frame already, that frame should automatically be
> reused.

But the above portion of the emacsclient help message seems to mean
that emacsclient already does what you want by default.  That's why
you need the -c option to override that default and create a new
frame even if one already exist.

Doesn't the default work for you?  Perhaps you should report a bug,
then.






^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one  already?
  2009-03-13  9:35     ` Eli Zaretskii
@ 2009-03-13 11:08       ` Hugo Heden
  2009-03-13 11:20         ` Eli Zaretskii
  2009-03-13 11:39         ` Peter Dyballa
  0 siblings, 2 replies; 18+ messages in thread
From: Hugo Heden @ 2009-03-13 11:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Fri, Mar 13, 2009 at 10:35 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Fri, 13 Mar 2009 00:44:25 +0100
>> From: Hugo Heden <hugoheden@gmail.com>
>> Cc: help-gnu-emacs@gnu.org
>>
>> >> Is there a way for emacsclient to ask the daemon to make a new frame
>> >
>> > Have you invoked
>> >
>> >        emacsclient --help
>> >
>> > Yes, in GNU Emacs 23.0.91 it can!
>> >
>>
>> Yes, thanks Peter, I have, but this is not what I want to do:
>>   "-c, --create-frame Create a new frame instead of trying to use the
>> current Emacs frame"
>>
>> What I want is a command line option (or some hacky script ) to
>> automatically create a new frame only if there is no frame currently
>> open. If there is a frame already, that frame should automatically be
>> reused.
>
> But the above portion of the emacsclient help message seems to mean
> that emacsclient already does what you want by default.  That's why
> you need the -c option to override that default and create a new
> frame even if one already exist.
>
> Doesn't the default work for you?  Perhaps you should report a bug,
> then.
>

Thanks all! I have diffuculties explaining what I am looking for.


1) I already have a daemon running, so that is not the problem. (Yes,
the alternate-editor option is good for that)


2) The --create-frame option creates a new frame yes, but it does so
every time the option is used. And that is a problem for me :-) I want
max *one* frame open at any given time!


3) Ok ok -- I *could* use my brain to manually do this:

   if( there-is-a-frame-currently-open )
     open-the-file-*without*-the-[--create-frame]-option
   else
     open-the-file-*with*-the-[--create-frame]-option
  endif

 --that would achieve what I am looking for.


4) But that would be a little to much waste of brain power! My problem
is that I do not want to have to remeber whether I already have a
frame open or not. The if-statement above is just too much for me to
bare. So I would want to write a little script that *autoamtiaclly*
achieve the above logic..

The cleanest solution would be to always invoke emacsclient with an
--eval option, something like this:

  emacsclient --eval "( unless( x-display-list ) make-frame ) "

or this:

  emacsclient.emacs-snapshot --eval "(unless(x-display-list)(new-frame))"

-- but I can't figure out how to write that eval (neither of the above
will work)..


5) This is similar to how I use Firefox: When I click on a link in a
mail, that link opens in a new tab in a currently existing frame..
unless there isn't one, in which case a new frame is automatically
opened.


Hmm, is this clearer? Any ideas?


Best regards

Hugo Heden




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-13 11:08       ` Hugo Heden
@ 2009-03-13 11:20         ` Eli Zaretskii
  2009-03-13 11:39         ` Peter Dyballa
  1 sibling, 0 replies; 18+ messages in thread
From: Eli Zaretskii @ 2009-03-13 11:20 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 13 Mar 2009 12:08:26 +0100
> From: Hugo Heden <hugoheden@gmail.com>
> Cc: help-gnu-emacs@gnu.org
> 
>    if( there-is-a-frame-currently-open )
>      open-the-file-*without*-the-[--create-frame]-option
>    else
>      open-the-file-*with*-the-[--create-frame]-option
>   endif
> 
>  --that would achieve what I am looking for.
> 
> 
> 4) But that would be a little to much waste of brain power! My problem
> is that I do not want to have to remeber whether I already have a
> frame open or not. The if-statement above is just too much for me to
> bare. So I would want to write a little script that *autoamtiaclly*
> achieve the above logic..

Again, doesn't emacsclient behave _exactly_ like that by default?
That is, doesn't emacsclient create a frame if it does not exist, and
reuses it if it does exist?  If not, perhaps you should submit a bug
report.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-13 11:08       ` Hugo Heden
  2009-03-13 11:20         ` Eli Zaretskii
@ 2009-03-13 11:39         ` Peter Dyballa
  2009-03-13 14:34           ` Hugo Heden
  1 sibling, 1 reply; 18+ messages in thread
From: Peter Dyballa @ 2009-03-13 11:39 UTC (permalink / raw)
  To: Hugo Heden; +Cc: help-gnu-emacs


Am 13.03.2009 um 12:08 schrieb Hugo Heden:

> Hmm, is this clearer? Any ideas?


Just use 'emacsclient.emacs-snapshot <whatsoever>.' If this does not  
behave as you wish, then you've found a potential bug. Before you  
submit a report, check the place where you launched the daemon for  
messages. Check also whether the daemon has DISPLAY set in its  
process environment. *I* have some problems:

	Warning (initialization): An error occurred while loading `/Users/ 
pete/.emacs':

	Wrong type argument: number-or-marker-p, 85

Because initialisation did not finish, the server hasn't started and  
emacsclient can't connect ...

--
Greetings

   Pete

I love deadlines. I love the whooshing noise they make as they go by.
				– Douglas Adams







^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one  already?
  2009-03-13 11:39         ` Peter Dyballa
@ 2009-03-13 14:34           ` Hugo Heden
  2009-03-13 21:20             ` Johan Bockgård
  0 siblings, 1 reply; 18+ messages in thread
From: Hugo Heden @ 2009-03-13 14:34 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: help-gnu-emacs

On Fri, Mar 13, 2009 at 12:39 PM, Peter Dyballa <Peter_Dyballa@web.de> wrote:
>
> Just use 'emacsclient.emacs-snapshot <whatsoever>.' If this does not behave
> as you wish, then you've found a potential bug. Before you submit a report,
> check the place where you launched the daemon for messages. Check also
> whether the daemon has DISPLAY set in its process environment. *I* have some
> problems:
>

Thanks all, I apologize for having been dense. I thought the whole
time that the behaviour I was seeing was to be expected. The first
time I invoke emacsclient it opens in a terminal, not in a
window-manager-managed GUI-frame. I have to manually create a
GUI-frame using --create-frame. Subsequent invocations of the client
does not need --create-frame however.

The daemon does not emit any error messages, and there seems to be no
problem with my DISPLAY settings.  Removing my clunky  ~/.emacs does
not help. Invoking the emacs daemon with -Q and/or -D does not help
either. Will investigate a bit more (not sure how though) and possibly
file a bug report.

Thanks again all!

Best regards

Hugo Heden

--

$ emacs-snapshot --version
GNU Emacs 23.0.90.1

$ echo $DISPLAY
:0.0

# adding -Q and/or -D does not help either..:
$ emacs-snapshot --daemon
("emacs-snapshot")
Loading 00debian-vars...
Loading 00debian-vars...done
Loading /etc/emacs/site-start.d/50cmake.el (source)...
Loading /etc/emacs/site-start.d/50cmake.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Skipping dictionaries-common setup for emacs-snapshot
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50psvn.el (source)...
Loading /etc/emacs/site-start.d/50psvn.el (source)...done
Loading /etc/emacs-snapshot/site-start.d/60nxml-mode.el (source)...
Loading /usr/share/emacs-snapshot/site-lisp/nxml-mode/rng-auto.el (source)...
Loading /usr/share/emacs-snapshot/site-lisp/nxml-mode/rng-auto.el
(source)...done
Loading /etc/emacs-snapshot/site-start.d/60nxml-mode.el (source)...done
Starting Emacs daemon.

# Always opens up in the terminal, never a GUI-frame:
$ emacsclient.emacs-snapshot test.txt




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-13 14:34           ` Hugo Heden
@ 2009-03-13 21:20             ` Johan Bockgård
  2009-03-13 21:26               ` Peter Dyballa
                                 ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Johan Bockgård @ 2009-03-13 21:20 UTC (permalink / raw)
  To: help-gnu-emacs

Hugo Heden <hugoheden@gmail.com> writes:


> The first time I invoke emacsclient it opens in a terminal, not in a
> window-manager-managed GUI-frame. I have to manually create a
> GUI-frame using --create-frame.

That seems to be the intended behavior

    "If the Emacs process has no existing frame--which can happen if it
     was started as a daemon--then Emacs opens a frame on the terminal
     in which you called `emacsclient', as though you had used the `-t'
     option."

(info "(emacs) Invoking emacsclient")





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-13 21:20             ` Johan Bockgård
@ 2009-03-13 21:26               ` Peter Dyballa
  2009-03-13 22:11                 ` thierry.volpiatto
  2009-03-14 10:38               ` Hugo Heden
  2009-03-15 12:31               ` Hugo Heden
  2 siblings, 1 reply; 18+ messages in thread
From: Peter Dyballa @ 2009-03-13 21:26 UTC (permalink / raw)
  To: Johan Bockgård; +Cc: help-gnu-emacs


Am 13.03.2009 um 22:20 schrieb Johan Bockgård:

> Hugo Heden <hugoheden@ > writes:
>
>
>> The first time I invoke emacsclient it opens in a terminal, not in a
>> window-manager-managed GUI-frame. I have to manually create a
>> GUI-frame using --create-frame.
>
> That seems to be the intended behavior
>
>     "If the Emacs process has no existing frame--which can happen  
> if it
>      was started as a daemon--then Emacs opens a frame on the terminal
>      in which you called `emacsclient', as though you had used the  
> `-t'
>      option."
>
> (info "(emacs) Invoking emacsclient")


This is not really clever: after I successfully compiled GNU Emacs  
from CVS I launch it for testing from the elder Emacs' *shell* buffer  
– this has to fail then!

--
Greetings

   Pete

People say that if you play Microsoft CD's backwards, you hear  
satanic things, but that's nothing, because if you play them  
forwards, they install MS Windows.





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-13 21:26               ` Peter Dyballa
@ 2009-03-13 22:11                 ` thierry.volpiatto
  2009-03-13 22:35                   ` Peter Dyballa
  0 siblings, 1 reply; 18+ messages in thread
From: thierry.volpiatto @ 2009-03-13 22:11 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Peter,
Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 13.03.2009 um 22:20 schrieb Johan Bockgård:
>
>> Hugo Heden <hugoheden@ > writes:
>>
>>
>>> The first time I invoke emacsclient it opens in a terminal, not in a
>>> window-manager-managed GUI-frame. I have to manually create a
>>> GUI-frame using --create-frame.
>>
>> That seems to be the intended behavior
>>
>>     "If the Emacs process has no existing frame--which can happen if
>> it
>>      was started as a daemon--then Emacs opens a frame on the terminal
>>      in which you called `emacsclient', as though you had used the
>> -t'
>>      option."
>>
>> (info "(emacs) Invoking emacsclient")
>
>
> This is not really clever: after I successfully compiled GNU Emacs
> from CVS I launch it for testing from the elder Emacs' *shell* buffer
> – this has to fail then!

I think it's because emacs --daemon should fail if a second emacs-server
process is found.

So if you launch the first emacs with emacs -Q (without server-start)
and then from it, emacsclient -c -a "", it should start a second emacs
process (emacs --daemon) with an emacsclient linked to it.
(not tested)

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-13 22:11                 ` thierry.volpiatto
@ 2009-03-13 22:35                   ` Peter Dyballa
  0 siblings, 0 replies; 18+ messages in thread
From: Peter Dyballa @ 2009-03-13 22:35 UTC (permalink / raw)
  To: thierry.volpiatto; +Cc: help-gnu-emacs


Am 13.03.2009 um 23:11 schrieb thierry.volpiatto:

> So if you launch the first emacs with emacs -Q (without server-start)
> and then from it, emacsclient -c -a "", it should start a second emacs
> process (emacs --daemon) with an emacsclient linked to it.
> (not tested)


I won't do it this way, Thierry. Since I usually have more than one  
Emacs running at the same time I tend to control server business  
tightly.

Anyway, I hope this strange behaviour in daemon mode will be  
corrected before GNU Emacs 23.1 is released. It's outside one's  
imagination that an X client will open inside some terminal  
emulation ... OTOH: a second X11 in my Terminal – I should go ahead  
and patent this before some MS guy does!

--
Greetings

   Pete

A common mistake that people make when trying to design something  
completely foolproof is to underestimate the ingenuity of complete  
fools.






^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one  already?
  2009-03-13 21:20             ` Johan Bockgård
  2009-03-13 21:26               ` Peter Dyballa
@ 2009-03-14 10:38               ` Hugo Heden
  2009-03-14 11:08                 ` Peter Dyballa
  2009-03-15 12:31               ` Hugo Heden
  2 siblings, 1 reply; 18+ messages in thread
From: Hugo Heden @ 2009-03-14 10:38 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Mar 13, 2009 at 10:20 PM, Johan Bockgård
<bojohan+news@dd.chalmers.se> wrote:
> Hugo Heden <hugoheden@gmail.com> writes:
>
>
>> The first time I invoke emacsclient it opens in a terminal, not in a
>> window-manager-managed GUI-frame. I have to manually create a
>> GUI-frame using --create-frame.
>
> That seems to be the intended behavior
>
>    "If the Emacs process has no existing frame--which can happen if it
>     was started as a daemon--then Emacs opens a frame on the terminal
>     in which you called `emacsclient', as though you had used the `-t'
>     option."
>
> (info "(emacs) Invoking emacsclient")
>

Thanks Johan, I won't have to file a bug report then. Unless there is
a huge consensus here that this behaviour should be changed?

I am not sure how to achieve what I want to do, but I think I can make
some clunky bash-script that does

  emacsclient.emacs-snapshot -e "(x-display-list)"

to see the whether or not there is a emacs GUI-frame on the current $DISPLAY.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one already?
  2009-03-14 10:38               ` Hugo Heden
@ 2009-03-14 11:08                 ` Peter Dyballa
  0 siblings, 0 replies; 18+ messages in thread
From: Peter Dyballa @ 2009-03-14 11:08 UTC (permalink / raw)
  To: Hugo Heden; +Cc: help-gnu-emacs


Am 14.03.2009 um 11:38 schrieb Hugo Heden:

> Unless there is a huge consensus here that this behaviour should be  
> changed?


This should be changed!

--
Greetings

   Pete

      _o    o         o   o
    _<<     \\_/\_,   \\_ \\_/\_,
   (*)/(*) (*)   (*) (*) `-    (*)






^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one  already?
  2009-03-13 21:20             ` Johan Bockgård
  2009-03-13 21:26               ` Peter Dyballa
  2009-03-14 10:38               ` Hugo Heden
@ 2009-03-15 12:31               ` Hugo Heden
  2009-03-21 16:52                 ` Hugo Heden
  2 siblings, 1 reply; 18+ messages in thread
From: Hugo Heden @ 2009-03-15 12:31 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Mar 13, 2009 at 10:20 PM, Johan Bockgård
<bojohan+news@dd.chalmers.se> wrote:
> Hugo Heden <hugoheden@gmail.com> writes:
>
>
>> The first time I invoke emacsclient it opens in a terminal, not in a
>> window-manager-managed GUI-frame. I have to manually create a
>> GUI-frame using --create-frame.
>
> That seems to be the intended behavior
>
>    "If the Emacs process has no existing frame--which can happen if it
>     was started as a daemon--then Emacs opens a frame on the terminal
>     in which you called `emacsclient', as though you had used the `-t'
>     option."
>
> (info "(emacs) Invoking emacsclient")
>

Below follows a bash-script that does what I want to do:

If there is no daemon running, one is started automatically. If the
user has *not* specified -nw, -t, -tty, -c or --create-frame, then the
script figures out whether there is a frame open on the current
$DISPLAY, and if not the script *adds* the option --create-frame to
the options before passing them on to the real emacsclient.

Best regards

Hugo Heden

--

#!/bin/bash

# If user has specified -nw, -t or -tty, or for that matter -c or
# --create-frame, then we will do nothing special, just pass on all
# arguments arguments to emacsclient. But if none of that is
# specified, we will add --create-frame if (and only if) there is no
# frame currently open on the current $DISPLAY


function start_daemon() {
    emacs-snapshot --daemon
}

function invoke_client() {
    emacsclient.emacs-snapshot $@
}

args="$@"

if [ "x$DISPLAY" != "x" ] ; then

    user_has_specified=false;
    for opt in $args ; do
        case $opt in
            -t)   user_has_specified=true; break ;; # break out of the loop
            -tty) user_has_specified=true; break ;;
            -nw)  user_has_specified=true; break ;;
            -c)   user_has_specified=true; break ;;
            --create-frame) user_has_specified=true; break ;;
        esac
    done

    if [ $user_has_specified == false ] ; then
        display="\"$DISPLAY\""
            # display will contain something like "", ":0.0" or
            # "localhost:10.0" (including the quotes)
        current_emacs_displays=`invoke_client --eval
"(x-display-list)" 2>/dev/null || start_daemon`
            # current_emacs_displays will contain something like (":0.0"
            # "localhost:10.0") current_emacs_displays may also be
empty if there
            # was no daemon running, of if there is no frame open.
        if [[ ! "$current_emacs_displays" =~ "$display" ]] ; then
                # If there is a match (display is included in
                # current_emacs_displays), then there is already a frame open in
                # this $DISPLAY. *Otherwise* we'll add the --create-frame
                # option
            args="$args --create-frame"
        fi
    fi

fi # if DISPLAY

invoke_client $args || ( start_daemon && invoke_client $args )




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Daemon and client: Only open new frame if there isn't one  already?
  2009-03-15 12:31               ` Hugo Heden
@ 2009-03-21 16:52                 ` Hugo Heden
  0 siblings, 0 replies; 18+ messages in thread
From: Hugo Heden @ 2009-03-21 16:52 UTC (permalink / raw)
  To: help-gnu-emacs

>
> Below follows a bash-script that does what I want to do:
>

I have fixed some limitations in the script. Mainly, the script can
now handle command line options containing spaces (typically --eval
options). I will maintain an updated version on
http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/




^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2009-03-21 16:52 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-12 22:52 Daemon and client: Only open new frame if there isn't one already? Hugo Heden
2009-03-12 23:10 ` Peter Dyballa
2009-03-12 23:44   ` Hugo Heden
2009-03-13  5:55     ` thierry.volpiatto
2009-03-13  9:35     ` Peter Dyballa
2009-03-13  9:35     ` Eli Zaretskii
2009-03-13 11:08       ` Hugo Heden
2009-03-13 11:20         ` Eli Zaretskii
2009-03-13 11:39         ` Peter Dyballa
2009-03-13 14:34           ` Hugo Heden
2009-03-13 21:20             ` Johan Bockgård
2009-03-13 21:26               ` Peter Dyballa
2009-03-13 22:11                 ` thierry.volpiatto
2009-03-13 22:35                   ` Peter Dyballa
2009-03-14 10:38               ` Hugo Heden
2009-03-14 11:08                 ` Peter Dyballa
2009-03-15 12:31               ` Hugo Heden
2009-03-21 16:52                 ` Hugo Heden

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).