aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/edebug.el74
-rw-r--r--lisp/progmodes/elisp-mode.el12
2 files changed, 21 insertions, 65 deletions
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 45996945948..45e76c751fe 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -88,7 +88,6 @@ using, but only when you also use Edebug."
88;; because the byte compiler binds them; as a result, if edebug 88;; because the byte compiler binds them; as a result, if edebug
89;; is first loaded for a require in a compilation, they will be left unbound. 89;; is first loaded for a require in a compilation, they will be left unbound.
90 90
91;;;###autoload
92(defcustom edebug-all-defs nil 91(defcustom edebug-all-defs nil
93 "If non-nil, evaluating defining forms instruments for Edebug. 92 "If non-nil, evaluating defining forms instruments for Edebug.
94This applies to `eval-defun', `eval-region', `eval-buffer', and 93This applies to `eval-defun', `eval-region', `eval-buffer', and
@@ -101,11 +100,6 @@ variable. You may wish to make it local to each buffer with
101`emacs-lisp-mode-hook'." 100`emacs-lisp-mode-hook'."
102 :type 'boolean) 101 :type 'boolean)
103 102
104;; edebug-all-defs and edebug-all-forms need to be autoloaded
105;; because the byte compiler binds them; as a result, if edebug
106;; is first loaded for a require in a compilation, they will be left unbound.
107
108;;;###autoload
109(defcustom edebug-all-forms nil 103(defcustom edebug-all-forms nil
110 "Non-nil means evaluation of all forms will instrument for Edebug. 104 "Non-nil means evaluation of all forms will instrument for Edebug.
111This doesn't apply to loading or evaluations in the minibuffer. 105This doesn't apply to loading or evaluations in the minibuffer.
@@ -457,66 +451,24 @@ the option `edebug-all-forms'."
457 451
458;; We should somehow arrange to be able to do this 452;; We should somehow arrange to be able to do this
459;; without actually replacing the eval-defun command. 453;; without actually replacing the eval-defun command.
460(defun edebug-eval-defun (edebug-it) 454(defun edebug--eval-defun (orig-fun edebug-it)
461 "Evaluate the top-level form containing point, or after point. 455 "Setting option `edebug-all-defs' to a non-nil value reverses the meaning
462
463If the current defun is actually a call to `defvar', then reset the
464variable using its initial value expression even if the variable
465already has some other value. (Normally `defvar' does not change the
466variable's value if it already has a value.) Treat `defcustom'
467similarly. Reinitialize the face according to `defface' specification.
468
469With a prefix argument, instrument the code for Edebug.
470
471Setting option `edebug-all-defs' to a non-nil value reverses the meaning
472of the prefix argument. Code is then instrumented when this function is 456of the prefix argument. Code is then instrumented when this function is
473invoked without a prefix argument. 457invoked without a prefix argument.
474 458
475If acting on a `defun' for FUNCTION, and the function was instrumented, 459If acting on a `defun' for FUNCTION, and the function was instrumented,
476`Edebug: FUNCTION' is printed in the minibuffer. If not instrumented, 460`Edebug: FUNCTION' is printed in the minibuffer. If not instrumented,
477just FUNCTION is printed. 461just FUNCTION is printed."
462 (let* ((edebug-all-forms (not (eq (not edebug-it) (not edebug-all-defs))))
463 (edebug-all-defs edebug-all-forms))
464 (funcall orig-fun nil)))
478 465
479If not acting on a `defun', the result of evaluation is displayed in 466(defun edebug-eval-defun (edebug-it)
480the minibuffer." 467 (declare (obsolete "use eval-defun or edebug--eval-defun instead" "28.1"))
481 (interactive "P") 468 (interactive "P")
482 (let* ((edebugging (not (eq (not edebug-it) (not edebug-all-defs)))) 469 (if (advice-member-p #'edebug--eval-defun 'eval-defun)
483 (edebug-result) 470 (eval-defun edebug-it)
484 (form 471 (edebug--eval-defun #'eval-defun edebug-it)))
485 (let ((edebug-all-forms edebugging)
486 (edebug-all-defs (eq edebug-all-defs (not edebug-it))))
487 (edebug-read-top-level-form))))
488 ;; This should be consistent with `eval-defun-1', but not the
489 ;; same, since that gets a macroexpanded form.
490 (cond ((and (eq (car form) 'defvar)
491 (cdr-safe (cdr-safe form)))
492 ;; Force variable to be bound.
493 (makunbound (nth 1 form)))
494 ((and (eq (car form) 'defcustom)
495 (default-boundp (nth 1 form)))
496 ;; Force variable to be bound.
497 ;; FIXME: Shouldn't this use the :setter or :initializer?
498 (set-default (nth 1 form) (eval (nth 2 form) lexical-binding)))
499 ((eq (car form) 'defface)
500 ;; Reset the face.
501 (setq face-new-frame-defaults
502 (assq-delete-all (nth 1 form) face-new-frame-defaults))
503 (put (nth 1 form) 'face-defface-spec nil)
504 (put (nth 1 form) 'face-documentation (nth 3 form))
505 ;; See comments in `eval-defun-1' for purpose of code below
506 (setq form (prog1 `(prog1 ,form
507 (put ',(nth 1 form) 'saved-face
508 ',(get (nth 1 form) 'saved-face))
509 (put ',(nth 1 form) 'customized-face
510 ,(nth 2 form)))
511 (put (nth 1 form) 'saved-face nil)))))
512 (setq edebug-result (eval (eval-sexp-add-defvars form) lexical-binding))
513 (if (not edebugging)
514 (prog1
515 (prin1 edebug-result)
516 (let ((str (eval-expression-print-format edebug-result)))
517 (if str (princ str))))
518 edebug-result)))
519
520 472
521;;;###autoload 473;;;###autoload
522(defalias 'edebug-defun 'edebug-eval-top-level-form) 474(defalias 'edebug-defun 'edebug-eval-top-level-form)
@@ -588,12 +540,12 @@ already is one.)"
588(defun edebug-install-read-eval-functions () 540(defun edebug-install-read-eval-functions ()
589 (interactive) 541 (interactive)
590 (add-function :around load-read-function #'edebug--read) 542 (add-function :around load-read-function #'edebug--read)
591 (advice-add 'eval-defun :override #'edebug-eval-defun)) 543 (advice-add 'eval-defun :around #'edebug--eval-defun))
592 544
593(defun edebug-uninstall-read-eval-functions () 545(defun edebug-uninstall-read-eval-functions ()
594 (interactive) 546 (interactive)
595 (remove-function load-read-function #'edebug--read) 547 (remove-function load-read-function #'edebug--read)
596 (advice-remove 'eval-defun #'edebug-eval-defun)) 548 (advice-remove 'eval-defun #'edebug--eval-defun))
597 549
598;;; Edebug internal data 550;;; Edebug internal data
599 551
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index c14b18425f6..397eb269a71 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1342,6 +1342,7 @@ if it already has a value.)
1342Return the result of evaluation." 1342Return the result of evaluation."
1343 ;; FIXME: the print-length/level bindings should only be applied while 1343 ;; FIXME: the print-length/level bindings should only be applied while
1344 ;; printing, not while evaluating. 1344 ;; printing, not while evaluating.
1345 (defvar elisp--eval-defun-result)
1345 (let ((debug-on-error eval-expression-debug-on-error) 1346 (let ((debug-on-error eval-expression-debug-on-error)
1346 (print-length eval-expression-print-length) 1347 (print-length eval-expression-print-length)
1347 (print-level eval-expression-print-level) 1348 (print-level eval-expression-print-level)
@@ -1357,19 +1358,22 @@ Return the result of evaluation."
1357 (end-of-defun) 1358 (end-of-defun)
1358 (beginning-of-defun) 1359 (beginning-of-defun)
1359 (setq beg (point)) 1360 (setq beg (point))
1360 (setq form (read (current-buffer))) 1361 (setq form (funcall load-read-function (current-buffer)))
1361 (setq end (point))) 1362 (setq end (point)))
1362 ;; Alter the form if necessary. 1363 ;; Alter the form if necessary.
1363 (let ((form (eval-sexp-add-defvars 1364 (let ((form (eval-sexp-add-defvars
1364 (elisp--eval-defun-1 1365 (elisp--eval-defun-1
1365 (macroexpand 1366 (macroexpand form)))))
1366 `(setq elisp--eval-defun-result ,form))))))
1367 (eval-region beg end standard-output 1367 (eval-region beg end standard-output
1368 (lambda (_ignore) 1368 (lambda (_ignore)
1369 ;; Skipping to the end of the specified region 1369 ;; Skipping to the end of the specified region
1370 ;; will make eval-region return. 1370 ;; will make eval-region return.
1371 (goto-char end) 1371 (goto-char end)
1372 form))))) 1372 ;; This `setq' needs to be added *after* passing
1373 ;; form through `elisp--eval-defun-1' since it
1374 ;; would otherwise "hide" forms like `defvar's and
1375 ;; thus defeat their special treatment.
1376 `(setq elisp--eval-defun-result ,form))))))
1373 (let ((str (eval-expression-print-format elisp--eval-defun-result))) 1377 (let ((str (eval-expression-print-format elisp--eval-defun-result)))
1374 (if str (princ str))) 1378 (if str (princ str)))
1375 elisp--eval-defun-result)) 1379 elisp--eval-defun-result))