From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#65902: 29.0.92; emacsclient-mail.desktop fails due to complicated escaping Date: Sun, 22 Oct 2023 14:15:56 +0000 (UTC) Message-ID: <87h6mispyc.fsf@catern.com> References: <80d8aeb0-c9f1-410f-b83d-60f83ca5b3af@email.android.com> <83led8ls3z.fsf@gnu.org> <835y4ckkzu.fsf@gnu.org> <874jjnvvip.fsf@catern.com> <835y4290kf.fsf@gnu.org> <87zg1cprix.fsf@catern.com> <83a5tc4096.fsf@gnu.org> <87wmwfps9s.fsf@catern.com> <87o7gsroib.fsf@catern.com> <83wmvfp6qc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31185"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65902@debbugs.gnu.org, sbaugh@janestreet.com, jporterbugs@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 22 16:16:49 2023 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 1quZG4-0007sa-AM for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 22 Oct 2023 16:16:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1quZFv-0007Yd-6U; Sun, 22 Oct 2023 10:16:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1quZFq-0007WG-6m for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2023 10:16:34 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1quZFp-0001N2-V4 for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2023 10:16:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1quZGI-0004q7-Ah for bug-gnu-emacs@gnu.org; Sun, 22 Oct 2023 10:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Oct 2023 14:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65902 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65902-submit@debbugs.gnu.org id=B65902.169798419418555 (code B ref 65902); Sun, 22 Oct 2023 14:17:02 +0000 Original-Received: (at 65902) by debbugs.gnu.org; 22 Oct 2023 14:16:34 +0000 Original-Received: from localhost ([127.0.0.1]:47888 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quZFq-0004pC-02 for submit@debbugs.gnu.org; Sun, 22 Oct 2023 10:16:34 -0400 Original-Received: from s.wrqvtbkv.outbound-mail.sendgrid.net ([149.72.123.24]:48384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1quZFm-0004oj-16 for 65902@debbugs.gnu.org; Sun, 22 Oct 2023 10:16:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: cc:content-type:from:subject:to; s=s1; bh=jQLNs2iRB4KD4/MZ9B7vkQsl8B/A37IC++EUIZxIxZg=; b=ipJnmnlRlJuyWYn7aZ0ELcByKidR7UX//3Ahu3bOMrCIc4+5hKD/qak2dSSJEJtV8FJ2 TiFfmyG8xbwUCUa1GJSB+dHOCLvmSCe9LdNYkk5d3xNvYnVphWZujD69wCrvgoA6filQ87 biOmvDgtHreISktEE0ane5qYwKtqy0mf4lv1G9/wMnGGmX65BZx51TS43N7DXLmZWjwoL4 GeCN1Gt4vmT2x9/DrVZiuERTsfyaE/57JranLTNYbGBo8N1WFAJkPGkkMuQXv54Qv2CiIc S/8iREzwPkrECzPVV2/YcGm7/iha0MlfSfMB/V/KBYtR0sM9D9m7PspbF14yUyVA== Original-Received: by filterdrecv-656b5b4c75-gb89s with SMTP id filterdrecv-656b5b4c75-gb89s-1-65352E9B-39 2023-10-22 14:15:55.974235587 +0000 UTC m=+416164.770985231 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-38 (SG) with ESMTP id SRabVXRNRrG8n573dIBiug Sun, 22 Oct 2023 14:15:55.923 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=gnu.org Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id 67E20601BB; Sun, 22 Oct 2023 10:15:55 -0400 (EDT) In-Reply-To: <83wmvfp6qc.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 22 Oct 2023 08:27:07 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbIIVfzbSmzC1C+qGg9ULPihHJANLyM5ZQMB217rMLZpxt5DgEVhblVoGteblqfkGOA9h5JCM2biaOm2Ymxk1b72AZFoPAMKm+hQNWlOWZFhTjmAkVz3XF2BTANAHzuuj44dOsGKvEzcH5iv6PipPw1MRUt0Ce/rRZhX5U9KO4nmqA== X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272979 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii writes: >> From: sbaugh@catern.com >> Date: Sat, 21 Oct 2023 15:20:13 +0000 (UTC) >> Cc: jporterbugs@gmail.com, sbaugh@janestreet.com, 65902@debbugs.gnu.org >> >> >> Any remaining concerns about this patch? It would be nice to install >> it. > > It no longer applies, so please rebase and repost. TIA. Rebased --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-server-eval-args-left-to-server.el.patch >From bd49b918e57363593660f605c3e0efc3d0155c2b Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Thu, 21 Sep 2023 21:35:50 -0400 Subject: [PATCH] Add server-eval-args-left to server.el Passing arbitrary arguments to functions through emacsclient --eval requires complicated escaping to avoid them being parsed as Lisp (as seen in emacsclient-mail.desktop before this change). This new variable server-eval-args-left allows access to the arguments before they are parsed as Lisp. By removing arguments from the variable before they're parsed, a snippet of Lisp can consume arguments, as in emacsclient-mail.desktop. org-protocol might be able to use this as well, which might allow it to drop its current advice on server-visit-files. * etc/emacsclient-mail.desktop: Use server-eval-args-left. (bug#65902) * lisp/server.el (server-eval-args-left): Add. (server-process-filter, server-execute): Make -eval arguments available through server-eval-args-left. * lisp/startup.el (argv): Mention server-eval-args-left in docstring. * etc/NEWS: Announce server-eval-args-left. * doc/emacs/misc.texi (emacsclient Options): Document server-eval-args-left. --- doc/emacs/misc.texi | 9 +++++++++ etc/NEWS | 10 ++++++++++ etc/emacsclient-mail.desktop | 7 ++----- lisp/server.el | 27 ++++++++++++++++++++------- lisp/startup.el | 5 ++++- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 7a88b7ef5e0..1ce1713b01c 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -2078,6 +2078,15 @@ emacsclient Options @command{emacsclient} are interpreted as a list of expressions to evaluate, @emph{not} as a list of files to visit. +@vindex server-eval-args-left +If you have arbitrary data which you want to provide as input to one +of your expressions, you can pass the data as another argument to +@command{emacsclient} and use @var{server-eval-args-left} in the +expression to access the data. Be careful to have your expression +remove the data from @var{server-eval-args-left} regardless of whether +your code succeeds, such as by using @code{pop}, otherwise Emacs will +attempt to evaluate the data as a Lisp expression. + @item -f @var{server-file} @itemx --server-file=@var{server-file} Specify a server file (@pxref{TCP Emacs server}) for connecting to an diff --git a/etc/NEWS b/etc/NEWS index cd4c414a64c..de1d79fcb98 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -121,6 +121,16 @@ Anything following the symbol 'mode-line-format-right-align' in right-aligned to is controlled by the new user option 'mode-line-right-align-edge'. +** Emacs Server and Client + +--- +*** 'server-eval-args-left' can be used to pop subsequent eval args +When '--eval' is passed to emacsclient and Emacs is evaluating each +argument, this variable is set to those which have not yet been +evaluated. It can be used to 'pop' arguments to prevent them from +being evaluated, which is useful when those arguments contain +arbitrary data. + * Editing Changes in Emacs 30.1 diff --git a/etc/emacsclient-mail.desktop b/etc/emacsclient-mail.desktop index 0a2420ddead..5962fa1764c 100644 --- a/etc/emacsclient-mail.desktop +++ b/etc/emacsclient-mail.desktop @@ -1,10 +1,7 @@ [Desktop Entry] Categories=Network;Email; Comment=GNU Emacs is an extensible, customizable text editor - and more -# We want to pass the following commands to the shell wrapper: -# u=$(echo "$1" | sed 's/[\"]/\\&/g'); exec emacsclient --alternate-editor= --display="$DISPLAY" --eval "(message-mailto \"$u\")" -# Special chars '"', '$', and '\' must be escaped as '\\"', '\\$', and '\\\\'. -Exec=sh -c "u=\\$(echo \\"\\$1\\" | sed 's/[\\\\\\"]/\\\\\\\\&/g'); exec emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" --eval \\"(message-mailto \\\\\\"\\$u\\\\\\")\\"" sh %u +Exec=emacsclient --alternate-editor= --eval '(message-mailto (pop server-eval-args-left))' %u Icon=emacs Name=Emacs (Mail, Client) MimeType=x-scheme-handler/mailto; @@ -16,7 +13,7 @@ Actions=new-window;new-instance; [Desktop Action new-window] Name=New Window -Exec=sh -c "u=\\$(echo \\"\\$1\\" | sed 's/[\\\\\\"]/\\\\\\\\&/g'); exec emacsclient --alternate-editor= --create-frame --eval \\"(message-mailto \\\\\\"\\$u\\\\\\")\\"" sh %u +Exec=emacsclient --alternate-editor= --create-frame --eval '(message-mailto (pop server-eval-args-left))' %u [Desktop Action new-instance] Name=New Instance diff --git a/lisp/server.el b/lisp/server.el index c3325e5a24c..3970d7a7e81 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1189,6 +1189,7 @@ server-process-filter parent-id ; Window ID for XEmbed dontkill ; t if client should not be killed. commands + evalexprs dir use-current-frame frame-parameters ;parameters for newly created frame @@ -1319,8 +1320,7 @@ server-process-filter (let ((expr (pop args-left))) (if coding-system (setq expr (decode-coding-string expr coding-system))) - (push (lambda () (server-eval-and-print expr proc)) - commands) + (push expr evalexprs) (setq filepos nil))) ;; -env NAME=VALUE: An environment variable. @@ -1345,7 +1345,7 @@ server-process-filter ;; arguments, use an existing frame. (and nowait (not (eq tty-name 'window-system)) - (or files commands) + (or files commands evalexprs) (setq use-current-frame t)) (setq frame @@ -1394,7 +1394,7 @@ server-process-filter (let ((default-directory (if (and dir (file-directory-p dir)) dir default-directory))) - (server-execute proc files nowait commands + (server-execute proc files nowait commands evalexprs dontkill frame tty-name))))) (when (or frame files) @@ -1404,22 +1404,35 @@ server-process-filter ;; condition-case (t (server-return-error proc err)))) -(defun server-execute (proc files nowait commands dontkill frame tty-name) +(defvar server-eval-args-left nil + "List of eval args not yet processed. + +Adding or removing strings from this variable while the Emacs +server is processing a series of eval requests will affect what +Emacs evaluates. + +See also `argv' for a similar variable which works for +invocations of \"emacs\".") + +(defun server-execute (proc files nowait commands evalexprs dontkill frame tty-name) ;; This is run from timers and process-filters, i.e. "asynchronously". ;; But w.r.t the user, this is not really asynchronous since the timer ;; is run after 0s and the process-filter is run in response to the ;; user running `emacsclient'. So it is OK to override the - ;; inhibit-quit flag, which is good since `commands' (as well as + ;; inhibit-quit flag, which is good since `evalexprs' (as well as ;; find-file-noselect via the major-mode) can run arbitrary code, ;; including code that needs to wait. (with-local-quit (condition-case err (let ((buffers (server-visit-files files proc nowait))) (mapc 'funcall (nreverse commands)) + (let ((server-eval-args-left (nreverse evalexprs))) + (while server-eval-args-left + (server-eval-and-print (pop server-eval-args-left) proc))) ;; If we were told only to open a new client, obey ;; `initial-buffer-choice' if it specifies a file ;; or a function. - (unless (or files commands) + (unless (or files commands evalexprs) (let ((buf (cond ((stringp initial-buffer-choice) (find-file-noselect initial-buffer-choice)) diff --git a/lisp/startup.el b/lisp/startup.el index 7f601668369..f2c84751211 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -120,7 +120,10 @@ command-switch-alist "List of command-line args not yet processed. This is a convenience alias, so that one can write (pop argv) inside of --eval command line arguments in order to access -following arguments.")) +following arguments. + +See also `server-eval-args-left' for a similar variable which +works for invocations of \"emacsclient --eval\".")) (internal-make-var-non-special 'argv) (defvar command-line-args-left nil -- 2.41.0 --=-=-=--