Don't intercept background processes in Eshell

* eat.el (eat--eshell-adjust-make-process-args): Don't do any
change to the environment if 'eshell-current-subjob-p' is
non-nil.
This commit is contained in:
Akib Azmain Turja 2022-12-12 10:22:14 +06:00
parent 6756e72d88
commit f76c27cd93
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

94
eat.el
View file

@ -5474,6 +5474,8 @@ PROGRAM can be a shell command."
(eat--eshell-cleanup))))
(eshell-sentinel process message))
(defvar eshell-current-subjob-p) ; In `esh-proc'.
;; HACK: This is a dirty hack, it can break easily.
(defun eat--eshell-adjust-make-process-args (fn command args)
"Setup an environment to adjust `make-process' arguments.
@ -5481,53 +5483,55 @@ PROGRAM can be a shell command."
Call FN with COMMAND and ARGS, and whenever `make-process' is called,
modify its argument to change the filter, the sentinel and invoke
`stty' from the new process."
(cl-letf*
(;; For Emacs 29 and above.
(make-process (symbol-function #'make-process))
((symbol-function #'make-process)
(if (< emacs-major-version 29)
make-process
(lambda (&rest plist)
;; Make sure we don't attack wrong process.
(if (not (equal (plist-get plist :command)
(cons (file-local-name
(expand-file-name command))
args)))
(apply make-process plist)
(setf (plist-get plist :command)
`("/usr/bin/env" "sh" "-c"
,(format "stty -nl echo rows %d columns %d \
(if eshell-current-subjob-p
(funcall fn command args)
(cl-letf*
(;; For Emacs 29 and above.
(make-process (symbol-function #'make-process))
((symbol-function #'make-process)
(if (< emacs-major-version 29)
make-process
(lambda (&rest plist)
;; Make sure we don't attack wrong process.
(if (not (equal (plist-get plist :command)
(cons (file-local-name
(expand-file-name command))
args)))
(apply make-process plist)
(setf (plist-get plist :command)
`("/usr/bin/env" "sh" "-c"
,(format "stty -nl echo rows %d columns %d \
sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
(floor (window-screen-lines))
(window-max-chars-per-line)
null-device)
".." ,@(plist-get plist :command)))
(apply make-process plist)))))
;; For Emacs 28.
(start-file-process (symbol-function #'start-file-process))
((symbol-function #'start-file-process)
(if (< emacs-major-version 29)
(lambda (name buffer &rest command)
(apply start-file-process name buffer
`("/usr/bin/env" "sh" "-c"
,(format "stty -nl echo rows %d columns %d \
(floor (window-screen-lines))
(window-max-chars-per-line)
null-device)
".." ,@(plist-get plist :command)))
(apply make-process plist)))))
;; For Emacs 28.
(start-file-process (symbol-function #'start-file-process))
((symbol-function #'start-file-process)
(if (< emacs-major-version 29)
(lambda (name buffer &rest command)
(apply start-file-process name buffer
`("/usr/bin/env" "sh" "-c"
,(format "stty -nl echo rows %d columns %d \
sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
(floor (window-screen-lines))
(window-max-chars-per-line)
null-device)
".." ,@command)))
;; Don't override on Emacs 28.
start-file-process)))
(let ((hook
(lambda (proc)
(set-process-filter proc #'eat--eshell-filter)
(set-process-sentinel proc #'eat--eshell-sentinel)
(eat--eshell-setup-proc-and-term proc))))
(unwind-protect
(progn
(add-hook 'eshell-exec-hook hook 99)
(funcall fn command args))
(remove-hook 'eshell-exec-hook hook)))))
(floor (window-screen-lines))
(window-max-chars-per-line)
null-device)
".." ,@command)))
;; Don't override on Emacs 28.
start-file-process)))
(let ((hook
(lambda (proc)
(set-process-filter proc #'eat--eshell-filter)
(set-process-sentinel proc #'eat--eshell-sentinel)
(eat--eshell-setup-proc-and-term proc))))
(unwind-protect
(progn
(add-hook 'eshell-exec-hook hook 99)
(funcall fn command args))
(remove-hook 'eshell-exec-hook hook))))))
;;;;; Minor Modes.