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

* eat.el (eat--eshell-adjust-make-process-args): Avoid
unnecessary function overrides.  Overriding functions with
'cl-letf*' is not well documented, and self-overriding a
function (override a function with its own definition) may not
a nop.
This commit is contained in:
Akib Azmain Turja 2022-12-14 14:32:03 +06:00
parent fc195410e4
commit 35df1bc2a4
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

95
eat.el
View file

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