Created
May 25, 2025 05:12
-
-
Save jwiegley/b035ad749caaa41f5418fc1f26854ba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun eshell-lisp-command (object &optional args) | |
"Insert Lisp OBJECT, using ARGS if a function." | |
(unless eshell-allow-commands | |
(signal 'eshell-commands-forbidden '(lisp))) | |
(catch 'eshell-external ; deferred to an external command | |
(when (memq eshell-in-pipeline-p '(nil last)) | |
(eshell-set-exit-info 0)) | |
(setq eshell-last-arguments args) | |
(let* ((eshell-ensure-newline-p t) | |
(command-form-p (functionp object)) | |
(result | |
(if command-form-p | |
(let ((numeric (not (get object | |
'eshell-no-numeric-conversions))) | |
(fname-args (get object 'eshell-filename-arguments))) | |
(when (or numeric fname-args) | |
(while args | |
(let ((arg (car args))) | |
(cond | |
((and numeric (eshell--numeric-string-p arg)) | |
;; If any of the arguments are flagged as | |
;; numbers waiting for conversion, convert | |
;; them now. | |
(setcar args (string-to-number arg))) | |
((and fname-args (stringp arg) | |
(string-equal arg "~")) | |
;; If any of the arguments match "~", | |
;; prepend "./" to treat it as a regular | |
;; file name. | |
(setcar args (concat "./" arg))))) | |
(setq args (cdr args)))) | |
(setq eshell-last-command-name | |
(concat "#<function " (symbol-name object) ">")) | |
(eshell-apply* #'eshell-print-maybe-n | |
#'eshell-error-maybe-n | |
object eshell-last-arguments)) | |
(setq eshell-last-command-name "#<Lisp object>") | |
(eshell-eval* #'eshell-print-maybe-n | |
#'eshell-error-maybe-n | |
object)))) | |
(when (memq eshell-in-pipeline-p '(nil last)) | |
(eshell-set-exit-info | |
;; If `eshell-lisp-form-nil-is-failure' is non-nil, Lisp forms | |
;; that succeeded but have a nil result should have an exit | |
;; status of 2. | |
(when (and eshell-lisp-form-nil-is-failure | |
(not command-form-p) | |
(= eshell-last-command-status 0) | |
(not result)) | |
2) | |
result)) | |
(and (eshell-function-target-p result) | |
result)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment