Function: elisp--eval-defun

elisp--eval-defun is a byte-compiled function defined in elisp-mode.el.gz.

Signature

(elisp--eval-defun)

Documentation

Evaluate defun that point is in or before.

The value is displayed in the echo area. If the current defun is actually a call to defvar, then reset the variable using the initial value expression even if the variable already has some other value.
(Normally defvar does not change the variable's value
if it already has a value.)

Return the result of evaluation.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/elisp-mode.el.gz
(defun elisp--eval-defun ()
  "Evaluate defun that point is in or before.
The value is displayed in the echo area.
If the current defun is actually a call to `defvar',
then reset the variable using the initial value expression
even if the variable already has some other value.
\(Normally `defvar' does not change the variable's value
if it already has a value.)

Return the result of evaluation."
  ;; FIXME: the print-length/level bindings should only be applied while
  ;; printing, not while evaluating.
  (defvar elisp--eval-defun-result)
  (let ((debug-on-error eval-expression-debug-on-error)
	(print-length eval-expression-print-length)
	(print-level eval-expression-print-level)
        elisp--eval-defun-result)
    (save-excursion
      ;; Arrange for eval-region to "read" the (possibly) altered form.
      ;; eval-region handles recording which file defines a function or
      ;; variable.
      (let ((standard-output t)
            beg end form)
        ;; Read the form from the buffer, and record where it ends.
        (save-excursion
          (end-of-defun)
          (beginning-of-defun)
          (setq beg (point))
          (setq form (funcall load-read-function (current-buffer)))
          (setq end (point)))
        ;; Alter the form if necessary.
        (let ((form (eval-sexp-add-defvars
                     (elisp--eval-defun-1
                      (macroexpand form)))))
          (eval-region beg end standard-output
                       (lambda (_ignore)
                         ;; Skipping to the end of the specified region
                         ;; will make eval-region return.
                         (goto-char end)
                         ;; This `setq' needs to be added *after* passing
                         ;; form through `elisp--eval-defun-1' since it
                         ;; would otherwise "hide" forms like `defvar's and
                         ;; thus defeat their special treatment.
                         `(setq elisp--eval-defun-result ,form))))))
    (let ((str (eval-expression-print-format elisp--eval-defun-result)))
      (if str (princ str)))
    elisp--eval-defun-result))