1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Add edebug-bounce-to-previous-value

Command edebug-bounce-to-previous-value uses the previous value
observed while single-stepping or evaluating an expression to
bounce point in the outside current buffer to the buffer
position corresponding to that value.

* lisp/emacs-lisp/edebug.el (edebug-previous-value): Add
variable.
(edebug-compute-previous-result, edebug-eval-expression): Update
it.
(edebug-bounce-to-previous-value): Add command.
(edebug-mode-map): Add keybinding for the new command, replacing
the binding of "P" to edebug-view-outside.
(edebug-mode-menus): Add menu entry for the new command.
* doc/lispref/edebug.texi (Edebug Views): Add documentation.
* test/lisp/emacs-lisp/edebug-resources/edebug-test-code.el
(edebug-test-code-bounce-point): Add test code.
* test/lisp/emacs-lisp/edebug-tests.el
(edebug-tests-bounce-outside-buffer)
(edebug-tests-bounce-outside-point)
(edebug-tests-bounce-outside-mark)
(edebug-tests-bounce-record-outside-environment)
(edebug-tests-should-have-bounced-to): Add infrastructure to
test bounces.
(edebug-tests-check-keymap): Update tests to new key bindings.
(edebug-tests-bounce-point)
(edebug-tests-bounce-to-previous-value)
(edebug-tests-bounce-to-previous-non-position): Add tests.
(edebug-tests-evaluation-of-current-buffer-bug-19611): Clean up
side effects.  (Bug#79288)
This commit is contained in:
Jens Schmidt 2025-08-21 20:58:42 +02:00 committed by Eli Zaretskii
parent 34f3ac6c5b
commit fdc6bb2caf
5 changed files with 222 additions and 22 deletions

View file

@ -2617,7 +2617,11 @@ when edebug becomes active."
(defvar edebug-eval-list nil) ;; List of expressions to evaluate.
(defvar edebug-previous-result nil) ;; Last result returned.
;; Last value seen while single-stepping or evaluating in the outside
;; environment.
(defvar edebug-previous-value nil)
;; Last value seen while single-stepping, converted to a string.
(defvar edebug-previous-result nil)
(defun edebug--display (value offset-index arg-mode)
;; edebug--display-1 is too big, we should split it. This function
@ -3113,6 +3117,37 @@ before returning. The default is one second."
(sit-for arg)
(edebug-pop-to-buffer edebug-buffer (car edebug-window-data)))))
(defun edebug-bounce-to-previous-value (arg)
"Bounce point to previous value in the outside current buffer.
The previous value is what Edebug has evaluated before its last stop
point or what you have evaluated in the context outside of Edebug, for
example, by calling function `edebug-eval-expression', whatever comes
later.
If prefix argument ARG is supplied, sit for that many seconds before
returning. The default is one second."
(interactive "p")
(if (not edebug-active)
(error "Edebug is not active"))
(if (not (integer-or-marker-p edebug-previous-value))
(error "Previous value not a number or marker"))
(save-excursion
;; If the buffer's currently displayed, avoid set-window-configuration.
(save-window-excursion
(let ((point-info ""))
(edebug-pop-to-buffer edebug-outside-buffer)
(cond
((< edebug-previous-value (point-min))
(setq point-info (format " (< Point min: %s)" (point-min))))
((> edebug-previous-value (point-max))
(setq point-info (format " (> Point max: %s)" (point-max))))
((invisible-p edebug-previous-value)
(setq point-info (format " (invisible)"))))
(goto-char edebug-previous-value)
(message "Current buffer: %s Point: %s%s"
(current-buffer) edebug-previous-value point-info)
(sit-for arg)
(edebug-pop-to-buffer edebug-buffer (car edebug-window-data))))))
;; Joe Wells, here is a start at your idea of adding a buffer to the internal
;; display list. Still need to use this list in edebug--display.
@ -3743,7 +3778,8 @@ Return the result of the last expression."
(if edebug-unwrap-results
(setq previous-value
(edebug-unwrap* previous-value)))
(setq edebug-previous-result
(setq edebug-previous-value previous-value
edebug-previous-result
(concat "Result: "
(edebug-safe-prin1-to-string previous-value)
(eval-expression-print-format previous-value))))
@ -3785,6 +3821,8 @@ this is the prefix key.)"
(values--store-value value)
(concat (edebug-safe-prin1-to-string value)
(eval-expression-print-format value)))))
;; Provide a defined previous value also in case of an error.
(setq edebug-previous-value (if errored nil value))
(cond
(errored
(message "Error: %s" errored))
@ -3901,9 +3939,9 @@ be installed in `emacs-lisp-mode-map'.")
;; views
"w" #'edebug-where
"v" #'edebug-view-outside ; maybe obsolete??
"v" #'edebug-view-outside
"p" #'edebug-bounce-point
"P" #'edebug-view-outside ; same as v
"P" #'edebug-bounce-to-previous-value
"W" #'edebug-toggle-save-windows
;; misc
@ -4517,6 +4555,7 @@ It is removed when you hit any char."
("Views"
["Where am I?" edebug-where t]
["Bounce to Current Point" edebug-bounce-point t]
["Bounce to Previous Value" edebug-bounce-to-previous-value t]
["View Outside Windows" edebug-view-outside t]
["Previous Result" edebug-previous-result t]
["Show Backtrace" edebug-pop-to-backtrace t]