(Fsave_current_buffer): New function.
[bpt/emacs.git] / lisp / emacs-lisp / edebug.el
CommitLineData
f7359658 1;;; edebug.el --- a source-level debugger for Emacs Lisp
84fc2cfa 2
f7359658 3;; Copyright (C) 1988,'89,'90,'91,'92,'93,'94,'95 Free Software Foundation, Inc
84fc2cfa 4
3a801d0c 5;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
e9571d2a 6;; Keywords: lisp, tools, maint
3a801d0c 7
1fe3d507
DL
8;; LCD Archive Entry:
9;; edebug|Daniel LaLiberte|liberte@cs.uiuc.edu
10;; |A source level debugger for Emacs Lisp.
dc0e03f3 11;; |$Date: 1996/05/29 17:16:52 $|$Revision: 3.7 $|~/modes/edebug.el|
e41b2db1 12
84fc2cfa
ER
13;; This file is part of GNU Emacs.
14
1fe3d507
DL
15;; GNU Emacs is free software; you can redistribute it and/or modify
16;; it under the terms of the GNU General Public License as published by
17;; the Free Software Foundation; either version 2, or (at your option)
18;; any later version.
19
84fc2cfa 20;; GNU Emacs is distributed in the hope that it will be useful,
1fe3d507
DL
21;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23;; GNU General Public License for more details.
24
25;; You should have received a copy of the GNU General Public License
f7359658
RS
26;; along with GNU Emacs; see the file COPYING. If not, write to the
27;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28;; Boston, MA 02111-1307, USA.
29
30;;; Commentary:
31
32;; This minor mode allows programmers to step through Emacs Lisp
33;; source code while executing functions. You can also set
34;; breakpoints, trace (stopping at each expression), evaluate
35;; expressions as if outside Edebug, reevaluate and display a list of
36;; expressions, trap errors normally caught by debug, and display a
37;; debug style backtrace.
38
39;;; Installation
40;; =============
41
42;; Put edebug.el in some directory in your load-path and
43;; byte-compile it. Also read the beginning of edebug-epoch.el,
44;; cl-specs.el, and edebug-cl-read.el if they apply to you.
45
46;; Unless you are using Emacs 19 which is already set up to use Edebug,
47;; put the following forms in your .emacs file.
48;; (define-key emacs-lisp-mode-map "\C-xx" 'edebug-eval-top-level-form)
49;; (autoload 'edebug-eval-top-level-form "edebug")
50
51;; If you wish to change the default edebug global command prefix, change:
52;; (setq edebug-global-prefix "\C-xX")
53
54;; Other options, are described in the manual.
55
56;; In previous versions of Edebug, users were directed to set
57;; `debugger' to `edebug-debug'. This is no longer necessary
58;; since Edebug automatically sets it whenever Edebug is active.
59
60;;; Minimal Instructions
61;; =====================
62
63;; First evaluate a defun with C-xx, then run the function. Step
64;; through the code with SPC, mark breakpoints with b, go until a
65;; breakpoint is reached with g, and quit execution with q. Use the
66;; "?" command in edebug to describe other commands. See edebug.tex
67;; or the Emacs 19 Lisp Reference Manual for more instructions.
68
69;; Send me your enhancements, ideas, bugs, or fixes.
70;; For bugs, you can call edebug-submit-bug-report if you have reporter.el.
71;; There is an edebug mailing list if you want to keep up
72;; with the latest developments. Requests to: edebug-request@cs.uiuc.edu
73
74;; Daniel LaLiberte 217-398-4114
75;; University of Illinois, Urbana-Champaign
76;; Department of Computer Science
77;; 1304 W Springfield
78;; Urbana, IL 61801
79
80;; uiucdcs!liberte
81;; liberte@cs.uiuc.edu
82
83;; For the early revision history, see edebug-history.
84
85;;; Code:
1fe3d507
DL
86
87(defconst edebug-version
dc0e03f3 88 (let ((raw-version "$Revision: 3.7 $"))
1576fe1d 89 (substring raw-version (string-match "[0-9.]*" raw-version)
1fe3d507
DL
90 (match-end 0))))
91
92(require 'backquote)
93
f7359658 94;; Emacs 18 doesn't have defalias.
1fe3d507
DL
95(eval-and-compile
96 (or (fboundp 'defalias) (fset 'defalias 'fset)))
84fc2cfa 97
84fc2cfa 98
f7359658 99;;; Bug reporting
84fc2cfa 100
1fe3d507 101(defconst edebug-maintainer-address "liberte@cs.uiuc.edu")
84fc2cfa 102
1fe3d507
DL
103(defun edebug-submit-bug-report ()
104 "Submit, via mail, a bug report on edebug."
105 (interactive)
106 (require 'reporter)
107 (and (y-or-n-p "Do you really want to submit a report on edebug? ")
108 (reporter-submit-bug-report
109 edebug-maintainer-address
110 (concat "edebug.el " edebug-version)
111 (list 'edebug-setup-hook
112 'edebug-all-defs
113 'edebug-all-forms
114 'edebug-eval-macro-args
115 'edebug-stop-before-symbols
116 'edebug-save-windows
117 'edebug-save-displayed-buffer-points
118 'edebug-initial-mode
119 'edebug-trace
120 'edebug-test-coverage
121 'edebug-continue-kbd-macro
122 'edebug-print-length
123 'edebug-print-level
124 'edebug-print-circle
125 ))))
126
f7359658 127;;; Options
1fe3d507
DL
128
129(defvar edebug-setup-hook nil
130 "*Functions to call before edebug is used.
a50d4326
DL
131Each time it is set to a new value, Edebug will call those functions
132once and then `edebug-setup-hook' is reset to nil. You could use this
133to load up Edebug specifications associated with a package you are
134using but only when you also use Edebug.")
1fe3d507
DL
135
136(defvar edebug-all-defs nil
a50d4326
DL
137 "*If non-nil, evaluation of any defining forms will instrument for Edebug.
138This applies to `eval-defun', `eval-region', `eval-buffer', and
139`eval-current-buffer'. `eval-region' is also called by
1fe3d507
DL
140`eval-last-sexp', and `eval-print-last-sexp'.
141
142You can use the command `edebug-all-defs' to toggle the value of this
a50d4326 143variable. You may wish to make it local to each buffer with
f7359658 144\(make-local-variable 'edebug-all-defs) in your
1fe3d507
DL
145`emacs-lisp-mode-hook'.")
146
147(defvar edebug-all-forms nil
a50d4326 148 "*Non-nil evaluation of all forms will instrument for Edebug.
1fe3d507 149This doesn't apply to loading or evaluations in the minibuffer.
f7359658 150Use the command `edebug-all-forms' to toggle the value of this option.")
84fc2cfa
ER
151
152(defvar edebug-eval-macro-args nil
1fe3d507 153 "*Non-nil means all macro call arguments may be evaluated.
f7359658 154If this variable is nil, the default, Edebug will *not* wrap
1fe3d507 155macro call arguments as if they will be evaluated.
f7359658 156For each macro, a `edebug-form-spec' overrides this option.
1fe3d507 157So to specify exceptions for macros that have some arguments evaluated
f7359658 158and some not, you should specify an `edebug-form-spec'.
1fe3d507
DL
159
160This option is going away soon.")
84fc2cfa
ER
161
162(defvar edebug-stop-before-symbols nil
a50d4326
DL
163 "*Non-nil causes Edebug to stop before symbols as well as after.
164In any case, a breakpoint or interrupt may stop before a symbol.
165
166This option is going away soon.")
84fc2cfa
ER
167
168(defvar edebug-save-windows t
a50d4326
DL
169 "*If non-nil, Edebug saves and restores the window configuration.
170That takes some time, so if your program does not care what happens to
171the window configurations, it is better to set this variable to nil.
1fe3d507
DL
172
173If the value is a list, only the listed windows are saved and
174restored.
84fc2cfa 175
1fe3d507 176`edebug-toggle-save-windows' may be used to change this variable.")
84fc2cfa 177
1fe3d507 178(defvar edebug-save-displayed-buffer-points nil
a50d4326 179 "*If non-nil, save and restore point in all displayed buffers.
84fc2cfa 180
a50d4326
DL
181Saving and restoring point in other buffers is necessary if you are
182debugging code that changes the point of a buffer which is displayed
183in a non-selected window. If Edebug or the user then selects the
84fc2cfa
ER
184window, the buffer's point will be changed to the window's point.
185
a50d4326
DL
186Saving and restoring point in all buffers is expensive, since it
187requires selecting each window twice, so enable this only if you need
188it.")
84fc2cfa
ER
189
190(defvar edebug-initial-mode 'step
a50d4326
DL
191 "*Initial execution mode for Edebug, if non-nil. If this variable
192is non-@code{nil}, it specifies the initial execution mode for Edebug
193when it is first activated. Possible values are step, next, go,
84fc2cfa
ER
194Go-nonstop, trace, Trace-fast, continue, and Continue-fast.")
195
196(defvar edebug-trace nil
a50d4326
DL
197 "*Non-nil means display a trace of function entry and exit.
198Tracing output is displayed in a buffer named `*edebug-trace*', one
199function entry or exit per line, indented by the recursion level.
200
201You can customize by replacing functions `edebug-print-trace-before'
202and `edebug-print-trace-after'.")
84fc2cfa 203
1fe3d507
DL
204(defvar edebug-test-coverage nil
205 "*If non-nil, Edebug tests coverage of all expressions debugged.
206This is done by comparing the result of each expression
207with the previous result. Coverage is considered OK if two different
a50d4326 208results are found.
84fc2cfa 209
1fe3d507
DL
210Use `edebug-display-freq-count' to display the frequency count and
211coverage information for a definition.")
212
213(defvar edebug-continue-kbd-macro nil
a50d4326
DL
214 "*If non-nil, continue defining or executing any keyboard macro.
215Use this with caution since it is not debugged.")
1fe3d507
DL
216
217
218(defvar edebug-print-length 50
f7359658 219 "*Default value of `print-length' to use while printing results in Edebug.")
1fe3d507 220(defvar edebug-print-level 50
f7359658 221 "*Default value of `print-level' to use while printing results in Edebug.")
1fe3d507 222(defvar edebug-print-circle t
f7359658 223 "*Default value of `print-circle' to use while printing results in Edebug.")
1fe3d507
DL
224
225(defvar edebug-unwrap-results nil
226 "*Non-nil if Edebug should unwrap results of expressions.
227This is useful when debugging macros where the results of expressions
228are instrumented expressions. But don't do this when results might be
229circular or an infinite loop will result.")
230
231(defvar edebug-on-error t
232 "*Value bound to `debug-on-error' while Edebug is active.
233
234If `debug-on-error' is non-nil, that value is still used.
235
236If the value is a list of signal names, Edebug will stop when any of
237these errors are signaled from Lisp code whether or not the signal is
238handled by a `condition-case'. This option is useful for debugging
239signals that *are* handled since they would otherwise be missed.
240After execution is resumed, the error is signaled again.")
241
242(defvar edebug-on-quit t
243 "*Value bound to `debug-on-quit' while Edebug is active.")
244
a50d4326
DL
245(defvar edebug-global-break-condition nil
246 "*If non-nil, an expression to test for at every stop point.
247If the result is non-nil, then break. Errors are ignored.")
248
f7359658 249;;; Form spec utilities.
1fe3d507
DL
250
251;;;###autoload
252(defmacro def-edebug-spec (symbol spec)
253 "Set the edebug-form-spec property of SYMBOL according to SPEC.
254Both SYMBOL and SPEC are unevaluated. The SPEC can be 0, t, a symbol
f7359658 255\(naming a function), or a list."
1fe3d507
DL
256 (` (put (quote (, symbol)) 'edebug-form-spec (quote (, spec)))))
257
258(defmacro def-edebug-form-spec (symbol spec-form)
f7359658 259 "For compatibility with old version. Use `def-edebug-spec' instead."
1fe3d507
DL
260 (message "Obsolete: use def-edebug-spec instead.")
261 (def-edebug-spec symbol (eval spec-form)))
262
263(defun get-edebug-spec (symbol)
264 ;; Get the spec of symbol resolving all indirection.
265 (let ((edebug-form-spec (get symbol 'edebug-form-spec))
266 indirect)
267 (while (and (symbolp edebug-form-spec)
268 (setq indirect (get edebug-form-spec 'edebug-form-spec)))
269 ;; (edebug-trace "indirection: %s" edebug-form-spec)
270 (setq edebug-form-spec indirect))
271 edebug-form-spec
272 ))
273
f7359658 274;;; Utilities
1fe3d507 275
f7359658
RS
276;; Define edebug-gensym - from old cl.el
277(defvar edebug-gensym-index 0
278 "Integer used by `edebug-gensym' to produce new names.")
1fe3d507 279
f7359658 280(defun edebug-gensym (&optional prefix)
1fe3d507
DL
281 "Generate a fresh uninterned symbol.
282There is an optional argument, PREFIX. PREFIX is the
283string that begins the new name. Most people take just the default,
284except when debugging needs suggest otherwise."
285 (if (null prefix)
286 (setq prefix "G"))
287 (let ((newsymbol nil)
288 (newname ""))
289 (while (not newsymbol)
f7359658
RS
290 (setq newname (concat prefix (int-to-string edebug-gensym-index)))
291 (setq edebug-gensym-index (+ edebug-gensym-index 1))
1fe3d507
DL
292 (if (not (intern-soft newname))
293 (setq newsymbol (make-symbol newname))))
294 newsymbol))
1fe3d507 295
a50d4326 296;; Only used by CL-like code.
f7359658
RS
297(defun edebug-keywordp (object)
298 "Return t if OBJECT is a keyword.
299A keyword is a symbol that starts with `:'."
300 (and (symbolp object)
301 (= ?: (aref (symbol-name object) 0))))
302
303(defun edebug-lambda-list-keywordp (object)
1fe3d507 304 "Return t if OBJECT is a lambda list keyword.
f7359658 305A lambda list keyword is a symbol that starts with `&'."
1fe3d507
DL
306 (and (symbolp object)
307 (= ?& (aref (symbol-name object) 0))))
84fc2cfa 308
84fc2cfa
ER
309
310(defun edebug-last-sexp ()
1fe3d507 311 ;; Return the last sexp before point in current buffer.
f7359658 312 ;; Assumes Emacs Lisp syntax is active.
84fc2cfa
ER
313 (car
314 (read-from-string
315 (buffer-substring
316 (save-excursion
317 (forward-sexp -1)
318 (point))
319 (point)))))
320
321(defun edebug-window-list ()
f7359658
RS
322 "Return a list of windows, in order of `next-window'."
323 ;; This doesn't work for epoch.
84fc2cfa
ER
324 (let* ((first-window (selected-window))
325 (window-list (list first-window))
326 (next (next-window first-window)))
327 (while (not (eq next first-window))
328 (setq window-list (cons next window-list))
329 (setq next (next-window next)))
330 (nreverse window-list)))
331
1fe3d507
DL
332(defun edebug-window-live-p (window)
333 "Return non-nil if WINDOW is visible."
334 (let* ((first-window (selected-window))
335 (next (next-window first-window t)))
336 (while (not (or (eq next window)
337 (eq next first-window)))
338 (setq next (next-window next t)))
339 (eq next window)))
340
341;; Not used.
342'(defun edebug-two-window-p ()
84fc2cfa
ER
343 "Return t if there are two windows."
344 (and (not (one-window-p))
345 (eq (selected-window)
346 (next-window (next-window (selected-window))))))
347
1fe3d507 348(defsubst edebug-lookup-function (object)
84fc2cfa
ER
349 (while (and (symbolp object) (fboundp object))
350 (setq object (symbol-function object)))
1fe3d507
DL
351 object)
352
353(defun edebug-macrop (object)
354 "Return the macro named by OBJECT, or nil if it is not a macro."
355 (setq object (edebug-lookup-function object))
84fc2cfa
ER
356 (if (and (listp object)
357 (eq 'macro (car object))
358 (edebug-functionp (cdr object)))
359 object))
360
361(defun edebug-functionp (object)
362 "Returns the function named by OBJECT, or nil if it is not a function."
1fe3d507 363 (setq object (edebug-lookup-function object))
84fc2cfa 364 (if (or (subrp object)
f7359658 365 (byte-code-function-p object)
84fc2cfa
ER
366 (and (listp object)
367 (eq (car object) 'lambda)
368 (listp (car (cdr object)))))
369 object))
370
371(defun edebug-sort-alist (alist function)
1fe3d507
DL
372 ;; Return the ALIST sorted with comparison function FUNCTION.
373 ;; This uses 'sort so the sorting is destructive.
84fc2cfa
ER
374 (sort alist (function
375 (lambda (e1 e2)
376 (funcall function (car e1) (car e2))))))
377
1fe3d507 378;;(def-edebug-spec edebug-save-restriction t)
84fc2cfa 379
1fe3d507
DL
380;; Not used. If it is used, def-edebug-spec must be defined before use.
381'(defmacro edebug-save-restriction (&rest body)
84fc2cfa
ER
382 "Evaluate BODY while saving the current buffers restriction.
383BODY may change buffer outside of current restriction, unlike
384save-restriction. BODY may change the current buffer,
385and the restriction will be restored to the original buffer,
386and the current buffer remains current.
387Return the result of the last expression in BODY."
388 (` (let ((edebug:s-r-beg (point-min-marker))
389 (edebug:s-r-end (point-max-marker)))
390 (unwind-protect
391 (progn (,@ body))
392 (save-excursion
393 (set-buffer (marker-buffer edebug:s-r-beg))
394 (narrow-to-region edebug:s-r-beg edebug:s-r-end))))))
395
f7359658 396;;; Display
1fe3d507
DL
397
398(defconst edebug-trace-buffer "*edebug-trace*"
399 "Name of the buffer to put trace info in.")
400
401(defun edebug-pop-to-buffer (buffer &optional window)
402 ;; Like pop-to-buffer, but select window where BUFFER was last shown.
403 ;; Select WINDOW if it provided and it still exists. Otherwise,
404 ;; if buffer is currently shown in several windows, choose one.
405 ;; Otherwise, find a new window, possibly splitting one.
406 (setq window (if (and (windowp window) (edebug-window-live-p window)
407 (eq (window-buffer window) buffer))
408 window
409 (if (eq (window-buffer (selected-window)) buffer)
410 (selected-window)
411 (edebug-get-buffer-window buffer))))
412 (if window
413 (select-window window)
414 (if (one-window-p)
415 (split-window))
416 ;; (message "next window: %s" (next-window)) (sit-for 1)
417 (if (eq (get-buffer-window edebug-trace-buffer) (next-window))
f7359658 418 ;; Don't select trace window
1fe3d507
DL
419 nil
420 (select-window (next-window))))
421 (set-window-buffer (selected-window) buffer)
422 (set-window-hscroll (selected-window) 0);; should this be??
423 ;; Selecting the window does not set the buffer until command loop.
424 ;;(set-buffer buffer)
425 )
84fc2cfa 426
1fe3d507
DL
427
428(defun edebug-get-displayed-buffer-points ()
429 ;; Return a list of buffer point pairs, for all displayed buffers.
430 (save-excursion
431 (let* ((first-window (selected-window))
432 (next (next-window first-window))
433 (buffer-point-list nil)
434 buffer)
435 (while (not (eq next first-window))
436 (set-buffer (setq buffer (window-buffer next)))
437 (setq buffer-point-list
438 (cons (cons buffer (point)) buffer-point-list))
439 (setq next (next-window next)))
440 buffer-point-list)))
441
442
443(defun edebug-set-buffer-points (buffer-points)
444 ;; Restore the buffer-points created by edebug-get-displayed-buffer-points.
445 (let ((current-buffer (current-buffer)))
446 (mapcar (function (lambda (buf-point)
447 (if (buffer-name (car buf-point)) ; still exists
448 (progn
449 (set-buffer (car buf-point))
450 (goto-char (cdr buf-point))))))
451 buffer-points)
452 (set-buffer current-buffer)))
453
454(defun edebug-current-windows (which-windows)
455 ;; Get either a full window configuration or some window information.
456 (if (listp which-windows)
457 (mapcar (function (lambda (window)
458 (if (edebug-window-live-p window)
459 (list window
460 (window-buffer window)
461 (window-point window)
462 (window-start window)
463 (window-hscroll window)))))
464 which-windows)
465 (current-window-configuration)))
466
467(defun edebug-set-windows (window-info)
468 ;; Set either a full window configuration or some window information.
469 (if (listp window-info)
470 (mapcar (function
471 (lambda (one-window-info)
472 (if one-window-info
473 (apply (function
474 (lambda (window buffer point start hscroll)
475 (if (edebug-window-live-p window)
476 (progn
477 (set-window-buffer window buffer)
478 (set-window-point window point)
479 (set-window-start window start)
480 (set-window-hscroll window hscroll)))))
481 one-window-info))))
482 window-info)
483 (set-window-configuration window-info)))
484
485(defalias 'edebug-get-buffer-window 'get-buffer-window)
486(defalias 'edebug-sit-for 'sit-for)
487(defalias 'edebug-input-pending-p 'input-pending-p)
488
489
f7359658
RS
490;;; Redefine read and eval functions
491;; read is redefined to maybe instrument forms.
492;; eval-defun is redefined to check edebug-all-forms and edebug-all-defs.
1fe3d507 493
f7359658
RS
494;; Use the Lisp version of eval-region.
495(require 'eval-reg "eval-reg")
1fe3d507
DL
496
497;; Save the original read function
498(or (fboundp 'edebug-original-read)
499 (defalias 'edebug-original-read (symbol-function 'read)))
500
88668147
DL
501(defun edebug-read (&optional stream)
502 "Read one Lisp expression as text from STREAM, return as Lisp object.
503If STREAM is nil, use the value of `standard-input' (which see).
504STREAM or the value of `standard-input' may be:
505 a buffer (read from point and advance it)
506 a marker (read from where it points and advance it)
507 a function (call it with no arguments for each character,
508 call it with a char as argument to push a char back)
509 a string (takes text from string, starting at the beginning)
510 t (read text line using minibuffer and use it).
511
512This version, from Edebug, maybe instruments the expression. But the
f7359658 513STREAM must be the current buffer to do so. Whether it instruments is
88668147 514also dependent on the values of `edebug-all-defs' and
1fe3d507 515`edebug-all-forms'."
88668147
DL
516 (or stream (setq stream standard-input))
517 (if (eq stream (current-buffer))
1fe3d507
DL
518 (edebug-read-and-maybe-wrap-form)
519 (edebug-original-read stream)))
520
1fe3d507
DL
521(or (fboundp 'edebug-original-eval-defun)
522 (defalias 'edebug-original-eval-defun (symbol-function 'eval-defun)))
523
f7359658
RS
524;; We should somehow arrange to be able to do this
525;; without actually replacing the eval-defun command.
1fe3d507
DL
526(defun edebug-eval-defun (edebug-it)
527 "Evaluate the top-level form containing point, or after point.
528
529This version, from Edebug, has the following differences: With a
88668147 530prefix argument instrument the code for Edebug. If `edebug-all-defs' is
1fe3d507 531non-nil, then the code is instrumented *unless* there is a prefix
f7359658 532argument. If instrumenting, it prints: `Edebug: FUNCTIONNAME'.
1fe3d507
DL
533Otherwise, it prints in the minibuffer."
534 (interactive "P")
f7359658
RS
535 (let* ((edebugging (not (eq (not edebug-it) (not edebug-all-defs))))
536 (edebug-result)
537 (form
538 (let ((edebug-all-forms edebugging)
539 (edebug-all-defs (eq edebug-all-defs (not edebug-it))))
540 (edebug-read-top-level-form))))
541 (if (and (eq (car form) 'defvar)
542 (cdr-safe (cdr-safe form)))
543 (setq form (cons 'defconst (cdr form))))
544 (setq edebug-result (eval form))
1fe3d507
DL
545 (if (not edebugging)
546 (princ edebug-result)
547 edebug-result)))
548
549
550;;;###autoload
551(defalias 'edebug-defun 'edebug-eval-top-level-form)
552
553;;;###autoload
554(defun edebug-eval-top-level-form ()
555 "Evaluate a top level form, such as a defun or defmacro.
556This is like `eval-defun', but the code is always instrumented for Edebug.
557Print its name in the minibuffer and leave point where it is,
f7359658 558or if an error occurs, leave point after it with mark at the original point."
84fc2cfa 559 (interactive)
1fe3d507 560 (eval
f7359658 561 ;; Bind edebug-all-forms only while reading, not while evalling
1fe3d507 562 ;; but this causes problems while edebugging edebug.
88668147
DL
563 (let ((edebug-all-forms t)
564 (edebug-all-defs t))
1fe3d507 565 (edebug-read-top-level-form))))
84fc2cfa
ER
566
567
1fe3d507
DL
568(defun edebug-read-top-level-form ()
569 (let ((starting-point (point)))
570 (end-of-defun)
571 (beginning-of-defun)
572 (prog1
573 (edebug-read-and-maybe-wrap-form)
574 ;; Recover point, but only if no error occurred.
575 (goto-char starting-point))))
84fc2cfa 576
84fc2cfa 577
1fe3d507
DL
578;; Compatibility with old versions.
579(defalias 'edebug-all-defuns 'edebug-all-defs)
84fc2cfa 580
1fe3d507
DL
581(defun edebug-all-defs ()
582 "Toggle edebugging of all definitions."
583 (interactive)
584 (setq edebug-all-defs (not edebug-all-defs))
585 (message "Edebugging all definitions is %s."
586 (if edebug-all-defs "on" "off")))
84fc2cfa 587
84fc2cfa 588
1fe3d507
DL
589(defun edebug-all-forms ()
590 "Toggle edebugging of all forms."
591 (interactive)
592 (setq edebug-all-forms (not edebug-all-forms))
593 (message "Edebugging all forms is %s."
594 (if edebug-all-forms "on" "off")))
84fc2cfa
ER
595
596
1fe3d507 597(defun edebug-install-read-eval-functions ()
1c222bca 598 (interactive)
88668147 599 ;; Don't install if already installed.
f7359658 600 (if (eq (symbol-function 'read) 'edebug-read) nil
88668147
DL
601 (elisp-eval-region-install)
602 (defalias 'read 'edebug-read)
603 (defalias 'eval-defun 'edebug-eval-defun)))
daa37602 604
1fe3d507
DL
605(defun edebug-uninstall-read-eval-functions ()
606 (interactive)
88668147
DL
607 (elisp-eval-region-uninstall)
608 (defalias 'read (symbol-function 'edebug-original-read))
609 (defalias 'eval-defun (symbol-function 'edebug-original-eval-defun)))
1fe3d507
DL
610
611
f7359658 612;;; Edebug internal data
1fe3d507 613
f7359658
RS
614;; The internal data that is needed for edebugging is kept in the
615;; buffer-local variable `edebug-form-data'.
1fe3d507
DL
616
617(make-variable-buffer-local 'edebug-form-data)
618
619(defconst edebug-form-data nil)
620;; A list of entries associating symbols with buffer regions.
621;; This is an automatic buffer local variable. Each entry looks like:
622;; @code{(@var{symbol} @var{begin-marker} @var{end-marker}). The markers
623;; are at the beginning and end of an entry level form and @var{symbol} is
624;; a symbol that holds all edebug related information for the form on its
625;; property list.
626
627;; In the future, the symbol will be irrelevant and edebug data will
628;; be stored in the definitions themselves rather than in the property
629;; list of a symbol.
630
631(defun edebug-make-form-data-entry (symbol begin end)
632 (list symbol begin end))
633
634(defsubst edebug-form-data-name (entry)
635 (car entry))
636
637(defsubst edebug-form-data-begin (entry)
638 (nth 1 entry))
639
640(defsubst edebug-form-data-end (entry)
641 (nth 2 entry))
642
643(defsubst edebug-set-form-data-entry (entry name begin end)
644 (setcar entry name);; in case name is changed
645 (set-marker (nth 1 entry) begin)
646 (set-marker (nth 2 entry) end))
647
648(defun edebug-get-form-data-entry (pnt &optional end-point)
649 ;; Find the edebug form data entry which is closest to PNT.
650 ;; If END-POINT is supplied, match must be exact.
651 ;; Return `nil' if none found.
652 (let ((rest edebug-form-data)
653 closest-entry
654 (closest-dist 999999)) ;; need maxint here
655 (while (and rest (< 0 closest-dist))
656 (let* ((entry (car rest))
657 (begin (edebug-form-data-begin entry))
658 (dist (- pnt begin)))
659 (setq rest (cdr rest))
660 (if (and (<= 0 dist)
661 (< dist closest-dist)
662 (or (not end-point)
663 (= end-point (edebug-form-data-end entry)))
664 (<= pnt (edebug-form-data-end entry)))
665 (setq closest-dist dist
666 closest-entry entry))))
667 closest-entry))
668
669;; Also need to find all contained entries,
670;; and find an entry given a symbol, which should be just assq.
671
672(defun edebug-form-data-symbol ()
673;; Return the edebug data symbol of the form where point is in.
674;; If point is not inside a edebuggable form, cause error.
675 (or (edebug-form-data-name (edebug-get-form-data-entry (point)))
676 (error "Not inside instrumented form")))
677
678(defun edebug-make-top-form-data-entry (new-entry)
679 ;; Make NEW-ENTRY the first element in the `edebug-form-data' list.
680 (edebug-clear-form-data-entry new-entry)
681 (setq edebug-form-data (cons new-entry edebug-form-data)))
682
683(defun edebug-clear-form-data-entry (entry)
684;; If non-nil, clear ENTRY out of the form data.
685;; Maybe clear the markers and delete the symbol's edebug property?
686 (if entry
687 (progn
688 ;; Instead of this, we could just find all contained forms.
689 ;; (put (car entry) 'edebug nil) ;
690 ;; (mapcar 'edebug-clear-form-data-entry ; dangerous
691 ;; (get (car entry) 'edebug-dependents))
692 ;; (set-marker (nth 1 entry) nil)
693 ;; (set-marker (nth 2 entry) nil)
694 (setq edebug-form-data (delq entry edebug-form-data)))))
daa37602 695
f7359658 696;;; Parser utilities
1fe3d507
DL
697
698(defun edebug-syntax-error (&rest args)
699 ;; Signal an invalid-read-syntax with ARGS.
700 (signal 'invalid-read-syntax args))
701
84fc2cfa 702
1fe3d507
DL
703(defconst edebug-read-syntax-table
704 ;; Lookup table for significant characters indicating the class of the
705 ;; token that follows. This is not a \"real\" syntax table.
706 (let ((table (make-vector 256 'symbol))
707 (i 0))
708 (while (< i ?!)
709 (aset table i 'space)
710 (setq i (1+ i)))
711 (aset table ?\( 'lparen)
712 (aset table ?\) 'rparen)
713 (aset table ?\' 'quote)
f7359658
RS
714 (aset table ?\` 'backquote)
715 (aset table ?\, 'comma)
1fe3d507
DL
716 (aset table ?\" 'string)
717 (aset table ?\? 'char)
718 (aset table ?\[ 'lbracket)
719 (aset table ?\] 'rbracket)
720 (aset table ?\. 'dot)
721 (aset table ?\# 'hash)
722 ;; We treat numbers as symbols, because of confusion with -, -1, and 1-.
f7359658 723 ;; We don't care about any other chars since they won't be seen.
1fe3d507 724 table))
84fc2cfa 725
1fe3d507
DL
726(defun edebug-next-token-class ()
727 ;; Move to the next token and return its class. We only care about
f7359658
RS
728 ;; lparen, rparen, dot, quote, backquote, comma, string, char, vector,
729 ;; or symbol.
1fe3d507
DL
730 (edebug-skip-whitespace)
731 (aref edebug-read-syntax-table (following-char)))
84fc2cfa 732
84fc2cfa 733
1fe3d507
DL
734(defun edebug-skip-whitespace ()
735 ;; Leave point before the next token, skipping white space and comments.
736 (skip-chars-forward " \t\r\n\f")
737 (while (= (following-char) ?\;)
738 ;; \r is counted as a comment terminator to support selective display.
739 (skip-chars-forward "^\n\r") ; skip the comment
740 (skip-chars-forward " \t\r\n\f")))
84fc2cfa 741
84fc2cfa 742
1fe3d507 743;; Mostly obsolete reader; still used in one case.
84fc2cfa 744
1fe3d507
DL
745(defun edebug-read-sexp ()
746 ;; Read one sexp from the current buffer starting at point.
747 ;; Leave point immediately after it. A sexp can be a list or atom.
748 ;; An atom is a symbol (or number), character, string, or vector.
749 ;; This works for reading anything legitimate, but it
750 ;; is gummed up by parser inconsistencies (bugs?)
751 (let ((class (edebug-next-token-class)))
752 (cond
753 ;; read goes one too far if a (possibly quoted) string or symbol
754 ;; is immediately followed by non-whitespace.
755 ((eq class 'symbol) (prog1
756 (edebug-original-read (current-buffer))
757 (if (not (eq (aref edebug-read-syntax-table
758 (preceding-char)) 'symbol))
759 (forward-char -1))))
760 ((eq class 'string) (prog1
761 (edebug-original-read (current-buffer))
762 (if (/= (preceding-char) ?\")
763 (forward-char -1))))
764 ((eq class 'quote) (forward-char 1)
765 (list 'quote (edebug-read-sexp)))
f7359658
RS
766 ((eq class 'backquote)
767 (list '\` (edebug-read-sexp)))
768 ((eq class 'comma)
769 (list '\, (edebug-read-sexp)))
1fe3d507
DL
770 (t ; anything else, just read it.
771 (edebug-original-read (current-buffer))))))
772
f7359658 773;;; Offsets for reader
1fe3d507
DL
774
775;; Define a structure to represent offset positions of expressions.
776;; Each offset structure looks like: (before . after) for constituents,
777;; or for structures that have elements: (before <subexpressions> . after)
778;; where the <subexpressions> are the offset structures for subexpressions
779;; including the head of a list.
780(defconst edebug-offsets nil)
781
782;; Stack of offset structures in reverse order of the nesting.
783;; This is used to get back to previous levels.
784(defconst edebug-offsets-stack nil)
785(defconst edebug-current-offset nil) ; Top of the stack, for convenience.
786
787;; We must store whether we just read a list with a dotted form that
788;; is itself a list. This structure will be condensed, so the offsets
789;; must also be condensed.
790(defconst edebug-read-dotted-list nil)
791
792(defsubst edebug-initialize-offsets ()
793 ;; Reinitialize offset recording.
794 (setq edebug-current-offset nil))
795
796(defun edebug-store-before-offset (point)
797 ;; Add a new offset pair with POINT as the before offset.
798 (let ((new-offset (list point)))
799 (if edebug-current-offset
800 (setcdr edebug-current-offset
801 (cons new-offset (cdr edebug-current-offset)))
802 ;; Otherwise, we are at the top level, so initialize.
803 (setq edebug-offsets new-offset
804 edebug-offsets-stack nil
805 edebug-read-dotted-list nil))
806 ;; Cons the new offset to the front of the stack.
807 (setq edebug-offsets-stack (cons new-offset edebug-offsets-stack)
808 edebug-current-offset new-offset)
84fc2cfa
ER
809 ))
810
1fe3d507
DL
811(defun edebug-store-after-offset (point)
812 ;; Finalize the current offset struct by reversing it and
813 ;; store POINT as the after offset.
814 (if (not edebug-read-dotted-list)
815 ;; Just reverse the offsets of all subexpressions.
816 (setcdr edebug-current-offset (nreverse (cdr edebug-current-offset)))
817
818 ;; We just read a list after a dot, which will be abbreviated out.
819 (setq edebug-read-dotted-list nil)
820 ;; Drop the corresponding offset pair.
821 ;; That is, nconc the reverse of the rest of the offsets
822 ;; with the cdr of last offset.
823 (setcdr edebug-current-offset
824 (nconc (nreverse (cdr (cdr edebug-current-offset)))
825 (cdr (car (cdr edebug-current-offset))))))
826
827 ;; Now append the point using nconc.
828 (setq edebug-current-offset (nconc edebug-current-offset point))
829 ;; Pop the stack.
830 (setq edebug-offsets-stack (cdr edebug-offsets-stack)
831 edebug-current-offset (car edebug-offsets-stack)))
832
833(defun edebug-ignore-offset ()
834 ;; Ignore the last created offset pair.
835 (setcdr edebug-current-offset (cdr (cdr edebug-current-offset))))
836
837(def-edebug-spec edebug-storing-offsets (form body))
838(put 'edebug-storing-offsets 'lisp-indent-hook 1)
839
840(defmacro edebug-storing-offsets (point &rest body)
841 (` (unwind-protect
842 (progn
843 (edebug-store-before-offset (, point))
844 (,@ body))
845 (edebug-store-after-offset (point)))))
846
847
f7359658
RS
848;;; Reader for Emacs Lisp.
849
1fe3d507
DL
850;; Uses edebug-next-token-class (and edebug-skip-whitespace) above.
851
852(defconst edebug-read-alist
853 '((symbol . edebug-read-symbol)
854 (lparen . edebug-read-list)
855 (string . edebug-read-string)
856 (quote . edebug-read-quote)
f7359658
RS
857 (backquote . edebug-read-backquote)
858 (comma . edebug-read-comma)
1fe3d507
DL
859 (lbracket . edebug-read-vector)
860 (hash . edebug-read-function)
861 ))
84fc2cfa 862
1fe3d507
DL
863(defun edebug-read-storing-offsets (stream)
864 (let ((class (edebug-next-token-class))
865 func
866 edebug-read-dotted-list) ; see edebug-store-after-offset
867 (edebug-storing-offsets (point)
868 (if (setq func (assq class edebug-read-alist))
869 (funcall (cdr func) stream)
870 ;; anything else, just read it.
871 (edebug-original-read stream))
872 )))
84fc2cfa 873
1fe3d507
DL
874(defun edebug-read-symbol (stream)
875 (prog1
876 (edebug-original-read stream)
877 ;; loses for escaped chars
878 (if (not (eq (aref edebug-read-syntax-table
879 (preceding-char)) 'symbol))
880 (forward-char -1))))
84fc2cfa 881
1fe3d507
DL
882(defun edebug-read-string (stream)
883 (prog1
884 (edebug-original-read stream)
885 (if (/= (preceding-char) ?\")
886 (forward-char -1))))
84fc2cfa 887
1fe3d507
DL
888(defun edebug-read-quote (stream)
889 ;; Turn 'thing into (quote thing)
890 (forward-char 1)
891 (list
892 (edebug-storing-offsets (point) 'quote)
893 (edebug-read-storing-offsets stream)))
894
f7359658
RS
895(defun edebug-read-backquote (stream)
896 ;; Turn `thing into (\` thing)
897 (let ((opoint (point)))
898 (forward-char 1)
899 ;; Generate the same structure of offsets we would have
900 ;; if the resulting list appeared verbatim in the input text.
901 (edebug-storing-offsets opoint
902 (list
903 (edebug-storing-offsets opoint '\`)
904 (edebug-read-storing-offsets stream)))))
905
906(defvar edebug-read-backquote-new nil
907 "Non-nil if reading the inside of a new-style backquote with no parens around it.
908Value of nil means reading the inside of an old-style backquote construct
909which is surrounded by an extra set of parentheses.
910This controls how we read comma constructs.")
911
912(defun edebug-read-comma (stream)
913 ;; Turn ,thing into (\, thing). Handle ,@ and ,. also.
914 (let ((opoint (point)))
915 (forward-char 1)
916 (let ((symbol '\,))
917 (cond ((eq (following-char) ?\.)
918 (setq symbol '\,\.)
919 (forward-char 1))
920 ((eq (following-char) ?\@)
921 (setq symbol '\,@)
922 (forward-char 1)))
923 ;; Generate the same structure of offsets we would have
924 ;; if the resulting list appeared verbatim in the input text.
925 (if edebug-read-backquote-new
926 (list
927 (edebug-storing-offsets opoint symbol)
928 (edebug-read-storing-offsets stream))
929 (edebug-storing-offsets opoint symbol)))))
930
1fe3d507
DL
931(defun edebug-read-function (stream)
932 ;; Turn #'thing into (function thing)
933 (forward-char 1)
934 (if (/= ?\' (following-char)) (edebug-syntax-error "Bad char"))
935 (forward-char 1)
936 (list
937 (edebug-storing-offsets (point)
938 (if (featurep 'cl) 'function* 'function))
939 (edebug-read-storing-offsets stream)))
940
941(defun edebug-read-list (stream)
942 (forward-char 1) ; skip \(
943 (prog1
944 (let ((elements))
945 (while (not (memq (edebug-next-token-class) '(rparen dot)))
f7359658
RS
946 (if (eq (edebug-next-token-class) 'backquote)
947 (let ((edebug-read-backquote-new (not (null elements)))
948 (opoint (point)))
949 (if edebug-read-backquote-new
950 (setq elements (cons (edebug-read-backquote stream) elements))
951 (forward-char 1) ; Skip backquote.
952 ;; Call edebug-storing-offsets here so that we
953 ;; produce the same offsets we would have had
954 ;; if the backquote were an ordinary symbol.
955 (setq elements (cons (edebug-storing-offsets opoint '\`)
956 elements))))
957 (setq elements (cons (edebug-read-storing-offsets stream) elements))))
1fe3d507
DL
958 (setq elements (nreverse elements))
959 (if (eq 'dot (edebug-next-token-class))
960 (let (dotted-form)
961 (forward-char 1) ; skip \.
962 (setq dotted-form (edebug-read-storing-offsets stream))
963 elements (nconc elements dotted-form)
964 (if (not (eq (edebug-next-token-class) 'rparen))
965 (edebug-syntax-error "Expected `)'"))
966 (setq edebug-read-dotted-list (listp dotted-form))
967 ))
968 elements)
969 (forward-char 1) ; skip \)
970 ))
84fc2cfa 971
1fe3d507
DL
972(defun edebug-read-vector (stream)
973 (forward-char 1) ; skip \[
974 (prog1
975 (let ((elements))
976 (while (not (eq 'rbracket (edebug-next-token-class)))
977 (setq elements (cons (edebug-read-storing-offsets stream) elements)))
978 (apply 'vector (nreverse elements)))
979 (forward-char 1) ; skip \]
84fc2cfa
ER
980 ))
981
f7359658 982;;; Cursors for traversal of list and vector elements with offsets.
1fe3d507
DL
983
984(defvar edebug-dotted-spec nil)
985
986(defun edebug-new-cursor (expressions offsets)
987 ;; Return a new cursor for EXPRESSIONS with OFFSETS.
988 (if (vectorp expressions)
989 (setq expressions (append expressions nil)))
990 (cons expressions offsets))
991
992(defsubst edebug-set-cursor (cursor expressions offsets)
993 ;; Set the CURSOR's EXPRESSIONS and OFFSETS to the given.
994 ;; Return the cursor.
995 (setcar cursor expressions)
996 (setcdr cursor offsets)
997 cursor)
998
999'(defun edebug-copy-cursor (cursor)
1000 ;; Copy the cursor using the same object and offsets.
1001 (cons (car cursor) (cdr cursor)))
1002
1003(defsubst edebug-cursor-expressions (cursor)
1004 (car cursor))
1005(defsubst edebug-cursor-offsets (cursor)
1006 (cdr cursor))
1007
1008(defsubst edebug-empty-cursor (cursor)
1009 ;; Return non-nil if CURSOR is empty - meaning no more elements.
1010 (null (car cursor)))
1011
1012(defsubst edebug-top-element (cursor)
1013 ;; Return the top element at the cursor.
1014 ;; Assumes not empty.
1015 (car (car cursor)))
1016
1017(defun edebug-top-element-required (cursor &rest error)
1018 ;; Check if a dotted form is required.
1019 (if edebug-dotted-spec (edebug-no-match cursor "Dot expected."))
1020 ;; Check if there is at least one more argument.
1021 (if (edebug-empty-cursor cursor) (apply 'edebug-no-match cursor error))
1022 ;; Return that top element.
1023 (edebug-top-element cursor))
1024
1025(defsubst edebug-top-offset (cursor)
1026 ;; Return the top offset pair corresponding to the top element.
1027 (car (cdr cursor)))
1028
1029(defun edebug-move-cursor (cursor)
1030 ;; Advance and return the cursor to the next element and offset.
1031 ;; throw no-match if empty before moving.
1032 ;; This is a violation of the cursor encapsulation, but
1033 ;; there is plenty of that going on while matching.
1034 ;; The following test should always fail.
1035 (if (edebug-empty-cursor cursor)
1036 (edebug-no-match cursor "Not enough arguments."))
1037 (setcar cursor (cdr (car cursor)))
1038 (setcdr cursor (cdr (cdr cursor)))
1039 cursor)
1040
1041
1042(defun edebug-before-offset (cursor)
1043 ;; Return the before offset of the cursor.
1044 ;; If there is nothing left in the offsets,
1045 ;; return one less than the offset itself,
1046 ;; which is the after offset for a list.
1047 (let ((offset (edebug-cursor-offsets cursor)))
1048 (if (consp offset)
1049 (car (car offset))
1050 (1- offset))))
1051
1052(defun edebug-after-offset (cursor)
1053 ;; Return the after offset of the cursor object.
1054 (let ((offset (edebug-top-offset cursor)))
1055 (while (consp offset)
1056 (setq offset (cdr offset)))
1057 offset))
1058
f7359658 1059;;; The Parser
1fe3d507 1060
f7359658
RS
1061;; The top level function for parsing forms is
1062;; edebug-read-and-maybe-wrap-form; it calls all the rest. It checks the
1063;; syntax a bit and leaves point at any error it finds, but otherwise
1064;; should appear to work like eval-defun.
1fe3d507 1065
f7359658
RS
1066;; The basic plan is to surround each expression with a call to
1067;; the edebug debugger together with indexes into a table of positions of
1068;; all expressions. Thus an expression "exp" becomes:
1fe3d507 1069
f7359658 1070;; (edebug-after (edebug-before 1) 2 exp)
1fe3d507 1071
f7359658
RS
1072;; When this is evaluated, first point is moved to the beginning of
1073;; exp at offset 1 of the current function. The expression is
1074;; evaluated, which may cause more edebug calls, and then point is
1075;; moved to offset 2 after the end of exp.
1fe3d507 1076
f7359658
RS
1077;; The highest level expressions of the function are wrapped in a call to
1078;; edebug-enter, which supplies the function name and the actual
1079;; arguments to the function. See functions edebug-enter, edebug-before,
1080;; and edebug-after for more details.
1fe3d507
DL
1081
1082;; Dynamically bound vars, left unbound, but globally declared.
1083;; This is to quiet the byte compiler.
1084
1085;; Window data of the highest definition being wrapped.
1086;; This data is shared by all embedded definitions.
1087(defvar edebug-top-window-data)
1088
1089(defvar edebug-&optional)
1090(defvar edebug-&rest)
1091(defvar edebug-gate nil) ;; whether no-match forces an error.
1092
1093(defconst edebug-def-name nil) ; name of definition, used by interactive-form
1094(defconst edebug-old-def-name nil) ; previous name of containing definition.
1095
1096(defconst edebug-error-point nil)
1097(defconst edebug-best-error nil)
1098
1099
1100(defun edebug-read-and-maybe-wrap-form ()
1101 ;; Read a form and wrap it with edebug calls, if the conditions are right.
1102 ;; Here we just catch any no-match not caught below and signal an error.
1103
1104 ;; Run the setup hook.
1105 (run-hooks 'edebug-setup-hook)
1106 (setq edebug-setup-hook nil)
1107
1108 (let (result
1109 edebug-top-window-data
1110 edebug-def-name;; make sure it is locally nil
f7359658 1111 ;; I don't like these here!!
1fe3d507
DL
1112 edebug-&optional
1113 edebug-&rest
1114 edebug-gate
1115 edebug-best-error
1116 edebug-error-point
1117 no-match
1118 ;; Do this once here instead of several times.
1119 (max-lisp-eval-depth (+ 800 max-lisp-eval-depth))
f7359658 1120 (max-specpdl-size (+ 2000 max-specpdl-size)))
1fe3d507
DL
1121 (setq no-match
1122 (catch 'no-match
1123 (setq result (edebug-read-and-maybe-wrap-form1))
1124 nil))
1125 (if no-match
1126 (apply 'edebug-syntax-error no-match))
1127 result))
1128
1129
1130(defun edebug-read-and-maybe-wrap-form1 ()
1131 (let (spec
1132 def-kind
1133 defining-form-p
1134 def-name
f7359658 1135 ;; These offset things don't belong here, but to support recursive
1fe3d507
DL
1136 ;; calls to edebug-read, they need to be here.
1137 edebug-offsets
1138 edebug-offsets-stack
1139 edebug-current-offset ; reset to nil
1140 )
1141 (save-excursion
1142 (if (and (eq 'lparen (edebug-next-token-class))
1143 (eq 'symbol (progn (forward-char 1) (edebug-next-token-class))))
1144 ;; Find out if this is a defining form from first symbol
88668147 1145 (setq def-kind (edebug-original-read (current-buffer))
1fe3d507
DL
1146 spec (and (symbolp def-kind) (get-edebug-spec def-kind))
1147 defining-form-p (and (listp spec)
1148 (eq '&define (car spec)))
1149 ;; This is incorrect in general!! But OK most of the time.
1150 def-name (if (and defining-form-p
1151 (eq 'name (car (cdr spec)))
1152 (eq 'symbol (edebug-next-token-class)))
88668147
DL
1153 (edebug-original-read (current-buffer))))))
1154;;;(message "all defs: %s all forms: %s" edebug-all-defs edebug-all-forms)
84fc2cfa 1155 (cond
1fe3d507
DL
1156 (defining-form-p
1157 (if (or edebug-all-defs edebug-all-forms)
1158 ;; If it is a defining form and we are edebugging defs,
1159 ;; then let edebug-list-form start it.
1160 (let ((cursor (edebug-new-cursor
1161 (list (edebug-read-storing-offsets (current-buffer)))
1162 (list edebug-offsets))))
1163 (car
1164 (edebug-make-form-wrapper
1165 cursor
1166 (edebug-before-offset cursor)
1167 (1- (edebug-after-offset cursor))
1168 (list (cons (symbol-name def-kind) (cdr spec))))))
1169
1170 ;; Not edebugging this form, so reset the symbol's edebug
1171 ;; property to be just a marker at the definition's source code.
1172 ;; This only works for defs with simple names.
1173 (put def-name 'edebug (point-marker))
1174 ;; Also nil out dependent defs.
1175 '(mapcar (function
1176 (lambda (def)
1177 (put def-name 'edebug nil)))
1178 (get def-name 'edebug-dependents))
1179 (edebug-read-sexp)))
1180
1181 ;; If all forms are being edebugged, explicitly wrap it.
1182 (edebug-all-forms
1183 (let ((cursor (edebug-new-cursor
1184 (list (edebug-read-storing-offsets (current-buffer)))
1185 (list edebug-offsets))))
1186 (edebug-make-form-wrapper
1187 cursor
1188 (edebug-before-offset cursor)
1189 (edebug-after-offset cursor)
1190 nil)))
1191
1192 ;; Not a defining form, and not edebugging.
1193 (t (edebug-read-sexp)))
1194 ))
1195
1196
1197(defvar edebug-def-args) ; args of defining form.
1198(defvar edebug-def-interactive) ; is it an emacs interactive function?
1199(defvar edebug-inside-func) ;; whether code is inside function context.
1200;; Currently def-form sets this to nil; def-body sets it to t.
1201
1202(defun edebug-interactive-p-name ()
1203 ;; Return a unique symbol for the variable used to store the
1204 ;; status of interactive-p for this function.
1205 (intern (format "edebug-%s-interactive-p" edebug-def-name)))
1206
1207
1208(defun edebug-wrap-def-body (forms)
1209 "Wrap the FORMS of a definition body."
1210 (if edebug-def-interactive
1211 (` (let (((, (edebug-interactive-p-name))
1212 (interactive-p)))
1213 (, (edebug-make-enter-wrapper forms))))
1214 (edebug-make-enter-wrapper forms)))
1215
1216
1217(defun edebug-make-enter-wrapper (forms)
1218 ;; Generate the enter wrapper for some forms of a definition.
1219 ;; This is not to be used for the body of other forms, e.g. `while',
1220 ;; since it wraps the list of forms with a call to `edebug-enter'.
1221 ;; Uses the dynamically bound vars edebug-def-name and edebug-def-args.
1222 ;; Do this after parsing since that may find a name.
1223 (setq edebug-def-name
f7359658 1224 (or edebug-def-name edebug-old-def-name (edebug-gensym "edebug-anon")))
1fe3d507
DL
1225 (` (edebug-enter
1226 (quote (, edebug-def-name))
1227 (, (if edebug-inside-func
1228 (` (list (,@
f7359658 1229 ;; Doesn't work with more than one def-body!!
1fe3d507
DL
1230 ;; But the list will just be reversed.
1231 (nreverse edebug-def-args))))
1232 'nil))
1233 (function (lambda () (,@ forms)))
1234 )))
1235
1236
1237(defvar edebug-form-begin-marker) ; the mark for def being instrumented
1238
1239(defvar edebug-offset-index) ; the next available offset index.
1240(defvar edebug-offset-list) ; the list of offset positions.
1241
1242(defun edebug-inc-offset (offset)
1243 ;; modifies edebug-offset-index and edebug-offset-list
1244 ;; accesses edebug-func-marc and buffer point
1245 (prog1
1246 edebug-offset-index
1247 (setq edebug-offset-list (cons (- offset edebug-form-begin-marker)
1248 edebug-offset-list)
1249 edebug-offset-index (1+ edebug-offset-index))))
1250
1251
1252(defun edebug-make-before-and-after-form (before-index form after-index)
1253 ;; Return the edebug form for the current function at offset BEFORE-INDEX
1254 ;; given FORM. Looks like:
1255 ;; (edebug-after (edebug-before BEFORE-INDEX) AFTER-INDEX FORM)
1256 ;; Also increment the offset index for subsequent use.
1257 ;; if (not edebug-stop-before-symbols) and form is a symbol,
f7359658 1258 ;; then don't call edebug-before.
1fe3d507
DL
1259 (list 'edebug-after
1260 (list 'edebug-before before-index)
1261 after-index form))
1262
1263(defun edebug-make-after-form (form after-index)
1264 ;; Like edebug-make-before-and-after-form, but only after.
1265 (list 'edebug-after 0 after-index form))
1266
1267
1268(defun edebug-unwrap (sexp)
1269 "Return the unwrapped SEXP or return it as is if it is not wrapped.
1270The SEXP might be the result of wrapping a body, which is a list of
1271expressions; a `progn' form will be returned enclosing these forms."
1272 (if (consp sexp)
1273 (cond
1274 ((eq 'edebug-after (car sexp))
1275 (nth 3 sexp))
1276 ((eq 'edebug-enter (car sexp))
1277 (let ((forms (nthcdr 2 (nth 1 (nth 3 sexp)))))
1278 (if (> (length forms) 1)
1279 (cons 'progn forms) ;; could return (values forms) instead.
1280 (car forms))))
1281 (t sexp);; otherwise it is not wrapped, so just return it.
1282 )
1283 sexp))
1284
1285(defun edebug-unwrap* (sexp)
1286 "Return the sexp recursively unwrapped."
1287 (let ((new-sexp (edebug-unwrap sexp)))
1288 (while (not (eq sexp new-sexp))
1289 (setq sexp new-sexp
1290 new-sexp (edebug-unwrap sexp)))
1291 (if (consp new-sexp)
1292 (mapcar 'edebug-unwrap* new-sexp)
1293 new-sexp)))
1294
1295
1296(defun edebug-defining-form (cursor form-begin form-end speclist)
1297 ;; Process the defining form, starting outside the form.
1298 ;; The speclist is a generated list spec that looks like:
1299 ;; (("def-symbol" defining-form-spec-sans-&define))
1300 ;; Skip the first offset.
1301 (edebug-set-cursor cursor (edebug-cursor-expressions cursor)
1302 (cdr (edebug-cursor-offsets cursor)))
1303 (edebug-make-form-wrapper
1304 cursor
1305 form-begin (1- form-end)
1306 speclist))
1307
1308(defun edebug-make-form-wrapper (cursor form-begin form-end
1309 &optional speclist)
1310 ;; Wrap a form, usually a defining form, but any evaluated one.
1311 ;; If speclist is non-nil, this is being called by edebug-defining-form.
1312 ;; Otherwise it is being called from edebug-read-and-maybe-wrap-form1.
1313 ;; This is a hack, but I havent figured out a simpler way yet.
1314 (let* ((form-data-entry (edebug-get-form-data-entry form-begin form-end))
1315 ;; Set this marker before parsing.
1316 (edebug-form-begin-marker
1317 (if form-data-entry
1318 (edebug-form-data-begin form-data-entry)
1319 ;; Buffer must be current-buffer for this to work:
1320 (set-marker (make-marker) form-begin))))
1321
1322 (let (edebug-offset-list
1323 (edebug-offset-index 0)
1324 result
1325 ;; For definitions.
1326 ;; (edebug-containing-def-name edebug-def-name)
1327 ;; Get name from form-data, if any.
1328 (edebug-old-def-name (edebug-form-data-name form-data-entry))
1329 edebug-def-name
1330 edebug-def-args
1331 edebug-def-interactive
1332 edebug-inside-func;; whether wrapped code executes inside a function.
1333 )
84fc2cfa 1334
1fe3d507
DL
1335 (setq result
1336 (if speclist
1337 (edebug-match cursor speclist)
1338
1339 ;; else wrap as an enter-form.
1340 (edebug-make-enter-wrapper (list (edebug-form cursor)))))
84fc2cfa 1341
1fe3d507
DL
1342 ;; Set the name here if it was not set by edebug-make-enter-wrapper.
1343 (setq edebug-def-name
f7359658 1344 (or edebug-def-name edebug-old-def-name (edebug-gensym "edebug-anon")))
1fe3d507
DL
1345
1346 ;; Add this def as a dependent of containing def. Buggy.
1347 '(if (and edebug-containing-def-name
1348 (not (get edebug-containing-def-name 'edebug-dependents)))
1349 (put edebug-containing-def-name 'edebug-dependents
1350 (cons edebug-def-name
1351 (get edebug-containing-def-name
1352 'edebug-dependents))))
1353
1354 ;; Create a form-data-entry or modify existing entry's markers.
1355 ;; In the latter case, pointers to the entry remain eq.
1356 (if (not form-data-entry)
1357 (setq form-data-entry
1358 (edebug-make-form-data-entry
1359 edebug-def-name
1360 edebug-form-begin-marker
1361 ;; Buffer must be current-buffer.
1362 (set-marker (make-marker) form-end)
1363 ))
1364 (edebug-set-form-data-entry
1365 form-data-entry edebug-def-name ;; in case name is changed
1366 form-begin form-end))
1367
1368 ;; (message "defining: %s" edebug-def-name) (sit-for 2)
1369 (edebug-make-top-form-data-entry form-data-entry)
1370 (message "Edebug: %s" edebug-def-name)
1371 ;;(debug edebug-def-name)
1372
1373 ;; Destructively reverse edebug-offset-list and make vector from it.
1374 (setq edebug-offset-list (vconcat (nreverse edebug-offset-list)))
1375
1376 ;; Side effects on the property list of edebug-def-name.
1377 (edebug-clear-frequency-count edebug-def-name)
1378 (edebug-clear-coverage edebug-def-name)
1379
1380 ;; Set up the initial window data.
1381 (if (not edebug-top-window-data) ;; if not already set, do it now.
1382 (let ((window ;; Find the best window for this buffer.
1383 (or (get-buffer-window (current-buffer))
1384 (selected-window))))
1385 (setq edebug-top-window-data
1386 (cons window (window-start window)))))
1387
1388 ;; Store the edebug data in symbol's property list.
1389 (put edebug-def-name 'edebug
1390 ;; A struct or vector would be better here!!
1391 (list edebug-form-begin-marker
1392 nil ; clear breakpoints
1393 edebug-offset-list
1394 edebug-top-window-data
1395 ))
1396 result
84fc2cfa
ER
1397 )))
1398
1399
1fe3d507
DL
1400(defun edebug-clear-frequency-count (name)
1401 ;; Create initial frequency count vector.
1402 ;; For each stop point, the counter is incremented each time it is visited.
1403 (put name 'edebug-freq-count
1404 (make-vector (length edebug-offset-list) 0)))
1405
1406
1407(defun edebug-clear-coverage (name)
1408 ;; Create initial coverage vector.
1409 ;; Only need one per expression, but it is simpler to use stop points.
1410 (put name 'edebug-coverage
1411 (make-vector (length edebug-offset-list) 'unknown)))
84fc2cfa 1412
84fc2cfa 1413
1fe3d507
DL
1414(defun edebug-form (cursor)
1415 ;; Return the instrumented form for the following form.
1416 ;; Add the point offsets to the edebug-offset-list for the form.
1417 (let* ((form (edebug-top-element-required cursor "Expected form"))
1418 (offset (edebug-top-offset cursor)))
1419 (prog1
84fc2cfa 1420 (cond
1fe3d507
DL
1421 ((consp form)
1422 ;; The first offset for a list form is for the list form itself.
1423 (if (eq 'quote (car form))
1424 form
1425 (let* ((head (car form))
1426 (spec (and (symbolp head) (get-edebug-spec head)))
1427 (new-cursor (edebug-new-cursor form offset)))
1428 ;; Find out if this is a defining form from first symbol.
1429 ;; An indirect spec would not work here, yet.
1430 (if (and (consp spec) (eq '&define (car spec)))
1431 (edebug-defining-form
1432 new-cursor
1433 (car offset);; before the form
1434 (edebug-after-offset cursor)
1435 (cons (symbol-name head) (cdr spec)))
1436 ;; Wrap a regular form.
1437 (edebug-make-before-and-after-form
1438 (edebug-inc-offset (car offset))
1439 (edebug-list-form new-cursor)
1440 ;; After processing the list form, the new-cursor is left
1441 ;; with the offset after the form.
1442 (edebug-inc-offset (edebug-cursor-offsets new-cursor))))
1443 )))
1444
1445 ((symbolp form)
1446 (cond
f7359658 1447 ;; Check for constant symbols that don't get wrapped.
1fe3d507 1448 ((or (memq form '(t nil))
f7359658 1449 (and (fboundp 'edebug-keywordp) (edebug-keywordp form)))
1fe3d507
DL
1450 form)
1451
1452 ;; This option may go away.
1453 (edebug-stop-before-symbols
1454 (edebug-make-before-and-after-form
1455 (edebug-inc-offset (car offset))
1456 form
1457 (edebug-inc-offset (cdr offset))
1458 ))
1459
1460 (t ;; just a variable
1461 (edebug-make-after-form form (edebug-inc-offset (cdr offset))))))
1462
1463 ;; Anything else is self-evaluating.
1464 (t form))
1465 (edebug-move-cursor cursor))))
1466
1467
1468(defsubst edebug-forms (cursor) (edebug-match cursor '(&rest form)))
1469(defsubst edebug-sexps (cursor) (edebug-match cursor '(&rest sexp)))
1470
1471(defsubst edebug-list-form-args (head cursor)
1472 ;; Process the arguments of a list form given that head of form is a symbol.
1473 ;; Helper for edebug-list-form
1474 (let ((spec (get-edebug-spec head)))
1475 (cond
1476 (spec
1477 (cond
1478 ((consp spec)
1479 ;; It is a speclist.
1480 (let (edebug-best-error
1481 edebug-error-point);; This may not be needed.
1482 (edebug-match-sublist cursor spec)))
1483 ((eq t spec) (edebug-forms cursor))
1484 ((eq 0 spec) (edebug-sexps cursor))
1485 ((symbolp spec) (funcall spec cursor));; Not used by edebug,
1486 ; but leave it in for compatibility.
1487 ))
1488 ;; No edebug-form-spec provided.
1489 ((edebug-macrop head)
1490 (if edebug-eval-macro-args
1491 (edebug-forms cursor)
1492 (edebug-sexps cursor)))
1493 (t ;; Otherwise it is a function call.
1494 (edebug-forms cursor)))))
1495
1496
1497(defun edebug-list-form (cursor)
1498 ;; Return an instrumented form built from the list form.
1499 ;; The after offset will be left in the cursor after processing the form.
1500 (let ((head (edebug-top-element-required cursor "Expected elements"))
1501 ;; Prevent backtracking whenever instrumenting.
1502 (edebug-gate t)
1503 ;; A list form is never optional because it matches anything.
1504 (edebug-&optional nil)
1505 (edebug-&rest nil))
1506 ;; Skip the first offset.
1507 (edebug-set-cursor cursor (edebug-cursor-expressions cursor)
1508 (cdr (edebug-cursor-offsets cursor)))
1509 (cond
1510 ((null head) nil) ; () is legal.
1511
1512 ((symbolp head)
1513 (cond
1514 ((null head)
1515 (edebug-syntax-error "nil head"))
1516 ((eq head 'interactive-p)
1517 ;; Special case: replace (interactive-p) with variable
1518 (setq edebug-def-interactive 'check-it)
1519 (edebug-move-cursor cursor)
1520 (edebug-interactive-p-name))
1521 (t
1522 (cons head (edebug-list-form-args
1523 head (edebug-move-cursor cursor))))))
1524
1525 ((consp head)
1526 (if (and (listp head) (eq (car head) ',))
1527 (edebug-match cursor '(("," def-form) body))
1528 ;; Process anonymous function and args.
1529 ;; This assumes no anonymous macros.
1530 (edebug-match-specs cursor '(lambda-expr body) 'edebug-match-specs)))
1531
1532 (t (edebug-syntax-error
1533 "Head of list form must be a symbol or lambda expression.")))
1534 ))
1535
f7359658 1536;;; Matching of specs.
1fe3d507
DL
1537
1538(defvar edebug-after-dotted-spec nil)
1539
1540(defvar edebug-matching-depth 0) ;; initial value
1541(defconst edebug-max-depth 150) ;; maximum number of matching recursions.
1542
1543
f7359658
RS
1544;;; Failure to match
1545
1fe3d507
DL
1546;; This throws to no-match, if there are higher alternatives.
1547;; Otherwise it signals an error. The place of the error is found
1548;; with the two before- and after-offset functions.
1549
1550(defun edebug-no-match (cursor &rest edebug-args)
1551 ;; Throw a no-match, or signal an error immediately if gate is active.
1552 ;; Remember this point in case we need to report this error.
1553 (setq edebug-error-point (or edebug-error-point
1554 (edebug-before-offset cursor))
1555 edebug-best-error (or edebug-best-error edebug-args))
1556 (if (and edebug-gate (not edebug-&optional))
1557 (progn
1558 (if edebug-error-point
1559 (goto-char edebug-error-point))
1560 (apply 'edebug-syntax-error edebug-args))
1561 (funcall 'throw 'no-match edebug-args)))
1562
1563
1564(defun edebug-match (cursor specs)
1565 ;; Top level spec matching function.
1566 ;; Used also at each lower level of specs.
1567 (let (edebug-&optional
1568 edebug-&rest
1569 edebug-best-error
1570 edebug-error-point
1571 (edebug-gate edebug-gate) ;; locally bound to limit effect
1572 )
1573 (edebug-match-specs cursor specs 'edebug-match-specs)))
1574
1575
1576(defun edebug-match-one-spec (cursor spec)
1577 ;; Match one spec, which is not a keyword &-spec.
1578 (cond
1579 ((symbolp spec) (edebug-match-symbol cursor spec))
1580 ((vectorp spec) (edebug-match cursor (append spec nil)))
1581 ((stringp spec) (edebug-match-string cursor spec))
1582 ((listp spec) (edebug-match-list cursor spec))
1583 ))
1584
1585
1586(defun edebug-match-specs (cursor specs remainder-handler)
1587 ;; Append results of matching the list of specs.
1588 ;; The first spec is handled and the remainder-handler handles the rest.
1589 (let ((edebug-matching-depth
1590 (if (> edebug-matching-depth edebug-max-depth)
1591 (error "too deep - perhaps infinite loop in spec?")
1592 (1+ edebug-matching-depth))))
1593 (cond
1594 ((null specs) nil)
1595
1596 ;; Is the spec dotted?
1597 ((atom specs)
1598 (let ((edebug-dotted-spec t));; Containing spec list was dotted.
1599 (edebug-match-specs cursor (list specs) remainder-handler)))
1600
1601 ;; Is the form dotted?
1602 ((not (listp (edebug-cursor-expressions cursor)));; allow nil
1603 (if (not edebug-dotted-spec)
1604 (edebug-no-match cursor "Dotted spec required."))
1605 ;; Cancel dotted spec and dotted form.
1606 (let ((edebug-dotted-spec)
1607 (this-form (edebug-cursor-expressions cursor))
1608 (this-offset (edebug-cursor-offsets cursor)))
1609 ;; Wrap the form in a list, (by changing the cursor??)...
1610 (edebug-set-cursor cursor (list this-form) this-offset)
1611 ;; and process normally, then unwrap the result.
1612 (car (edebug-match-specs cursor specs remainder-handler))))
1613
1614 (t;; Process normally.
1615 (let* ((spec (car specs))
1616 (rest)
1617 (first-char (and (symbolp spec) (aref (symbol-name spec) 0))))
1618 ;;(message "spec = %s first char = %s" spec first-char) (sit-for 1)
1619 (nconc
1620 (cond
1621 ((eq ?& first-char);; "&" symbols take all following specs.
1622 (funcall (get-edebug-spec spec) cursor (cdr specs)))
1623 ((eq ?: first-char);; ":" symbols take one following spec.
1624 (setq rest (cdr (cdr specs)))
1625 (funcall (get-edebug-spec spec) cursor (car (cdr specs))))
1626 (t;; Any other normal spec.
1627 (setq rest (cdr specs))
1628 (edebug-match-one-spec cursor spec)))
1629 (funcall remainder-handler cursor rest remainder-handler)))))))
1630
1631
1632;; Define specs for all the symbol specs with functions used to process them.
f7359658 1633;; Perhaps we shouldn't be doing this with edebug-form-specs since the
1fe3d507
DL
1634;; user may want to define macros or functions with the same names.
1635;; We could use an internal obarray for these primitive specs.
1636
1637(mapcar
1638 (function (lambda (pair)
1639 (put (car pair) 'edebug-form-spec (cdr pair))))
1640 '((&optional . edebug-match-&optional)
1641 (&rest . edebug-match-&rest)
1642 (&or . edebug-match-&or)
1643 (form . edebug-match-form)
1644 (sexp . edebug-match-sexp)
1645 (body . edebug-match-body)
1646 (&define . edebug-match-&define)
1647 (name . edebug-match-name)
1648 (:name . edebug-match-colon-name)
1649 (arg . edebug-match-arg)
1650 (def-body . edebug-match-def-body)
1651 (def-form . edebug-match-def-form)
1652 ;; Less frequently used:
1653 ;; (function . edebug-match-function)
1654 (lambda-expr . edebug-match-lambda-expr)
1fe3d507
DL
1655 (&not . edebug-match-&not)
1656 (&key . edebug-match-&key)
1657 (place . edebug-match-place)
1658 (gate . edebug-match-gate)
1659 ;; (nil . edebug-match-nil) not this one - special case it.
1660 ))
1661
1662(defun edebug-match-symbol (cursor symbol)
1663 ;; Match a symbol spec.
1664 (let* ((spec (get-edebug-spec symbol)))
1665 (cond
1666 (spec
1667 (if (consp spec)
1668 ;; It is an indirect spec.
1669 (edebug-match cursor spec)
1670 ;; Otherwise it should be the symbol name of a function.
1671 ;; There could be a bug here - maybe need to do edebug-match bindings.
1672 (funcall spec cursor)))
1673
1674 ((null symbol) ;; special case this.
1675 (edebug-match-nil cursor))
1676
1677 ((fboundp symbol) ; is it a predicate?
1678 (let ((sexp (edebug-top-element-required cursor "Expected" symbol)))
1679 ;; Special case for edebug-`.
1680 (if (and (listp sexp) (eq (car sexp) ',))
1681 (edebug-match cursor '(("," def-form)))
1682 (if (not (funcall symbol sexp))
1683 (edebug-no-match cursor symbol "failed"))
1684 (edebug-move-cursor cursor)
1685 (list sexp))))
1686 (t (error "%s is not a form-spec or function" symbol))
1687 )))
1688
1689
1690(defun edebug-match-sexp (cursor)
1691 (list (prog1 (edebug-top-element-required cursor "Expected sexp")
1692 (edebug-move-cursor cursor))))
1693
1694(defun edebug-match-form (cursor)
1695 (list (edebug-form cursor)))
1696
1697(defalias 'edebug-match-place 'edebug-match-form)
1698 ;; Currently identical to edebug-match-form.
1699 ;; This is for common lisp setf-style place arguments.
1700
1701(defsubst edebug-match-body (cursor) (edebug-forms cursor))
1702
1703(defun edebug-match-&optional (cursor specs)
1704 ;; Keep matching until one spec fails.
1705 (edebug-&optional-wrapper cursor specs 'edebug-&optional-wrapper))
1706
1707(defun edebug-&optional-wrapper (cursor specs remainder-handler)
1708 (let (result
1709 (edebug-&optional specs)
1710 (edebug-gate nil)
1711 (this-form (edebug-cursor-expressions cursor))
1712 (this-offset (edebug-cursor-offsets cursor)))
1713 (if (null (catch 'no-match
1714 (setq result
1715 (edebug-match-specs cursor specs remainder-handler))
1716 ;; Returning nil means no no-match was thrown.
1717 nil))
1718 result
1719 ;; no-match, but don't fail; just reset cursor and return nil.
1720 (edebug-set-cursor cursor this-form this-offset)
1721 nil)))
1722
1723
1724(defun edebug-&rest-wrapper (cursor specs remainder-handler)
1725 (if (null specs) (setq specs edebug-&rest))
1726 ;; Reuse the &optional handler with this as the remainder handler.
1727 (edebug-&optional-wrapper cursor specs remainder-handler))
1728
1729(defun edebug-match-&rest (cursor specs)
1730 ;; Repeatedly use specs until failure.
1731 (let ((edebug-&rest specs) ;; remember these
1732 edebug-best-error
1733 edebug-error-point)
1734 (edebug-&rest-wrapper cursor specs 'edebug-&rest-wrapper)))
1735
1736
1737(defun edebug-match-&or (cursor specs)
1738 ;; Keep matching until one spec succeeds, and return its results.
1739 ;; If none match, fail.
1740 ;; This needs to be optimized since most specs spend time here.
1741 (let ((original-specs specs)
1742 (this-form (edebug-cursor-expressions cursor))
1743 (this-offset (edebug-cursor-offsets cursor)))
1744 (catch 'matched
1745 (while specs
1746 (catch 'no-match
1747 (throw 'matched
1748 (let (edebug-gate ;; only while matching each spec
1749 edebug-best-error
1750 edebug-error-point)
f7359658 1751 ;; Doesn't support e.g. &or symbolp &rest form
1fe3d507
DL
1752 (edebug-match-one-spec cursor (car specs)))))
1753 ;; Match failed, so reset and try again.
1754 (setq specs (cdr specs))
1755 ;; Reset the cursor for the next match.
1756 (edebug-set-cursor cursor this-form this-offset))
1757 ;; All failed.
1758 (apply 'edebug-no-match cursor "Expected one of" original-specs))
84fc2cfa
ER
1759 ))
1760
1761
1fe3d507
DL
1762(defun edebug-match-&not (cursor specs)
1763 ;; If any specs match, then fail
1764 (if (null (catch 'no-match
1765 (let ((edebug-gate nil))
1766 (save-excursion
1767 (edebug-match-&or cursor specs)))
1768 nil))
1769 ;; This means something matched, so it is a no match.
1770 (edebug-no-match cursor "Unexpected"))
1771 ;; This means nothing matched, so it is OK.
1772 nil) ;; So, return nothing
1773
1774
1775(def-edebug-spec &key edebug-match-&key)
1776
1777(defun edebug-match-&key (cursor specs)
1778 ;; Following specs must look like (<name> <spec>) ...
1779 ;; where <name> is the name of a keyword, and spec is its spec.
f7359658 1780 ;; This really doesn't save much over the expanded form and takes time.
1fe3d507
DL
1781 (edebug-match-&rest
1782 cursor
1783 (cons '&or
1784 (mapcar (function (lambda (pair)
1785 (vector (format ":%s" (car pair))
1786 (car (cdr pair)))))
1787 specs))))
1788
1789
1790(defun edebug-match-gate (cursor)
1791 ;; Simply set the gate to prevent backtracking at this level.
1792 (setq edebug-gate t)
1793 nil)
1794
1795
1796(defun edebug-match-list (cursor specs)
1797 ;; The spec is a list, but what kind of list, and what context?
1798 (if edebug-dotted-spec
1799 ;; After dotted spec but form did not contain dot,
1800 ;; so match list spec elements as if spliced in.
1801 (prog1
1802 (let ((edebug-dotted-spec))
1803 (edebug-match-specs cursor specs 'edebug-match-specs))
1804 ;; If it matched, really clear the dotted-spec flag.
1805 (setq edebug-dotted-spec nil))
1806 (let ((spec (car specs))
1807 (form (edebug-top-element-required cursor "Expected" specs)))
1808 (cond
1809 ((eq 'quote spec)
1810 (let ((spec (car (cdr specs))))
1811 (cond
1812 ((symbolp spec)
1813 ;; Special case: spec quotes a symbol to match.
1814 ;; Change in future. Use "..." instead.
1815 (if (not (eq spec form))
1816 (edebug-no-match cursor "Expected" spec))
1817 (edebug-move-cursor cursor)
1818 (setq edebug-gate t)
1819 form)
1820 (t
1821 (error "Bad spec: %s" specs)))))
1822
1823 ((listp form)
1824 (prog1
1825 (list (edebug-match-sublist
1826 ;; First offset is for the list form itself.
1827 ;; Treat nil as empty list.
1828 (edebug-new-cursor form (cdr (edebug-top-offset cursor)))
1829 specs))
1830 (edebug-move-cursor cursor)))
1831
1832 ((and (eq 'vector spec) (vectorp form))
1833 ;; Special case: match a vector with the specs.
1834 (let ((result (edebug-match-sublist
1835 (edebug-new-cursor
1836 form (cdr (edebug-top-offset cursor)))
1837 (cdr specs))))
1838 (edebug-move-cursor cursor)
1839 (list (apply 'vector result))))
84fc2cfa 1840
1fe3d507
DL
1841 (t (edebug-no-match cursor "Expected" specs)))
1842 )))
84fc2cfa
ER
1843
1844
1fe3d507
DL
1845(defun edebug-match-sublist (cursor specs)
1846 ;; Match a sublist of specs.
1847 (let (edebug-&optional
1848 ;;edebug-best-error
1849 ;;edebug-error-point
1850 )
1851 (prog1
1852 ;; match with edebug-match-specs so edebug-best-error is not bound.
1853 (edebug-match-specs cursor specs 'edebug-match-specs)
1854 (if (not (edebug-empty-cursor cursor))
1855 (if edebug-best-error
1856 (apply 'edebug-no-match cursor edebug-best-error)
1857 ;; A failed &rest or &optional spec may leave some args.
1858 (edebug-no-match cursor "Failed matching" specs)
1859 )))))
1860
1861
1862(defun edebug-match-string (cursor spec)
1863 (let ((sexp (edebug-top-element-required cursor "Expected" spec)))
1864 (if (not (eq (intern spec) sexp))
1865 (edebug-no-match cursor "Expected" spec)
1866 ;; Since it matched, failure means immediate error, unless &optional.
1867 (setq edebug-gate t)
1868 (edebug-move-cursor cursor)
1869 (list sexp)
1870 )))
84fc2cfa 1871
1fe3d507
DL
1872(defun edebug-match-nil (cursor)
1873 ;; There must be nothing left to match a nil.
1874 (if (not (edebug-empty-cursor cursor))
1875 (edebug-no-match cursor "Unmatched argument(s)")
1876 nil))
1877
1878
1879(defun edebug-match-function (cursor)
1880 (error "Use function-form instead of function in edebug spec"))
1881
1882(defun edebug-match-&define (cursor specs)
1883 ;; Match a defining form.
f7359658 1884 ;; Normally, &define is interpreted specially other places.
1fe3d507
DL
1885 ;; This should only be called inside of a spec list to match the remainder
1886 ;; of the current list. e.g. ("lambda" &define args def-body)
1887 (edebug-make-form-wrapper
1888 cursor
1889 (edebug-before-offset cursor)
1890 ;; Find the last offset in the list.
1891 (let ((offsets (edebug-cursor-offsets cursor)))
1892 (while (consp offsets) (setq offsets (cdr offsets)))
1893 offsets)
1894 specs))
1895
1896(defun edebug-match-lambda-expr (cursor)
1897 ;; The expression must be a function.
1898 ;; This will match any list form that begins with a symbol
1899 ;; that has an edebug-form-spec beginning with &define. In
1900 ;; practice, only lambda expressions should be used.
1901 ;; I could add a &lambda specification to avoid confusion.
1902 (let* ((sexp (edebug-top-element-required
1903 cursor "Expected lambda expression"))
1904 (offset (edebug-top-offset cursor))
1905 (head (and (consp sexp) (car sexp)))
1906 (spec (and (symbolp head) (get-edebug-spec head)))
1907 (edebug-inside-func nil))
1908 ;; Find out if this is a defining form from first symbol.
1909 (if (and (consp spec) (eq '&define (car spec)))
1910 (prog1
1911 (list
1912 (edebug-defining-form
1913 (edebug-new-cursor sexp offset)
1914 (car offset);; before the sexp
1915 (edebug-after-offset cursor)
1916 (cons (symbol-name head) (cdr spec))))
1917 (edebug-move-cursor cursor))
1918 (edebug-no-match cursor "Expected lambda expression")
1919 )))
84fc2cfa 1920
84fc2cfa 1921
1fe3d507
DL
1922(defun edebug-match-name (cursor)
1923 ;; Set the edebug-def-name bound in edebug-defining-form.
1924 (let ((name (edebug-top-element-required cursor "Expected name")))
1925 ;; Maybe strings and numbers could be used.
1926 (if (not (symbolp name))
1927 (edebug-no-match cursor "Symbol expected for name of definition"))
1928 (setq edebug-def-name
1929 (if edebug-def-name
1930 ;; Construct a new name by appending to previous name.
1931 (intern (format "%s@%s" edebug-def-name name))
1932 name))
1933 (edebug-move-cursor cursor)
1934 (list name)))
1935
1936(defun edebug-match-colon-name (cursor spec)
1937 ;; Set the edebug-def-name to the spec.
1938 (setq edebug-def-name
1939 (if edebug-def-name
1940 ;; Construct a new name by appending to previous name.
1941 (intern (format "%s@%s" edebug-def-name spec))
1942 spec))
1943 nil)
1944
1945(defun edebug-match-arg (cursor)
1946 ;; set the def-args bound in edebug-defining-form
1947 (let ((edebug-arg (edebug-top-element-required cursor "Expected arg")))
1948 (if (or (not (symbolp edebug-arg))
f7359658 1949 (edebug-lambda-list-keywordp edebug-arg))
1fe3d507
DL
1950 (edebug-no-match cursor "Bad argument:" edebug-arg))
1951 (edebug-move-cursor cursor)
1952 (setq edebug-def-args (cons edebug-arg edebug-def-args))
1953 (list edebug-arg)))
1954
1955(defun edebug-match-def-form (cursor)
1956 ;; Like form but the form is wrapped in edebug-enter form.
1957 ;; The form is assumed to be executing outside of the function context.
1958 ;; This is a hack for now, since a def-form might execute inside as well.
1959 ;; Not to be used otherwise.
1960 (let ((edebug-inside-func nil))
1961 (list (edebug-make-enter-wrapper (list (edebug-form cursor))))))
1962
1963(defun edebug-match-def-body (cursor)
1964 ;; Like body but body is wrapped in edebug-enter form.
1965 ;; The body is assumed to be executing inside of the function context.
1966 ;; Not to be used otherwise.
1967 (let ((edebug-inside-func t))
1968 (list (edebug-wrap-def-body (edebug-forms cursor)))))
1969
1970
1971;;;; Edebug Form Specs
1972;;; ==========================================================
1973;;; See cl-specs.el for common lisp specs.
1974
1975;;;;* Spec for def-edebug-spec
1976;;; Out of date.
1977
1978(defun edebug-spec-p (object)
1979 "Return non-nil if OBJECT is a symbol with an edebug-form-spec property."
1980 (and (symbolp object)
1981 (get object 'edebug-form-spec)))
1982
1983(def-edebug-spec def-edebug-spec
1984 ;; Top level is different from lower levels.
1985 (&define :name edebug-spec name
1986 &or "nil" edebug-spec-p "t" "0" (&rest edebug-spec)))
1987
1988(def-edebug-spec edebug-spec-list
1989 ;; A list must have something in it, or it is nil, a symbolp
1990 ((edebug-spec . [&or nil edebug-spec])))
1991
1992(def-edebug-spec edebug-spec
1993 (&or
1994 (vector &rest edebug-spec) ; matches a vector
1995 ("vector" &rest edebug-spec) ; matches a vector spec
1996 ("quote" symbolp)
1997 edebug-spec-list
1998 stringp
f7359658
RS
1999 [edebug-lambda-list-keywordp &rest edebug-spec]
2000 ;; [edebug-keywordp gate edebug-spec] ;; need edebug-keywordp for this.
1fe3d507
DL
2001 edebug-spec-p ;; Including all the special ones e.g. form.
2002 symbolp;; a predicate
2003 ))
84fc2cfa
ER
2004
2005
f7359658 2006;;;* Emacs special forms and some functions.
84fc2cfa 2007
1fe3d507
DL
2008;; quote expects only one argument, although it allows any number.
2009(def-edebug-spec quote sexp)
84fc2cfa 2010
1fe3d507
DL
2011;; The standard defining forms.
2012(def-edebug-spec defconst defvar)
2013(def-edebug-spec defvar (symbolp &optional form stringp))
84fc2cfa 2014
1fe3d507
DL
2015(def-edebug-spec defun
2016 (&define name lambda-list
2017 [&optional stringp]
2018 [&optional ("interactive" interactive)]
2019 def-body))
2020(def-edebug-spec defmacro
2021 (&define name lambda-list def-body))
84fc2cfa 2022
f7359658 2023(def-edebug-spec arglist lambda-list) ;; deprecated - use lambda-list.
84fc2cfa 2024
1fe3d507
DL
2025(def-edebug-spec lambda-list
2026 (([&rest arg]
2027 [&optional ["&optional" arg &rest arg]]
2028 &optional ["&rest" arg]
2029 )))
84fc2cfa 2030
1fe3d507
DL
2031(def-edebug-spec interactive
2032 (&optional &or stringp def-form))
84fc2cfa 2033
1fe3d507
DL
2034;; A function-form is for an argument that may be a function or a form.
2035;; This specially recognizes anonymous functions quoted with quote.
2036(def-edebug-spec function-form
2037 ;; form at the end could also handle "function",
2038 ;; but recognize it specially to avoid wrapping function forms.
2039 (&or ([&or "quote" "function"] &or symbolp lambda-expr) form))
84fc2cfa 2040
1fe3d507
DL
2041;; function expects a symbol or a lambda or macro expression
2042;; A macro is allowed by Emacs.
2043(def-edebug-spec function (&or symbolp lambda-expr))
84fc2cfa 2044
1fe3d507
DL
2045;; lambda is a macro in emacs 19.
2046(def-edebug-spec lambda (&define lambda-list
2047 [&optional stringp]
2048 [&optional ("interactive" interactive)]
2049 def-body))
2050
2051;; A macro expression is a lambda expression with "macro" prepended.
2052(def-edebug-spec macro (&define "lambda" lambda-list def-body))
2053
2054;; (def-edebug-spec anonymous-form ((&or ["lambda" lambda] ["macro" macro])))
2055
2056;; Standard functions that take function-forms arguments.
2057(def-edebug-spec mapcar (function-form form))
2058(def-edebug-spec mapconcat (function-form form form))
2059(def-edebug-spec mapatoms (function-form &optional form))
2060(def-edebug-spec apply (function-form &rest form))
2061(def-edebug-spec funcall (function-form &rest form))
2062
2063(def-edebug-spec let
2064 ((&rest &or (symbolp &optional form) symbolp)
2065 body))
2066
2067(def-edebug-spec let* let)
2068
2069(def-edebug-spec setq (&rest symbolp form))
2070(def-edebug-spec setq-default setq)
2071
2072(def-edebug-spec cond (&rest (&rest form)))
2073
2074(def-edebug-spec condition-case
2075 (symbolp
2076 form
2077 &rest (symbolp body)))
2078
2079
f7359658 2080(def-edebug-spec \` (backquote-form))
1fe3d507
DL
2081
2082;; Supports quotes inside backquotes,
2083;; but only at the top level inside unquotes.
2084(def-edebug-spec backquote-form
2085 (&or
2086 ([&or "," ",@"] &or ("quote" backquote-form) form)
2087 (backquote-form &rest backquote-form)
2088 ;; If you use dotted forms in backquotes, replace the previous line
2089 ;; with the following. This takes quite a bit more stack space, however.
2090 ;; (backquote-form . [&or nil backquote-form])
2091 (vector &rest backquote-form)
2092 sexp))
84fc2cfa 2093
1fe3d507
DL
2094;; Special version of backquote that instruments backquoted forms
2095;; destined to be evaluated, usually as the result of a
2096;; macroexpansion. Backquoted code can only have unquotes (, and ,@)
2097;; in places where list forms are allowed, and predicates. If the
2098;; backquote is used in a macro, unquoted code that come from
2099;; arguments must be instrumented, if at all, with def-form not def-body.
84fc2cfa 2100
1fe3d507
DL
2101;; We could assume that all forms (not nested in other forms)
2102;; in arguments of macros should be def-forms, whether or not the macros
2103;; are defined with edebug-` but this would be expensive.
84fc2cfa 2104
1fe3d507
DL
2105;; ,@ might have some problems.
2106
f7359658
RS
2107(defalias 'edebug-\` '\`) ;; same macro as regular backquote.
2108(def-edebug-spec edebug-\` (def-form))
1fe3d507
DL
2109
2110;; Assume immediate quote in unquotes mean backquote at next higher level.
2111(def-edebug-spec , (&or ("quote" edebug-`) def-form))
2112(def-edebug-spec ,@ (&define ;; so (,@ form) is never wrapped.
2113 &or ("quote" edebug-`) def-form))
2114
2115;; New byte compiler.
2116(def-edebug-spec defsubst defun)
2117(def-edebug-spec dont-compile t)
2118(def-edebug-spec eval-when-compile t)
2119(def-edebug-spec eval-and-compile t)
2120
2121;; Anything else?
2122
2123
1fe3d507
DL
2124;; Some miscellaneous specs for macros in public packages.
2125;; Send me yours.
2126
2127;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu)
2128
2129(def-edebug-spec ad-dolist ((symbolp form &optional form) body))
2130(def-edebug-spec defadvice
2131 (&define name ;; thing being advised.
2132 (name ;; class is [&or "before" "around" "after"
2133 ;; "activation" "deactivation"]
2134 name ;; name of advice
2135 &rest sexp ;; optional position and flags
2136 )
2137 [&optional stringp]
2138 [&optional ("interactive" interactive)]
2139 def-body))
2140
f7359658 2141;;; The debugger itself
1fe3d507
DL
2142
2143(defvar edebug-active nil) ;; Non-nil when edebug is active
84fc2cfa
ER
2144
2145;;; add minor-mode-alist entry
2146(or (assq 'edebug-active minor-mode-alist)
2147 (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*")
2148 minor-mode-alist)))
2149
1fe3d507
DL
2150(defvar edebug-stack nil)
2151;; Stack of active functions evaluated via edebug.
2152;; Should be nil at the top level.
2153
2154(defvar edebug-stack-depth -1)
2155;; Index of last edebug-stack item.
2156
2157(defvar edebug-offset-indices nil)
2158;; Stack of offset indices of visited edebug sexps.
2159;; Should be nil at the top level.
2160;; Each function adds one cons. Top is modified with setcar.
84fc2cfa 2161
84fc2cfa
ER
2162
2163(defvar edebug-entered nil
1fe3d507
DL
2164 ;; Non-nil if edebug has already been entered at this recursive edit level.
2165 ;; This should stay nil at the top level.
2166 )
2167
2168;; Should these be options?
2169(defconst edebug-debugger 'edebug
2170 ;; Name of function to use for debugging when error or quit occurs.
2171 ;; Set this to 'debug if you want to debug edebug.
2172 )
2173
2174
2175;; Dynamically bound variables, declared globally but left unbound.
2176(defvar edebug-function) ; the function being executed. change name!!
2177(defvar edebug-args) ; the arguments of the function
2178(defvar edebug-data) ; the edebug data for the function
2179(defvar edebug-value) ; the result of the expression
2180(defvar edebug-after-index)
2181(defvar edebug-def-mark) ; the mark for the definition
2182(defvar edebug-freq-count) ; the count of expression visits.
2183(defvar edebug-coverage) ; the coverage results of each expression of function.
2184
2185(defvar edebug-buffer) ; which buffer the function is in.
2186(defvar edebug-result) ; the result of the function call returned by body
2187(defvar edebug-outside-executing-macro)
2188(defvar edebug-outside-defining-kbd-macro)
2189
2190(defvar edebug-execution-mode 'step) ; Current edebug mode set by user.
2191(defvar edebug-next-execution-mode nil) ; Use once instead of initial mode.
2192
2193(defvar edebug-outside-debug-on-error) ; the value of debug-on-error outside
2194(defvar edebug-outside-debug-on-quit) ; the value of debug-on-quit outside
2195
88668147
DL
2196(defvar edebug-outside-pre-command-hook)
2197(defvar edebug-outside-post-command-hook)
f7359658 2198(defvar edebug-outside-post-command-idle-hook)
88668147
DL
2199
2200;; Emacs 19
2201(defvar pre-command-hook nil)
2202(defvar post-command-hook nil)
f7359658 2203(defvar post-command-idle-hook nil)
88668147
DL
2204
2205(defvar cl-lexical-debug) ;; Defined in cl.el
2206
1fe3d507 2207;;; Handling signals
1fe3d507 2208
88668147
DL
2209(if (not (fboundp 'edebug-original-signal))
2210 (defalias 'edebug-original-signal (symbol-function 'signal)))
1fe3d507
DL
2211;; We should use advise for this!!
2212
2213(defun edebug-signal (edebug-signal-name edebug-signal-data)
2214 "Signal an error. Args are SIGNAL-NAME, and associated DATA.
2215A signal name is a symbol with an `error-conditions' property
2216that is a list of condition names.
2217A handler for any of those names will get to handle this signal.
2218The symbol `error' should always be one of them.
2219
2220DATA should be a list. Its elements are printed as part of the error message.
2221If the signal is handled, DATA is made available to the handler.
2222See `condition-case'.
2223
2224This is the Edebug replacement for the standard `signal'. It should
2225only be active while Edebug is. It checks `debug-on-error' to see
2226whether it should call the debugger. When execution is resumed, the
2227error is signaled again."
2228 (if (and (listp debug-on-error) (memq edebug-signal-name debug-on-error))
2229 (edebug 'error (cons edebug-signal-name edebug-signal-data)))
2230 ;; If we reach here without another non-local exit, then send signal again.
2231 ;; i.e. the signal is not continuable, yet.
88668147 2232 (edebug-original-signal edebug-signal-name edebug-signal-data))
1fe3d507
DL
2233
2234
2235;;; Entering Edebug
84fc2cfa 2236
1fe3d507
DL
2237(defun edebug-enter (edebug-function edebug-args edebug-body)
2238 ;; Entering FUNC. The arguments are ARGS, and the body is BODY.
2239 ;; Setup edebug variables and evaluate BODY. This function is called
2240 ;; when a function evaluated with edebug-eval-top-level-form is entered.
2241 ;; Return the result of BODY.
84fc2cfa
ER
2242
2243 ;; Is this the first time we are entering edebug since
2244 ;; lower-level recursive-edit command?
1fe3d507
DL
2245 ;; More precisely, this tests whether Edebug is currently active.
2246 (if (not edebug-entered)
2247 (let ((edebug-entered t)
2248 ;; Binding max-lisp-eval-depth here is OK,
88668147
DL
2249 ;; but not inside an unwind-protect.
2250 ;; Doing it here also keeps it from growing too large.
1fe3d507
DL
2251 (max-lisp-eval-depth (+ 100 max-lisp-eval-depth)) ; too much??
2252 (max-specpdl-size (+ 200 max-specpdl-size))
2253
2254 (debugger edebug-debugger) ; only while edebug is active.
2255 (edebug-outside-debug-on-error debug-on-error)
2256 (edebug-outside-debug-on-quit debug-on-quit)
2257 ;; Binding these may not be the right thing to do.
2258 ;; We want to allow the global values to be changed.
2259 (debug-on-error (or debug-on-error edebug-on-error))
2260 (debug-on-quit edebug-on-quit)
2261
88668147
DL
2262 ;; Lexical bindings must be uncompiled for this to work.
2263 (cl-lexical-debug t)
2264
1fe3d507 2265 ;; Save the outside value of executing macro. (here??)
efcf38c7 2266 (edebug-outside-executing-macro executing-kbd-macro)
88668147 2267 (edebug-outside-pre-command-hook pre-command-hook)
f7359658
RS
2268 (edebug-outside-post-command-hook post-command-hook)
2269 (edebug-outside-post-command-idle-hook post-command-idle-hook))
1fe3d507 2270 (unwind-protect
88668147
DL
2271 (let (;; Don't keep reading from an executing kbd macro
2272 ;; within edebug unless edebug-continue-kbd-macro is
2273 ;; non-nil. Again, local binding may not be best.
efcf38c7
KH
2274 (executing-kbd-macro
2275 (if edebug-continue-kbd-macro executing-kbd-macro))
88668147
DL
2276
2277 ;; Disable command hooks. This is essential when
2278 ;; a hook function is instrumented - to avoid infinite loop.
2279 ;; This may be more than we need, however.
2280 (pre-command-hook nil)
f7359658
RS
2281 (post-command-hook nil)
2282 (post-command-idle-hook nil))
88668147
DL
2283 (setq edebug-execution-mode (or edebug-next-execution-mode
2284 edebug-initial-mode
2285 edebug-execution-mode)
2286 edebug-next-execution-mode nil)
2287 ;; Bind signal to edebug-signal only while Edebug is active.
2288 (fset 'signal 'edebug-signal)
2289 (unwind-protect
2290 (edebug-enter edebug-function edebug-args edebug-body)
2291 (fset 'signal (symbol-function 'edebug-original-signal))))
2292 ;; Reset global variables in case outside value was changed.
efcf38c7 2293 (setq executing-kbd-macro edebug-outside-executing-macro
f7359658
RS
2294 pre-command-hook edebug-outside-pre-command-hook
2295 post-command-hook edebug-outside-post-command-hook
2296 post-command-idle-hook edebug-outside-post-command-idle-hook
88668147 2297 )))
1fe3d507
DL
2298
2299 (let* ((edebug-data (get edebug-function 'edebug))
2300 (edebug-def-mark (car edebug-data)) ; mark at def start
2301 (edebug-freq-count (get edebug-function 'edebug-freq-count))
2302 (edebug-coverage (get edebug-function 'edebug-coverage))
2303 (edebug-buffer (marker-buffer edebug-def-mark))
2304
2305 (edebug-stack (cons edebug-function edebug-stack))
2306 (edebug-offset-indices (cons 0 edebug-offset-indices))
2307 )
2308 (if (get edebug-function 'edebug-on-entry)
2309 (progn
2310 (setq edebug-execution-mode 'step)
2311 (if (eq (get edebug-function 'edebug-on-entry) 'temp)
2312 (put edebug-function 'edebug-on-entry nil))))
2313 (if edebug-trace
2314 (edebug-enter-trace edebug-body)
2315 (funcall edebug-body))
84fc2cfa
ER
2316 )))
2317
84fc2cfa 2318
1fe3d507
DL
2319(defun edebug-enter-trace (edebug-body)
2320 (let ((edebug-stack-depth (1+ edebug-stack-depth))
2321 edebug-result)
2322 (edebug-print-trace-before
2323 (format "%s args: %s" edebug-function edebug-args))
2324 (prog1 (setq edebug-result (funcall edebug-body))
2325 (edebug-print-trace-after
2326 (format "%s result: %s" edebug-function edebug-result)))))
2327
2328(def-edebug-spec edebug-tracing (form body))
2329
2330(defmacro edebug-tracing (msg &rest body)
2331 "Print MSG in *edebug-trace* before and after evaluating BODY.
2332The result of BODY is also printed."
2333 (` (let ((edebug-stack-depth (1+ edebug-stack-depth))
2334 edebug-result)
2335 (edebug-print-trace-before (, msg))
2336 (prog1 (setq edebug-result (progn (,@ body)))
2337 (edebug-print-trace-after
2338 (format "%s result: %s" (, msg) edebug-result))))))
2339
2340(defun edebug-print-trace-before (msg)
2341 "Function called to print trace info before expression evaluation.
2342MSG is printed after `::::{ '."
84fc2cfa 2343 (edebug-trace-display
1fe3d507 2344 edebug-trace-buffer "%s{ %s" (make-string edebug-stack-depth ?\:) msg))
84fc2cfa 2345
1fe3d507
DL
2346(defun edebug-print-trace-after (msg)
2347 "Function called to print trace info after expression evaluation.
2348MSG is printed after `::::} '."
84fc2cfa 2349 (edebug-trace-display
1fe3d507
DL
2350 edebug-trace-buffer "%s} %s" (make-string edebug-stack-depth ?\:) msg))
2351
2352
84fc2cfa 2353
1fe3d507
DL
2354(defun edebug-slow-before (edebug-before-index)
2355 ;; Debug current function given BEFORE position.
2356 ;; Called from functions compiled with edebug-eval-top-level-form.
2357 ;; Return the before index.
2358 (setcar edebug-offset-indices edebug-before-index)
84fc2cfa 2359
1fe3d507
DL
2360 ;; Increment frequency count
2361 (aset edebug-freq-count edebug-before-index
2362 (1+ (aref edebug-freq-count edebug-before-index)))
2363
2364 (if (or (not (memq edebug-execution-mode '(Go-nonstop next)))
2365 (edebug-input-pending-p))
2366 (edebug-debugger edebug-before-index 'before nil))
2367 edebug-before-index)
2368
2369(defun edebug-fast-before (edebug-before-index)
2370 ;; Do nothing.
2371 )
2372
2373(defun edebug-slow-after (edebug-before-index edebug-after-index edebug-value)
2374 ;; Debug current function given AFTER position and VALUE.
2375 ;; Called from functions compiled with edebug-eval-top-level-form.
2376 ;; Return VALUE.
2377 (setcar edebug-offset-indices edebug-after-index)
2378
2379 ;; Increment frequency count
2380 (aset edebug-freq-count edebug-after-index
2381 (1+ (aref edebug-freq-count edebug-after-index)))
2382 (if edebug-test-coverage (edebug-update-coverage))
2383
2384 (if (and (eq edebug-execution-mode 'Go-nonstop)
2385 (not (edebug-input-pending-p)))
2386 ;; Just return result.
2387 edebug-value
2388 (edebug-debugger edebug-after-index 'after edebug-value)
2389 ))
2390
2391(defun edebug-fast-after (edebug-before-index edebug-after-index edebug-value)
2392 ;; Do nothing but return the value.
2393 edebug-value)
2394
2395(defun edebug-run-slow ()
2396 (defalias 'edebug-before 'edebug-slow-before)
2397 (defalias 'edebug-after 'edebug-slow-after))
2398
2399;; This is not used, yet.
2400(defun edebug-run-fast ()
2401 (defalias 'edebug-before 'edebug-fast-before)
2402 (defalias 'edebug-after 'edebug-fast-after))
2403
2404(edebug-run-slow)
2405
2406
2407(defun edebug-update-coverage ()
2408 (let ((old-result (aref edebug-coverage edebug-after-index)))
2409 (cond
2410 ((eq 'ok-coverage old-result))
2411 ((eq 'unknown old-result)
2412 (aset edebug-coverage edebug-after-index edebug-value))
2413 ;; Test if a different result.
2414 ((not (eq edebug-value old-result))
2415 (aset edebug-coverage edebug-after-index 'ok-coverage)))))
2416
2417
2418;; Dynamically declared unbound variables.
2419(defvar edebug-arg-mode) ; the mode, either before, after, or error
2420(defvar edebug-breakpoints)
2421(defvar edebug-break-data) ; break data for current function.
2422(defvar edebug-break) ; whether a break occurred.
2423(defvar edebug-global-break) ; whether a global break occurred.
2424(defvar edebug-break-condition) ; whether the breakpoint is conditional.
2425
2426(defvar edebug-break-result nil)
2427(defvar edebug-global-break-result nil)
2428
2429
2430(defun edebug-debugger (edebug-offset-index edebug-arg-mode edebug-value)
2431 ;; Check breakpoints and pending input.
2432 ;; If edebug display should be updated, call edebug-display.
2433 ;; Return edebug-value.
2434 (let* (;; This needs to be here since breakpoints may be changed.
84fc2cfa
ER
2435 (edebug-breakpoints (car (cdr edebug-data))) ; list of breakpoints
2436 (edebug-break-data (assq edebug-offset-index edebug-breakpoints))
1fe3d507
DL
2437 (edebug-break-condition (car (cdr edebug-break-data)))
2438 (edebug-global-break
2439 (if edebug-global-break-condition
2440 (condition-case nil
2441 (setq edebug-global-break-result
2442 (eval edebug-global-break-condition))
2443 (error nil))))
2444 (edebug-break))
2445
2446;;; (edebug-trace "exp: %s" edebug-value)
2447 ;; Test whether we should break.
2448 (setq edebug-break
2449 (or edebug-global-break
2450 (and edebug-break-data
2451 (or (not edebug-break-condition)
2452 (setq edebug-break-result
2453 (eval edebug-break-condition))))))
84fc2cfa 2454 (if (and edebug-break
1fe3d507 2455 (nth 2 edebug-break-data)) ; is it temporary?
84fc2cfa
ER
2456 ;; Delete the breakpoint.
2457 (setcdr edebug-data
2458 (cons (delq edebug-break-data edebug-breakpoints)
2459 (cdr (cdr edebug-data)))))
1fe3d507
DL
2460
2461 ;; Display if mode is not go, continue, or Continue-fast
2462 ;; or break, or input is pending,
2463 (if (or (not (memq edebug-execution-mode '(go continue Continue-fast)))
2464 edebug-break
2465 (edebug-input-pending-p))
2466 (edebug-display)) ; <--------------- display
84fc2cfa 2467
1fe3d507 2468 edebug-value
84fc2cfa
ER
2469 ))
2470
2471
1fe3d507
DL
2472;; window-start now stored with each function.
2473;;(defvar edebug-window-start nil)
2474;; Remember where each buffers' window starts between edebug calls.
2475;; This is to avoid spurious recentering.
2476;; Does this still need to be buffer-local??
2477;;(setq-default edebug-window-start nil)
2478;;(make-variable-buffer-local 'edebug-window-start)
2479
2480
2481;; Dynamically declared unbound vars
2482(defvar edebug-point) ; the point in edebug buffer
2483(defvar edebug-outside-buffer) ; the current-buffer outside of edebug
2484(defvar edebug-outside-point) ; the point outside of edebug
2485(defvar edebug-outside-mark) ; the mark outside of edebug
2486(defvar edebug-window-data) ; window and window-start for current function
2487(defvar edebug-outside-windows) ; outside window configuration
2488(defvar edebug-eval-buffer) ; for the evaluation list.
2489(defvar edebug-outside-o-a-p) ; outside overlay-arrow-position
2490(defvar edebug-outside-o-a-s) ; outside overlay-arrow-string
2491(defvar edebug-outside-c-i-e-a) ; outside cursor-in-echo-area
2492
2493(defvar edebug-eval-list nil) ;; List of expressions to evaluate.
2494
2495(defvar edebug-previous-result nil) ;; Last result returned.
2496
88668147 2497;; Emacs 19 adds an arg to mark and mark-marker.
1fe3d507
DL
2498(defalias 'edebug-mark 'mark)
2499(defalias 'edebug-mark-marker 'mark-marker)
84fc2cfa 2500
84fc2cfa
ER
2501
2502(defun edebug-display ()
1fe3d507
DL
2503 ;; Setup windows for edebug, determine mode, maybe enter recursive-edit.
2504 ;; Uses local variables of edebug-enter, edebug-before, edebug-after
2505 ;; and edebug-debugger.
84fc2cfa
ER
2506 (let ((edebug-active t) ; for minor mode alist
2507 edebug-stop ; should we enter recursive-edit
1fe3d507
DL
2508 (edebug-point (+ edebug-def-mark
2509 (aref (nth 2 edebug-data) edebug-offset-index)))
2510 edebug-buffer-outside-point ; current point in edebug-buffer
2511 ;; window displaying edebug-buffer
2512 (edebug-window-data (nth 3 edebug-data))
84fc2cfa
ER
2513 (edebug-outside-window (selected-window))
2514 (edebug-outside-buffer (current-buffer))
2515 (edebug-outside-point (point))
1fe3d507 2516 (edebug-outside-mark (edebug-mark))
84fc2cfa 2517 edebug-outside-windows ; window or screen configuration
1fe3d507 2518 edebug-buffer-points
84fc2cfa
ER
2519
2520 edebug-eval-buffer ; declared here so we can kill it below
2521 (edebug-eval-result-list (and edebug-eval-list
2522 (edebug-eval-result-list)))
1fe3d507
DL
2523 edebug-trace-window
2524 edebug-trace-window-start
88668147
DL
2525
2526 (edebug-outside-o-a-p overlay-arrow-position)
2527 (edebug-outside-o-a-s overlay-arrow-string)
2528 (edebug-outside-c-i-e-a cursor-in-echo-area))
2529 (unwind-protect
2530 (let ((overlay-arrow-position overlay-arrow-position)
2531 (overlay-arrow-string overlay-arrow-string)
2532 (cursor-in-echo-area nil)
2533 ;; any others??
2534 )
2535 (if (not (buffer-name edebug-buffer))
2536 (let ((debug-on-error nil))
2537 (error "Buffer defining %s not found" edebug-function)))
84fc2cfa 2538
88668147
DL
2539 (if (eq 'after edebug-arg-mode)
2540 ;; Compute result string now before windows are modified.
2541 (edebug-compute-previous-result edebug-value))
2542
2543 (if edebug-save-windows
2544 ;; Save windows now before we modify them.
2545 (setq edebug-outside-windows
2546 (edebug-current-windows edebug-save-windows)))
84fc2cfa 2547
88668147
DL
2548 (if edebug-save-displayed-buffer-points
2549 (setq edebug-buffer-points (edebug-get-displayed-buffer-points)))
2550
2551 ;; First move the edebug buffer point to edebug-point
f7359658
RS
2552 ;; so that window start doesn't get changed when we display it.
2553 ;; I don't know if this is going to help.
88668147
DL
2554 ;;(set-buffer edebug-buffer)
2555 ;;(goto-char edebug-point)
2556
2557 ;; If edebug-buffer is not currently displayed,
2558 ;; first find a window for it.
2559 (edebug-pop-to-buffer edebug-buffer (car edebug-window-data))
2560 (setcar edebug-window-data (selected-window))
2561
2562 ;; Now display eval list, if any.
2563 ;; This is done after the pop to edebug-buffer
2564 ;; so that buffer-window correspondence is correct after quitting.
2565 (edebug-eval-display edebug-eval-result-list)
2566 ;; The evaluation list better not have deleted edebug-window-data.
2567 (select-window (car edebug-window-data))
2568 (set-buffer edebug-buffer)
2569
2570 (setq edebug-buffer-outside-point (point))
2571 (goto-char edebug-point)
84fc2cfa 2572
88668147
DL
2573 (if (eq 'before edebug-arg-mode)
2574 ;; Check whether positions are up-to-date.
2575 ;; This assumes point is never before symbol.
2576 (if (not (memq (following-char) '(?\( ?\# ?\` )))
2577 (let ((debug-on-error nil))
2578 (error "Source has changed - reevaluate definition of %s"
2579 edebug-function)
2580 )))
1fe3d507 2581
88668147
DL
2582 (setcdr edebug-window-data
2583 (edebug-adjust-window (cdr edebug-window-data)))
84fc2cfa 2584
88668147
DL
2585 ;; Test if there is input, not including keyboard macros.
2586 (if (edebug-input-pending-p)
2587 (progn
2588 (setq edebug-execution-mode 'step
2589 edebug-stop t)
2590 (edebug-stop)
2591 ;; (discard-input) ; is this unfriendly??
2592 ))
2593 ;; Now display arrow based on mode.
2594 (edebug-overlay-arrow)
84fc2cfa 2595
88668147
DL
2596 (cond
2597 ((eq 'error edebug-arg-mode)
2598 ;; Display error message
2599 (setq edebug-execution-mode 'step)
2600 (edebug-overlay-arrow)
2601 (beep)
2602 (if (eq 'quit (car edebug-value))
2603 (message "Quit")
2604 (edebug-report-error edebug-value)))
2605 (edebug-break
2606 (cond
2607 (edebug-global-break
2608 (message "Global Break: %s => %s"
2609 edebug-global-break-condition
2610 edebug-global-break-result))
2611 (edebug-break-condition
2612 (message "Break: %s => %s"
2613 edebug-break-condition
2614 edebug-break-result))
2615 ((not (eq edebug-execution-mode 'Continue-fast))
2616 (message "Break"))
2617 (t)))
2618
2619 (t (message "")))
2620
2621 (if (eq 'after edebug-arg-mode)
2622 (progn
2623 ;; Display result of previous evaluation.
2624 (if (and edebug-break
2625 (not (eq edebug-execution-mode 'Continue-fast)))
2626 (sit-for 1)) ; Show break message.
2627 (edebug-previous-result)))
1fe3d507 2628
88668147
DL
2629 (cond
2630 (edebug-break
2631 (cond
2632 ((eq edebug-execution-mode 'continue) (edebug-sit-for 1))
2633 ((eq edebug-execution-mode 'Continue-fast) (edebug-sit-for 0))
2634 (t (setq edebug-stop t))))
2635 ;; not edebug-break
2636 ((eq edebug-execution-mode 'trace)
2637 (edebug-sit-for 1)) ; Force update and pause.
2638 ((eq edebug-execution-mode 'Trace-fast)
2639 (edebug-sit-for 0)) ; Force update and continue.
2640 )
1fe3d507 2641
88668147
DL
2642 (unwind-protect
2643 (if (or edebug-stop
2644 (memq edebug-execution-mode '(step next))
2645 (eq edebug-arg-mode 'error))
2646 (progn
2647 ;; (setq edebug-execution-mode 'step)
f7359658 2648 ;; (edebug-overlay-arrow) ; This doesn't always show up.
88668147
DL
2649 (edebug-recursive-edit))) ; <---------- Recursive edit
2650
2651 ;; Reset the edebug-window-data to whatever it is now.
2652 (let ((window (if (eq (window-buffer) edebug-buffer)
2653 (selected-window)
2654 (edebug-get-buffer-window edebug-buffer))))
2655 ;; Remember window-start for edebug-buffer, if still displayed.
2656 (if window
2657 (progn
2658 (setcar edebug-window-data window)
2659 (setcdr edebug-window-data (window-start window)))))
1fe3d507 2660
88668147
DL
2661 ;; Save trace window point before restoring outside windows.
2662 ;; Could generalize this for other buffers.
2663 (setq edebug-trace-window (get-buffer-window edebug-trace-buffer))
2664 (if edebug-trace-window
2665 (setq edebug-trace-window-start
2666 (and edebug-trace-window
2667 (window-start edebug-trace-window))))
2668
2669 ;; Restore windows before continuing.
2670 (if edebug-save-windows
2671 (progn
2672 (edebug-set-windows edebug-outside-windows)
2673
2674 ;; Restore displayed buffer points.
2675 ;; Needed even if restoring windows because
2676 ;; window-points are not restored. (should they be??)
2677 (if edebug-save-displayed-buffer-points
2678 (edebug-set-buffer-points edebug-buffer-points))
2679
2680 ;; Unrestore trace window's window-point.
2681 (if edebug-trace-window
2682 (set-window-start edebug-trace-window
2683 edebug-trace-window-start))
2684
2685 ;; Unrestore edebug-buffer's window-start, if displayed.
2686 (let ((window (car edebug-window-data)))
2687 (if (and window (edebug-window-live-p window)
2688 (eq (window-buffer) edebug-buffer))
2689 (progn
2690 (set-window-start window (cdr edebug-window-data)
2691 'no-force)
2692 ;; Unrestore edebug-buffer's window-point.
2693 ;; Needed in addition to setting the buffer point
f7359658 2694 ;; - otherwise quitting doesn't leave point as is.
88668147
DL
2695 ;; But this causes point to not be restored at times.
2696 ;; Also, it may not be a visible window.
2697 ;; (set-window-point window edebug-point)
2698 )))
2699
2700 ;; Unrestore edebug-buffer's point. Rerestored below.
2701 ;; (goto-char edebug-point) ;; in edebug-buffer
2702 )
2703 ;; Since we may be in a save-excursion, in case of quit,
2704 ;; reselect the outside window only.
2705 ;; Only needed if we are not recovering windows??
2706 (if (edebug-window-live-p edebug-outside-window)
2707 (select-window edebug-outside-window))
2708 ) ; if edebug-save-windows
2709
2710 ;; Restore current buffer always, in case application needs it.
2711 (set-buffer edebug-outside-buffer)
2712 ;; Restore point, and mark.
1fe3d507 2713 ;; Needed even if restoring windows because
f7359658
RS
2714 ;; that doesn't restore point and mark in the current buffer.
2715 ;; But don't restore point if edebug-buffer is current buffer.
88668147
DL
2716 (if (not (eq edebug-buffer edebug-outside-buffer))
2717 (goto-char edebug-outside-point))
2718 (if (marker-buffer (edebug-mark-marker))
2719 ;; Does zmacs-regions need to be nil while doing set-marker?
2720 (set-marker (edebug-mark-marker) edebug-outside-mark))
2721 ) ; unwind-protect
2722 ;; None of the following is done if quit or signal occurs.
2723
2724 ;; Restore edebug-buffer's outside point.
2725 ;; (edebug-trace "restore edebug-buffer point: %s"
2726 ;; edebug-buffer-outside-point)
2727 (let ((current-buffer (current-buffer)))
2728 (set-buffer edebug-buffer)
2729 (goto-char edebug-buffer-outside-point)
2730 (set-buffer current-buffer))
2731 ;; ... nothing more.
2732 )
2733 ;; Reset global variables to outside values in case they were changed.
2734 (setq
2735 overlay-arrow-position edebug-outside-o-a-p
2736 overlay-arrow-string edebug-outside-o-a-s
2737 cursor-in-echo-area edebug-outside-c-i-e-a)
2738 )))
1fe3d507 2739
84fc2cfa 2740
1fe3d507
DL
2741(defvar edebug-number-of-recursions 0)
2742;; Number of recursive edits started by edebug.
2743;; Should be 0 at the top level.
2744
2745(defvar edebug-recursion-depth 0)
2746;; Value of recursion-depth when edebug was called.
2747
2748;; Dynamically declared unbound vars
2749(defvar edebug-outside-match-data) ; match data outside of edebug
2750(defvar edebug-backtrace-buffer) ; each recursive edit gets its own
2751(defvar edebug-inside-windows)
2752(defvar edebug-interactive-p)
2753
2754(defvar edebug-outside-map)
2755(defvar edebug-outside-standard-output)
2756(defvar edebug-outside-standard-input)
2757(defvar edebug-outside-last-command-char)
2758(defvar edebug-outside-last-command)
2759(defvar edebug-outside-this-command)
2760(defvar edebug-outside-last-input-char)
2761
100aa77c
RS
2762;; Note: here we have defvars for variables that are
2763;; built-in in certain versions.
2764;; Each defvar makes a difference
2765;; in versions where the variable is *not* built-in.
2766
1fe3d507
DL
2767;; Emacs 18
2768(defvar edebug-outside-unread-command-char)
1fe3d507
DL
2769
2770;; Lucid Emacs
2771(defvar edebug-outside-unread-command-event) ;; like unread-command-events
2772(defvar unread-command-event nil)
2773
2774;; Emacs 19.
2775(defvar edebug-outside-last-command-event)
2776(defvar edebug-outside-unread-command-events)
2777(defvar edebug-outside-last-input-event)
2778(defvar edebug-outside-last-event-frame)
2779(defvar edebug-outside-last-nonmenu-event)
2780(defvar edebug-outside-track-mouse)
2781
1fe3d507
DL
2782;; Disable byte compiler warnings about unread-command-char and -event
2783;; (maybe works with byte-compile-version 2.22 at least)
2784(defvar edebug-unread-command-char-warning)
2785(defvar edebug-unread-command-event-warning)
2786(eval-when-compile
2787 (setq edebug-unread-command-char-warning
2788 (get 'unread-command-char 'byte-obsolete-variable))
2789 (put 'unread-command-char 'byte-obsolete-variable nil)
2790 (setq edebug-unread-command-event-warning
2791 (get 'unread-command-event 'byte-obsolete-variable))
2792 (put 'unread-command-event 'byte-obsolete-variable nil))
84fc2cfa
ER
2793
2794(defun edebug-recursive-edit ()
1fe3d507 2795 ;; Start up a recursive edit inside of edebug.
84fc2cfa 2796 ;; The current buffer is the edebug-buffer, which is put into edebug-mode.
1fe3d507 2797 ;; Assume that none of the variables below are buffer-local.
84fc2cfa
ER
2798 (let ((edebug-buffer-read-only buffer-read-only)
2799 ;; match-data must be done in the outside buffer
2800 (edebug-outside-match-data
1fe3d507
DL
2801 (save-excursion ; might be unnecessary now??
2802 (set-buffer edebug-outside-buffer) ; in case match buffer different
84fc2cfa
ER
2803 (match-data)))
2804
1fe3d507 2805 ;;(edebug-number-of-recursions (1+ edebug-number-of-recursions))
84fc2cfa
ER
2806 (edebug-recursion-depth (recursion-depth))
2807 edebug-entered ; bind locally to nil
1fe3d507 2808 (edebug-interactive-p nil) ; again non-interactive
84fc2cfa
ER
2809 edebug-backtrace-buffer ; each recursive edit gets its own
2810 ;; The window configuration may be saved and restored
2811 ;; during a recursive-edit
2812 edebug-inside-windows
2813
2814 (edebug-outside-map (current-local-map))
88668147 2815
84fc2cfa
ER
2816 (edebug-outside-standard-output standard-output)
2817 (edebug-outside-standard-input standard-input)
88668147 2818 (edebug-outside-defining-kbd-macro defining-kbd-macro)
84fc2cfa
ER
2819
2820 (edebug-outside-last-command-char last-command-char)
2821 (edebug-outside-last-command last-command)
2822 (edebug-outside-this-command this-command)
2823 (edebug-outside-last-input-char last-input-char)
1fe3d507
DL
2824
2825 (edebug-outside-unread-command-char unread-command-char)
2826
2827 (edebug-outside-last-input-event last-input-event)
2828 (edebug-outside-last-command-event last-command-event)
2829 (edebug-outside-unread-command-event unread-command-event)
2830 (edebug-outside-unread-command-events unread-command-events)
2831 (edebug-outside-last-event-frame last-event-frame)
2832 (edebug-outside-last-nonmenu-event last-nonmenu-event)
2833 (edebug-outside-track-mouse track-mouse)
84fc2cfa
ER
2834 )
2835
84fc2cfa 2836 (unwind-protect
88668147
DL
2837 (let (
2838 ;; Declare global values local but using the same global value.
2839 ;; We could set these to the values for previous edebug call.
2840 (last-command-char last-command-char)
2841 (last-command last-command)
2842 (this-command this-command)
2843 (last-input-char last-input-char)
2844
2845 ;; Assume no edebug command sets unread-command-char.
2846 (unread-command-char -1)
2847
2848 ;; More for Emacs 19
2849 (last-input-event nil)
2850 (last-command-event nil)
2851 (unread-command-event nil);; lemacs
2852 (unread-command-events nil)
2853 (last-event-frame nil)
2854 (last-nonmenu-event nil)
2855 (track-mouse nil)
2856
2857 ;; Bind again to outside values.
2858 (debug-on-error edebug-outside-debug-on-error)
2859 (debug-on-quit edebug-outside-debug-on-quit)
2860
2861 ;; Don't keep defining a kbd macro.
2862 (defining-kbd-macro
2863 (if edebug-continue-kbd-macro defining-kbd-macro))
2864
2865 ;; others??
2866 )
2867
2868 (if (fboundp 'zmacs-deactivate-region);; for lemacs
2869 (zmacs-deactivate-region))
2870 (if (and (eq edebug-execution-mode 'go)
2871 (not (memq edebug-arg-mode '(after error))))
2872 (message "Break"))
2873
2874 (setq buffer-read-only t)
2875 (fset 'signal (symbol-function 'edebug-original-signal))
2876
2877 (edebug-mode)
2878 (unwind-protect
2879 (recursive-edit) ; <<<<<<<<<< Recursive edit
2880
2881 ;; Do the following, even if quit occurs.
2882 (fset 'signal 'edebug-signal)
2883 (if edebug-backtrace-buffer
2884 (kill-buffer edebug-backtrace-buffer))
2885 ;; Could be an option to keep eval display up.
2886 (if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
2887
2888 ;; Remember selected-window after recursive-edit.
2889 ;; (setq edebug-inside-window (selected-window))
2890
2891 (store-match-data edebug-outside-match-data)
2892
2893 ;; Recursive edit may have changed buffers,
2894 ;; so set it back before exiting let.
2895 (if (buffer-name edebug-buffer) ; if it still exists
2896 (progn
2897 (set-buffer edebug-buffer)
2898 (if (memq edebug-execution-mode '(go Go-nonstop))
2899 (edebug-overlay-arrow))
2900 (setq buffer-read-only edebug-buffer-read-only)
2901 (use-local-map edebug-outside-map)
2902 )
2903 ;; gotta have a buffer to let its buffer local variables be set
2904 (get-buffer-create " bogus edebug buffer"))
2905 ));; inner let
2906
2907 ;; Reset global vars to outside values, in case they have been changed.
2908 (setq
2909 last-command-char edebug-outside-last-command-char
2910 last-command-event edebug-outside-last-command-event
2911 last-command edebug-outside-last-command
2912 this-command edebug-outside-this-command
2913 unread-command-char edebug-outside-unread-command-char
2914 unread-command-event edebug-outside-unread-command-event
2915 unread-command-events edebug-outside-unread-command-events
2916 last-input-char edebug-outside-last-input-char
2917 last-input-event edebug-outside-last-input-event
2918 last-event-frame edebug-outside-last-event-frame
2919 last-nonmenu-event edebug-outside-last-nonmenu-event
2920 track-mouse edebug-outside-track-mouse
2921
2922 standard-output edebug-outside-standard-output
2923 standard-input edebug-outside-standard-input
2924 defining-kbd-macro edebug-outside-defining-kbd-macro
2925 ))
2926 ))
84fc2cfa 2927
1fe3d507
DL
2928
2929;;; Display related functions
84fc2cfa
ER
2930
2931(defun edebug-adjust-window (old-start)
1fe3d507
DL
2932 ;; If pos is not visible, adjust current window to fit following context.
2933;;; (message "window: %s old-start: %s window-start: %s pos: %s"
2934;;; (selected-window) old-start (window-start) (point)) (sit-for 5)
84fc2cfa
ER
2935 (if (not (pos-visible-in-window-p))
2936 (progn
1fe3d507
DL
2937 ;; First try old-start
2938 (if old-start
2939 (set-window-start (selected-window) old-start))
84fc2cfa 2940 (if (not (pos-visible-in-window-p))
1fe3d507
DL
2941 (progn
2942;; (message "resetting window start") (sit-for 2)
2943 (set-window-start
2944 (selected-window)
2945 (save-excursion
2946 (forward-line
2947 (if (< (point) (window-start)) -1 ; one line before if in back
2948 (- (/ (window-height) 2)) ; center the line moving forward
2949 ))
2950 (beginning-of-line)
2951 (point)))))))
84fc2cfa 2952 (window-start))
1fe3d507 2953
84fc2cfa
ER
2954
2955
1fe3d507
DL
2956(defconst edebug-arrow-alist
2957 '((Continue-fast . "=")
2958 (Trace-fast . "-")
2959 (continue . ">")
2960 (trace . "->")
2961 (step . "=>")
2962 (next . "=>")
2963 (go . "<>")
2964 (Go-nonstop . "..") ; not used
2965 )
2966 "Association list of arrows for each edebug mode.")
2967
2968(defun edebug-overlay-arrow ()
2969 ;; Set up the overlay arrow at beginning-of-line in current buffer.
2970 ;; The arrow string is derived from edebug-arrow-alist and
2971 ;; edebug-execution-mode.
88668147 2972 (let ((pos (save-excursion (beginning-of-line) (point))))
1fe3d507
DL
2973 (setq overlay-arrow-string
2974 (cdr (assq edebug-execution-mode edebug-arrow-alist)))
2975 (setq overlay-arrow-position (make-marker))
2976 (set-marker overlay-arrow-position pos (current-buffer))))
84fc2cfa 2977
1fe3d507
DL
2978
2979(defun edebug-toggle-save-all-windows ()
2980 "Toggle the saving and restoring of all windows.
2981Also, each time you toggle it on, the inside and outside window
2982configurations become the same as the current configuration."
84fc2cfa 2983 (interactive)
1fe3d507
DL
2984 (setq edebug-save-windows (not edebug-save-windows))
2985 (if edebug-save-windows
84fc2cfa
ER
2986 (setq edebug-inside-windows
2987 (setq edebug-outside-windows
1fe3d507
DL
2988 (edebug-current-windows
2989 edebug-save-windows))))
2990 (message "Window saving is %s for all windows."
84fc2cfa
ER
2991 (if edebug-save-windows "on" "off")))
2992
1fe3d507
DL
2993(defmacro edebug-changing-windows (&rest body)
2994 (` (let ((window (selected-window)))
2995 (setq edebug-inside-windows (edebug-current-windows t))
2996 (edebug-set-windows edebug-outside-windows)
2997 (,@ body) ;; Code to change edebug-save-windows
2998 (setq edebug-outside-windows (edebug-current-windows
2999 edebug-save-windows))
3000 ;; Problem: what about outside windows that are deleted inside?
3001 (edebug-set-windows edebug-inside-windows))))
3002
3003(defun edebug-toggle-save-selected-window ()
3004 "Toggle the saving and restoring of the selected window.
3005Also, each time you toggle it on, the inside and outside window
3006configurations become the same as the current configuration."
3007 (interactive)
3008 (cond
3009 ((eq t edebug-save-windows)
3010 ;; Save all outside windows except the selected one.
3011 ;; Remove (selected-window) from outside-windows.
3012 (edebug-changing-windows
3013 (setq edebug-save-windows (delq window (edebug-window-list)))))
3014
3015 ((memq (selected-window) edebug-save-windows)
3016 (setq edebug-outside-windows
3017 (delq (assq (selected-window) edebug-outside-windows)
3018 edebug-outside-windows))
3019 (setq edebug-save-windows
3020 (delq (selected-window) edebug-save-windows)))
3021 (t ; Save a new window.
3022 (edebug-changing-windows
3023 (setq edebug-save-windows (cons window edebug-save-windows)))))
3024
3025 (message "Window saving is %s for %s."
3026 (if (memq (selected-window) edebug-save-windows)
3027 "on" "off")
3028 (selected-window)))
3029
3030(defun edebug-toggle-save-windows (arg)
3031 "Toggle the saving and restoring of windows.
3032With prefix, toggle for just the selected window.
3033Otherwise, toggle for all windows."
3034 (interactive "P")
3035 (if arg
3036 (edebug-toggle-save-selected-window)
3037 (edebug-toggle-save-all-windows)))
3038
84fc2cfa
ER
3039
3040(defun edebug-where ()
3041 "Show the debug windows and where we stopped in the program."
3042 (interactive)
3043 (if (not edebug-active)
1fe3d507
DL
3044 (error "Edebug is not active"))
3045 ;; Restore the window configuration to what it last was inside.
3046 ;; But it is not always set. - experiment
3047 ;;(if edebug-inside-windows
3048 ;; (edebug-set-windows edebug-inside-windows))
84fc2cfa 3049 (edebug-pop-to-buffer edebug-buffer)
1fe3d507 3050 (goto-char edebug-point))
84fc2cfa
ER
3051
3052(defun edebug-view-outside ()
3053 "Change to the outside window configuration."
3054 (interactive)
3055 (if (not edebug-active)
1fe3d507
DL
3056 (error "Edebug is not active"))
3057 (setq edebug-inside-windows
3058 (edebug-current-windows edebug-save-windows))
3059 (edebug-set-windows edebug-outside-windows)
84fc2cfa 3060 (goto-char edebug-outside-point)
1fe3d507 3061 (message "Window configuration outside of Edebug. Return with %s"
84fc2cfa
ER
3062 (substitute-command-keys "\\<global-map>\\[edebug-where]")))
3063
3064
1fe3d507
DL
3065(defun edebug-bounce-point (arg)
3066 "Bounce the point in the outside current buffer.
3067If prefix arg is supplied, sit for that many seconds before returning.
3068The default is one second."
3069 (interactive "p")
84fc2cfa 3070 (if (not edebug-active)
1fe3d507 3071 (error "Edebug is not active"))
84fc2cfa 3072 (save-excursion
1fe3d507 3073 ;; If the buffer's currently displayed, avoid set-window-configuration.
84fc2cfa
ER
3074 (save-window-excursion
3075 (edebug-pop-to-buffer edebug-outside-buffer)
84fc2cfa 3076 (goto-char edebug-outside-point)
1fe3d507
DL
3077 (message "Current buffer: %s Point: %s Mark: %s"
3078 (current-buffer) (point)
3079 (if (marker-buffer (edebug-mark-marker))
3080 (marker-position (edebug-mark-marker)) "<not set>"))
3081 (edebug-sit-for arg)
3082 (edebug-pop-to-buffer edebug-buffer (car edebug-window-data)))))
84fc2cfa 3083
84fc2cfa 3084
1fe3d507
DL
3085;; Joe Wells, here is a start at your idea of adding a buffer to the internal
3086;; display list. Still need to use this list in edebug-display.
84fc2cfa 3087
1fe3d507
DL
3088'(defvar edebug-display-buffer-list nil
3089 "List of buffers that edebug will display when it is active.")
84fc2cfa 3090
1fe3d507
DL
3091'(defun edebug-display-buffer (buffer)
3092 "Toggle display of a buffer inside of edebug."
3093 (interactive "bBuffer: ")
3094 (let ((already-displaying (memq buffer edebug-display-buffer-list)))
3095 (setq edebug-display-buffer-list
3096 (if already-displaying
3097 (delq buffer edebug-display-buffer-list)
3098 (cons buffer edebug-display-buffer-list)))
3099 (message "Displaying %s %s" buffer
3100 (if already-displaying "off" "on"))))
84fc2cfa 3101
1fe3d507 3102;;; Breakpoint related functions
84fc2cfa
ER
3103
3104(defun edebug-find-stop-point ()
1fe3d507
DL
3105 ;; Return (function . index) of the nearest edebug stop point.
3106 (let* ((edebug-def-name (edebug-form-data-symbol))
84fc2cfa 3107 (edebug-data
1fe3d507
DL
3108 (let ((data (get edebug-def-name 'edebug)))
3109 (if (or (null data) (markerp data))
3110 (error "%s is not instrumented for Edebug" edebug-def-name))
3111 data)) ; we could do it automatically, if data is a marker.
84fc2cfa 3112 ;; pull out parts of edebug-data.
1fe3d507
DL
3113 (edebug-def-mark (car edebug-data))
3114 ;; (edebug-breakpoints (car (cdr edebug-data)))
84fc2cfa 3115
1fe3d507 3116 (offset-vector (nth 2 edebug-data))
84fc2cfa
ER
3117 (offset (- (save-excursion
3118 (if (looking-at "[ \t]")
3119 ;; skip backwards until non-whitespace, or bol
3120 (skip-chars-backward " \t"))
3121 (point))
1fe3d507 3122 edebug-def-mark))
84fc2cfa
ER
3123 len i)
3124 ;; the offsets are in order so we can do a linear search
3125 (setq len (length offset-vector))
3126 (setq i 0)
3127 (while (and (< i len) (> offset (aref offset-vector i)))
3128 (setq i (1+ i)))
3129 (if (and (< i len)
3130 (<= offset (aref offset-vector i)))
3131 ;; return the relevant info
1fe3d507 3132 (cons edebug-def-name i)
84fc2cfa 3133 (message "Point is not on an expression in %s."
1fe3d507 3134 edebug-def-name)
84fc2cfa
ER
3135 )))
3136
3137
3138(defun edebug-next-breakpoint ()
3139 "Move point to the next breakpoint, or first if none past point."
3140 (interactive)
3141 (let ((edebug-stop-point (edebug-find-stop-point)))
3142 (if edebug-stop-point
1fe3d507 3143 (let* ((edebug-def-name (car edebug-stop-point))
84fc2cfa 3144 (index (cdr edebug-stop-point))
1fe3d507 3145 (edebug-data (get edebug-def-name 'edebug))
84fc2cfa
ER
3146
3147 ;; pull out parts of edebug-data
1fe3d507 3148 (edebug-def-mark (car edebug-data))
84fc2cfa 3149 (edebug-breakpoints (car (cdr edebug-data)))
1fe3d507 3150 (offset-vector (nth 2 edebug-data))
84fc2cfa
ER
3151 breakpoint)
3152 (if (not edebug-breakpoints)
3153 (message "No breakpoints in this function.")
3154 (let ((breaks edebug-breakpoints))
3155 (while (and breaks
3156 (<= (car (car breaks)) index))
3157 (setq breaks (cdr breaks)))
3158 (setq breakpoint
3159 (if breaks
3160 (car breaks)
3161 ;; goto the first breakpoint
3162 (car edebug-breakpoints)))
1fe3d507 3163 (goto-char (+ edebug-def-mark
84fc2cfa
ER
3164 (aref offset-vector (car breakpoint))))
3165
f7359658
RS
3166 (message "%s"
3167 (concat (if (nth 2 breakpoint)
84fc2cfa
ER
3168 "Temporary " "")
3169 (if (car (cdr breakpoint))
3170 (format "Condition: %s"
1fe3d507 3171 (edebug-safe-prin1-to-string
84fc2cfa
ER
3172 (car (cdr breakpoint))))
3173 "")))
3174 ))))))
3175
3176
3177(defun edebug-modify-breakpoint (flag &optional condition temporary)
3178 "Modify the breakpoint for the form at point or after it according
3179to FLAG: set if t, clear if nil. Then move to that point.
3180If CONDITION or TEMPORARY are non-nil, add those attributes to
3181the breakpoint. "
3182 (let ((edebug-stop-point (edebug-find-stop-point)))
3183 (if edebug-stop-point
1fe3d507 3184 (let* ((edebug-def-name (car edebug-stop-point))
84fc2cfa 3185 (index (cdr edebug-stop-point))
1fe3d507 3186 (edebug-data (get edebug-def-name 'edebug))
84fc2cfa
ER
3187
3188 ;; pull out parts of edebug-data
1fe3d507 3189 (edebug-def-mark (car edebug-data))
84fc2cfa 3190 (edebug-breakpoints (car (cdr edebug-data)))
1fe3d507 3191 (offset-vector (nth 2 edebug-data))
84fc2cfa
ER
3192 present)
3193 ;; delete it either way
3194 (setq present (assq index edebug-breakpoints))
3195 (setq edebug-breakpoints (delq present edebug-breakpoints))
3196 (if flag
3197 (progn
3198 ;; add it to the list and resort
3199 (setq edebug-breakpoints
3200 (edebug-sort-alist
3201 (cons
3202 (list index condition temporary)
3203 edebug-breakpoints) '<))
1fe3d507
DL
3204 (if condition
3205 (message "Breakpoint set in %s with condition: %s"
3206 edebug-def-name condition)
3207 (message "Breakpoint set in %s" edebug-def-name)))
84fc2cfa 3208 (if present
1fe3d507
DL
3209 (message "Breakpoint unset in %s" edebug-def-name)
3210 (message "No breakpoint here")))
84fc2cfa 3211
1fe3d507
DL
3212 (setcar (cdr edebug-data) edebug-breakpoints)
3213 (goto-char (+ edebug-def-mark (aref offset-vector index)))
84fc2cfa
ER
3214 ))))
3215
3216(defun edebug-set-breakpoint (arg)
3217 "Set the breakpoint of nearest sexp.
3218With prefix argument, make it a temporary breakpoint."
3219 (interactive "P")
3220 (edebug-modify-breakpoint t nil arg))
3221
3222(defun edebug-unset-breakpoint ()
3223 "Clear the breakpoint of nearest sexp."
3224 (interactive)
3225 (edebug-modify-breakpoint nil))
3226
1fe3d507
DL
3227
3228;; For emacs 18, no read-expression-history
84fc2cfa
ER
3229(defun edebug-set-conditional-breakpoint (arg condition)
3230 "Set a conditional breakpoint at nearest sexp.
3231The condition is evaluated in the outside context.
3232With prefix argument, make it a temporary breakpoint."
1fe3d507
DL
3233 ;; (interactive "P\nxCondition: ")
3234 (interactive
3235 (list
3236 current-prefix-arg
3237 ;; Edit previous condition as follows, but it is cumbersome:
3238 (let ((edebug-stop-point (edebug-find-stop-point)))
3239 (if edebug-stop-point
3240 (let* ((edebug-def-name (car edebug-stop-point))
3241 (index (cdr edebug-stop-point))
3242 (edebug-data (get edebug-def-name 'edebug))
3243 (edebug-breakpoints (car (cdr edebug-data)))
3244 (edebug-break-data (assq index edebug-breakpoints))
3245 (edebug-break-condition (car (cdr edebug-break-data))))
3246 (read-minibuffer
3247 (format "Condition in %s: " edebug-def-name)
3248 (if edebug-break-condition
3249 (format "%s" edebug-break-condition)
3250 (format ""))))))))
84fc2cfa
ER
3251 (edebug-modify-breakpoint t condition arg))
3252
1fe3d507
DL
3253
3254(defun edebug-set-global-break-condition (expression)
3255 (interactive (list (read-minibuffer
3256 "Global Condition: "
3257 (format "%s" edebug-global-break-condition))))
3258 (setq edebug-global-break-condition expression))
3259
3260
3261;;; Mode switching functions
84fc2cfa
ER
3262
3263(defun edebug-set-mode (mode shortmsg msg)
1fe3d507
DL
3264 ;; Set the edebug mode to MODE.
3265 ;; Display SHORTMSG, or MSG if not within edebug.
3266 (if (eq (1+ edebug-recursion-depth) (recursion-depth))
3267 (progn
3268 (setq edebug-execution-mode mode)
3269 (message shortmsg)
3270 ;; Continue execution
3271 (exit-recursive-edit))
3272 ;; This is not terribly useful!!
3273 (setq edebug-next-execution-mode mode)
84fc2cfa
ER
3274 (message msg)))
3275
3276
1fe3d507
DL
3277(defalias 'edebug-step-through-mode 'edebug-step-mode)
3278
3279(defun edebug-step-mode ()
3280 "Proceed to next stop point."
3281 (interactive)
3282 (edebug-set-mode 'step "" "Edebug will stop at next stop point."))
3283
3284(defun edebug-next-mode ()
3285 "Proceed to next `after' stop point."
84fc2cfa 3286 (interactive)
1fe3d507 3287 (edebug-set-mode 'next "" "Edebug will stop after next eval."))
84fc2cfa 3288
1fe3d507 3289(defun edebug-go-mode (arg)
84fc2cfa 3290 "Go, evaluating until break.
1fe3d507 3291With prefix ARG, set temporary break at current point and go."
84fc2cfa
ER
3292 (interactive "P")
3293 (if arg
3294 (edebug-set-breakpoint t))
1fe3d507 3295 (edebug-set-mode 'go "Go..." "Edebug will go until break."))
84fc2cfa 3296
1fe3d507 3297(defun edebug-Go-nonstop-mode ()
84fc2cfa
ER
3298 "Go, evaluating without debugging."
3299 (interactive)
3300 (edebug-set-mode 'Go-nonstop "Go-Nonstop..."
1fe3d507
DL
3301 "Edebug will not stop at breaks."))
3302
3303
3304(defun edebug-trace-mode ()
3305 "Begin trace mode."
3306 (interactive)
3307 (edebug-set-mode 'trace "Tracing..." "Edebug will trace with pause."))
3308
3309(defun edebug-Trace-fast-mode ()
3310 "Trace with no wait at each step."
3311 (interactive)
3312 (edebug-set-mode 'Trace-fast
3313 "Trace fast..." "Edebug will trace without pause."))
3314
3315(defun edebug-continue-mode ()
3316 "Begin continue mode."
3317 (interactive)
3318 (edebug-set-mode 'continue "Continue..."
3319 "Edebug will pause at breakpoints."))
3320
3321(defun edebug-Continue-fast-mode ()
3322 "Trace with no wait at each step."
3323 (interactive)
3324 (edebug-set-mode 'Continue-fast "Continue fast..."
3325 "Edebug will stop and go at breakpoints."))
3326
3327;; ------------------------------------------------------------
3328;; The following use the mode changing commands and breakpoints.
3329
3330
3331(defun edebug-goto-here ()
3332 "Proceed to this stop point."
3333 (interactive)
3334 (edebug-go-mode t))
3335
3336
3337(defun edebug-stop ()
3338 "Stop execution and do not continue.
3339Useful for exiting from trace or continue loop."
3340 (interactive)
3341 (message "Stop"))
3342
3343
3344'(defun edebug-forward ()
3345 "Proceed to the exit of the next expression to be evaluated."
3346 (interactive)
3347 (edebug-set-mode
3348 'forward "Forward"
3349 "Edebug will stop after exiting the next expression."))
3350
84fc2cfa
ER
3351
3352(defun edebug-forward-sexp (arg)
3353 "Proceed from the current point to the end of the ARGth sexp ahead.
3354If there are not ARG sexps ahead, then do edebug-step-out."
3355 (interactive "p")
1fe3d507 3356 (condition-case nil
84fc2cfa
ER
3357 (let ((parse-sexp-ignore-comments t))
3358 ;; Call forward-sexp repeatedly until done or failure.
3359 (forward-sexp arg)
1fe3d507 3360 (edebug-go-mode t))
84fc2cfa
ER
3361 (error
3362 (edebug-step-out)
3363 )))
3364
3365(defun edebug-step-out ()
3366 "Proceed from the current point to the end of the containing sexp.
3367If there is no containing sexp that is not the top level defun,
3368go to the end of the last sexp, or if that is the same point, then step."
3369 (interactive)
1fe3d507 3370 (condition-case nil
84fc2cfa
ER
3371 (let ((parse-sexp-ignore-comments t))
3372 (up-list 1)
3373 (save-excursion
3374 ;; Is there still a containing expression?
3375 (up-list 1))
1fe3d507 3376 (edebug-go-mode t))
84fc2cfa
ER
3377 (error
3378 ;; At top level - 1, so first check if there are more sexps at this level.
3379 (let ((start-point (point)))
3380;; (up-list 1)
3381 (down-list -1)
3382 (if (= (point) start-point)
1fe3d507
DL
3383 (edebug-step-mode) ; No more at this level, so step.
3384 (edebug-go-mode t)
84fc2cfa
ER
3385 )))))
3386
1fe3d507
DL
3387(defun edebug-instrument-function (func)
3388 ;; Func should be a function symbol.
3389 ;; Return the function symbol, or nil if not instrumented.
3390 (let ((func-marker))
3391 (setq func-marker (get func 'edebug))
3392 (cond
3393 ((markerp func-marker)
3394 ;; It is uninstrumented, so instrument it.
3395 (save-excursion
3396 (set-buffer (marker-buffer func-marker))
3397 (goto-char func-marker)
3398 (edebug-eval-top-level-form)
3399 func))
3400 ((consp func-marker)
3401 (message "%s is already instrumented." func)
3402 func)
3403 (t
3404 ;; We could try harder, e.g. do a tags search.
3405 (error "Don't know where %s is defined" func)
3406 nil))))
3407
3408(defun edebug-instrument-callee ()
3409 "Instrument the definition of the function or macro about to be called.
3410Do this when stopped before the form or it will be too late.
3411One side effect of using this command is that the next time the
3412function or macro is called, Edebug will be called there as well."
84fc2cfa 3413 (interactive)
1fe3d507
DL
3414 (if (not (looking-at "\("))
3415 (error "You must be before a list form")
3416 (let ((func
3417 (save-excursion
3418 (down-list 1)
3419 (if (looking-at "\(")
3420 (edebug-form-data-name
3421 (edebug-get-form-data-entry (point)))
88668147 3422 (edebug-original-read (current-buffer))))))
1fe3d507 3423 (edebug-instrument-function func))))
84fc2cfa 3424
84fc2cfa 3425
1fe3d507
DL
3426(defun edebug-step-in ()
3427 "Step into the definition of the function or macro about to be called.
3428This first does `edebug-instrument-callee' to ensure that it is
3429instrumented. Then it does `edebug-on-entry' and switches to `go' mode."
84fc2cfa 3430 (interactive)
1fe3d507
DL
3431 (let ((func (edebug-instrument-callee)))
3432 (if func
3433 (progn
3434 (edebug-on-entry func 'temp)
3435 (edebug-go-mode nil)))))
84fc2cfa 3436
1fe3d507
DL
3437(defun edebug-on-entry (function &optional flag)
3438 "Cause Edebug to stop when FUNCTION is called.
3439With prefix argument, make this temporary so it is automatically
3440cancelled the first time the function is entered."
3441 (interactive "aEdebug on entry to: \nP")
3442 ;; Could store this in the edebug data instead.
3443 (put function 'edebug-on-entry (if flag 'temp t)))
84fc2cfa 3444
1fe3d507
DL
3445(defun cancel-edebug-on-entry (function)
3446 (interactive "aEdebug on entry to: ")
3447 (put function 'edebug-on-entry nil))
84fc2cfa 3448
1fe3d507 3449
88668147
DL
3450(if (not (fboundp 'edebug-original-debug-on-entry))
3451 (fset 'edebug-original-debug-on-entry (symbol-function 'debug-on-entry)))
1fe3d507
DL
3452'(fset 'debug-on-entry 'edebug-debug-on-entry) ;; Should we do this?
3453;; Also need edebug-cancel-debug-on-entry
3454
3455'(defun edebug-debug-on-entry (function)
3456 "Request FUNCTION to invoke debugger each time it is called.
3457If the user continues, FUNCTION's execution proceeds.
3458Works by modifying the definition of FUNCTION,
3459which must be written in Lisp, not predefined.
3460Use `cancel-debug-on-entry' to cancel the effect of this command.
3461Redefining FUNCTION also does that.
3462
3463This version is from Edebug. If the function is instrumented for
3464Edebug, it calls `edebug-on-entry'"
3465 (interactive "aDebug on entry (to function): ")
3466 (let ((func-data (get function 'edebug)))
3467 (if (or (null func-data) (markerp func-data))
88668147 3468 (edebug-original-debug-on-entry function)
1fe3d507
DL
3469 (edebug-on-entry function))))
3470
3471
3472(defun edebug-top-level-nonstop ()
3473 "Set mode to Go-nonstop, and exit to top-level.
3474This is useful for exiting even if unwind-protect code may be executed."
84fc2cfa 3475 (interactive)
1fe3d507
DL
3476 (setq edebug-execution-mode 'Go-nonstop)
3477 (top-level))
84fc2cfa
ER
3478
3479
3480;;(defun edebug-exit-out ()
3481;; "Go until the current function exits."
3482;; (interactive)
3483;; (edebug-set-mode 'exiting "Exit..."))
3484
3485
84fc2cfa
ER
3486;;; The following initial mode setting definitions are not used yet.
3487
1fe3d507 3488'(defconst edebug-initial-mode-alist
84fc2cfa
ER
3489 '((edebug-Continue-fast . Continue-fast)
3490 (edebug-Trace-fast . Trace-fast)
3491 (edebug-continue . continue)
3492 (edebug-trace . trace)
3493 (edebug-go . go)
3494 (edebug-step-through . step)
3495 (edebug-Go-nonstop . Go-nonstop)
3496 )
3497 "Association list between commands and the modes they set.")
3498
3499
1fe3d507 3500'(defun edebug-set-initial-mode ()
84fc2cfa
ER
3501 "Ask for the initial mode of the enclosing function.
3502The mode is requested via the key that would be used to set the mode in
3503edebug-mode."
3504 (interactive)
3505 (let* ((this-function (edebug-which-function))
3506 (keymap (if (eq edebug-mode-map (current-local-map))
3507 edebug-mode-map))
3508 (old-mode (or (get this-function 'edebug-initial-mode)
3509 edebug-initial-mode))
3510 (key (read-key-sequence
3511 (format
3512 "Change initial edebug mode for %s from %s (%s) to (enter key): "
3513 this-function
3514 old-mode
3515 (where-is-internal
3516 (car (rassq old-mode edebug-initial-mode-alist))
3517 keymap 'firstonly
3518 ))))
3519 (mode (cdr (assq (key-binding key) edebug-initial-mode-alist)))
3520 )
3521 (if (and mode
3522 (or (get this-function 'edebug-initial-mode)
3523 (not (eq mode edebug-initial-mode))))
3524 (progn
3525 (put this-function 'edebug-initial-mode mode)
3526 (message "Initial mode for %s is now: %s"
3527 this-function mode))
4897b0a0 3528 (error "Key must map to one of the mode changing commands")
84fc2cfa
ER
3529 )))
3530
1fe3d507 3531;;; Evaluation of expressions
84fc2cfa 3532
1fe3d507 3533(def-edebug-spec edebug-outside-excursion t)
84fc2cfa 3534
1fe3d507
DL
3535(defmacro edebug-outside-excursion (&rest body)
3536 "Evaluate an expression list in the outside context.
3537Return the result of the last expression."
3538 (` (save-excursion ; of current-buffer
3539 (if edebug-save-windows
3540 (progn
3541 ;; After excursion, we will
3542 ;; restore to current window configuration.
3543 (setq edebug-inside-windows
3544 (edebug-current-windows edebug-save-windows))
3545 ;; Restore outside windows.
3546 (edebug-set-windows edebug-outside-windows)))
3547
3548 (set-buffer edebug-buffer) ; why?
3549 ;; (use-local-map edebug-outside-map)
3550 (store-match-data edebug-outside-match-data)
3551 ;; Restore outside context.
3552 (let (;; (edebug-inside-map (current-local-map)) ;; restore map??
3553 (last-command-char edebug-outside-last-command-char)
3554 (last-command-event edebug-outside-last-command-event)
3555 (last-command edebug-outside-last-command)
3556 (this-command edebug-outside-this-command)
3557 (unread-command-char edebug-outside-unread-command-char)
3558 (unread-command-event edebug-outside-unread-command-event)
3559 (unread-command-events edebug-outside-unread-command-events)
3560 (last-input-char edebug-outside-last-input-char)
3561 (last-input-event edebug-outside-last-input-event)
3562 (last-event-frame edebug-outside-last-event-frame)
3563 (last-nonmenu-event edebug-outside-last-nonmenu-event)
3564 (track-mouse edebug-outside-track-mouse)
1fe3d507
DL
3565 (standard-output edebug-outside-standard-output)
3566 (standard-input edebug-outside-standard-input)
88668147 3567
efcf38c7 3568 (executing-kbd-macro edebug-outside-executing-macro)
1fe3d507 3569 (defining-kbd-macro edebug-outside-defining-kbd-macro)
88668147
DL
3570 (pre-command-hook edebug-outside-pre-command-hook)
3571 (post-command-hook edebug-outside-post-command-hook)
f7359658 3572 (post-command-idle-hook edebug-outside-post-command-idle-hook)
88668147
DL
3573
3574 ;; See edebug-display
3575 (overlay-arrow-position edebug-outside-o-a-p)
3576 (overlay-arrow-string edebug-outside-o-a-s)
3577 (cursor-in-echo-area edebug-outside-c-i-e-a)
1fe3d507
DL
3578 )
3579 (unwind-protect
3580 (save-excursion ; of edebug-buffer
3581 (set-buffer edebug-outside-buffer)
3582 (goto-char edebug-outside-point)
3583 (if (marker-buffer (edebug-mark-marker))
3584 (set-marker (edebug-mark-marker) edebug-outside-mark))
3585 (,@ body))
3586
3587 ;; Back to edebug-buffer. Restore rest of inside context.
3588 ;; (use-local-map edebug-inside-map)
3589 (if edebug-save-windows
3590 ;; Restore inside windows.
3591 (edebug-set-windows edebug-inside-windows))
88668147
DL
3592
3593 ;; Save values that may have been changed.
3594 (setq
3595 edebug-outside-last-command-char last-command-char
3596 edebug-outside-last-command-event last-command-event
3597 edebug-outside-last-command last-command
3598 edebug-outside-this-command this-command
3599 edebug-outside-unread-command-char unread-command-char
3600 edebug-outside-unread-command-event unread-command-event
3601 edebug-outside-unread-command-events unread-command-events
3602 edebug-outside-last-input-char last-input-char
3603 edebug-outside-last-input-event last-input-event
3604 edebug-outside-last-event-frame last-event-frame
3605 edebug-outside-last-nonmenu-event last-nonmenu-event
3606 edebug-outside-track-mouse track-mouse
3607 edebug-outside-standard-output standard-output
3608 edebug-outside-standard-input standard-input
3609
efcf38c7 3610 edebug-outside-executing-macro executing-kbd-macro
88668147
DL
3611 edebug-outside-defining-kbd-macro defining-kbd-macro
3612 edebug-outside-pre-command-hook pre-command-hook
3613 edebug-outside-post-command-hook post-command-hook
f7359658 3614 edebug-outside-post-command-idle-hook post-command-idle-hook
88668147
DL
3615
3616 edebug-outside-o-a-p overlay-arrow-position
3617 edebug-outside-o-a-s overlay-arrow-string
3618 edebug-outside-c-i-e-a cursor-in-echo-area
3619 ))) ; let
1fe3d507
DL
3620 )))
3621
3622(defvar cl-debug-env nil) ;; defined in cl; non-nil when lexical env used.
3623
3624(defun edebug-eval (edebug-expr)
3625 ;; Are there cl lexical variables active?
3626 (if cl-debug-env
3627 (eval (cl-macroexpand-all edebug-expr cl-debug-env))
3628 (eval edebug-expr)))
3629
3630(defun edebug-safe-eval (edebug-expr)
3631 ;; Evaluate EXPR safely.
3632 ;; If there is an error, a string is returned describing the error.
3633 (condition-case edebug-err
3634 (edebug-eval edebug-expr)
3635 (error (edebug-format "%s: %s" ;; could
3636 (get (car edebug-err) 'error-message)
3637 (car (cdr edebug-err))))))
3638
f7359658
RS
3639;;; Printing
3640
1fe3d507
DL
3641;; Replace printing functions.
3642
3643;; obsolete names
3644(defalias 'edebug-install-custom-print-funcs 'edebug-install-custom-print)
3645(defalias 'edebug-reset-print-funcs 'edebug-uninstall-custom-print)
3646(defalias 'edebug-uninstall-custom-print-funcs 'edebug-uninstall-custom-print)
3647
3648(defun edebug-install-custom-print ()
3649 "Replace print functions used by Edebug with custom versions."
3650 ;; Modifying the custom print functions, or changing print-length,
3651 ;; print-level, print-circle, custom-print-list or custom-print-vector
3652 ;; have immediate effect.
84fc2cfa 3653 (interactive)
1fe3d507
DL
3654 (require 'cust-print)
3655 (defalias 'edebug-prin1 'custom-prin1)
3656 (defalias 'edebug-print 'custom-print)
3657 (defalias 'edebug-prin1-to-string 'custom-prin1-to-string)
3658 (defalias 'edebug-format 'custom-format)
3659 (defalias 'edebug-message 'custom-message)
3660 "Installed")
3661
3662(eval-and-compile
3663 (defun edebug-uninstall-custom-print ()
3664 "Replace edebug custom print functions with internal versions."
3665 (interactive)
3666 (defalias 'edebug-prin1 'prin1)
3667 (defalias 'edebug-print 'print)
3668 (defalias 'edebug-prin1-to-string 'prin1-to-string)
3669 (defalias 'edebug-format 'format)
3670 (defalias 'edebug-message 'message)
3671 "Uninstalled")
3672
3673 ;; Default print functions are the same as Emacs'.
3674 (edebug-uninstall-custom-print))
3675
3676
3677(defun edebug-report-error (edebug-value)
3678 ;; Print an error message like command level does.
3679 ;; This also prints the error name if it has no error-message.
3680 (message "%s: %s"
3681 (or (get (car edebug-value) 'error-message)
3682 (format "peculiar error (%s)" (car edebug-value)))
3683 (mapconcat (function (lambda (edebug-arg)
3684 ;; continuing after an error may
3685 ;; complain about edebug-arg. why??
3686 (prin1-to-string edebug-arg)))
3687 (cdr edebug-value) ", ")))
3688
3689;; Define here in case they are not already defined.
3690(defvar print-level nil)
3691(defvar print-circle nil)
3692(defvar print-readably) ;; defined by lemacs
3693;; Alternatively, we could change the definition of
88668147 3694;; edebug-safe-prin1-to-string to only use these if defined.
1fe3d507
DL
3695
3696(defun edebug-safe-prin1-to-string (value)
84fc2cfa 3697 (let ((print-escape-newlines t)
1fe3d507
DL
3698 (print-length (or edebug-print-length print-length))
3699 (print-level (or edebug-print-level print-level))
3700 (print-circle (or edebug-print-circle print-circle))
3701 (print-readably nil)) ;; lemacs uses this.
3702 (edebug-prin1-to-string value)))
3703
3704(defun edebug-compute-previous-result (edebug-previous-value)
3705 (setq edebug-previous-result
3706 (if (and (numberp edebug-previous-value)
3707 (< edebug-previous-value 256)
3708 (>= edebug-previous-value 0))
3709 (format "Result: %s = %s" edebug-previous-value
3710 (single-key-description edebug-previous-value))
3711 (if edebug-unwrap-results
3712 (setq edebug-previous-value
3713 (edebug-unwrap* edebug-previous-value)))
3714 (concat "Result: "
3715 (edebug-safe-prin1-to-string edebug-previous-value)))))
84fc2cfa 3716
1fe3d507
DL
3717(defun edebug-previous-result ()
3718 "Print the previous result."
3719 (interactive)
3720 (message "%s" edebug-previous-result))
84fc2cfa 3721
f7359658 3722;;; Read, Eval and Print
84fc2cfa 3723
1fe3d507
DL
3724(defun edebug-eval-expression (edebug-expr)
3725 "Evaluate an expression in the outside environment.
3726If interactive, prompt for the expression.
84fc2cfa
ER
3727Print result in minibuffer."
3728 (interactive "xEval: ")
1fe3d507
DL
3729 (princ
3730 (edebug-outside-excursion
3731 (setq values (cons (edebug-eval edebug-expr) values))
3732 (edebug-safe-prin1-to-string (car values)))))
84fc2cfa
ER
3733
3734(defun edebug-eval-last-sexp ()
3735 "Evaluate sexp before point in the outside environment;
3736print value in minibuffer."
3737 (interactive)
1fe3d507 3738 (edebug-eval-expression (edebug-last-sexp)))
84fc2cfa
ER
3739
3740(defun edebug-eval-print-last-sexp ()
3741 "Evaluate sexp before point in the outside environment;
3742print value into current buffer."
3743 (interactive)
1fe3d507
DL
3744 (let* ((edebug-form (edebug-last-sexp))
3745 (edebug-result-string
3746 (edebug-outside-excursion
3747 (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form))))
3748 (standard-output (current-buffer)))
3749 (princ "\n")
3750 ;; princ the string to get rid of quotes.
3751 (princ edebug-result-string)
3752 (princ "\n")
3753 ))
3754
f7359658 3755;;; Edebug Minor Mode
84fc2cfa 3756
1fe3d507
DL
3757;; Global GUD bindings for all emacs-lisp-mode buffers.
3758(define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode)
3759(define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode)
3760(define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode)
3761(define-key emacs-lisp-mode-map "\C-x\C-a\C-l" 'edebug-where)
3762
84fc2cfa
ER
3763
3764(defvar edebug-mode-map nil)
3765(if edebug-mode-map
3766 nil
3767 (progn
3768 (setq edebug-mode-map (copy-keymap emacs-lisp-mode-map))
3769 ;; control
1fe3d507
DL
3770 (define-key edebug-mode-map " " 'edebug-step-mode)
3771 (define-key edebug-mode-map "n" 'edebug-next-mode)
3772 (define-key edebug-mode-map "g" 'edebug-go-mode)
3773 (define-key edebug-mode-map "G" 'edebug-Go-nonstop-mode)
3774 (define-key edebug-mode-map "t" 'edebug-trace-mode)
3775 (define-key edebug-mode-map "T" 'edebug-Trace-fast-mode)
3776 (define-key edebug-mode-map "c" 'edebug-continue-mode)
3777 (define-key edebug-mode-map "C" 'edebug-Continue-fast-mode)
3778
3779 ;;(define-key edebug-mode-map "f" 'edebug-forward) not implemented
84fc2cfa
ER
3780 (define-key edebug-mode-map "f" 'edebug-forward-sexp)
3781 (define-key edebug-mode-map "h" 'edebug-goto-here)
3782
1fe3d507 3783 (define-key edebug-mode-map "I" 'edebug-instrument-callee)
84fc2cfa
ER
3784 (define-key edebug-mode-map "i" 'edebug-step-in)
3785 (define-key edebug-mode-map "o" 'edebug-step-out)
3786
1fe3d507 3787 ;; quitting and stopping
84fc2cfa 3788 (define-key edebug-mode-map "q" 'top-level)
1fe3d507 3789 (define-key edebug-mode-map "Q" 'edebug-top-level-nonstop)
84fc2cfa
ER
3790 (define-key edebug-mode-map "a" 'abort-recursive-edit)
3791 (define-key edebug-mode-map "S" 'edebug-stop)
3792
3793 ;; breakpoints
3794 (define-key edebug-mode-map "b" 'edebug-set-breakpoint)
3795 (define-key edebug-mode-map "u" 'edebug-unset-breakpoint)
3796 (define-key edebug-mode-map "B" 'edebug-next-breakpoint)
3797 (define-key edebug-mode-map "x" 'edebug-set-conditional-breakpoint)
1fe3d507 3798 (define-key edebug-mode-map "X" 'edebug-set-global-break-condition)
84fc2cfa
ER
3799
3800 ;; evaluation
1fe3d507 3801 (define-key edebug-mode-map "r" 'edebug-previous-result)
84fc2cfa
ER
3802 (define-key edebug-mode-map "e" 'edebug-eval-expression)
3803 (define-key edebug-mode-map "\C-x\C-e" 'edebug-eval-last-sexp)
3804 (define-key edebug-mode-map "E" 'edebug-visit-eval-list)
3805
3806 ;; views
3807 (define-key edebug-mode-map "w" 'edebug-where)
1fe3d507 3808 (define-key edebug-mode-map "v" 'edebug-view-outside) ;; maybe obsolete??
84fc2cfa 3809 (define-key edebug-mode-map "p" 'edebug-bounce-point)
1fe3d507 3810 (define-key edebug-mode-map "P" 'edebug-view-outside) ;; same as v
84fc2cfa 3811 (define-key edebug-mode-map "W" 'edebug-toggle-save-windows)
1fe3d507 3812
84fc2cfa
ER
3813 ;; misc
3814 (define-key edebug-mode-map "?" 'edebug-help)
3815 (define-key edebug-mode-map "d" 'edebug-backtrace)
3816
3817 (define-key edebug-mode-map "-" 'negative-argument)
1fe3d507
DL
3818
3819 ;; statistics
3820 (define-key edebug-mode-map "=" 'edebug-temp-display-freq-count)
3821
3822 ;; GUD bindings
3823 (define-key edebug-mode-map "\C-c\C-s" 'edebug-step-mode)
3824 (define-key edebug-mode-map "\C-c\C-n" 'edebug-next-mode)
3825 (define-key edebug-mode-map "\C-c\C-c" 'edebug-go-mode)
3826
3827 (define-key edebug-mode-map "\C-x " 'edebug-set-breakpoint)
3828 (define-key edebug-mode-map "\C-c\C-d" 'edebug-unset-breakpoint)
3829 (define-key edebug-mode-map "\C-c\C-t"
3830 (function (lambda () (edebug-set-breakpoint t))))
3831 (define-key edebug-mode-map "\C-c\C-l" 'edebug-where)
84fc2cfa
ER
3832 ))
3833
1fe3d507
DL
3834;; Autoloading these global bindings doesn't make sense because
3835;; they cannot be used anyway unless Edebug is already loaded and active.
3836
84fc2cfa
ER
3837(defvar global-edebug-prefix "\^XX"
3838 "Prefix key for global edebug commands, available from any buffer.")
3839
3840(defvar global-edebug-map nil
3841 "Global map of edebug commands, available from any buffer.")
3842
3843(if global-edebug-map
3844 nil
3845 (setq global-edebug-map (make-sparse-keymap))
3846
3847 (global-unset-key global-edebug-prefix)
3848 (global-set-key global-edebug-prefix global-edebug-map)
3849
1fe3d507
DL
3850 (define-key global-edebug-map " " 'edebug-step-mode)
3851 (define-key global-edebug-map "g" 'edebug-go-mode)
3852 (define-key global-edebug-map "G" 'edebug-Go-nonstop-mode)
3853 (define-key global-edebug-map "t" 'edebug-trace-mode)
3854 (define-key global-edebug-map "T" 'edebug-Trace-fast-mode)
3855 (define-key global-edebug-map "c" 'edebug-continue-mode)
3856 (define-key global-edebug-map "C" 'edebug-Continue-fast-mode)
3857
3858 ;; breakpoints
84fc2cfa 3859 (define-key global-edebug-map "b" 'edebug-set-breakpoint)
84fc2cfa 3860 (define-key global-edebug-map "u" 'edebug-unset-breakpoint)
1fe3d507
DL
3861 (define-key global-edebug-map "x" 'edebug-set-conditional-breakpoint)
3862 (define-key global-edebug-map "X" 'edebug-set-global-break-condition)
3863
3864 ;; views
84fc2cfa 3865 (define-key global-edebug-map "w" 'edebug-where)
1fe3d507
DL
3866 (define-key global-edebug-map "W" 'edebug-toggle-save-windows)
3867
3868 ;; quitting
84fc2cfa 3869 (define-key global-edebug-map "q" 'top-level)
1fe3d507
DL
3870 (define-key global-edebug-map "Q" 'edebug-top-level-nonstop)
3871 (define-key global-edebug-map "a" 'abort-recursive-edit)
84fc2cfa 3872
1fe3d507
DL
3873 ;; statistics
3874 (define-key global-edebug-map "=" 'edebug-display-freq-count)
3875 )
84fc2cfa
ER
3876
3877(defun edebug-help ()
3878 (interactive)
3879 (describe-function 'edebug-mode))
3880
84fc2cfa 3881(defun edebug-mode ()
1fe3d507
DL
3882 "Mode for Emacs Lisp buffers while in Edebug.
3883
3884In addition to all Emacs Lisp commands (except those that modify the
3885buffer) there are local and global key bindings to several Edebug
3886specific commands. E.g. `edebug-step-mode' is bound to \\[edebug-step-mode]
3887in the Edebug buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
84fc2cfa 3888
1fe3d507 3889Also see bindings for the eval list buffer, *edebug*.
84fc2cfa 3890
1fe3d507 3891The edebug buffer commands:
84fc2cfa
ER
3892\\{edebug-mode-map}
3893
1fe3d507 3894Global commands prefixed by `global-edebug-prefix':
84fc2cfa
ER
3895\\{global-edebug-map}
3896
3897Options:
1fe3d507
DL
3898edebug-setup-hook
3899edebug-all-defs
3900edebug-all-forms
84fc2cfa 3901edebug-save-windows
1fe3d507 3902edebug-save-displayed-buffer-points
84fc2cfa
ER
3903edebug-initial-mode
3904edebug-trace
1fe3d507
DL
3905edebug-test-coverage
3906edebug-continue-kbd-macro
3907edebug-print-length
3908edebug-print-level
3909edebug-print-circle
3910edebug-on-error
3911edebug-on-quit
3912edebug-on-signal
3913edebug-unwrap-results
3914edebug-global-break-condition
84fc2cfa
ER
3915"
3916 (use-local-map edebug-mode-map))
3917
f7359658 3918;;; edebug eval list mode
84fc2cfa 3919
1fe3d507 3920;; A list of expressions and their evaluations is displayed in *edebug*.
84fc2cfa
ER
3921
3922(defun edebug-eval-result-list ()
3923 "Return a list of evaluations of edebug-eval-list"
3924 ;; Assumes in outside environment.
88668147
DL
3925 ;; Don't do any edebug things now.
3926 (let ((edebug-execution-mode 'Go-nonstop)
3927 (edebug-trace nil))
3928 (mapcar 'edebug-safe-eval edebug-eval-list)))
84fc2cfa
ER
3929
3930(defun edebug-eval-display-list (edebug-eval-result-list)
3931 ;; Assumes edebug-eval-buffer exists.
3932 (let ((edebug-eval-list-temp edebug-eval-list)
3933 (standard-output edebug-eval-buffer)
1fe3d507 3934 (edebug-comment-line
84fc2cfa 3935 (format ";%s\n" (make-string (- (window-width) 2) ?-))))
1fe3d507 3936 (set-buffer edebug-eval-buffer)
84fc2cfa
ER
3937 (erase-buffer)
3938 (while edebug-eval-list-temp
3939 (prin1 (car edebug-eval-list-temp)) (terpri)
3940 (prin1 (car edebug-eval-result-list)) (terpri)
1fe3d507 3941 (princ edebug-comment-line)
84fc2cfa
ER
3942 (setq edebug-eval-list-temp (cdr edebug-eval-list-temp))
3943 (setq edebug-eval-result-list (cdr edebug-eval-result-list)))
1fe3d507 3944 (edebug-pop-to-buffer edebug-eval-buffer)
84fc2cfa
ER
3945 ))
3946
3947(defun edebug-create-eval-buffer ()
3948 (if (not (and edebug-eval-buffer (buffer-name edebug-eval-buffer)))
3949 (progn
3950 (set-buffer (setq edebug-eval-buffer (get-buffer-create "*edebug*")))
3951 (edebug-eval-mode))))
3952
3953;; Should generalize this to be callable outside of edebug
3954;; with calls in user functions, e.g. (edebug-eval-display)
3955
3956(defun edebug-eval-display (edebug-eval-result-list)
3957 "Display expressions and evaluations in EVAL-LIST.
3958It modifies the context by popping up the eval display."
3959 (if edebug-eval-result-list
3960 (progn
3961 (edebug-create-eval-buffer)
84fc2cfa
ER
3962 (edebug-eval-display-list edebug-eval-result-list)
3963 )))
3964
3965(defun edebug-eval-redisplay ()
3966 "Redisplay eval list in outside environment.
3967May only be called from within edebug-recursive-edit."
3968 (edebug-create-eval-buffer)
84fc2cfa
ER
3969 (edebug-outside-excursion
3970 (edebug-eval-display-list (edebug-eval-result-list))
3971 ))
3972
3973(defun edebug-visit-eval-list ()
3974 (interactive)
3975 (edebug-eval-redisplay)
3976 (edebug-pop-to-buffer edebug-eval-buffer))
3977
3978
3979(defun edebug-update-eval-list ()
3980 "Replace the evaluation list with the sexps now in the eval buffer."
3981 (interactive)
3982 (let ((starting-point (point))
3983 new-list)
3984 (goto-char (point-min))
3985 ;; get the first expression
3986 (edebug-skip-whitespace)
3987 (if (not (eobp))
3988 (progn
3989 (forward-sexp 1)
3990 (setq new-list (cons (edebug-last-sexp) new-list))))
3991
3992 (while (re-search-forward "^;" nil t)
3993 (forward-line 1)
3994 (skip-chars-forward " \t\n\r")
3995 (if (and (/= ?\; (following-char))
3996 (not (eobp)))
3997 (progn
3998 (forward-sexp 1)
3999 (setq new-list (cons (edebug-last-sexp) new-list)))))
4000
4001 (setq edebug-eval-list (nreverse new-list))
4002 (edebug-eval-redisplay)
4003 (goto-char starting-point)))
4004
4005
4006(defun edebug-delete-eval-item ()
4007 "Delete the item under point and redisplay."
4008 ;; could add arg to do repeatedly
4009 (interactive)
4010 (if (re-search-backward "^;" nil 'nofail)
4011 (forward-line 1))
4012 (delete-region
4013 (point) (progn (re-search-forward "^;" nil 'nofail)
4014 (beginning-of-line)
4015 (point)))
4016 (edebug-update-eval-list))
4017
4018
4019
4020(defvar edebug-eval-mode-map nil
4021 "Keymap for edebug-eval-mode. Superset of lisp-interaction-mode.")
4022
4023(if edebug-eval-mode-map
4024 nil
4025 (setq edebug-eval-mode-map (copy-keymap lisp-interaction-mode-map))
4026
4027 (define-key edebug-eval-mode-map "\C-c\C-w" 'edebug-where)
4028 (define-key edebug-eval-mode-map "\C-c\C-d" 'edebug-delete-eval-item)
4029 (define-key edebug-eval-mode-map "\C-c\C-u" 'edebug-update-eval-list)
4030 (define-key edebug-eval-mode-map "\C-x\C-e" 'edebug-eval-last-sexp)
4031 (define-key edebug-eval-mode-map "\C-j" 'edebug-eval-print-last-sexp)
4032 )
4033
4034
4035(defun edebug-eval-mode ()
1fe3d507
DL
4036 "Mode for evaluation list buffer while in Edebug.
4037
4038In addition to all Interactive Emacs Lisp commands there are local and
4039global key bindings to several Edebug specific commands. E.g.
4040`edebug-step-mode' is bound to \\[edebug-step-mode] in the Edebug
4041buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
84fc2cfa
ER
4042
4043Eval list buffer commands:
4044\\{edebug-eval-mode-map}
4045
1fe3d507 4046Global commands prefixed by global-edebug-prefix:
84fc2cfa
ER
4047\\{global-edebug-map}
4048"
4049 (lisp-interaction-mode)
4050 (setq major-mode 'edebug-eval-mode)
4051 (setq mode-name "Edebug-Eval")
4052 (use-local-map edebug-eval-mode-map))
4053
f7359658 4054;;; Interface with standard debugger.
84fc2cfa 4055
1fe3d507
DL
4056;; (setq debugger 'edebug) ; to use the edebug debugger
4057;; (setq debugger 'debug) ; use the standard debugger
84fc2cfa 4058
1fe3d507
DL
4059;; Note that debug and its utilities must be byte-compiled to work,
4060;; since they depend on the backtrace looking a certain way. But
4061;; edebug is not dependent on this, yet.
84fc2cfa 4062
1fe3d507 4063(defun edebug (&optional edebug-arg-mode &rest debugger-args)
84fc2cfa 4064 "Replacement for debug.
1fe3d507 4065If we are running an edebugged function,
84fc2cfa 4066show where we last were. Otherwise call debug normally."
1fe3d507
DL
4067;; (message "entered: %s depth: %s edebug-recursion-depth: %s"
4068;; edebug-entered (recursion-depth) edebug-recursion-depth) (sit-for 1)
4069 (if (and edebug-entered ; anything active?
4070 (eq (recursion-depth) edebug-recursion-depth))
4071 (let (;; Where were we before the error occurred?
4072 (edebug-offset-index (car edebug-offset-indices))
4073 ;; Bind variables required by edebug-display
4074 (edebug-value (car debugger-args))
4075 edebug-breakpoints
4076 edebug-break-data
4077 edebug-break-condition
4078 edebug-global-break
4079 (edebug-break (null edebug-arg-mode)) ;; if called explicitly
4080 )
84fc2cfa 4081 (edebug-display)
1fe3d507
DL
4082 (if (eq edebug-arg-mode 'error)
4083 nil
4084 edebug-value))
84fc2cfa
ER
4085
4086 ;; Otherwise call debug normally.
4087 ;; Still need to remove extraneous edebug calls from stack.
1fe3d507 4088 (apply 'debug edebug-arg-mode debugger-args)
84fc2cfa
ER
4089 ))
4090
4091
4092(defun edebug-backtrace ()
4093 "Display a non-working backtrace. Better than nothing..."
4094 (interactive)
1fe3d507
DL
4095 (if (or (not edebug-backtrace-buffer)
4096 (null (buffer-name edebug-backtrace-buffer)))
4097 (setq edebug-backtrace-buffer
4098 (generate-new-buffer "*Backtrace*"))
4099 ;; else, could just display edebug-backtrace-buffer
4100 )
4101 (with-output-to-temp-buffer (buffer-name edebug-backtrace-buffer)
4102 (setq edebug-backtrace-buffer standard-output)
4103 (let ((print-escape-newlines t)
84fc2cfa 4104 (print-length 50)
1fe3d507 4105 last-ok-point)
84fc2cfa
ER
4106 (backtrace)
4107
1fe3d507
DL
4108 ;; Clean up the backtrace.
4109 ;; Not quite right for current edebug scheme.
4110 (set-buffer edebug-backtrace-buffer)
4111 (setq truncate-lines t)
84fc2cfa 4112 (goto-char (point-min))
84fc2cfa 4113 (setq last-ok-point (point))
1fe3d507 4114 (if t (progn
84fc2cfa
ER
4115
4116 ;; Delete interspersed edebug internals.
1fe3d507
DL
4117 (while (re-search-forward "^ \(?edebug" nil t)
4118 (beginning-of-line)
4119 (cond
4120 ((looking-at "^ \(edebug-after")
4121 ;; Previous lines may contain code, so just delete this line
4122 (setq last-ok-point (point))
4123 (forward-line 1)
4124 (delete-region last-ok-point (point)))
4125
4126 ((looking-at "^ edebug")
4127 (forward-line 1)
4128 (delete-region last-ok-point (point))
4129 )))
4130 )))))
84fc2cfa
ER
4131
4132\f
f7359658 4133;;; Trace display
84fc2cfa
ER
4134
4135(defun edebug-trace-display (buf-name fmt &rest args)
4136 "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
4137The buffer is created if it does not exist.
1fe3d507
DL
4138You must include newlines in FMT to break lines, but one newline is appended."
4139;; e.g.
4140;; (edebug-trace-display "*trace-point*"
4141;; "saving: point = %s window-start = %s"
4142;; (point) (window-start))
dc0e03f3
RS
4143 (let* ((oldbuf (current-buffer))
4144 (selected-window (selected-window))
84fc2cfa 4145 (buffer (get-buffer-create buf-name))
1fe3d507
DL
4146 buf-window)
4147;; (message "before pop-to-buffer") (sit-for 1)
84fc2cfa 4148 (edebug-pop-to-buffer buffer)
1fe3d507
DL
4149 (setq truncate-lines t)
4150 (setq buf-window (selected-window))
4151 (goto-char (point-max))
4152 (insert (apply 'edebug-format fmt args) "\n")
4153 ;; Make it visible.
4154 (vertical-motion (- 1 (window-height)))
4155 (set-window-start buf-window (point))
4156 (goto-char (point-max))
4157;; (set-window-point buf-window (point))
4158;; (edebug-sit-for 0)
4159 (bury-buffer buffer)
dc0e03f3
RS
4160 (select-window selected-window)
4161 (set-buffer oldbuf))
1fe3d507
DL
4162 buf-name)
4163
4164
4165(defun edebug-trace (fmt &rest args)
4166 "Convenience call to edebug-trace-display using edebug-trace-buffer"
4167 (apply 'edebug-trace-display edebug-trace-buffer fmt args))
4168
4169\f
f7359658 4170;;; Frequency count and coverage
1fe3d507
DL
4171
4172(defun edebug-display-freq-count ()
4173 "Display the frequency count data for each line of the current
4174definition. The frequency counts are inserted as comment lines after
4175each line, and you can undo all insertions with one `undo' command.
4176
4177The counts are inserted starting under the `(' before an expression
4178or the `)' after an expression, or on the last char of a symbol.
4179The counts are only displayed when they differ from previous counts on
4180the same line.
4181
4182If coverage is being tested, whenever all known results of an expression
4183are `eq', the char `=' will be appended after the count
4184for that expression. Note that this is always the case for an
4185expression only evaluated once.
4186
4187To clear the frequency count and coverage data for a definition,
4188reinstrument it."
4189 (interactive)
4190 (let* ((function (edebug-form-data-symbol))
4191 (counts (get function 'edebug-freq-count))
4192 (coverages (get function 'edebug-coverage))
4193 (data (get function 'edebug))
4194 (def-mark (car data)) ; mark at def start
4195 (edebug-points (nth 2 data))
4196 (i (1- (length edebug-points)))
4197 (last-index)
4198 (first-index)
4199 (start-of-line)
4200 (start-of-count-line)
4201 (last-count)
4202 )
84fc2cfa 4203 (save-excursion
1fe3d507
DL
4204 ;; Traverse in reverse order so offsets are correct.
4205 (while (<= 0 i)
4206 ;; Start at last expression in line.
4207 (goto-char (+ def-mark (aref edebug-points i)))
4208 (beginning-of-line)
4209 (setq start-of-line (- (point) def-mark)
4210 last-index i)
4211
4212 ;; Find all indexes on same line.
4213 (while (and (<= 0 (setq i (1- i)))
4214 (<= start-of-line (aref edebug-points i))))
4215 ;; Insert all the indices for this line.
4216 (forward-line 1)
4217 (setq start-of-count-line (point)
4218 first-index i ; really last index for line above this one.
4219 last-count -1) ; cause first count to always appear.
4220 (insert ";#")
4221 ;; i == first-index still
4222 (while (<= (setq i (1+ i)) last-index)
4223 (let ((count (aref counts i))
4224 (coverage (aref coverages i))
4225 (col (save-excursion
4226 (goto-char (+ (aref edebug-points i) def-mark))
4227 (- (current-column)
4228 (if (= ?\( (following-char)) 0 1)))))
4229 (insert (make-string
4230 (max 0 (- col (- (point) start-of-count-line))) ?\ )
4231 (if (and (< 0 count)
4232 (not (memq coverage
4233 '(unknown ok-coverage))))
4234 "=" "")
4235 (if (= count last-count) "" (int-to-string count))
4236 " ")
4237 (setq last-count count)))
4238 (insert "\n")
4239 (setq i first-index)))))
4240
4241(defun edebug-temp-display-freq-count ()
4242 "Temporarily display the frequency count data for the current definition.
4243It is removed when you hit any char."
4244 ;; This seems not to work with Emacs 18.59. It undoes too far.
4245 (interactive)
4246 (let ((buffer-read-only nil))
4247 (undo-boundary)
4248 (edebug-display-freq-count)
4249 (setq unread-command-char (read-char))
4250 (undo)))
4251
4252\f
f7359658 4253;;; Menus
1fe3d507
DL
4254
4255(defun edebug-toggle (variable)
4256 (set variable (not (eval variable)))
4257 (message "%s: %s" variable (eval variable)))
4258
4259;; We have to require easymenu (even for Emacs 18) just so
4260;; the easy-menu-define macro call is compiled correctly.
4261(require 'easymenu)
4262
4263(defconst edebug-mode-menus
4264 '("Edebug"
4265 "----"
4266 ["Stop" edebug-stop t]
4267 ["Step" edebug-step-mode t]
4268 ["Next" edebug-next-mode t]
4269 ["Trace" edebug-trace-mode t]
4270 ["Trace Fast" edebug-Trace-fast-mode t]
4271 ["Continue" edebug-continue-mode t]
4272 ["Continue Fast" edebug-Continue-fast-mode t]
4273 ["Go" edebug-go-mode t]
4274 ["Go Nonstop" edebug-Go-nonstop-mode t]
4275 "----"
4276 ["Help" edebug-help t]
4277 ["Abort" abort-recursive-edit t]
4278 ["Quit to Top Level" top-level t]
4279 ["Quit Nonstop" edebug-top-level-nonstop t]
4280 "----"
4281 ("Jumps"
4282 ["Forward Sexp" edebug-forward-sexp t]
4283 ["Step In" edebug-step-in t]
4284 ["Step Out" edebug-step-out t]
4285 ["Goto Here" edebug-goto-here t])
4286
4287 ("Breaks"
4288 ["Set Breakpoint" edebug-set-breakpoint t]
4289 ["Unset Breakpoint" edebug-unset-breakpoint t]
4290 ["Set Conditional Breakpoint" edebug-set-conditional-breakpoint t]
4291 ["Set Global Break Condition" edebug-set-global-break-condition t]
4292 ["Show Next Breakpoint" edebug-next-breakpoint t])
4293
4294 ("Views"
4295 ["Where am I?" edebug-where t]
4296 ["Bounce to Current Point" edebug-bounce-point t]
4297 ["View Outside Windows" edebug-view-outside t]
4298 ["Previous Result" edebug-previous-result t]
4299 ["Show Backtrace" edebug-backtrace t]
4300 ["Display Freq Count" edebug-display-freq-count t])
4301
4302 ("Eval"
4303 ["Expression" edebug-eval-expression t]
4304 ["Last Sexp" edebug-eval-last-sexp t]
4305 ["Visit Eval List" edebug-visit-eval-list t])
4306
4307 ("Options"
4308 ["Edebug All Defs" edebug-all-defs t]
4309 ["Edebug All Forms" edebug-all-forms t]
4310 "----"
4311 ["Toggle Tracing" (edebug-toggle 'edebug-trace) t]
4312 ["Toggle Coverage Testing" (edebug-toggle 'edebug-test-coverage) t]
4313 ["Toggle Window Saving" edebug-toggle-save-windows t]
4314 ["Toggle Point Saving"
4315 (edebug-toggle 'edebug-save-displayed-buffer-points) t]
4316 ))
4317 "Lemacs style menus for Edebug.")
4318
4319\f
f7359658
RS
4320;;; Emacs version specific code
4321
1fe3d507
DL
4322;;; The default for all above is Emacs 18, because it is easier to compile
4323;;; Emacs 18 code in Emacs 19 than vice versa. This default will
4324;;; change once most people are using Emacs 19 or derivatives.
4325
4326;; Epoch specific code is in a separate file: edebug-epoch.el.
4327
4328;; The byte-compiler will complain about changes in number of arguments
4329;; to functions like mark and read-from-minibuffer. These warnings
4330;; may be ignored because the right call should always be made.
4331
100aa77c 4332(defun edebug-emacs-19-specific ()
1fe3d507
DL
4333
4334 (defalias 'edebug-window-live-p 'window-live-p)
4335
4336 ;; Mark takes an argument in Emacs 19.
4337 (defun edebug-mark ()
4338 (mark t));; Does this work for lemacs too?
4339
4340 ;; Use minibuffer-history when reading expressions.
4341 (defvar read-expression-history) ;; hush bytecomp
4342 (defvar read-expression-map)
4343
4344 (defun edebug-set-conditional-breakpoint (arg condition)
4345 "Set a conditional breakpoint at nearest sexp.
4346The condition is evaluated in the outside context.
4347With prefix argument, make it a temporary breakpoint."
4348 ;; (interactive "P\nxCondition: ")
4349 (interactive
4350 (list
4351 current-prefix-arg
4352 ;; Read condition as follows; getting previous condition is cumbersome:
4353 (let ((edebug-stop-point (edebug-find-stop-point)))
4354 (if edebug-stop-point
4355 (let* ((edebug-def-name (car edebug-stop-point))
4356 (index (cdr edebug-stop-point))
4357 (edebug-data (get edebug-def-name 'edebug))
4358 (edebug-breakpoints (car (cdr edebug-data)))
4359 (edebug-break-data (assq index edebug-breakpoints))
4360 (edebug-break-condition (car (cdr edebug-break-data)))
4361 (edebug-expression-history
4362 ;; Prepend the current condition, if any.
4363 (if edebug-break-condition
4364 (cons edebug-break-condition read-expression-history)
4365 read-expression-history)))
4366 (prog1
4367 (read-from-minibuffer
4368 "Condition: " nil read-expression-map t
4369 'edebug-expression-history)
4370 (setq read-expression-history edebug-expression-history)
4371 ))))))
4372 (edebug-modify-breakpoint t condition arg))
4373
4374 (defun edebug-eval-expression (edebug-expr)
4375 "Evaluate an expression in the outside environment.
4376If interactive, prompt for the expression.
4377Print result in minibuffer."
4378 (interactive (list (read-from-minibuffer
4379 "Eval: " nil read-expression-map t
4380 'read-expression-history)))
4381 (princ
4382 (edebug-outside-excursion
4383 (setq values (cons (edebug-eval edebug-expr) values))
4384 (edebug-safe-prin1-to-string (car values)))))
4385
f7359658
RS
4386 (easy-menu-define edebug-menu edebug-mode-map "Edebug menus" edebug-mode-menus)
4387 (if window-system
4388 (x-popup-menu nil (lookup-key edebug-mode-map [menu-bar Edebug])))
1fe3d507
DL
4389 )
4390
4391
4392(defun edebug-lemacs-specific ()
4393
4394 ;; We need to bind zmacs-regions to nil around all calls to `mark' and
4395 ;; `mark-marker' but don't bind it to nil before entering a recursive edit,
4396 ;; that is, don't interfere with the binding the user might see while
4397 ;; executing a command.
4398
4399 (defvar zmacs-regions)
4400
4401 (defun edebug-mark ()
4402 (let ((zmacs-regions nil))
4403 (mark)))
4404
4405 (defun edebug-mark-marker ()
4406 (let ((zmacs-regions nil));; for lemacs
4407 (mark-marker)))
4408
4409
4410 (defun edebug-mode-menu (event)
4411 (interactive "@event")
4412 (popup-menu edebug-mode-menus))
4413
4414 (define-key edebug-mode-map 'button3 'edebug-mode-menu)
4415 )
4416
4417(defun edebug-emacs-version-specific ()
4418 (cond
100aa77c 4419 ((string-match "Lucid" emacs-version);; Lucid Emacs
1fe3d507
DL
4420 (edebug-lemacs-specific))
4421
1fe3d507 4422 ((and (boundp 'epoch::version) epoch::version)
100aa77c
RS
4423 (require 'edebug-epoch))
4424
4425 ((not (string-match "^18" emacs-version))
4426 (edebug-emacs-19-specific))))
1fe3d507
DL
4427
4428(edebug-emacs-version-specific)
4429
4430\f
f7359658
RS
4431;;; Byte-compiler
4432
1fe3d507
DL
4433;; Extension for bytecomp to resolve undefined function references.
4434;; Requires new byte compiler.
4435
4436;; Reenable byte compiler warnings about unread-command-char and -event.
4437;; Disabled before edebug-recursive-edit.
4438(eval-when-compile
4439 (if edebug-unread-command-char-warning
4440 (put 'unread-command-char 'byte-obsolete-variable
4441 edebug-unread-command-char-warning))
4442 (if edebug-unread-command-event-warning
4443 (put 'unread-command-event 'byte-obsolete-variable
4444 edebug-unread-command-event-warning)))
4445
4446(eval-when-compile
4447 ;; The body of eval-when-compile seems to get evaluated with eval-defun.
4448 ;; We only want to evaluate when actually byte compiling.
4449 ;; But it is OK to evaluate as long as byte-compiler has been loaded.
4450 (if (featurep 'byte-compile) (progn
4451
4452 (defun byte-compile-resolve-functions (funcs)
4453 "Say it is OK for the named functions to be unresolved."
4454 (mapcar
4455 (function
4456 (lambda (func)
4457 (setq byte-compile-unresolved-functions
4458 (delq (assq func byte-compile-unresolved-functions)
4459 byte-compile-unresolved-functions))))
4460 funcs)
4461 nil)
4462
4463 '(defun byte-compile-resolve-free-references (vars)
4464 "Say it is OK for the named variables to be referenced."
4465 (mapcar
4466 (function
4467 (lambda (var)
4468 (setq byte-compile-free-references
4469 (delq var byte-compile-free-references))))
4470 vars)
4471 nil)
4472
4473 '(defun byte-compile-resolve-free-assignments (vars)
4474 "Say it is OK for the named variables to be assigned."
4475 (mapcar
4476 (function
4477 (lambda (var)
4478 (setq byte-compile-free-assignments
4479 (delq var byte-compile-free-assignments))))
4480 vars)
4481 nil)
4482
4483 (byte-compile-resolve-functions
4484 '(reporter-submit-bug-report
f7359658 4485 edebug-gensym ;; also in cl.el
1fe3d507
DL
4486 ;; Interfaces to standard functions.
4487 edebug-original-eval-defun
4488 edebug-original-read
4489 edebug-get-buffer-window
4490 edebug-mark
4491 edebug-mark-marker
4492 edebug-input-pending-p
4493 edebug-sit-for
4494 edebug-prin1-to-string
4495 edebug-format
88668147 4496 edebug-original-signal
1fe3d507
DL
4497 ;; lemacs
4498 zmacs-deactivate-region
4499 popup-menu
4500 ;; CL
4501 cl-macroexpand-all
f7359658 4502 ;; And believe it or not, the byte compiler doesn't know about:
1fe3d507
DL
4503 byte-compile-resolve-functions
4504 ))
4505
4506 '(byte-compile-resolve-free-references
4507 '(read-expression-history
4508 read-expression-map))
4509
4510 '(byte-compile-resolve-free-assignments
4511 '(read-expression-history))
4512
4513 )))
4514
4515\f
f7359658 4516;;; Autoloading of Edebug accessories
1fe3d507
DL
4517
4518(if (featurep 'cl)
4519 (add-hook 'edebug-setup-hook
4520 (function (lambda () (require 'cl-specs))))
4521 ;; The following causes cl-specs to be loaded if you load cl.el.
4522 (add-hook 'cl-load-hook
4523 (function (lambda () (require 'cl-specs)))))
4524
f7359658 4525;;; edebug-cl-read and cl-read are available from liberte@cs.uiuc.edu
1fe3d507
DL
4526(if (featurep 'cl-read)
4527 (add-hook 'edebug-setup-hook
4528 (function (lambda () (require 'edebug-cl-read))))
4529 ;; The following causes edebug-cl-read to be loaded when you load cl-read.el.
4530 (add-hook 'cl-read-load-hooks
4531 (function (lambda () (require 'edebug-cl-read)))))
4532
4533\f
f7359658 4534;;; Finalize Loading
1fe3d507
DL
4535
4536;;; Finally, hook edebug into the rest of Emacs.
4537;;; There are probably some other things that could go here.
4538
4539;; Install edebug read and eval functions.
4540(edebug-install-read-eval-functions)
84fc2cfa 4541
e8544af2
RS
4542(provide 'edebug)
4543
84fc2cfa 4544;;; edebug.el ends here