Function: eval-defun

eval-defun is an interactive and byte-compiled function defined in elisp-mode.el.gz.

Signature

(eval-defun EDEBUG-IT)

Documentation

Evaluate top-level form around point and instrument it if EDEBUG-IT is non-nil.

Interactively, EDEBUG-IT is the prefix argument. If edebug-all-defs(var)/edebug-all-defs(fun) is non-nil, that inverts the meaning of EDEBUG-IT and the prefix argument: this function will instrument the form unless EDEBUG-IT is non-nil. The command edebug-all-defs(var)/edebug-all-defs(fun) toggles the value of the variable edebug-all-defs(var)/edebug-all-defs(fun).

If point isn't in a top-level form, evaluate the first top-level form after point. If there is no top-level form after point, evaluate the first preceding top-level form.

If the current defun is actually a call to defvar or defcustom, evaluating it this way resets the variable using its initial value expression (using the defcustom's :set function if there is one), even if the variable already has some other value. (Normally defvar and
defcustom do not alter the value if there already is one.) In an
analogous way, evaluating a defface overrides any customizations of the face, so that it becomes defined exactly as the defface expression says.

If eval-expression-debug-on-error is non-nil, which is the default, this command arranges for all errors to enter the debugger.

If acting on a defun for FUNCTION, and the function was instrumented, Edebug: FUNCTION is printed in the echo area. If not instrumented, just FUNCTION is printed.

If not acting on a defun, the result of evaluation is displayed in the echo area. This display is controlled by the variables eval-expression-print-length and eval-expression-print-level, which see.

This function has :around advice: edebug--eval-defun.

View in manual

Probably introduced at or before Emacs version 18.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/elisp-mode.el.gz
(defun eval-defun (edebug-it)
  "Evaluate top-level form around point and instrument it if EDEBUG-IT is non-nil.
Interactively, EDEBUG-IT is the prefix argument.
If `edebug-all-defs' is non-nil, that inverts the meaning of EDEBUG-IT
and the prefix argument: this function will instrument the form
unless EDEBUG-IT is non-nil.  The command `edebug-all-defs' toggles
the value of the variable `edebug-all-defs'.

If point isn't in a top-level form, evaluate the first top-level
form after point.  If there is no top-level form after point,
evaluate the first preceding top-level form.

If the current defun is actually a call to `defvar' or `defcustom',
evaluating it this way resets the variable using its initial value
expression (using the defcustom's :set function if there is one), even
if the variable already has some other value.  (Normally `defvar' and
`defcustom' do not alter the value if there already is one.)  In an
analogous way, evaluating a `defface' overrides any customizations of
the face, so that it becomes defined exactly as the `defface' expression
says.

If `eval-expression-debug-on-error' is non-nil, which is the default,
this command arranges for all errors to enter the debugger.

If acting on a `defun' for FUNCTION, and the function was
instrumented, `Edebug: FUNCTION' is printed in the echo area.  If not
instrumented, just FUNCTION is printed.

If not acting on a `defun', the result of evaluation is displayed in
the echo area.  This display is controlled by the variables
`eval-expression-print-length' and `eval-expression-print-level',
which see."
  (interactive "P")
  (cond (edebug-it
	 (require 'edebug)
	 (defvar edebug-all-defs)
	 (eval-defun (not edebug-all-defs)))
	(t
	 (handler-bind ((error (if eval-expression-debug-on-error
                                   #'eval-expression--debug #'ignore)))
	   (elisp--eval-defun)))))