comparison lisp/emacs-lisp/debug.el @ 46715:1320a274ce28

(debug): If redisplaying, just return.
author Richard M. Stallman <rms@gnu.org>
date Mon, 29 Jul 2002 01:49:45 +0000
parents 4a0f567d3c5f
children df65863c006a
comparison
equal deleted inserted replaced
46714:bebf069404ac 46715:1320a274ce28
99 99
100 You may call with no args, or you may pass nil as the first arg and 100 You may call with no args, or you may pass nil as the first arg and
101 any other args you like. In that case, the list of args after the 101 any other args you like. In that case, the list of args after the
102 first will be printed into the backtrace buffer." 102 first will be printed into the backtrace buffer."
103 (interactive) 103 (interactive)
104 (unless noninteractive 104 (if inhibit-redisplay
105 (message "Entering debugger...")) 105 ;; Don't really try to enter debugger within an eval from redisplay.
106 (let (debugger-value 106 debugger-value
107 (debug-on-error nil) 107 (unless noninteractive
108 (debug-on-quit nil) 108 (message "Entering debugger..."))
109 (debugger-buffer (let ((default-major-mode 'fundamental-mode)) 109 (let (debugger-value
110 (get-buffer-create "*Backtrace*"))) 110 (debug-on-error nil)
111 (debugger-old-buffer (current-buffer)) 111 (debug-on-quit nil)
112 (debugger-step-after-exit nil) 112 (debugger-buffer (let ((default-major-mode 'fundamental-mode))
113 ;; Don't keep reading from an executing kbd macro! 113 (get-buffer-create "*Backtrace*")))
114 (executing-kbd-macro nil) 114 (debugger-old-buffer (current-buffer))
115 ;; Save the outer values of these vars for the `e' command 115 (debugger-step-after-exit nil)
116 ;; before we replace the values. 116 ;; Don't keep reading from an executing kbd macro!
117 (debugger-outer-match-data (match-data)) 117 (executing-kbd-macro nil)
118 (debugger-outer-load-read-function load-read-function) 118 ;; Save the outer values of these vars for the `e' command
119 (debugger-outer-overriding-local-map overriding-local-map) 119 ;; before we replace the values.
120 (debugger-outer-overriding-terminal-local-map 120 (debugger-outer-match-data (match-data))
121 overriding-terminal-local-map) 121 (debugger-outer-load-read-function load-read-function)
122 (debugger-outer-track-mouse track-mouse) 122 (debugger-outer-overriding-local-map overriding-local-map)
123 (debugger-outer-last-command last-command) 123 (debugger-outer-overriding-terminal-local-map
124 (debugger-outer-this-command this-command) 124 overriding-terminal-local-map)
125 (debugger-outer-unread-command-char unread-command-char) 125 (debugger-outer-track-mouse track-mouse)
126 (debugger-outer-unread-command-events unread-command-events) 126 (debugger-outer-last-command last-command)
127 (debugger-outer-unread-post-input-method-events 127 (debugger-outer-this-command this-command)
128 unread-post-input-method-events) 128 (debugger-outer-unread-command-char unread-command-char)
129 (debugger-outer-last-input-event last-input-event) 129 (debugger-outer-unread-command-events unread-command-events)
130 (debugger-outer-last-command-event last-command-event) 130 (debugger-outer-unread-post-input-method-events
131 (debugger-outer-last-nonmenu-event last-nonmenu-event) 131 unread-post-input-method-events)
132 (debugger-outer-last-event-frame last-event-frame) 132 (debugger-outer-last-input-event last-input-event)
133 (debugger-outer-standard-input standard-input) 133 (debugger-outer-last-command-event last-command-event)
134 (debugger-outer-standard-output standard-output) 134 (debugger-outer-last-nonmenu-event last-nonmenu-event)
135 (debugger-outer-inhibit-redisplay inhibit-redisplay) 135 (debugger-outer-last-event-frame last-event-frame)
136 (debugger-outer-cursor-in-echo-area cursor-in-echo-area)) 136 (debugger-outer-standard-input standard-input)
137 ;; Set this instead of binding it, so that `q' 137 (debugger-outer-standard-output standard-output)
138 ;; will not restore it. 138 (debugger-outer-inhibit-redisplay inhibit-redisplay)
139 (setq overriding-terminal-local-map nil) 139 (debugger-outer-cursor-in-echo-area cursor-in-echo-area))
140 ;; Don't let these magic variables affect the debugger itself. 140 ;; Set this instead of binding it, so that `q'
141 (let ((last-command nil) this-command track-mouse 141 ;; will not restore it.
142 (unread-command-char -1) unread-command-events 142 (setq overriding-terminal-local-map nil)
143 unread-post-input-method-events 143 ;; Don't let these magic variables affect the debugger itself.
144 last-input-event last-command-event last-nonmenu-event 144 (let ((last-command nil) this-command track-mouse
145 last-event-frame 145 (unread-command-char -1) unread-command-events
146 overriding-local-map 146 unread-post-input-method-events
147 load-read-function 147 last-input-event last-command-event last-nonmenu-event
148 ;; If we are inside a minibuffer, allow nesting 148 last-event-frame
149 ;; so that we don't get an error from the `e' command. 149 overriding-local-map
150 (enable-recursive-minibuffers 150 load-read-function
151 (or enable-recursive-minibuffers (> (minibuffer-depth) 0))) 151 ;; If we are inside a minibuffer, allow nesting
152 (standard-input t) (standard-output t) 152 ;; so that we don't get an error from the `e' command.
153 inhibit-redisplay 153 (enable-recursive-minibuffers
154 (cursor-in-echo-area nil)) 154 (or enable-recursive-minibuffers (> (minibuffer-depth) 0)))
155 (unwind-protect 155 (standard-input t) (standard-output t)
156 (save-excursion 156 inhibit-redisplay
157 (save-window-excursion 157 (cursor-in-echo-area nil))
158 (pop-to-buffer debugger-buffer) 158 (unwind-protect
159 (debugger-mode) 159 (save-excursion
160 (debugger-setup-buffer debugger-args) 160 (save-window-excursion
161 (when noninteractive 161 (pop-to-buffer debugger-buffer)
162 ;; If the backtrace is long, save the beginning 162 (debugger-mode)
163 ;; and the end, but discard the middle. 163 (debugger-setup-buffer debugger-args)
164 (when (> (count-lines (point-min) (point-max)) 164 (when noninteractive
165 debugger-batch-max-lines) 165 ;; If the backtrace is long, save the beginning
166 ;; and the end, but discard the middle.
167 (when (> (count-lines (point-min) (point-max))
168 debugger-batch-max-lines)
169 (goto-char (point-min))
170 (forward-line (/ 2 debugger-batch-max-lines))
171 (let ((middlestart (point)))
172 (goto-char (point-max))
173 (forward-line (- (/ 2 debugger-batch-max-lines)
174 debugger-batch-max-lines))
175 (delete-region middlestart (point)))
176 (insert "...\n"))
166 (goto-char (point-min)) 177 (goto-char (point-min))
167 (forward-line (/ 2 debugger-batch-max-lines)) 178 (message (buffer-string))
168 (let ((middlestart (point))) 179 (kill-emacs))
169 (goto-char (point-max)) 180 (if (eq (car debugger-args) 'debug)
170 (forward-line (- (/ 2 debugger-batch-max-lines) 181 ;; Skip the frames for backtrace-debug, byte-code, and debug.
171 debugger-batch-max-lines)) 182 (backtrace-debug 3 t))
172 (delete-region middlestart (point))) 183 (debugger-reenable)
173 (insert "...\n"))
174 (goto-char (point-min))
175 (message (buffer-string))
176 (kill-emacs))
177 (if (eq (car debugger-args) 'debug)
178 ;; Skip the frames for backtrace-debug, byte-code, and debug.
179 (backtrace-debug 3 t))
180 (debugger-reenable)
181 (message "")
182 (let ((inhibit-trace t)
183 (standard-output nil)
184 (buffer-read-only t))
185 (message "") 184 (message "")
186 ;; Make sure we unbind buffer-read-only in the right buffer. 185 (let ((inhibit-trace t)
187 (save-excursion 186 (standard-output nil)
188 (recursive-edit))))) 187 (buffer-read-only t))
189 ;; Kill or at least neuter the backtrace buffer, so that users 188 (message "")
190 ;; don't try to execute debugger commands in an invalid context. 189 ;; Make sure we unbind buffer-read-only in the right buffer.
191 (if (get-buffer-window debugger-buffer 'visible) 190 (save-excursion
192 ;; Still visible despite the save-window-excursion? Maybe it 191 (recursive-edit)))))
193 ;; it's in a pop-up frame. It would be annoying to delete and 192 ;; Kill or at least neuter the backtrace buffer, so that users
194 ;; recreate it every time the debugger stops, so instead we'll 193 ;; don't try to execute debugger commands in an invalid context.
195 ;; erase it but leave it visible. 194 (if (get-buffer-window debugger-buffer 'visible)
196 (save-excursion 195 ;; Still visible despite the save-window-excursion? Maybe it
197 (set-buffer debugger-buffer) 196 ;; it's in a pop-up frame. It would be annoying to delete and
198 (erase-buffer) 197 ;; recreate it every time the debugger stops, so instead we'll
199 (fundamental-mode)) 198 ;; erase it but leave it visible.
200 (kill-buffer debugger-buffer)) 199 (save-excursion
201 (set-match-data debugger-outer-match-data))) 200 (set-buffer debugger-buffer)
202 ;; Put into effect the modified values of these variables 201 (erase-buffer)
203 ;; in case the user set them with the `e' command. 202 (fundamental-mode))
204 (setq load-read-function debugger-outer-load-read-function) 203 (kill-buffer debugger-buffer))
205 (setq overriding-local-map debugger-outer-overriding-local-map) 204 (set-match-data debugger-outer-match-data)))
206 (setq overriding-terminal-local-map 205 ;; Put into effect the modified values of these variables
207 debugger-outer-overriding-terminal-local-map) 206 ;; in case the user set them with the `e' command.
208 (setq track-mouse debugger-outer-track-mouse) 207 (setq load-read-function debugger-outer-load-read-function)
209 (setq last-command debugger-outer-last-command) 208 (setq overriding-local-map debugger-outer-overriding-local-map)
210 (setq this-command debugger-outer-this-command) 209 (setq overriding-terminal-local-map
211 (setq unread-command-char debugger-outer-unread-command-char) 210 debugger-outer-overriding-terminal-local-map)
212 (setq unread-command-events debugger-outer-unread-command-events) 211 (setq track-mouse debugger-outer-track-mouse)
213 (setq unread-post-input-method-events 212 (setq last-command debugger-outer-last-command)
214 debugger-outer-unread-post-input-method-events) 213 (setq this-command debugger-outer-this-command)
215 (setq last-input-event debugger-outer-last-input-event) 214 (setq unread-command-char debugger-outer-unread-command-char)
216 (setq last-command-event debugger-outer-last-command-event) 215 (setq unread-command-events debugger-outer-unread-command-events)
217 (setq last-nonmenu-event debugger-outer-last-nonmenu-event) 216 (setq unread-post-input-method-events
218 (setq last-event-frame debugger-outer-last-event-frame) 217 debugger-outer-unread-post-input-method-events)
219 (setq standard-input debugger-outer-standard-input) 218 (setq last-input-event debugger-outer-last-input-event)
220 (setq standard-output debugger-outer-standard-output) 219 (setq last-command-event debugger-outer-last-command-event)
221 (setq inhibit-redisplay debugger-outer-inhibit-redisplay) 220 (setq last-nonmenu-event debugger-outer-last-nonmenu-event)
222 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area) 221 (setq last-event-frame debugger-outer-last-event-frame)
223 (setq debug-on-next-call debugger-step-after-exit) 222 (setq standard-input debugger-outer-standard-input)
224 debugger-value)) 223 (setq standard-output debugger-outer-standard-output)
224 (setq inhibit-redisplay debugger-outer-inhibit-redisplay)
225 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area)
226 (setq debug-on-next-call debugger-step-after-exit)
227 debugger-value)))
225 228
226 (defun debugger-setup-buffer (debugger-args) 229 (defun debugger-setup-buffer (debugger-args)
227 "Initialize the `*Backtrace*' buffer for entry to the debugger. 230 "Initialize the `*Backtrace*' buffer for entry to the debugger.
228 That buffer should be current already." 231 That buffer should be current already."
229 (setq buffer-read-only nil) 232 (setq buffer-read-only nil)