emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/eat 532f7221b7: Send input to correct process in Eshell pi


From: ELPA Syncer
Subject: [nongnu] elpa/eat 532f7221b7: Send input to correct process in Eshell pipeline
Date: Mon, 20 Mar 2023 15:00:33 -0400 (EDT)

branch: elpa/eat
commit 532f7221b7f25ce3b42e140b6b43d8076671c211
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>

    Send input to correct process in Eshell pipeline
    
    * eat.el (eat--process): Remove.
    * eat.el (eat-mode): Don't make 'eat--process' buffer-local.
    Use 'eat--terminal' to determine whether terminal is live.
    * eat.el (eat--eshell-set-input-process): New function.
    * eat.el (eat--eshell-local-mode): Don't make 'eat--process'
    buffer-local.  Add 'eat--eshell-set-input-process' as a advice
    after 'eshell-resume-eval'.
    * eat.el (eat-exec): Use the terminal parameters
    'eat--process', 'eat--input-process' and 'eat--output-process'
    instead of the buffer-local variable 'eat--process' store the
    process object.
    * eat.el (eat--sentinel): Don't set 'eat--process' to nil.
    * eat.el (eat--eshell-setup-proc-and-term): Set the terminal
    parameters instead of buffer-local 'eat--process'.
    * eat.el (eat--pre-prompt, eat--pre-cmd, eat-kill-process, eat)
    (eat--send-input, eat--trace-eshell-adjust-make-process-args)
    (eat--eshell-cleanup, eat--eshell-output-filter): Get the
    process from terminal parameter.
---
 eat.el | 87 ++++++++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 55 insertions(+), 32 deletions(-)

diff --git a/eat.el b/eat.el
index 10affab228..49599d0d03 100644
--- a/eat.el
+++ b/eat.el
@@ -4582,8 +4582,8 @@ If HOST isn't the host Emacs is running on, don't do 
anything."
   (setq eat--shell-prompt-begin (point-marker))
   ;; FIXME: It's a crime to touch processes in this section.
   (when (eq eat-query-before-killing-running-terminal 'auto)
-    (when (bound-and-true-p eat--process)
-      (set-process-query-on-exit-flag eat--process nil))))
+    (set-process-query-on-exit-flag
+     (eat-term-parameter eat--terminal 'eat--process) nil)))
 
 (defun eat--post-prompt (_)
   "Put a mark in the marginal area on current line."
@@ -4687,8 +4687,8 @@ BUFFER is the terminal buffer."
   "Update shell prompt mark to indicate command is running."
   ;; FIXME: It's a crime to touch processes in this section.
   (when (eq eat-query-before-killing-running-terminal 'auto)
-    (when (bound-and-true-p eat--process)
-      (set-process-query-on-exit-flag eat--process t)))
+    (set-process-query-on-exit-flag
+     (eat-term-parameter eat--terminal 'eat--process) t))
   (when (and eat-enable-shell-prompt-annotation
              eat--shell-prompt-mark)
     (setf (cadr eat--shell-prompt-mark)
@@ -5152,7 +5152,6 @@ END if it's safe to do so."
           cursor-type
           track-mouse
           eat--terminal
-          eat--process
           eat--synchronize-scroll-function
           eat--mouse-grabbing-type
           eat--shell-command-status
@@ -5173,7 +5172,7 @@ END if it's safe to do so."
   (setq mode-line-process
         '(""
           (:eval
-           (when eat--process
+           (when eat--terminal
              (cond
               (eat--semi-char-mode
                '("["
@@ -5257,9 +5256,6 @@ mouse-3: Switch to char mode"
 
 ;;;;; Process Handling.
 
-(defvar eat--process nil
-  "The running process.")
-
 (defvar eat--pending-output-chunks nil
   "The list of pending output chunks.
 
@@ -5277,8 +5273,9 @@ The output chunks are pushed, so last output appears 
first.")
 (defun eat-kill-process ()
   "Kill Eat process in current buffer."
   (interactive)
-  (when eat--process
-    (kill-process eat--process)))
+  (when-let* ((eat--terminal)
+              (proc (eat-term-parameter eat--terminal 'eat--process)))
+    (delete-process proc)))
 
 (defun eat--send-string (process string)
   "Send to PROCESS the contents of STRING as input.
@@ -5299,8 +5296,9 @@ OS's."
 
 (defun eat--send-input (_ input)
   "Send INPUT to subprocess."
-  (when eat--process
-    (eat--send-string eat--process input)))
+  (when-let* ((eat--terminal)
+              (proc (eat-term-parameter eat--terminal 'eat--process)))
+    (eat--send-string proc input)))
 
 (defun eat--process-output-queue (buffer)
   "Process the output queue on BUFFER."
@@ -5385,7 +5383,6 @@ to it."
                   (setq eat--shell-prompt-mark nil)
                   (setq eat--shell-prompt-mark-overlays nil))
                 (eat-emacs-mode)
-                (setq eat--process nil)
                 (delete-process process)
                 (eat-term-delete eat--terminal)
                 (setq eat--terminal nil)
@@ -5424,9 +5421,11 @@ mode.  You can use this to cheaply run a series of 
processes in the
 same Eat buffer.  The hook `eat-exec-hook' is run after each exec."
   (with-current-buffer buffer
     (let ((inhibit-read-only t))
-      (when eat--process
+      (when-let*
+          ((eat--terminal)
+           (proc (eat-term-parameter eat--terminal 'eat--process)))
         (let ((eat-kill-buffer-on-exit nil))
-          (delete-process eat--process)))
+          (delete-process proc)))
       ;; Ensure final newline.
       (goto-char (point-max))
       (unless (or (= (point-min) (point-max))
@@ -5493,14 +5492,19 @@ same Eat buffer.  The hook `eat-exec-hook' is run after 
each exec."
         ;; Jump to the end, and set the process mark.
         (goto-char (point-max))
         (set-marker (process-mark process) (point))
-        (setq eat--process process)
+        (setf (eat-term-parameter eat--terminal 'eat--process)
+              process)
+        (setf (eat-term-parameter eat--terminal 'eat--input-process)
+              process)
+        (setf (eat-term-parameter eat--terminal 'eat--output-process)
+              process)
         ;; Feed it the startfile.
         (when startfile
-          ;;This is guaranteed to wait long enough
-          ;;but has bad results if the shell does not prompt at all
-          ;;         (while (= size (buffer-size))
-          ;;           (sleep-for 1))
-          ;;I hope 1 second is enough!
+          ;; This is guaranteed to wait long enough
+          ;; but has bad results if the shell does not prompt at all
+          ;;          (while (= size (buffer-size))
+          ;;            (sleep-for 1))
+          ;; I hope 1 second is enough!
           (sleep-for 1)
           (goto-char (point-max))
           (insert-file-contents startfile)
@@ -5567,7 +5571,8 @@ PROGRAM can be a shell command."
       (unless (eq major-mode #'eat-mode)
         (eat-mode))
       (pop-to-buffer-same-window buffer)
-      (unless eat--process
+      (unless (and eat--terminal
+                   (eat-term-parameter eat--terminal 'eat--process))
         (eat-exec buffer (buffer-name) "/usr/bin/env" nil
                   (list "sh" "-c" program)))
       buffer)))
@@ -5697,6 +5702,8 @@ PROGRAM can be a shell command."
 
 (defvar eshell-last-output-start) ; In `esh-mode'.
 (defvar eshell-last-output-end) ; In `esh-mode'.
+(declare-function eshell-head-process "esh-cmd" ())
+(declare-function eshell-resume-eval "esh-cmd" ())
 
 (defun eat--eshell-term-name (&rest _)
   "Return the value of `TERM' environment variable for Eshell."
@@ -5717,12 +5724,13 @@ PROGRAM can be a shell command."
     (let ((end (eat-term-end eat--terminal)))
       (set-marker eshell-last-output-start end)
       (set-marker eshell-last-output-end end)
-      (set-marker (process-mark eat--process) end))))
+      (set-marker (process-mark (eat-term-parameter
+                                 eat--terminal 'eat--output-process))
+                  end))))
 
 (defun eat--eshell-setup-proc-and-term (proc)
   "Setup process PROC and a new terminal for it."
-  (unless (or eat--terminal eat--process)
-    (setq eat--process proc)
+  (unless eat--terminal
     (process-put proc 'adjust-window-size-function
                  #'eat--adjust-process-window-size)
     (setq eat--terminal (eat-term-make (current-buffer)
@@ -5738,6 +5746,9 @@ PROGRAM can be a shell command."
     (setf (eat-term-ring-bell-function eat--terminal) #'eat--bell)
     (setf (eat-term-set-cwd-function eat--terminal) #'eat--set-cwd)
     (setf (eat-term-set-cmd-function eat--terminal) #'eat--set-cmd)
+    (setf (eat-term-parameter eat--terminal 'eat--process) proc)
+    (setf (eat-term-parameter eat--terminal 'eat--output-process)
+          proc)
     (when-let* ((window (get-buffer-window nil t)))
       (with-selected-window window
         (eat-term-resize eat--terminal (window-max-chars-per-line)
@@ -5762,9 +5773,10 @@ PROGRAM can be a shell command."
       (set-marker eshell-last-output-end (point))
       (eat--cursor-blink-mode -1)
       (eat--grab-mouse nil nil)
+      (set-process-filter (eat-term-parameter
+                           eat--terminal 'eat--output-process)
+                          #'eshell-output-filter)
       (eat-term-delete eat--terminal)
-      (set-process-filter eat--process #'eshell-output-filter)
-      (setq eat--process nil)
       (setq eat--terminal nil)
       (kill-local-variable 'eshell-output-filter-functions)
       (eat--eshell-semi-char-mode -1)
@@ -5903,6 +5915,12 @@ sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
               (funcall fn command args))))
         (remove-hook 'eshell-exec-hook hook)))))
 
+(defun eat--eshell-set-input-process ()
+  "Set the process that gets user input."
+  (when eat--terminal
+    (setf (eat-term-parameter eat--terminal 'eat--input-process)
+          (eshell-head-process))))
+
 
 ;;;;; Minor Modes.
 
@@ -5946,7 +5964,6 @@ symbol `buffer', in which case the point of current 
buffer is set."
                   track-mouse
                   filter-buffer-substring-function
                   eat--terminal
-                  eat--process
                   eat--synchronize-scroll-function
                   eat--mouse-grabbing-type
                   eat--pending-output-chunks
@@ -6064,7 +6081,9 @@ symbol `buffer', in which case the point of current 
buffer is set."
              eat-term-shell-integration-directory t)
             ,@eshell-variable-aliases-list))
     (advice-add #'eshell-gather-process-output :around
-                #'eat--eshell-adjust-make-process-args))
+                #'eat--eshell-adjust-make-process-args)
+    (advice-add #'eshell-resume-eval :after
+                #'eat--eshell-set-input-process))
    (t
     (let ((buffers nil))
       (setq eat-eshell-mode t)
@@ -6095,7 +6114,9 @@ symbol `buffer', in which case the point of current 
buffer is set."
                        ("INSIDE_EMACS" eat-term-inside-emacs t))))
            eshell-variable-aliases-list))
     (advice-remove #'eshell-gather-process-output
-                   #'eat--eshell-adjust-make-process-args))))
+                   #'eat--eshell-adjust-make-process-args)
+    (advice-remove #'eshell-resume-eval
+                   #'eat--eshell-set-input-process))))
 
 
 ;;;; Eshell Visual Command Handling.
@@ -6363,7 +6384,9 @@ see."
           (let ((time (current-time)))
             (prog1
                 (funcall eat--eshell-setup-proc-and-term proc)
-              (when (eq eat--process proc)
+              (when (eq (eat-term-parameter
+                         eat--terminal 'eat--output-process)
+                        proc)
                 (let ((buf (generate-new-buffer
                             (format "*eat-trace %s*: %s"
                                     (buffer-name)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]