Function: eshell-lisp-command

eshell-lisp-command is a byte-compiled function defined in esh-cmd.el.gz.

Signature

(eshell-lisp-command OBJECT &optional ARGS)

Documentation

Insert Lisp OBJECT, using ARGS if a function.

Aliases

eshell-lisp-command* (obsolete since 31.1)

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
(defvar eshell-last-output-end)         ;Defined in esh-mode.el.

(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))
    (let* ((eshell-ensure-newline-p t)
           (command-form-p (and (functionp object)
                                (symbolp object)))
           (literal-result (when command-form-p
                             (get object 'eshell-literal-result)))
           result worker-result
           (printer
            (lambda (object)
              (setq worker-result
                    (cond
                     ((and (not literal-result) (eshell-worker-p object))
                      object)
                     ((and (not literal-result)
                           (memq eshell-in-pipeline-p '(t last))
                           (eshell-get-pipe object)))
                     (t
                      (ignore (eshell-print-maybe-n object))))))))
      (if command-form-p
          (setq eshell-last-arguments (eshell-convert-args args object)
                eshell-last-command-name (format "#<function %s>"
                                                 (symbol-name object)))
        (setq eshell-last-arguments args
              eshell-last-command-name "#<Lisp object>"))
      (setq result (eshell-exec-lisp
                    printer #'eshell-error-maybe-n
                    object eshell-last-arguments (not command-form-p)))
      (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))
      worker-result)))