]> git.eshelyaron.com Git - emacs.git/commitdiff
; Move common Eshell pipeline code to a separate function
authorJim Porter <jporterbugs@gmail.com>
Fri, 31 Mar 2023 23:57:18 +0000 (16:57 -0700)
committerJim Porter <jporterbugs@gmail.com>
Sun, 10 Sep 2023 17:38:25 +0000 (10:38 -0700)
* 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

index ed2d6c71fc83763959dfa71533ff59ed5735ea9f..f6846345d7da057c799e346600194efdf5b0f06c 100644 (file)
@@ -790,10 +790,25 @@ current ones (see `eshell-duplicate-handles')."
      (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 @@ This macro calls itself recursively, with NOTFIRST non-nil."
                   (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 @@ This macro calls itself recursively, with NOTFIRST non-nil."
 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))