Don't discard empty string arguments from emacsclient

* lisp/server.el (server--process-filter-1): Don't discard empty
string arguments from emacsclient.
(server-eval-args-left):
* doc/emacs/misc.texi (emacsclient Options):
* etc/NEWS: Document the change.
This commit is contained in:
Sean Whitton 2025-11-07 12:33:21 +00:00
parent be527b5704
commit 68e337e630
3 changed files with 18 additions and 6 deletions

View file

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

View file

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

View file

@ -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\".")