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-filter proc #'eat--eshell-filter)
(set-process-sentinel proc #'eat--eshell-sentinel) (set-process-sentinel proc #'eat--eshell-sentinel)
(eat--eshell-setup-proc-and-term proc)))) (eat--eshell-setup-proc-and-term proc))))
(add-hook 'eshell-exec-hook hook 99)
(unwind-protect (unwind-protect
(progn (cond
(add-hook 'eshell-exec-hook hook 99) ;; Emacs 29 and above.
(cond ((>= emacs-major-version 29)
;; Emacs 29 and above. (cl-letf*
((>= emacs-major-version 29) ((make-process (symbol-function #'make-process))
(cl-letf* ((symbol-function #'make-process)
((make-process (symbol-function #'make-process)) (lambda (&rest plist)
((symbol-function #'make-process) ;; Make sure we don't attack wrong process.
(lambda (&rest plist) (if (not (equal
;; Make sure we don't attack wrong process. (plist-get plist :command)
(if (not (equal (cons (file-local-name
(plist-get plist :command) (expand-file-name command))
(cons (file-local-name args)))
(expand-file-name command)) (apply make-process plist)
args))) (setf (plist-get plist :command)
(apply make-process plist) `("/usr/bin/env" "sh" "-c"
(setf (plist-get plist :command) ,(format "stty -nl echo rows %d columns\
`("/usr/bin/env" "sh" "-c" %d sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
,(format "stty -nl echo rows %d \ (floor (window-screen-lines))
columns %d sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\"" (window-max-chars-per-line)
(floor (window-screen-lines)) null-device)
(window-max-chars-per-line) ".." ,@(plist-get plist :command)))
null-device) (apply make-process plist)))))
".." ,@(plist-get plist :command))) (funcall fn command args)))
(apply make-process plist))))) ;; Emacs 28.
(funcall fn command args))) (t
;; Emacs 28. (cl-letf*
(t ((start-file-process
(cl-letf* (symbol-function #'start-file-process))
((start-file-process ((symbol-function #'start-file-process)
(symbol-function #'start-file-process)) (lambda (name buffer &rest command)
((symbol-function #'start-file-process) (apply start-file-process name buffer
(lambda (name buffer &rest command) "/usr/bin/env" "sh" "-c"
(apply start-file-process name buffer (format "stty -nl echo rows %d columns %d \
"/usr/bin/env" "sh" "-c" sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
(format "stty -nl echo rows %d columns \ (floor (window-screen-lines))
%d sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\"" (window-max-chars-per-line)
(floor (window-screen-lines)) null-device)
(window-max-chars-per-line) ".." command))))
null-device) (funcall fn command args))))
".." command))))
(funcall fn command args)))))
(remove-hook 'eshell-exec-hook hook))))) (remove-hook 'eshell-exec-hook hook)))))