diff options
Diffstat (limited to 'lisp/emacs-lisp/debug.el')
-rw-r--r-- | lisp/emacs-lisp/debug.el | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index 4a43f59c9e2..28962595ace 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el @@ -118,9 +118,12 @@ first will be printed into the backtrace buffer." (let (debugger-value (debug-on-error nil) (debug-on-quit nil) + (debugger-previous-state + (if (get-buffer "*Backtrace*") + (with-current-buffer (get-buffer "*Backtrace*") + (list major-mode (buffer-string))))) (debugger-buffer (get-buffer-create "*Backtrace*")) (debugger-old-buffer (current-buffer)) - (debugger-previous-contents nil) (debugger-step-after-exit nil) (debugger-will-be-back nil) ;; Don't keep reading from an executing kbd macro! @@ -182,7 +185,6 @@ first will be printed into the backtrace buffer." (when (eq 'lambda (car-safe (cadr (backtrace-frame 4)))) (backtrace-debug 5 t))) (pop-to-buffer debugger-buffer) - (setq debugger-previous-contents (buffer-string)) (debugger-mode) (debugger-setup-buffer debugger-args) (when noninteractive @@ -216,9 +218,6 @@ first will be printed into the backtrace buffer." ;; recreate it every time the debugger stops, so instead we'll ;; erase it (and maybe hide it) but keep it alive. (with-current-buffer debugger-buffer - (erase-buffer) - (insert debugger-previous-contents) - (fundamental-mode) (with-selected-window (get-buffer-window debugger-buffer 0) (when (and (window-dedicated-p (selected-window)) (not debugger-will-be-back)) @@ -235,7 +234,17 @@ first will be printed into the backtrace buffer." ;; to be left at the top-level, still working on how ;; best to do that. (bury-buffer)))) - (kill-buffer debugger-buffer)) + (unless debugger-previous-state + (kill-buffer debugger-buffer))) + ;; Restore the previous state of the debugger-buffer, in case we were + ;; in a recursive invocation of the debugger. + (when (and debugger-previous-state + (buffer-live-p debugger-buffer)) + (with-current-buffer debugger-buffer + (let ((inhibit-read-only t)) + (erase-buffer) + (insert (nth 1 debugger-previous-state)) + (funcall (nth 0 debugger-previous-state))))) (with-timeout-unsuspend debugger-with-timeout-suspend) (set-match-data debugger-outer-match-data))) ;; Put into effect the modified values of these variables |