From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#51374: New options for emacsclient Date: Sat, 30 Oct 2021 08:25:03 -0700 Message-ID: References: <90ba36dcccf5550a3348@heytings.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11726"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 51374@debbugs.gnu.org To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 30 17:26:22 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgqFS-0002my-Gl for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Oct 2021 17:26:22 +0200 Original-Received: from localhost ([::1]:46000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mgqFQ-0002Zv-Lc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Oct 2021 11:26:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mgqF9-0002ZI-O3 for bug-gnu-emacs@gnu.org; Sat, 30 Oct 2021 11:26:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46616) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mgqF8-0003Tq-Fd for bug-gnu-emacs@gnu.org; Sat, 30 Oct 2021 11:26:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mgqF8-0004xU-9m for bug-gnu-emacs@gnu.org; Sat, 30 Oct 2021 11:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Oct 2021 15:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51374 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51374-submit@debbugs.gnu.org id=B51374.163560751218986 (code B ref 51374); Sat, 30 Oct 2021 15:26:02 +0000 Original-Received: (at 51374) by debbugs.gnu.org; 30 Oct 2021 15:25:12 +0000 Original-Received: from localhost ([127.0.0.1]:58162 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgqEK-0004wA-48 for submit@debbugs.gnu.org; Sat, 30 Oct 2021 11:25:12 -0400 Original-Received: from mail-pf1-f177.google.com ([209.85.210.177]:34699) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mgqEH-0004vo-W3 for 51374@debbugs.gnu.org; Sat, 30 Oct 2021 11:25:10 -0400 Original-Received: by mail-pf1-f177.google.com with SMTP id 127so12145938pfu.1 for <51374@debbugs.gnu.org>; Sat, 30 Oct 2021 08:25:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc; bh=YcJq8fFnREdp/ZhqfcZ5HxwOtrEwtd49wIfq67u7TJs=; b=vlWcZS/zWjgBUgRkhuQ3CzGVb8+w6ncDotlASI1WPKk0HEXWqSwY761kuJVBKlfAAN dqXciX/0cX1vMRW1AJzyISs8112TlDijUWdOyQF30bxu0HMzC98i+FcZ6M/wzt0ZQM58 I43FeT0QhoyYDC8gIu1dqIEYC6QRhvyCRGzzuVxB3qs2gxxaoCqoZmK/T0b1aQQAvDjZ syzPeC27B3EV8oVrhw2PnwYzf6Pb3FofDdb5gLWSKL6V6jzkV0hP78OW8kkF8sB/Y8f9 I+lCkYydwbdcN6Sst7f0RGmShefioqpGJX9z3pzPajK/tlSgttpsJGnhIm21xTDuhrAA sdIQ== X-Gm-Message-State: AOAM533OdOCn26fSuu5mhZAGeaXpri5KTTqtSiIXVjaN7L9HpLoUfBSe pN9+KcAYeVFCaXSdORIPBzmVBDNbPRqi+bqlxlLmoCQm X-Google-Smtp-Source: ABdhPJwFfZu8hWpueApofbqWwsyVROZCdfT1qIBu6OeycP52iML9nMQGnWwsUKvoKFqAGhaTD+1U+hNgsc1ZxhNXJWA= X-Received: by 2002:a05:6a00:1955:b0:47c:1d32:84de with SMTP id s21-20020a056a00195500b0047c1d3284demr17564580pfk.70.1635607504108; Sat, 30 Oct 2021 08:25:04 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 30 Oct 2021 08:25:03 -0700 In-Reply-To: <90ba36dcccf5550a3348@heytings.org> (Gregory Heytings's message of "Sun, 24 Oct 2021 14:27:42 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:218617 Archived-At: Gregory Heytings writes: > When emacsclient is used in a terminal, emacsclient FILE opens a non-graphical > Emacs frame, and emacsclient -c FILE always creates a new graphical Emacs frame. > A third option, which creates a graphical frame if none exist and reuses a > graphical frame is one exists, would be useful (see for example [1] and [2]). It seems like tons of users are using home-cooked solutions and scripts to do this, so there is a clear need for it. I think we should add it. > Patch attached. Your patch LGTM, but it's missing a NEWS entry. (Perhaps we could also update the man page, but that's no requirement as we don't really make an effort to maintain it.) > [1] > https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist > [2] > https://emacs.stackexchange.com/questions/12894/make-emacsclient-create-a-frame-only-if-there-isnt-one-already > > From f44c01bb1f1a90aa511186e5310fecda1d107985 Mon Sep 17 00:00:00 2001 > From: Gregory Heytings > Date: Sun, 24 Oct 2021 14:14:32 +0000 > Subject: [PATCH] New emacsclient option to either create or reuse an existing > frame. > > * lib-src/emacsclient.c (reuse_frame): New variable. > (longopts): New option. > (decode_options): Decode the new option. > (print_help_and_exit): Document the new option. > (main): Use the new option. > > * doc/emacs/misc.texi (emacsclient Options): Document the new option. > --- > doc/emacs/misc.texi | 5 +++++ > lib-src/emacsclient.c | 13 ++++++++++++- > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi > index 5123a716dc..810d212021 100644 > --- a/doc/emacs/misc.texi > +++ b/doc/emacs/misc.texi > @@ -1986,6 +1986,11 @@ emacsclient Options > can customize this behavior with the variable @code{initial-buffer-choice} > (@pxref{Entering Emacs}). > > +@item -r > +@itemx --reuse-frame > +Create a new graphical @dfn{client frame} if none exists, otherwise > +use an existing Emacs frame. > + > @item -F @var{alist} > @itemx --frame-parameters=@var{alist} > Set the parameters for a newly-created graphical frame > diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c > index cff3cec2a7..0e800dd7e8 100644 > --- a/lib-src/emacsclient.c > +++ b/lib-src/emacsclient.c > @@ -116,6 +116,9 @@ Copyright (C) 1986-1987, 1994, 1999-2021 Free Software Foundation, Inc. > /* True means open a new frame. --create-frame etc. */ > static bool create_frame; > > +/* True means reuse a frame if it already exists. */ > +static bool reuse_frame; > + > /* The display on which Emacs should work. --display. */ > static char const *display; > > @@ -165,6 +168,7 @@ Copyright (C) 1986-1987, 1994, 1999-2021 Free Software Foundation, Inc. > { "tty", no_argument, NULL, 't' }, > { "nw", no_argument, NULL, 't' }, > { "create-frame", no_argument, NULL, 'c' }, > + { "reuse-frame", no_argument, NULL, 'r' }, > { "alternate-editor", required_argument, NULL, 'a' }, > { "frame-parameters", required_argument, NULL, 'F' }, > #ifdef SOCKETS_IN_FILE_SYSTEM > @@ -551,6 +555,11 @@ decode_options (int argc, char **argv) > create_frame = true; > break; > > + case 'r': > + create_frame = true; > + reuse_frame = true; > + break; > + > case 'p': > parent_id = optarg; > create_frame = true; > @@ -647,6 +656,8 @@ print_help_and_exit (void) > -nw, -t, --tty Open a new Emacs frame on the current terminal\n\ > -c, --create-frame Create a new frame instead of trying to\n\ > use the current Emacs frame\n\ > +-r, --reuse-frame Create a new frame if none exists, otherwise\n\ > + use the current Emacs frame\n\ > ", "\ > -F ALIST, --frame-parameters=ALIST\n\ > Set the parameters of a new frame\n\ > @@ -1941,7 +1952,7 @@ main (int argc, char **argv) > if (nowait) > send_to_emacs (emacs_socket, "-nowait "); > > - if (!create_frame) > + if (!create_frame || reuse_frame) > send_to_emacs (emacs_socket, "-current-frame "); > > if (display)