From 627b85895590e75507fa329691f76a0a22daea7d Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Fri, 31 Mar 2023 16:57:18 -0700 Subject: [PATCH 1/5] ; Move common Eshell pipeline code to a separate function * lisp/eshell/esh-cmd.el (eshell-do-pipelines) (eshell-do-pipelines-synchronously): Move code for manipulating deferrable command forms to... (eshell--unmark-deferrable): ... here. --- lisp/eshell/esh-cmd.el | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index ed2d6c71fc8..f6846345d7d 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -790,10 +790,25 @@ eshell-protect (eshell-protect-handles eshell-current-handles) ,object)) +(defun eshell--unmark-deferrable (command) + "If COMMAND is (or ends with) a deferrable command, unmark it as such. +This changes COMMAND in-place by converting function calls listed +in `eshell-deferrable-commands' to their non-deferrable forms so +that Eshell doesn't erroneously allow deferring it. For example, +`eshell-named-command' becomes `eshell-named-command*', " + (let ((cmd command)) + (when (memq (car cmd) '(let progn)) + (setq cmd (car (last cmd)))) + (when (memq (car cmd) eshell-deferrable-commands) + (setcar cmd (intern-soft + (concat (symbol-name (car cmd)) "*")))) + command)) + (defmacro eshell-do-pipelines (pipeline &optional notfirst) "Execute the commands in PIPELINE, connecting each to one another. This macro calls itself recursively, with NOTFIRST non-nil." (when (setq pipeline (cadr pipeline)) + (eshell--unmark-deferrable (car pipeline)) `(eshell-with-copied-handles (progn ,(when (cdr pipeline) @@ -801,14 +816,6 @@ eshell-do-pipelines (eshell-do-pipelines (quote ,(cdr pipeline)) t))) (eshell-set-output-handle ,eshell-output-handle 'append nextproc))) - ,(let ((head (car pipeline))) - (if (memq (car head) '(let progn)) - (setq head (car (last head)))) - (when (memq (car head) eshell-deferrable-commands) - (ignore - (setcar head - (intern-soft - (concat (symbol-name (car head)) "*")))))) ;; First and last elements in a pipeline may need special treatment. ;; (Currently only eshell-ls-files uses 'last.) ;; Affects process-connection-type in eshell-gather-process-output. @@ -828,20 +835,13 @@ eshell-do-pipelines-synchronously Output of each command is passed as input to the next one in the pipeline. This is used on systems where async subprocesses are not supported." (when (setq pipeline (cadr pipeline)) + ;; FIXME: is deferrable significant here? + (eshell--unmark-deferrable (car pipeline)) `(progn ,(when (cdr pipeline) `(let ((output-marker ,(point-marker))) (eshell-set-output-handle ,eshell-output-handle 'append output-marker))) - ,(let ((head (car pipeline))) - (if (memq (car head) '(let progn)) - (setq head (car (last head)))) - ;; FIXME: is deferrable significant here? - (when (memq (car head) eshell-deferrable-commands) - (ignore - (setcar head - (intern-soft - (concat (symbol-name (car head)) "*")))))) ;; The last process in the pipe should get its handles ;; redirected as we found them before running the pipe. ,(if (null (cdr pipeline)) -- 2.25.1