]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/debug.el (debug): Save&restore not just the buffer's
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 31 May 2011 15:41:14 +0000 (12:41 -0300)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 31 May 2011 15:41:14 +0000 (12:41 -0300)
content but also its previous major mode.

lisp/ChangeLog
lisp/emacs-lisp/debug.el

index e6fdbd2372c524d108f15beadf918603210309c8..0070f3a39454c8dac8ecaf8e661f41ab601f8102 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-31  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * emacs-lisp/debug.el (debug): Save&restore not just the buffer's
+       content but also its previous major mode.
+
 2011-05-31  Helmut Eller  <eller.helmut@gmail.com>
 
        * debug.el (debug): Restore the previous content of the
index 4a43f59c9e254ab2291f8d73abc198ac36f38b74..28962595acec8905b91d943d480afcf9c4cb51c0 100644 (file)
@@ -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