unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#51374: New options for emacsclient
@ 2021-10-24 14:27 Gregory Heytings
  2021-10-30 15:25 ` Stefan Kangas
  0 siblings, 1 reply; 4+ messages in thread
From: Gregory Heytings @ 2021-10-24 14:27 UTC (permalink / raw)
  To: 51374

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]


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

Patch attached.

[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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=New-emacsclient-option-to-either-create-or-reuse-an-.patch, Size: 3097 bytes --]

From f44c01bb1f1a90aa511186e5310fecda1d107985 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
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)
-- 
2.33.0


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

* bug#51374: New options for emacsclient
  2021-10-24 14:27 bug#51374: New options for emacsclient Gregory Heytings
@ 2021-10-30 15:25 ` Stefan Kangas
  2021-10-30 22:31   ` Gregory Heytings
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Kangas @ 2021-10-30 15:25 UTC (permalink / raw)
  To: Gregory Heytings; +Cc: 51374

Gregory Heytings <gregory@heytings.org> 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 <gregory@heytings.org>
> 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)





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

* bug#51374: New options for emacsclient
  2021-10-30 15:25 ` Stefan Kangas
@ 2021-10-30 22:31   ` Gregory Heytings
  2021-11-04 23:14     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Gregory Heytings @ 2021-10-30 22:31 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 51374

[-- Attachment #1: Type: text/plain, Size: 717 bytes --]


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

Thanks for your comment!

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

Updated patch attached.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=New-emacsclient-option-to-either-create-or-reuse-an-.patch, Size: 4361 bytes --]

From c366e458f567e37b3b844808b56eaa95861be9d8 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Sat, 30 Oct 2021 22:29:00 +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.

* etc/NEWS: Mention the new option.

* doc/man/emacsclient.1: Mention the new option.
---
 doc/emacs/misc.texi   |  5 +++++
 doc/man/emacsclient.1 |  3 +++
 etc/NEWS              |  8 ++++++++
 lib-src/emacsclient.c | 13 ++++++++++++-
 4 files changed, 28 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/doc/man/emacsclient.1 b/doc/man/emacsclient.1
index ba64efa282..cc58f106e6 100644
--- a/doc/man/emacsclient.1
+++ b/doc/man/emacsclient.1
@@ -69,6 +69,9 @@ start Emacs in daemon mode, and try to connect to it.
 .B -c, \-\-create-frame
 Create a new frame instead of trying to use the current Emacs frame.
 .TP
+.B -r \-\-reuse-frame
+Reuse an existing frame if one exists, otherwise create a new frame.
+.TP
 .B \-F, \-\-frame-parameters=ALIST
 Set the parameters of a newly-created frame.
 .TP
diff --git a/etc/NEWS b/etc/NEWS
index 6d3256959e..a318d4c262 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -74,6 +74,14 @@ Image specifiers can now use ':type webp'.
 For example, an alist entry as '(window-width . (body-columns . 40))'
 will make the body of the chosen window 40 columns wide.
 \f
+
+** Emacs server and client changes
+
++++
+*** New command-line option '-r' for emacsclient.
+With this command-line option, Emacs reuses an existing graphical client
+frame if one exists; otherwise a new frame is created.
+
 * Editing Changes in Emacs 29.1
 
 ---
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)
-- 
2.33.0


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

* bug#51374: New options for emacsclient
  2021-10-30 22:31   ` Gregory Heytings
@ 2021-11-04 23:14     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-04 23:14 UTC (permalink / raw)
  To: Gregory Heytings; +Cc: Stefan Kangas, 51374

Gregory Heytings <gregory@heytings.org> writes:

> Updated patch attached.

Makes sense to me; pushed to Emacs 29 now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2021-11-04 23:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-24 14:27 bug#51374: New options for emacsclient Gregory Heytings
2021-10-30 15:25 ` Stefan Kangas
2021-10-30 22:31   ` Gregory Heytings
2021-11-04 23:14     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

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