From d309994aff03200ed8ef9fadd98f69d6d3166701 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 27 Sep 2018 18:48:06 +0300 Subject: Fix typos in documentation * doc/misc/vhdl-mode.texi (Custom Indentation Functions): * doc/misc/url.texi (Customization): * doc/misc/tramp.texi (Overview): * doc/misc/srecode.texi (Developing Template Functions): * doc/misc/sieve.texi (Sieve Mode): * doc/misc/reftex.texi (Options - Creating Citations): * doc/misc/org.texi (Cooperation, Conflicts): * doc/misc/gnus.texi (Misc Group Stuff): * doc/misc/eshell.texi (Bugs and ideas): * doc/misc/calc.texi (Summary): * doc/man/emacsclient.1: * doc/lispref/os.texi (Security Considerations): * doc/lispref/control.texi (pcase Macro): * CONTRIBUTE: Fix typos. Reported by Mak Kolybabi (Bug#32853) --- doc/man/emacsclient.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index daaacab7f3e..5aaa6d1f083 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -1,7 +1,7 @@ .\" See section COPYING for conditions for redistribution. .TH EMACSCLIENT 1 .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection -.\" other parms are allowed: see man(7), man(1) +.\" other params are allowed: see man(7), man(1) .SH NAME emacsclient \- tells a running Emacs to visit a file .SH SYNOPSIS -- cgit v1.2.3 From 3e81e9a0e7742197354515f3d3ea55fdb201eb29 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Wed, 5 Sep 2018 09:44:58 -0400 Subject: Add support in emacsclient for EMACS_SOCKET_NAME If the '--socket-name' argument is unspecified, the environment variable 'EMACS_SOCKET_NAME' is now consulted with the same semantics. This mirrors the behavior of the '--server-file' argument, and allows for easier configuration of emacsclient when the socket is in a location other than 'TMPDIR' or '/tmp'. * emacsclient.c (set_socket): Add support for the EMACS_SOCKET_NAME environment variable. (Bug#33095) * misc.texi (emacsclient Options): * emacsclient.1: Document the EMACS_SOCKET_NAME environment variable. * etc/NEWS: Announce the new feature. Copyright-paperwork-exempt: yes --- doc/emacs/misc.texi | 4 ++++ doc/man/emacsclient.1 | 1 + etc/NEWS | 6 ++++++ lib-src/emacsclient.c | 3 +++ 4 files changed, 14 insertions(+) (limited to 'doc/man/emacsclient.1') diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 236cb07785c..ab33cafb8e8 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1966,6 +1966,10 @@ is given by the variable @code{server-name} on the Emacs server. If this option is omitted, @command{emacsclient} connects to the first server it finds. (This option is not supported on MS-Windows.) +Alternatively, you can set the @env{EMACS_SOCKET_NAME} environment +variable to point to the server socket. (The command-line option +overrides the environment variable.) + @item -t @itemx --tty @itemx -nw diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index 5aaa6d1f083..24ca1c9a468 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -94,6 +94,7 @@ open a new Emacs frame on the current terminal .TP .B \-s, \-\-socket-name=FILENAME use socket named FILENAME for communication. +This can also be specified via the EMACS_SOCKET_NAME environment variable. .TP .B \-V, \-\-version print version information and exit diff --git a/etc/NEWS b/etc/NEWS index 2249aa48ab8..be32ac6b9bb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -119,6 +119,12 @@ the new version of the file again.) * Changes in Emacs 27.1 ++++ +** emacsclient uses EMACS_SOCKET_NAME if --socket-name is not set. +The behavior is identical to the EMACS_SERVER_FILE, in that the +command line value will override the environment, and the natural +default to TMPDIR, then /tmp, continues to apply. + +++ ** The function 'read-passwd' uses '*' as default character to hide passwords. diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 4fe3a588b19..42b8dd6227b 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -1409,6 +1409,9 @@ set_socket (int no_exit_if_error) #ifndef NO_SOCKETS_IN_FILE_SYSTEM /* Explicit --socket-name argument. */ + if (!socket_name) + socket_name = egetenv ("EMACS_SOCKET_NAME"); + if (socket_name) { s = set_local_socket (socket_name); -- cgit v1.2.3 From 10dba8a1b8cb647d6adc1e4894ccc65f46435ee3 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 2 Aug 2019 00:15:13 +0200 Subject: Document that --eval makes emacsclient ignore -n * doc/man/emacsclient.1: Mention that -n is ignored if --eval is given (bug#20524). --- doc/man/emacsclient.1 | 1 + 1 file changed, 1 insertion(+) (limited to 'doc/man/emacsclient.1') diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index 24ca1c9a468..3bdaafbfc54 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -88,6 +88,7 @@ This can also be specified via the EMACS_SERVER_FILE environment variable. .B \-n, \-\-no-wait returns immediately without waiting for you to "finish" the buffer in Emacs. +If combined with --eval, this option is ignored. .TP .B \-nw, \-t, \-\-tty open a new Emacs frame on the current terminal -- cgit v1.2.3 From a6c22271bcd0d7827e9ef5644bde1322f021fd0f Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 12 Oct 2020 20:59:14 +0200 Subject: Fix man page title lines and timestamps * doc/man/ebrowse.1: * doc/man/emacs.1.in: * doc/man/emacsclient.1: * doc/man/etags.1: Update date to match last significant change. Set file local variable time-stamp-pattern. Fix title line to match the recommendations in "man man-pages". Ref: https://lists.gnu.org/r/emacs-devel/2020-09/msg01002.html --- doc/man/ebrowse.1 | 6 +++++- doc/man/emacs.1.in | 6 +++++- doc/man/emacsclient.1 | 6 +++++- doc/man/etags.1 | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/man/ebrowse.1 b/doc/man/ebrowse.1 index 686658b20f8..330c1ea523e 100644 --- a/doc/man/ebrowse.1 +++ b/doc/man/ebrowse.1 @@ -1,5 +1,5 @@ .\" See section COPYING for copyright and redistribution information. -.TH EBROWSE 1 +.TH EBROWSE 1 "2008-12-14" "GNU Emacs" "GNU" .SH NAME ebrowse \- create a class hierarchy database .SH SYNOPSIS @@ -98,3 +98,7 @@ document into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. . + +.\" Local Variables: +.\" time-stamp-pattern: "3/.TH EBROWSE 1 \"%Y-%02m-%02d\" \"GNU Emacs\" \"GNU\"$" +.\" End: diff --git a/doc/man/emacs.1.in b/doc/man/emacs.1.in index 5a164e98cd3..3a5758e1aaa 100644 --- a/doc/man/emacs.1.in +++ b/doc/man/emacs.1.in @@ -1,5 +1,5 @@ .\" See section COPYING for copyright and redistribution information. -.TH EMACS 1 "2007 April 13" "GNU Emacs @version@" +.TH EMACS 1 "2020-04-05" "GNU Emacs @version@" "GNU" . . .SH NAME @@ -673,3 +673,7 @@ document into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. . + +.\" Local Variables: +.\" time-stamp-pattern: "3/.TH EMACS 1 \"%Y-%02m-%02d\" \"GNU Emacs @version@\" \"GNU\"$" +.\" End: diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index 3bdaafbfc54..9d14d0fe752 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -1,5 +1,5 @@ .\" See section COPYING for conditions for redistribution. -.TH EMACSCLIENT 1 +.TH EMACSCLIENT 1 "2019-08-02" "GNU Emacs" "GNU" .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection .\" other params are allowed: see man(7), man(1) .SH NAME @@ -114,3 +114,7 @@ This manual page was written by Stephane Bortzmeyer , for the Debian GNU/Linux system (but may be used by others). .SH COPYING This manual page is in the public domain. + +.\" Local Variables: +.\" time-stamp-pattern: "3/.TH EMACSCLIENT 1 \"%Y-%02m-%02d\" \"GNU Emacs\" \"GNU\"$" +.\" End: diff --git a/doc/man/etags.1 b/doc/man/etags.1 index e10fb840caf..8053e863fce 100644 --- a/doc/man/etags.1 +++ b/doc/man/etags.1 @@ -1,5 +1,5 @@ .\" See section COPYING for copyright and redistribution information. -.TH etags 1 "23nov2001" "GNU Tools" "GNU Tools" +.TH ETAGS 1 "2019-06-24" "GNU Tools" "GNU" .de BP .sp .ti -.2i @@ -296,3 +296,7 @@ Permission is granted to copy and distribute translations of this document into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. + +.\" Local Variables: +.\" time-stamp-pattern: "3/.TH ETAGS 1 \"%Y-%02m-%02d\" \"GNU Tools\" \"GNU\"$" +.\" End: -- cgit v1.2.3 From 519e23d727a293f04dadf9f6eaebf07b6723500f Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 15 Oct 2020 14:49:23 +0200 Subject: Move emacsclient.1 file history further down * doc/man/emacsclient.1: Move file history further down; it doesn't need to be prominently displayed in the introductory paragraph. --- doc/man/emacsclient.1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index 9d14d0fe752..62f5489653c 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -1,5 +1,5 @@ .\" See section COPYING for conditions for redistribution. -.TH EMACSCLIENT 1 "2019-08-02" "GNU Emacs" "GNU" +.TH EMACSCLIENT 1 "2020-10-15" "GNU Emacs" "GNU" .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection .\" other params are allowed: see man(7), man(1) .SH NAME @@ -12,8 +12,6 @@ This manual page documents briefly the .BR emacsclient command. Full documentation is available in the GNU Info format; see below. -This manual page was originally written for the Debian GNU/Linux -distribution, but is not specific to that system. .PP .B emacsclient works in conjunction with the built-in Emacs server. @@ -110,8 +108,9 @@ The program is documented fully in .IR "Using Emacs as a Server" available via the Info system. .SH AUTHOR -This manual page was written by Stephane Bortzmeyer , -for the Debian GNU/Linux system (but may be used by others). +This manual page was originally written by Stephane Bortzmeyer +, for the Debian GNU/Linux system, but is not +specific to that system. .SH COPYING This manual page is in the public domain. -- cgit v1.2.3 From 8299126521e4c166fe43aa7ac8eadf0ff1e41457 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 18 Oct 2020 02:46:31 +0200 Subject: Minor improvements to emacsclient man page * doc/man/emacsclient.1: Make flag descriptions into full sentences to be more consistent. --- doc/man/emacsclient.1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index 62f5489653c..ba64efa282c 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -1,5 +1,5 @@ .\" See section COPYING for conditions for redistribution. -.TH EMACSCLIENT 1 "2020-10-15" "GNU Emacs" "GNU" +.TH EMACSCLIENT 1 "2020-10-18" "GNU Emacs" "GNU" .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection .\" other params are allowed: see man(7), man(1) .SH NAME @@ -61,45 +61,45 @@ is treated as column 1. This option applies only to the next file specified. .TP .B \-a, \-\-alternate-editor=COMMAND -if the Emacs server is not running, run the specified shell command instead. +If the Emacs server is not running, run the specified shell command instead. This can also be specified via the ALTERNATE_EDITOR environment variable. If the value of ALTERNATE_EDITOR is the empty string, run "emacs \-\-daemon" to start Emacs in daemon mode, and try to connect to it. .TP .B -c, \-\-create-frame -create a new frame instead of trying to use the current Emacs frame +Create a new frame instead of trying to use the current Emacs frame. .TP .B \-F, \-\-frame-parameters=ALIST -set the parameters of a newly-created frame. +Set the parameters of a newly-created frame. .TP .B \-d, \-\-display=DISPLAY -tell the server to display the files on the given display. +Tell the server to display the files on the given display. .TP .B \-e, \-\-eval -do not visit files but instead evaluate the arguments as Emacs +Do not visit files but instead evaluate the arguments as Emacs Lisp expressions. .TP .B \-f, \-\-server-file=FILENAME -use TCP configuration file FILENAME for communication. +Use TCP configuration file FILENAME for communication. This can also be specified via the EMACS_SERVER_FILE environment variable. .TP .B \-n, \-\-no-wait -returns +Return immediately without waiting for you to "finish" the buffer in Emacs. If combined with --eval, this option is ignored. .TP .B \-nw, \-t, \-\-tty -open a new Emacs frame on the current terminal +Open a new Emacs frame on the current terminal. .TP .B \-s, \-\-socket-name=FILENAME -use socket named FILENAME for communication. +Use socket named FILENAME for communication. This can also be specified via the EMACS_SOCKET_NAME environment variable. .TP .B \-V, \-\-version -print version information and exit +Print version information and exit. .TP .B \-H, \-\-help -print this usage information message and exit +Print this usage information message and exit. .SH "EXIT STATUS" Normally, the exit status is 0. If emacsclient shuts down due to Emacs signaling an error, the exit status is 1. -- cgit v1.2.3 From 2bcc2160c9f7f16c5e9cd815b8074de27f30896d Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Fri, 5 Nov 2021 00:14:30 +0100 Subject: New emacsclient option to either create or reuse an existing frame. * doc/emacs/misc.texi (emacsclient Options): Document the new option. * doc/man/emacsclient.1: Mention the new option (bug#51374). * etc/NEWS: Mention the new option. * 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 | 5 +++++ doc/man/emacsclient.1 | 3 +++ etc/NEWS | 8 ++++++++ lib-src/emacsclient.c | 13 ++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index f66b69cdd73..4be47990d1f 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -1992,6 +1992,11 @@ the new frame displays the @file{*scratch*} buffer by default. You 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 ba64efa282c..cc58f106e69 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 1b3f4c0524f..899f3567e6e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -102,6 +102,14 @@ highlights segments of buffer text whose reordering for display is suspicious and could be malicious. + +** 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 cff3cec2a79..0e800dd7e89 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -116,6 +116,9 @@ static bool eval; /* 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 @@ static struct option const longopts[] = { "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 @@ The following OPTIONS are accepted:\n\ -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) -- cgit v1.2.3 From 3601e236792a4d3f87d17877926fea9d17c3a5a4 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 5 Nov 2021 01:10:32 +0100 Subject: ; * doc/man/emacsclient.1: Bump date after last change. --- doc/man/emacsclient.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index cc58f106e69..e5d1bbe09ae 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -1,5 +1,5 @@ .\" See section COPYING for conditions for redistribution. -.TH EMACSCLIENT 1 "2020-10-18" "GNU Emacs" "GNU" +.TH EMACSCLIENT 1 "2021-11-05" "GNU Emacs" "GNU" .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection .\" other params are allowed: see man(7), man(1) .SH NAME -- cgit v1.2.3 From 6a19f2a024b4cede80e2896318696008d1dd1b21 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Tue, 6 Sep 2022 02:05:18 +0200 Subject: Add new --timeout flag to emacsclient * lib-src/emacsclient.c (DEFAULT_TIMEOUT): New constant. (timeout): New static variable. (longopts, shortopts, decode_options, print_help_and_exit): Add new flag --timeout. (set_socket_timeout, check_socket_timeout): New helper functions. (main): Display a status message or exit after Emacs has not responded for a while, depending on above new --timeout flag. (Bug#50849) * doc/emacs/misc.texi (emacsclient Options): * doc/man/emacsclient.1: Document the above new option. * etc/NEWS: Announce it. --- doc/emacs/misc.texi | 7 +++++ doc/man/emacsclient.1 | 11 +++++--- etc/NEWS | 7 ++++- lib-src/emacsclient.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 92 insertions(+), 8 deletions(-) (limited to 'doc/man/emacsclient.1') diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index df74577592a..d8ad0bee34f 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -2089,6 +2089,13 @@ all server buffers are finished. You can take as long as you like to edit the server buffers within Emacs, and they are @emph{not} killed when you type @kbd{C-x #} in them. +@item -w +@itemx --timeout=@var{N} +Wait for a response from Emacs for @var{N} seconds before giving up. +If there is no response within that time, @command{emacsclient} will +display a warning and exit. The default is @samp{0}, which means to +wait forever. + @item --parent-id @var{id} Open an @command{emacsclient} frame as a client frame in the parent X window with id @var{id}, via the XEmbed protocol. Currently, this diff --git a/doc/man/emacsclient.1 b/doc/man/emacsclient.1 index e5d1bbe09ae..83c8a366f8b 100644 --- a/doc/man/emacsclient.1 +++ b/doc/man/emacsclient.1 @@ -1,5 +1,5 @@ .\" See section COPYING for conditions for redistribution. -.TH EMACSCLIENT 1 "2021-11-05" "GNU Emacs" "GNU" +.TH EMACSCLIENT 1 "2022-09-05" "GNU Emacs" "GNU" .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection .\" other params are allowed: see man(7), man(1) .SH NAME @@ -87,9 +87,12 @@ Use TCP configuration file FILENAME for communication. This can also be specified via the EMACS_SERVER_FILE environment variable. .TP .B \-n, \-\-no-wait -Return -immediately without waiting for you to "finish" the buffer in Emacs. -If combined with --eval, this option is ignored. +Return immediately without waiting for you to "finish" the buffer in +Emacs. If combined with --eval, this option is ignored. +.TP +.B \-w, \-\-timeout=N +How long to wait, in seconds, for Emacs to respond before giving up. +The default is 0, which means to wait forever. .TP .B \-nw, \-t, \-\-tty Open a new Emacs frame on the current terminal. diff --git a/etc/NEWS b/etc/NEWS index e99c2f21982..b61b88d6fbe 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1003,10 +1003,15 @@ suspicious and could be malicious. ** Emacs server and client changes +++ -*** New command-line option '-r' for emacsclient. +*** New command-line option '-r'/'--reuse-frame' for emacsclient. With this command-line option, Emacs reuses an existing graphical client frame if one exists; otherwise it creates a new frame. ++++ +*** New command-line option '-w N'/'--timeout=N' for emacsclient. +With this command-line option, emacsclient will exit if Emacs does not +respond within N seconds. The default is to wait forever. + +++ *** 'server-stop-automatically' can be used to automatically stop the server. The Emacs server will be automatically stopped when certain conditions diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index 73c8e45a865..15acb4589a9 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c @@ -1,6 +1,6 @@ /* Client process that communicates with GNU Emacs acting as server. -Copyright (C) 1986-1987, 1994, 1999-2022 Free Software Foundation, Inc. +Copyright (C) 1986-2022 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -55,6 +55,8 @@ char *w32_getenv (const char *); # include # include +# define DEFAULT_TIMEOUT (30) + # define SOCKETS_IN_FILE_SYSTEM # define INVALID_SOCKET (-1) @@ -144,6 +146,9 @@ static char const *socket_name; /* If non-NULL, the filename of the authentication file. */ static char const *server_file; +/* Seconds to wait before timing out (0 means wait forever). */ +static uintmax_t timeout; + /* If non-NULL, the tramp prefix emacs must use to find the files. */ static char const *tramp_prefix; @@ -178,6 +183,7 @@ static struct option const longopts[] = { "server-file", required_argument, NULL, 'f' }, { "display", required_argument, NULL, 'd' }, { "parent-id", required_argument, NULL, 'p' }, + { "timeout", required_argument, NULL, 'w' }, { "tramp", required_argument, NULL, 'T' }, { 0, 0, 0, 0 } }; @@ -185,7 +191,7 @@ static struct option const longopts[] = /* Short options, in the same order as the corresponding long options. There is no '-p' short option. */ static char const shortopts[] = - "nqueHVtca:F:" + "nqueHVtca:F:w:" #ifdef SOCKETS_IN_FILE_SYSTEM "s:" #endif @@ -497,6 +503,7 @@ decode_options (int argc, char **argv) if (opt < 0) break; + char* endptr; switch (opt) { case 0: @@ -530,6 +537,17 @@ decode_options (int argc, char **argv) nowait = true; break; + case 'w': + timeout = strtoumax (optarg, &endptr, 10); + if (timeout <= 0 || + ((timeout == INTMAX_MAX || timeout == INTMAX_MIN) + && errno == ERANGE)) + { + fprintf (stderr, "Invalid timeout: \"%s\"\n", optarg); + exit (EXIT_FAILURE); + } + break; + case 'e': eval = true; break; @@ -671,6 +689,7 @@ The following OPTIONS are accepted:\n\ Set the parameters of a new frame\n\ -e, --eval Evaluate the FILE arguments as ELisp expressions\n\ -n, --no-wait Don't wait for the server to return\n\ +-w, --timeout Seconds to wait before timing out\n\ -q, --quiet Don't display messages on success\n\ -u, --suppress-output Don't display return values from the server\n\ -d DISPLAY, --display=DISPLAY\n\ @@ -1870,6 +1889,33 @@ start_daemon_and_retry_set_socket (void) return emacs_socket; } +static void +set_socket_timeout (HSOCKET socket, int seconds) +{ +#ifndef WINDOWSNT + struct timeval timeout; + timeout.tv_sec = seconds; + timeout.tv_usec = 0; + setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout); +#else + DWORD timeout = seconds * 1000; + setsockopt (socket, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, sizeof timeout); +#endif +} + +static bool +check_socket_timeout (int rl) +{ +#ifndef WINDOWSNT + return (rl == -1) + && (errno == EAGAIN) + && (errno == EWOULDBLOCK); +#else + return (rl == SOCKET_ERROR) + && (WSAGetLastError() == WSAETIMEDOUT); +#endif +} + int main (int argc, char **argv) { @@ -2086,19 +2132,42 @@ main (int argc, char **argv) } fflush (stdout); + set_socket_timeout (emacs_socket, timeout > 0 ? timeout : DEFAULT_TIMEOUT); + bool saw_response = false; /* Now, wait for an answer and print any messages. */ while (exit_status == EXIT_SUCCESS) { + bool retry = true; + bool msg_showed = quiet; do { act_on_signals (emacs_socket); rl = recv (emacs_socket, string, BUFSIZ, 0); + retry = check_socket_timeout (rl); + if (retry) + { + if (timeout > 0 && !saw_response) + { + /* Don't retry if we were given a --timeout flag. */ + fprintf (stderr, "\nServer not responding; timed out after %lu seconds", + timeout); + retry = false; + } + else if (!msg_showed) + { + msg_showed = true; + fprintf (stderr, "\nServer not responding; use Ctrl+C to break"); + } + } } - while (rl < 0 && errno == EINTR); + while ((rl < 0 && errno == EINTR) || retry); if (rl <= 0) break; + if (msg_showed) + fprintf (stderr, "\nGot response from server"); + saw_response = true; string[rl] = '\0'; /* Loop over all NL-terminated messages. */ -- cgit v1.2.3