From dbd223d4cfbdb07ed87c7f497c2ba691a112a16c Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Tue, 17 Sep 2024 22:05:50 -0700 Subject: [PATCH 1/3] Simplify creation of Eshell command forms Previously, Eshell over-aggressively converted subcommands, which forced control flow commands to undo that change. * lisp/eshell/esh-cmd.el (eshell-pre-rewrite-command-hook): Remove 'eshell-subcommand-arg-values' call from here... (eshell-rewrite-named-command): ... and put it here. (eshell-invokify-arg): Make obsolete. (eshell-structure-basic-command): Handle subcommand test forms. (eshell-rewrite-for-command, eshell-rewrite-while-command) (eshell-rewrite-if-command): Don't call 'eshell-invokify-arg'; it's not necessary. --- lisp/eshell/esh-cmd.el | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 09fc65522ad..2a299125f22 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -181,8 +181,7 @@ eshell-named-command-hook :type 'hook) (defcustom eshell-pre-rewrite-command-hook - '(eshell-no-command-conversion - eshell-subcommand-arg-values) + '(eshell-no-command-conversion) "A hook run before command rewriting begins. The terms of the command to be rewritten is passed as arguments, and may be modified in place. Any return value is ignored." @@ -478,6 +477,7 @@ eshell-rewrite-initial-subcommand (defun eshell-rewrite-named-command (terms) "If no other rewriting rule transforms TERMS, assume a named command." + (eshell-subcommand-arg-values terms) (let ((sym (if eshell-in-pipeline-p 'eshell-named-command* 'eshell-named-command)) @@ -503,6 +503,7 @@ eshell-invokify-arg means the user and/or any redirections shouldn't see any output from this command. If both SHARE-OUTPUT and SILENT are non-nil, the second is ignored." + (declare (obsolete nil "31.1")) ;; something that begins with `eshell-convert' means that it ;; intends to return a Lisp value. We want to get past this, ;; but if it's not _actually_ a value interpolation -- in which @@ -543,7 +544,7 @@ eshell-rewrite-for-command (let ((,(intern (cadr terms)) (car ,for-items)) (eshell--local-vars (cons ',(intern (cadr terms)) eshell--local-vars))) - ,(eshell-invokify-arg body t)) + ,body) (setq ,for-items (cdr ,for-items))))))) (defun eshell-structure-basic-command (func names keyword test body @@ -552,6 +553,11 @@ eshell-structure-basic-command The first of NAMES should be the positive form, and the second the negative. It's not likely that users should ever need to call this function." + ;; If the test form is a subcommand, wrap it in `eshell-commands' to + ;; silence the output. + (when (eq (car test) 'eshell-as-subcommand) + (setq test `(eshell-commands ,test t))) + ;; If the test form begins with `eshell-convert' or ;; `eshell-escape-arg', it means something data-wise will be ;; returned, and we should let that determine the truth of the @@ -583,8 +589,8 @@ eshell-rewrite-while-command (member (car terms) '("while" "until"))) (eshell-structure-basic-command 'while '("while" "until") (car terms) - (eshell-invokify-arg (cadr terms) nil t) - (eshell-invokify-arg (car (last terms)) t)))) + (cadr terms) + (car (last terms))))) (defun eshell-rewrite-if-command (terms) "Rewrite an `if' command into its equivalent Eshell command form. @@ -595,10 +601,10 @@ eshell-rewrite-if-command (member (car terms) '("if" "unless"))) (eshell-structure-basic-command 'if '("if" "unless") (car terms) - (eshell-invokify-arg (cadr terms) nil t) - (eshell-invokify-arg (car (last terms (if (= (length terms) 4) 2))) t) + (cadr terms) + (car (last terms (if (= (length terms) 4) 2))) (when (= (length terms) 4) - (eshell-invokify-arg (car (last terms)) t))))) + (car (last terms)))))) (defun eshell-set-exit-info (status &optional result) "Set the exit status and result for the last command. -- 2.25.1