diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 2c2c710eea4..6c700869182 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -2024,8 +2024,8 @@ server file, as the default @code{server-auth-dir} is hard-coded in relative filenames. @node Invoking emacsclient -@subsection Invoking @code{emacsclient} -@cindex @code{emacsclient} invocation +@subsection Invoking @command{emacsclient} +@cindex @command{emacsclient} invocation The simplest way to use the @command{emacsclient} program is to run the shell command @samp{emacsclient @var{file}}, where @var{file} is a @@ -2193,8 +2193,9 @@ option sometimes requires elaborate escaping of characters special to the shell. To avoid this, you can pass arguments to Lisp functions in your expression as additional separate arguments to @command{emacsclient}, and use @var{server-eval-args-left} in the -expression to access those arguments. Be careful to have your -expression remove the processed arguments from +expression to access those arguments. If empty string arguments are +passed to @command{emacsclient}, those are included as well. Be careful +to have your expression remove the processed arguments from @var{server-eval-args-left} regardless of whether your code succeeds, for example by using @code{pop}, otherwise Emacs will attempt to evaluate those arguments as separate Lisp expressions. diff --git a/etc/NEWS b/etc/NEWS index 0dbe168d8c1..b3f8061f742 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -715,6 +715,12 @@ debugger and show the backtrace. If 'debug-on-error' is nil, these errors will be sent to 'emacsclient', as before, and will be displayed on the terminal from which 'emacsclient' was invoked. ++++ +** Empty string arguments to emacsclient are no longer ignored. +Emacs previously discarded arguments to emacsclient of zero length, such +as in 'emacsclient --eval "(length (pop server-eval-args-left))" ""'. +These are no longer discarded. + * Editing Changes in Emacs 31.1 diff --git a/lisp/server.el b/lisp/server.el index 4390562a580..bf3430b48d7 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1267,8 +1267,10 @@ The following commands are accepted by the client: args-left) ;; Remove this line from STRING. (setq string (substring string (match-end 0))) - (setq args-left - (mapcar #'server-unquote-arg (split-string request " " t))) + (cl-assert (equal (substring request -1) " ") + nil "emacsclient request did not end in SPC") + (setq args-left (mapcar #'server-unquote-arg + (nbutlast (split-string request " ")))) (while args-left (pcase (pop args-left) ;; -version CLIENT-VERSION: obsolete at birth. @@ -1481,6 +1483,9 @@ Adding or removing strings from this variable while the Emacs server is processing a series of eval requests will affect what Emacs evaluates. +This list includes empty strings if empty string arguments were passed +when invoking emacsclient. + See also `argv' for a similar variable which works for invocations of \"emacs\".")