Function: eshell-exec-lisp

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

Signature

(eshell-exec-lisp PRINTER ERRPRINT FUNC-OR-FORM ARGS FORM-P)

Documentation

Execute a Lisp FUNC-OR-FORM, maybe passing ARGS.

PRINTER and ERRPRINT are functions to use for printing regular messages and errors, respectively. FORM-P should be non-nil if FUNC-OR-FORM represent a Lisp form; ARGS will be ignored in that case.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
(defun eshell-exec-lisp (printer errprint func-or-form args form-p)
  "Execute a Lisp FUNC-OR-FORM, maybe passing ARGS.
PRINTER and ERRPRINT are functions to use for printing regular
messages and errors, respectively.  FORM-P should be non-nil if
FUNC-OR-FORM represent a Lisp form; ARGS will be ignored in that
case."
  (eshell-condition-case err
      (let ((result
             (save-current-buffer
               (if form-p
                   (eval func-or-form)
                 (apply func-or-form args)))))
        (and result (funcall printer result))
        result)
    (eshell-pipe-broken
     ;; If FUNC-OR-FORM tried and failed to write some output to a
     ;; process, it will raise an `eshell-pipe-broken' signal (this is
     ;; analogous to SIGPIPE on POSIX systems).  In this case, set the
     ;; command status to some non-zero value to indicate an error; to
     ;; match GNU/Linux, we use 141, which the numeric value of
     ;; SIGPIPE on GNU/Linux (13) with the high bit (2^7) set.
     (when (memq eshell-in-pipeline-p '(nil last))
       (eshell-set-exit-info 141))
     nil)
    (error
     (when (memq eshell-in-pipeline-p '(nil last))
       (eshell-set-exit-info 1))
     (let ((msg (error-message-string err)))
       (unless form-p
         (let ((prog-name (string-trim-left (symbol-name func-or-form)
                                            "eshell/")))
           (if (eq (car err) 'wrong-number-of-arguments)
               (setq msg (format "%s usage: %s" prog-name
                                 (elisp-get-fnsym-args-string func-or-form)))
             (setq msg (format "%s: %s" prog-name msg)))))
       (funcall errprint msg))
     nil)))