Refactor 'eat--eshell-adjust-make-process-args'

* eat.el (eat--eshell-adjust-make-process-args): Move the
'add-hook' out of 'unwind-protect'.
This commit is contained in:
Akib Azmain Turja 2022-12-15 13:00:06 +06:00
parent 162ec61f3d
commit 559c9c362c
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

83
eat.el
View file

@ -5543,49 +5543,48 @@ Disable terminal emulation?")))
(set-process-filter proc #'eat--eshell-filter)
(set-process-sentinel proc #'eat--eshell-sentinel)
(eat--eshell-setup-proc-and-term proc))))
(add-hook 'eshell-exec-hook hook 99)
(unwind-protect
(progn
(add-hook 'eshell-exec-hook hook 99)
(cond
;; Emacs 29 and above.
((>= emacs-major-version 29)
(cl-letf*
((make-process (symbol-function #'make-process))
((symbol-function #'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)))))
(funcall fn command args)))
;; Emacs 28.
(t
(cl-letf*
((start-file-process
(symbol-function #'start-file-process))
((symbol-function #'start-file-process)
(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))))
(funcall fn command args)))))
(cond
;; Emacs 29 and above.
((>= emacs-major-version 29)
(cl-letf*
((make-process (symbol-function #'make-process))
((symbol-function #'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)))))
(funcall fn command args)))
;; Emacs 28.
(t
(cl-letf*
((start-file-process
(symbol-function #'start-file-process))
((symbol-function #'start-file-process)
(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))))
(funcall fn command args))))
(remove-hook 'eshell-exec-hook hook)))))