From: Hugo Heden <hugoheden@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Daemon and client: Only open new frame if there isn't one already?
Date: Sun, 15 Mar 2009 13:31:45 +0100 [thread overview]
Message-ID: <2bdf908c0903150531j7f5343c4vf4fceff3396f27ef@mail.gmail.com> (raw)
In-Reply-To: <yoij3adhqfvh.fsf@remote2.student.chalmers.se>
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 )
next prev parent reply other threads:[~2009-03-15 12:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-03-21 16:52 ` Hugo Heden
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2bdf908c0903150531j7f5343c4vf4fceff3396f27ef@mail.gmail.com \
--to=hugoheden@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/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.
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.