all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* emacsclient frame reuse
@ 2009-08-04 21:07 jem
  2009-08-04 22:18 ` A.Politz
  0 siblings, 1 reply; 4+ messages in thread
From: jem @ 2009-08-04 21:07 UTC (permalink / raw
  To: help-gnu-emacs

I've been testing the new 23 build and the --daemon option and have a
question how to get it to operate as I used to have gnuserv working.

Here's the scenario -- I have running in the background an emacs
instance using the --daemon flag.  Now, I want to edit a new file in
an X window frame so I have a script that will launch:

emacsclient -c -n file

This fires a new frame with the file and returns.  Now I want to edit
a second file, in the same frame.  If I use the same command

emacsclient -c -n file2

I get a new frame, where I wanted to share the previous frame.
Instead I have to use

emacsclient -n file2

to reuse the frame.

If I don't have any running frames (either TTY or X) and use the
emacsclient -n file command, there is a quick flash in the terminal
then it goes away as the client assumes TTY and the process
terminates.

I would like to have a single script that I can invoke that will do
the right thing.  If there is no visible frame, use the -c option.  If
there is a visible frame do not use the -c option.   The problem is, I
can't find a way to determine if there is a visible frame.  Because of
the -n option, the previous emacsclient process has exited.

In the older model with gnuserv I was able to add

(setq gnuserv-frame (car (frame-list)))

and my startup script looked like

gunclient -n $@ 2>/dev/null
if [ $? -ne 0 ]
then
       emacs $@ &
fi

which would start emacs if not started (I loaded gnuserv in the
init.el file) or connect to the existing one and share the frame.

How can you detect if there is already a running frame with the newest
version?

Thanks

Jere
~


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

* Re: emacsclient frame reuse
  2009-08-04 21:07 emacsclient frame reuse jem
@ 2009-08-04 22:18 ` A.Politz
  2009-08-05  0:22   ` jem
  0 siblings, 1 reply; 4+ messages in thread
From: A.Politz @ 2009-08-04 22:18 UTC (permalink / raw
  To: help-gnu-emacs

On Aug 4, 11:07 pm, jem <jere.mcdev...@gmail.com> wrote:

> How can you detect if there is already a running frame with the newest
> version?
>
> Thanks
>
> Jere
> ~


#!/bin/sh

EMACS=emacs-23.1
EMACSCLIENT=emacsclient-23.1
FLAGS=-n

$EMACSCLIENT -e nil >/dev/null || $EMACS --daemon

NR_FRAMES=$($EMACSCLIENT -e '(1- (length (frame-list)))')

if [ $NR_FRAMES -eq 0 ];then
    FLAGS="$FLAGS -c"
fi

$EMACSCLIENT $FLAGS "$@"


There seems to be an invisible frame, representing the daemon or
something.


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

* Re: emacsclient frame reuse
  2009-08-04 22:18 ` A.Politz
@ 2009-08-05  0:22   ` jem
  2009-08-05  0:40     ` jem
  0 siblings, 1 reply; 4+ messages in thread
From: jem @ 2009-08-05  0:22 UTC (permalink / raw
  To: help-gnu-emacs

On Aug 4, 6:18 pm, "A.Politz" <poli...@googlemail.com> wrote:
> On Aug 4, 11:07 pm, jem <jere.mcdev...@gmail.com> wrote:
>
> > How can you detect if there is already a running frame with the newest
> > version?
>
> > Thanks
>
> > Jere
> > ~
>
> #!/bin/sh
>
> EMACS=emacs-23.1
> EMACSCLIENT=emacsclient-23.1
> FLAGS=-n
>
> $EMACSCLIENT -e nil >/dev/null || $EMACS --daemon
>
> NR_FRAMES=$($EMACSCLIENT -e '(1- (length (frame-list)))')
>
> if [ $NR_FRAMES -eq 0 ];then
>     FLAGS="$FLAGS -c"
> fi
>
> $EMACSCLIENT $FLAGS "$@"
>
> There seems to be an invisible frame, representing the daemon or
> something.

Thanks, this works quite well.

Jere


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

* Re: emacsclient frame reuse
  2009-08-05  0:22   ` jem
@ 2009-08-05  0:40     ` jem
  0 siblings, 0 replies; 4+ messages in thread
From: jem @ 2009-08-05  0:40 UTC (permalink / raw
  To: help-gnu-emacs

On Aug 4, 8:22 pm, jem <jere.mcdev...@gmail.com> wrote:
> On Aug 4, 6:18 pm, "A.Politz" <poli...@googlemail.com> wrote:
>
>
>
> > On Aug 4, 11:07 pm, jem <jere.mcdev...@gmail.com> wrote:
>
> > > How can you detect if there is already a running frame with the newest
> > > version?
>
> > > Thanks
>
> > > Jere
> > > ~
>
> > #!/bin/sh
>
> > EMACS=emacs-23.1
> > EMACSCLIENT=emacsclient-23.1
> > FLAGS=-n
>
> > $EMACSCLIENT -e nil >/dev/null || $EMACS --daemon
>
> > NR_FRAMES=$($EMACSCLIENT -e '(1- (length (frame-list)))')
>
> > if [ $NR_FRAMES -eq 0 ];then
> >     FLAGS="$FLAGS -c"
> > fi
>
> > $EMACSCLIENT $FLAGS "$@"
>
> > There seems to be an invisible frame, representing the daemon or
> > something.
>
> Thanks, this works quite well.
>
> Jere

Had to make one minor change:

   (- 1 (length (frame-list)))

but otherwise it works great.


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

end of thread, other threads:[~2009-08-05  0:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-04 21:07 emacsclient frame reuse jem
2009-08-04 22:18 ` A.Politz
2009-08-05  0:22   ` jem
2009-08-05  0:40     ` jem

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.