From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hugo Heden Newsgroups: gmane.emacs.help Subject: Re: Daemon and client: Only open new frame if there isn't one already? Date: Sun, 15 Mar 2009 13:31:45 +0100 Message-ID: <2bdf908c0903150531j7f5343c4vf4fceff3396f27ef@mail.gmail.com> References: <2bdf908c0903121552i28e1da76t8f47975f2ff820ab@mail.gmail.com> <90717509-0527-434D-94F0-5BA9B979FB8F@Web.DE> <2bdf908c0903121644u7e8c01a2nb96d0200c83d2319@mail.gmail.com> <2bdf908c0903130408t23772cfex48b4d1abf2afccb9@mail.gmail.com> <60D55027-1709-437B-A5A1-B24AE9EDB629@Web.DE> <2bdf908c0903130734u17db1aa6oc298dc0b7796cd15@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1237120345 28673 80.91.229.12 (15 Mar 2009 12:32:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Mar 2009 12:32:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 15 13:33:42 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LipXB-0007CG-IM for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Mar 2009 13:33:41 +0100 Original-Received: from localhost ([127.0.0.1]:48032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LipVo-00061e-T2 for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Mar 2009 08:32:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LipVO-00061K-HT for help-gnu-emacs@gnu.org; Sun, 15 Mar 2009 08:31:50 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LipVN-00060e-De for help-gnu-emacs@gnu.org; Sun, 15 Mar 2009 08:31:50 -0400 Original-Received: from [199.232.76.173] (port=34690 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LipVN-00060Z-9o for help-gnu-emacs@gnu.org; Sun, 15 Mar 2009 08:31:49 -0400 Original-Received: from fg-out-1718.google.com ([72.14.220.156]:58254) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LipVM-0000Qq-J1 for help-gnu-emacs@gnu.org; Sun, 15 Mar 2009 08:31:48 -0400 Original-Received: by fg-out-1718.google.com with SMTP id l27so1012791fgb.30 for ; Sun, 15 Mar 2009 05:31:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=KgnLjNwVfjK0fMby0yl3D5DPKuEgaaU/KQsu+kyc02w=; b=KrwzKXVhuxTOhnBiNAxHMtdEalxYHkSV/ydCT8nUDCeQXuClVU/P2nTbrJ0j2X4qXX dN85NgDHFPDcwYygiIh74yZBCCYxXInHsqEw/YXiAT9dunLx98EWqmPUQmYWyPQDEBAY KTrePkNEVBcP4UWkE3/quCaT5cYQXuG/5Neiw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=hbYtkmD6s3pVP2GMY/1/k3QOfkDM9JRMt9SyCYUkZHCv9eUkfaSi17kvGV4SllVTuf SDCvoyWP4EvY3VNl4QUDIpsEnxpT69wHdZ0cnbzmQTbzTZXSFLE15YQUBoIZ2jCu/z42 8LCx8SebmuLGftlQb8nU2hYU8bVnP0Pk+YcCo= Original-Received: by 10.86.61.13 with SMTP id j13mr31741fga.59.1237120306013; Sun, 15 Mar 2009 05:31:46 -0700 (PDT) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62928 Archived-At: On Fri, Mar 13, 2009 at 10:20 PM, Johan Bockg=E5rd wrote: > Hugo Heden 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 > > =A0 =A0"If the Emacs process has no existing frame--which can happen if i= t > =A0 =A0 was started as a daemon--then Emacs opens a frame on the terminal > =A0 =A0 in which you called `emacsclient', as though you had used the `-t= ' > =A0 =A0 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=3D"$@" if [ "x$DISPLAY" !=3D "x" ] ; then user_has_specified=3Dfalse; for opt in $args ; do case $opt in -t) user_has_specified=3Dtrue; break ;; # break out of the lo= op -tty) user_has_specified=3Dtrue; break ;; -nw) user_has_specified=3Dtrue; break ;; -c) user_has_specified=3Dtrue; break ;; --create-frame) user_has_specified=3Dtrue; break ;; esac done if [ $user_has_specified =3D=3D false ] ; then display=3D"\"$DISPLAY\"" # display will contain something like "", ":0.0" or # "localhost:10.0" (including the quotes) current_emacs_displays=3D`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" =3D~ "$display" ]] ; then # If there is a match (display is included in # current_emacs_displays), then there is already a frame op= en in # this $DISPLAY. *Otherwise* we'll add the --create-frame # option args=3D"$args --create-frame" fi fi fi # if DISPLAY invoke_client $args || ( start_daemon && invoke_client $args )