(vc-next-action-on-file, vc-update-change-log,
[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.
5398a9e7 11;; |$Date: 1996/10/02 21:41:56 $|$Revision: 3.11 $|~/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
5398a9e7 88 (let ((raw-version "$Revision: 3.11 $"))
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
8fd29408
RS
2121(def-edebug-spec save-selected-window t)
2122(def-edebug-spec save-current-buffer t)
2123(def-edebug-spec save-match-data t)
2124(def-edebug-spec with-output-to-string t)
2125(def-edebug-spec with-current-buffer t)
5398a9e7 2126(def-edebug-spec combine-after-change-calls t)
8fd29408
RS
2127(def-edebug-spec with-temp-file t)
2128(def-edebug-spec with-temp-buffer t)
2129
1fe3d507
DL
2130;; Anything else?
2131
2132
1fe3d507
DL
2133;; Some miscellaneous specs for macros in public packages.
2134;; Send me yours.
2135
2136;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu)
2137
2138(def-edebug-spec ad-dolist ((symbolp form &optional form) body))
2139(def-edebug-spec defadvice
2140 (&define name ;; thing being advised.
2141 (name ;; class is [&or "before" "around" "after"
2142 ;; "activation" "deactivation"]
2143 name ;; name of advice
2144 &rest sexp ;; optional position and flags
2145 )
2146 [&optional stringp]
2147 [&optional ("interactive" interactive)]
2148 def-body))
2149
f7359658 2150;;; The debugger itself
1fe3d507
DL
2151
2152(defvar edebug-active nil) ;; Non-nil when edebug is active
84fc2cfa
ER
2153
2154;;; add minor-mode-alist entry
2155(or (assq 'edebug-active minor-mode-alist)
2156 (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*")
2157 minor-mode-alist)))
2158
1fe3d507
DL
2159(defvar edebug-stack nil)
2160;; Stack of active functions evaluated via edebug.
2161;; Should be nil at the top level.
2162
2163(defvar edebug-stack-depth -1)
2164;; Index of last edebug-stack item.
2165
2166(defvar edebug-offset-indices nil)
2167;; Stack of offset indices of visited edebug sexps.
2168;; Should be nil at the top level.
2169;; Each function adds one cons. Top is modified with setcar.
84fc2cfa 2170
84fc2cfa
ER
2171
2172(defvar edebug-entered nil
1fe3d507
DL
2173 ;; Non-nil if edebug has already been entered at this recursive edit level.
2174 ;; This should stay nil at the top level.
2175 )
2176
2177;; Should these be options?
2178(defconst edebug-debugger 'edebug
2179 ;; Name of function to use for debugging when error or quit occurs.
2180 ;; Set this to 'debug if you want to debug edebug.
2181 )
2182
2183
2184;; Dynamically bound variables, declared globally but left unbound.
2185(defvar edebug-function) ; the function being executed. change name!!
2186(defvar edebug-args) ; the arguments of the function
2187(defvar edebug-data) ; the edebug data for the function
2188(defvar edebug-value) ; the result of the expression
2189(defvar edebug-after-index)
2190(defvar edebug-def-mark) ; the mark for the definition
2191(defvar edebug-freq-count) ; the count of expression visits.
2192(defvar edebug-coverage) ; the coverage results of each expression of function.
2193
2194(defvar edebug-buffer) ; which buffer the function is in.
2195(defvar edebug-result) ; the result of the function call returned by body
2196(defvar edebug-outside-executing-macro)
2197(defvar edebug-outside-defining-kbd-macro)
2198
2199(defvar edebug-execution-mode 'step) ; Current edebug mode set by user.
2200(defvar edebug-next-execution-mode nil) ; Use once instead of initial mode.
2201
2202(defvar edebug-outside-debug-on-error) ; the value of debug-on-error outside
2203(defvar edebug-outside-debug-on-quit) ; the value of debug-on-quit outside
2204
88668147
DL
2205(defvar edebug-outside-pre-command-hook)
2206(defvar edebug-outside-post-command-hook)
88668147
DL
2207
2208(defvar cl-lexical-debug) ;; Defined in cl.el
2209
1fe3d507 2210;;; Handling signals
1fe3d507 2211
1fe3d507
DL
2212(defun edebug-signal (edebug-signal-name edebug-signal-data)
2213 "Signal an error. Args are SIGNAL-NAME, and associated DATA.
2214A signal name is a symbol with an `error-conditions' property
2215that is a list of condition names.
2216A handler for any of those names will get to handle this signal.
2217The symbol `error' should always be one of them.
2218
2219DATA should be a list. Its elements are printed as part of the error message.
2220If the signal is handled, DATA is made available to the handler.
2221See `condition-case'.
2222
2223This is the Edebug replacement for the standard `signal'. It should
2224only be active while Edebug is. It checks `debug-on-error' to see
2225whether it should call the debugger. When execution is resumed, the
2226error is signaled again."
2227 (if (and (listp debug-on-error) (memq edebug-signal-name debug-on-error))
2228 (edebug 'error (cons edebug-signal-name edebug-signal-data)))
2229 ;; If we reach here without another non-local exit, then send signal again.
2230 ;; i.e. the signal is not continuable, yet.
1e3ab67b 2231 (signal edebug-signal-name edebug-signal-data))
1fe3d507
DL
2232
2233;;; Entering Edebug
84fc2cfa 2234
1fe3d507
DL
2235(defun edebug-enter (edebug-function edebug-args edebug-body)
2236 ;; Entering FUNC. The arguments are ARGS, and the body is BODY.
2237 ;; Setup edebug variables and evaluate BODY. This function is called
2238 ;; when a function evaluated with edebug-eval-top-level-form is entered.
2239 ;; Return the result of BODY.
84fc2cfa
ER
2240
2241 ;; Is this the first time we are entering edebug since
2242 ;; lower-level recursive-edit command?
1fe3d507
DL
2243 ;; More precisely, this tests whether Edebug is currently active.
2244 (if (not edebug-entered)
2245 (let ((edebug-entered t)
2246 ;; Binding max-lisp-eval-depth here is OK,
88668147
DL
2247 ;; but not inside an unwind-protect.
2248 ;; Doing it here also keeps it from growing too large.
1fe3d507
DL
2249 (max-lisp-eval-depth (+ 100 max-lisp-eval-depth)) ; too much??
2250 (max-specpdl-size (+ 200 max-specpdl-size))
2251
2252 (debugger edebug-debugger) ; only while edebug is active.
2253 (edebug-outside-debug-on-error debug-on-error)
2254 (edebug-outside-debug-on-quit debug-on-quit)
2255 ;; Binding these may not be the right thing to do.
2256 ;; We want to allow the global values to be changed.
2257 (debug-on-error (or debug-on-error edebug-on-error))
2258 (debug-on-quit edebug-on-quit)
2259
88668147
DL
2260 ;; Lexical bindings must be uncompiled for this to work.
2261 (cl-lexical-debug t)
2262
1fe3d507 2263 ;; Save the outside value of executing macro. (here??)
efcf38c7 2264 (edebug-outside-executing-macro executing-kbd-macro)
88668147 2265 (edebug-outside-pre-command-hook pre-command-hook)
ba88fc3a 2266 (edebug-outside-post-command-hook post-command-hook))
1fe3d507 2267 (unwind-protect
88668147
DL
2268 (let (;; Don't keep reading from an executing kbd macro
2269 ;; within edebug unless edebug-continue-kbd-macro is
2270 ;; non-nil. Again, local binding may not be best.
efcf38c7
KH
2271 (executing-kbd-macro
2272 (if edebug-continue-kbd-macro executing-kbd-macro))
88668147 2273
1e3ab67b
RS
2274 (signal-hook-function 'edebug-signal)
2275
88668147
DL
2276 ;; Disable command hooks. This is essential when
2277 ;; a hook function is instrumented - to avoid infinite loop.
2278 ;; This may be more than we need, however.
2279 (pre-command-hook nil)
ba88fc3a 2280 (post-command-hook nil))
88668147
DL
2281 (setq edebug-execution-mode (or edebug-next-execution-mode
2282 edebug-initial-mode
2283 edebug-execution-mode)
2284 edebug-next-execution-mode nil)
1e3ab67b 2285 (edebug-enter edebug-function edebug-args edebug-body))
88668147 2286 ;; Reset global variables in case outside value was changed.
efcf38c7 2287 (setq executing-kbd-macro edebug-outside-executing-macro
f7359658
RS
2288 pre-command-hook edebug-outside-pre-command-hook
2289 post-command-hook edebug-outside-post-command-hook
88668147 2290 )))
1fe3d507
DL
2291
2292 (let* ((edebug-data (get edebug-function 'edebug))
2293 (edebug-def-mark (car edebug-data)) ; mark at def start
2294 (edebug-freq-count (get edebug-function 'edebug-freq-count))
2295 (edebug-coverage (get edebug-function 'edebug-coverage))
2296 (edebug-buffer (marker-buffer edebug-def-mark))
2297
2298 (edebug-stack (cons edebug-function edebug-stack))
2299 (edebug-offset-indices (cons 0 edebug-offset-indices))
2300 )
2301 (if (get edebug-function 'edebug-on-entry)
2302 (progn
2303 (setq edebug-execution-mode 'step)
2304 (if (eq (get edebug-function 'edebug-on-entry) 'temp)
2305 (put edebug-function 'edebug-on-entry nil))))
2306 (if edebug-trace
2307 (edebug-enter-trace edebug-body)
2308 (funcall edebug-body))
84fc2cfa
ER
2309 )))
2310
84fc2cfa 2311
1fe3d507
DL
2312(defun edebug-enter-trace (edebug-body)
2313 (let ((edebug-stack-depth (1+ edebug-stack-depth))
2314 edebug-result)
2315 (edebug-print-trace-before
2316 (format "%s args: %s" edebug-function edebug-args))
2317 (prog1 (setq edebug-result (funcall edebug-body))
2318 (edebug-print-trace-after
2319 (format "%s result: %s" edebug-function edebug-result)))))
2320
2321(def-edebug-spec edebug-tracing (form body))
2322
2323(defmacro edebug-tracing (msg &rest body)
2324 "Print MSG in *edebug-trace* before and after evaluating BODY.
2325The result of BODY is also printed."
2326 (` (let ((edebug-stack-depth (1+ edebug-stack-depth))
2327 edebug-result)
2328 (edebug-print-trace-before (, msg))
2329 (prog1 (setq edebug-result (progn (,@ body)))
2330 (edebug-print-trace-after
2331 (format "%s result: %s" (, msg) edebug-result))))))
2332
2333(defun edebug-print-trace-before (msg)
2334 "Function called to print trace info before expression evaluation.
2335MSG is printed after `::::{ '."
84fc2cfa 2336 (edebug-trace-display
1fe3d507 2337 edebug-trace-buffer "%s{ %s" (make-string edebug-stack-depth ?\:) msg))
84fc2cfa 2338
1fe3d507
DL
2339(defun edebug-print-trace-after (msg)
2340 "Function called to print trace info after expression evaluation.
2341MSG is printed after `::::} '."
84fc2cfa 2342 (edebug-trace-display
1fe3d507
DL
2343 edebug-trace-buffer "%s} %s" (make-string edebug-stack-depth ?\:) msg))
2344
2345
84fc2cfa 2346
1fe3d507
DL
2347(defun edebug-slow-before (edebug-before-index)
2348 ;; Debug current function given BEFORE position.
2349 ;; Called from functions compiled with edebug-eval-top-level-form.
2350 ;; Return the before index.
2351 (setcar edebug-offset-indices edebug-before-index)
84fc2cfa 2352
1fe3d507
DL
2353 ;; Increment frequency count
2354 (aset edebug-freq-count edebug-before-index
2355 (1+ (aref edebug-freq-count edebug-before-index)))
2356
2357 (if (or (not (memq edebug-execution-mode '(Go-nonstop next)))
2358 (edebug-input-pending-p))
2359 (edebug-debugger edebug-before-index 'before nil))
2360 edebug-before-index)
2361
2362(defun edebug-fast-before (edebug-before-index)
2363 ;; Do nothing.
2364 )
2365
2366(defun edebug-slow-after (edebug-before-index edebug-after-index edebug-value)
2367 ;; Debug current function given AFTER position and VALUE.
2368 ;; Called from functions compiled with edebug-eval-top-level-form.
2369 ;; Return VALUE.
2370 (setcar edebug-offset-indices edebug-after-index)
2371
2372 ;; Increment frequency count
2373 (aset edebug-freq-count edebug-after-index
2374 (1+ (aref edebug-freq-count edebug-after-index)))
2375 (if edebug-test-coverage (edebug-update-coverage))
2376
2377 (if (and (eq edebug-execution-mode 'Go-nonstop)
2378 (not (edebug-input-pending-p)))
2379 ;; Just return result.
2380 edebug-value
2381 (edebug-debugger edebug-after-index 'after edebug-value)
2382 ))
2383
2384(defun edebug-fast-after (edebug-before-index edebug-after-index edebug-value)
2385 ;; Do nothing but return the value.
2386 edebug-value)
2387
2388(defun edebug-run-slow ()
2389 (defalias 'edebug-before 'edebug-slow-before)
2390 (defalias 'edebug-after 'edebug-slow-after))
2391
2392;; This is not used, yet.
2393(defun edebug-run-fast ()
2394 (defalias 'edebug-before 'edebug-fast-before)
2395 (defalias 'edebug-after 'edebug-fast-after))
2396
2397(edebug-run-slow)
2398
2399
2400(defun edebug-update-coverage ()
2401 (let ((old-result (aref edebug-coverage edebug-after-index)))
2402 (cond
2403 ((eq 'ok-coverage old-result))
2404 ((eq 'unknown old-result)
2405 (aset edebug-coverage edebug-after-index edebug-value))
2406 ;; Test if a different result.
2407 ((not (eq edebug-value old-result))
2408 (aset edebug-coverage edebug-after-index 'ok-coverage)))))
2409
2410
2411;; Dynamically declared unbound variables.
2412(defvar edebug-arg-mode) ; the mode, either before, after, or error
2413(defvar edebug-breakpoints)
2414(defvar edebug-break-data) ; break data for current function.
2415(defvar edebug-break) ; whether a break occurred.
2416(defvar edebug-global-break) ; whether a global break occurred.
2417(defvar edebug-break-condition) ; whether the breakpoint is conditional.
2418
2419(defvar edebug-break-result nil)
2420(defvar edebug-global-break-result nil)
2421
2422
2423(defun edebug-debugger (edebug-offset-index edebug-arg-mode edebug-value)
2424 ;; Check breakpoints and pending input.
2425 ;; If edebug display should be updated, call edebug-display.
2426 ;; Return edebug-value.
2427 (let* (;; This needs to be here since breakpoints may be changed.
84fc2cfa
ER
2428 (edebug-breakpoints (car (cdr edebug-data))) ; list of breakpoints
2429 (edebug-break-data (assq edebug-offset-index edebug-breakpoints))
1fe3d507
DL
2430 (edebug-break-condition (car (cdr edebug-break-data)))
2431 (edebug-global-break
2432 (if edebug-global-break-condition
2433 (condition-case nil
2434 (setq edebug-global-break-result
2435 (eval edebug-global-break-condition))
2436 (error nil))))
2437 (edebug-break))
2438
2439;;; (edebug-trace "exp: %s" edebug-value)
2440 ;; Test whether we should break.
2441 (setq edebug-break
2442 (or edebug-global-break
2443 (and edebug-break-data
2444 (or (not edebug-break-condition)
2445 (setq edebug-break-result
2446 (eval edebug-break-condition))))))
84fc2cfa 2447 (if (and edebug-break
1fe3d507 2448 (nth 2 edebug-break-data)) ; is it temporary?
84fc2cfa
ER
2449 ;; Delete the breakpoint.
2450 (setcdr edebug-data
2451 (cons (delq edebug-break-data edebug-breakpoints)
2452 (cdr (cdr edebug-data)))))
1fe3d507
DL
2453
2454 ;; Display if mode is not go, continue, or Continue-fast
2455 ;; or break, or input is pending,
2456 (if (or (not (memq edebug-execution-mode '(go continue Continue-fast)))
2457 edebug-break
2458 (edebug-input-pending-p))
2459 (edebug-display)) ; <--------------- display
84fc2cfa 2460
1fe3d507 2461 edebug-value
84fc2cfa
ER
2462 ))
2463
2464
1fe3d507
DL
2465;; window-start now stored with each function.
2466;;(defvar edebug-window-start nil)
2467;; Remember where each buffers' window starts between edebug calls.
2468;; This is to avoid spurious recentering.
2469;; Does this still need to be buffer-local??
2470;;(setq-default edebug-window-start nil)
2471;;(make-variable-buffer-local 'edebug-window-start)
2472
2473
2474;; Dynamically declared unbound vars
2475(defvar edebug-point) ; the point in edebug buffer
2476(defvar edebug-outside-buffer) ; the current-buffer outside of edebug
2477(defvar edebug-outside-point) ; the point outside of edebug
2478(defvar edebug-outside-mark) ; the mark outside of edebug
2479(defvar edebug-window-data) ; window and window-start for current function
2480(defvar edebug-outside-windows) ; outside window configuration
2481(defvar edebug-eval-buffer) ; for the evaluation list.
2482(defvar edebug-outside-o-a-p) ; outside overlay-arrow-position
2483(defvar edebug-outside-o-a-s) ; outside overlay-arrow-string
2484(defvar edebug-outside-c-i-e-a) ; outside cursor-in-echo-area
2485
2486(defvar edebug-eval-list nil) ;; List of expressions to evaluate.
2487
2488(defvar edebug-previous-result nil) ;; Last result returned.
2489
88668147 2490;; Emacs 19 adds an arg to mark and mark-marker.
1fe3d507
DL
2491(defalias 'edebug-mark 'mark)
2492(defalias 'edebug-mark-marker 'mark-marker)
84fc2cfa 2493
84fc2cfa
ER
2494
2495(defun edebug-display ()
1fe3d507
DL
2496 ;; Setup windows for edebug, determine mode, maybe enter recursive-edit.
2497 ;; Uses local variables of edebug-enter, edebug-before, edebug-after
2498 ;; and edebug-debugger.
84fc2cfa
ER
2499 (let ((edebug-active t) ; for minor mode alist
2500 edebug-stop ; should we enter recursive-edit
1fe3d507
DL
2501 (edebug-point (+ edebug-def-mark
2502 (aref (nth 2 edebug-data) edebug-offset-index)))
2503 edebug-buffer-outside-point ; current point in edebug-buffer
2504 ;; window displaying edebug-buffer
2505 (edebug-window-data (nth 3 edebug-data))
84fc2cfa
ER
2506 (edebug-outside-window (selected-window))
2507 (edebug-outside-buffer (current-buffer))
2508 (edebug-outside-point (point))
1fe3d507 2509 (edebug-outside-mark (edebug-mark))
84fc2cfa 2510 edebug-outside-windows ; window or screen configuration
1fe3d507 2511 edebug-buffer-points
84fc2cfa
ER
2512
2513 edebug-eval-buffer ; declared here so we can kill it below
2514 (edebug-eval-result-list (and edebug-eval-list
2515 (edebug-eval-result-list)))
1fe3d507
DL
2516 edebug-trace-window
2517 edebug-trace-window-start
88668147
DL
2518
2519 (edebug-outside-o-a-p overlay-arrow-position)
2520 (edebug-outside-o-a-s overlay-arrow-string)
2521 (edebug-outside-c-i-e-a cursor-in-echo-area))
2522 (unwind-protect
2523 (let ((overlay-arrow-position overlay-arrow-position)
2524 (overlay-arrow-string overlay-arrow-string)
2525 (cursor-in-echo-area nil)
2526 ;; any others??
2527 )
2528 (if (not (buffer-name edebug-buffer))
2529 (let ((debug-on-error nil))
2530 (error "Buffer defining %s not found" edebug-function)))
84fc2cfa 2531
88668147
DL
2532 (if (eq 'after edebug-arg-mode)
2533 ;; Compute result string now before windows are modified.
2534 (edebug-compute-previous-result edebug-value))
2535
2536 (if edebug-save-windows
2537 ;; Save windows now before we modify them.
2538 (setq edebug-outside-windows
2539 (edebug-current-windows edebug-save-windows)))
84fc2cfa 2540
88668147
DL
2541 (if edebug-save-displayed-buffer-points
2542 (setq edebug-buffer-points (edebug-get-displayed-buffer-points)))
2543
2544 ;; First move the edebug buffer point to edebug-point
f7359658
RS
2545 ;; so that window start doesn't get changed when we display it.
2546 ;; I don't know if this is going to help.
88668147
DL
2547 ;;(set-buffer edebug-buffer)
2548 ;;(goto-char edebug-point)
2549
2550 ;; If edebug-buffer is not currently displayed,
2551 ;; first find a window for it.
2552 (edebug-pop-to-buffer edebug-buffer (car edebug-window-data))
2553 (setcar edebug-window-data (selected-window))
2554
2555 ;; Now display eval list, if any.
2556 ;; This is done after the pop to edebug-buffer
2557 ;; so that buffer-window correspondence is correct after quitting.
2558 (edebug-eval-display edebug-eval-result-list)
2559 ;; The evaluation list better not have deleted edebug-window-data.
2560 (select-window (car edebug-window-data))
2561 (set-buffer edebug-buffer)
2562
2563 (setq edebug-buffer-outside-point (point))
2564 (goto-char edebug-point)
84fc2cfa 2565
88668147
DL
2566 (if (eq 'before edebug-arg-mode)
2567 ;; Check whether positions are up-to-date.
2568 ;; This assumes point is never before symbol.
2569 (if (not (memq (following-char) '(?\( ?\# ?\` )))
2570 (let ((debug-on-error nil))
2571 (error "Source has changed - reevaluate definition of %s"
2572 edebug-function)
2573 )))
1fe3d507 2574
88668147
DL
2575 (setcdr edebug-window-data
2576 (edebug-adjust-window (cdr edebug-window-data)))
84fc2cfa 2577
88668147
DL
2578 ;; Test if there is input, not including keyboard macros.
2579 (if (edebug-input-pending-p)
2580 (progn
2581 (setq edebug-execution-mode 'step
2582 edebug-stop t)
2583 (edebug-stop)
2584 ;; (discard-input) ; is this unfriendly??
2585 ))
2586 ;; Now display arrow based on mode.
2587 (edebug-overlay-arrow)
84fc2cfa 2588
88668147
DL
2589 (cond
2590 ((eq 'error edebug-arg-mode)
2591 ;; Display error message
2592 (setq edebug-execution-mode 'step)
2593 (edebug-overlay-arrow)
2594 (beep)
2595 (if (eq 'quit (car edebug-value))
2596 (message "Quit")
2597 (edebug-report-error edebug-value)))
2598 (edebug-break
2599 (cond
2600 (edebug-global-break
2601 (message "Global Break: %s => %s"
2602 edebug-global-break-condition
2603 edebug-global-break-result))
2604 (edebug-break-condition
2605 (message "Break: %s => %s"
2606 edebug-break-condition
2607 edebug-break-result))
2608 ((not (eq edebug-execution-mode 'Continue-fast))
2609 (message "Break"))
2610 (t)))
2611
2612 (t (message "")))
2613
2614 (if (eq 'after edebug-arg-mode)
2615 (progn
2616 ;; Display result of previous evaluation.
2617 (if (and edebug-break
2618 (not (eq edebug-execution-mode 'Continue-fast)))
2619 (sit-for 1)) ; Show break message.
2620 (edebug-previous-result)))
1fe3d507 2621
88668147
DL
2622 (cond
2623 (edebug-break
2624 (cond
2625 ((eq edebug-execution-mode 'continue) (edebug-sit-for 1))
2626 ((eq edebug-execution-mode 'Continue-fast) (edebug-sit-for 0))
2627 (t (setq edebug-stop t))))
2628 ;; not edebug-break
2629 ((eq edebug-execution-mode 'trace)
2630 (edebug-sit-for 1)) ; Force update and pause.
2631 ((eq edebug-execution-mode 'Trace-fast)
2632 (edebug-sit-for 0)) ; Force update and continue.
2633 )
1fe3d507 2634
88668147
DL
2635 (unwind-protect
2636 (if (or edebug-stop
2637 (memq edebug-execution-mode '(step next))
2638 (eq edebug-arg-mode 'error))
2639 (progn
2640 ;; (setq edebug-execution-mode 'step)
f7359658 2641 ;; (edebug-overlay-arrow) ; This doesn't always show up.
88668147
DL
2642 (edebug-recursive-edit))) ; <---------- Recursive edit
2643
2644 ;; Reset the edebug-window-data to whatever it is now.
2645 (let ((window (if (eq (window-buffer) edebug-buffer)
2646 (selected-window)
2647 (edebug-get-buffer-window edebug-buffer))))
2648 ;; Remember window-start for edebug-buffer, if still displayed.
2649 (if window
2650 (progn
2651 (setcar edebug-window-data window)
2652 (setcdr edebug-window-data (window-start window)))))
1fe3d507 2653
88668147
DL
2654 ;; Save trace window point before restoring outside windows.
2655 ;; Could generalize this for other buffers.
2656 (setq edebug-trace-window (get-buffer-window edebug-trace-buffer))
2657 (if edebug-trace-window
2658 (setq edebug-trace-window-start
2659 (and edebug-trace-window
2660 (window-start edebug-trace-window))))
2661
2662 ;; Restore windows before continuing.
2663 (if edebug-save-windows
2664 (progn
2665 (edebug-set-windows edebug-outside-windows)
2666
2667 ;; Restore displayed buffer points.
2668 ;; Needed even if restoring windows because
2669 ;; window-points are not restored. (should they be??)
2670 (if edebug-save-displayed-buffer-points
2671 (edebug-set-buffer-points edebug-buffer-points))
2672
2673 ;; Unrestore trace window's window-point.
2674 (if edebug-trace-window
2675 (set-window-start edebug-trace-window
2676 edebug-trace-window-start))
2677
2678 ;; Unrestore edebug-buffer's window-start, if displayed.
2679 (let ((window (car edebug-window-data)))
2680 (if (and window (edebug-window-live-p window)
2681 (eq (window-buffer) edebug-buffer))
2682 (progn
2683 (set-window-start window (cdr edebug-window-data)
2684 'no-force)
2685 ;; Unrestore edebug-buffer's window-point.
2686 ;; Needed in addition to setting the buffer point
f7359658 2687 ;; - otherwise quitting doesn't leave point as is.
88668147
DL
2688 ;; But this causes point to not be restored at times.
2689 ;; Also, it may not be a visible window.
2690 ;; (set-window-point window edebug-point)
2691 )))
2692
2693 ;; Unrestore edebug-buffer's point. Rerestored below.
2694 ;; (goto-char edebug-point) ;; in edebug-buffer
2695 )
2696 ;; Since we may be in a save-excursion, in case of quit,
2697 ;; reselect the outside window only.
2698 ;; Only needed if we are not recovering windows??
2699 (if (edebug-window-live-p edebug-outside-window)
2700 (select-window edebug-outside-window))
2701 ) ; if edebug-save-windows
2702
2703 ;; Restore current buffer always, in case application needs it.
2704 (set-buffer edebug-outside-buffer)
2705 ;; Restore point, and mark.
1fe3d507 2706 ;; Needed even if restoring windows because
f7359658
RS
2707 ;; that doesn't restore point and mark in the current buffer.
2708 ;; But don't restore point if edebug-buffer is current buffer.
88668147
DL
2709 (if (not (eq edebug-buffer edebug-outside-buffer))
2710 (goto-char edebug-outside-point))
2711 (if (marker-buffer (edebug-mark-marker))
2712 ;; Does zmacs-regions need to be nil while doing set-marker?
2713 (set-marker (edebug-mark-marker) edebug-outside-mark))
2714 ) ; unwind-protect
2715 ;; None of the following is done if quit or signal occurs.
2716
2717 ;; Restore edebug-buffer's outside point.
2718 ;; (edebug-trace "restore edebug-buffer point: %s"
2719 ;; edebug-buffer-outside-point)
2720 (let ((current-buffer (current-buffer)))
2721 (set-buffer edebug-buffer)
2722 (goto-char edebug-buffer-outside-point)
2723 (set-buffer current-buffer))
2724 ;; ... nothing more.
2725 )
2726 ;; Reset global variables to outside values in case they were changed.
2727 (setq
2728 overlay-arrow-position edebug-outside-o-a-p
2729 overlay-arrow-string edebug-outside-o-a-s
2730 cursor-in-echo-area edebug-outside-c-i-e-a)
2731 )))
1fe3d507 2732
84fc2cfa 2733
1fe3d507
DL
2734(defvar edebug-number-of-recursions 0)
2735;; Number of recursive edits started by edebug.
2736;; Should be 0 at the top level.
2737
2738(defvar edebug-recursion-depth 0)
2739;; Value of recursion-depth when edebug was called.
2740
2741;; Dynamically declared unbound vars
2742(defvar edebug-outside-match-data) ; match data outside of edebug
2743(defvar edebug-backtrace-buffer) ; each recursive edit gets its own
2744(defvar edebug-inside-windows)
2745(defvar edebug-interactive-p)
2746
2747(defvar edebug-outside-map)
2748(defvar edebug-outside-standard-output)
2749(defvar edebug-outside-standard-input)
2750(defvar edebug-outside-last-command-char)
2751(defvar edebug-outside-last-command)
2752(defvar edebug-outside-this-command)
2753(defvar edebug-outside-last-input-char)
2754
100aa77c
RS
2755;; Note: here we have defvars for variables that are
2756;; built-in in certain versions.
2757;; Each defvar makes a difference
2758;; in versions where the variable is *not* built-in.
2759
1fe3d507
DL
2760;; Emacs 18
2761(defvar edebug-outside-unread-command-char)
1fe3d507
DL
2762
2763;; Lucid Emacs
2764(defvar edebug-outside-unread-command-event) ;; like unread-command-events
2765(defvar unread-command-event nil)
2766
2767;; Emacs 19.
2768(defvar edebug-outside-last-command-event)
2769(defvar edebug-outside-unread-command-events)
2770(defvar edebug-outside-last-input-event)
2771(defvar edebug-outside-last-event-frame)
2772(defvar edebug-outside-last-nonmenu-event)
2773(defvar edebug-outside-track-mouse)
2774
1fe3d507
DL
2775;; Disable byte compiler warnings about unread-command-char and -event
2776;; (maybe works with byte-compile-version 2.22 at least)
2777(defvar edebug-unread-command-char-warning)
2778(defvar edebug-unread-command-event-warning)
2779(eval-when-compile
2780 (setq edebug-unread-command-char-warning
2781 (get 'unread-command-char 'byte-obsolete-variable))
2782 (put 'unread-command-char 'byte-obsolete-variable nil)
2783 (setq edebug-unread-command-event-warning
2784 (get 'unread-command-event 'byte-obsolete-variable))
2785 (put 'unread-command-event 'byte-obsolete-variable nil))
84fc2cfa
ER
2786
2787(defun edebug-recursive-edit ()
1fe3d507 2788 ;; Start up a recursive edit inside of edebug.
84fc2cfa 2789 ;; The current buffer is the edebug-buffer, which is put into edebug-mode.
1fe3d507 2790 ;; Assume that none of the variables below are buffer-local.
84fc2cfa
ER
2791 (let ((edebug-buffer-read-only buffer-read-only)
2792 ;; match-data must be done in the outside buffer
2793 (edebug-outside-match-data
1fe3d507
DL
2794 (save-excursion ; might be unnecessary now??
2795 (set-buffer edebug-outside-buffer) ; in case match buffer different
84fc2cfa
ER
2796 (match-data)))
2797
1fe3d507 2798 ;;(edebug-number-of-recursions (1+ edebug-number-of-recursions))
84fc2cfa
ER
2799 (edebug-recursion-depth (recursion-depth))
2800 edebug-entered ; bind locally to nil
1fe3d507 2801 (edebug-interactive-p nil) ; again non-interactive
84fc2cfa
ER
2802 edebug-backtrace-buffer ; each recursive edit gets its own
2803 ;; The window configuration may be saved and restored
2804 ;; during a recursive-edit
2805 edebug-inside-windows
2806
2807 (edebug-outside-map (current-local-map))
88668147 2808
84fc2cfa
ER
2809 (edebug-outside-standard-output standard-output)
2810 (edebug-outside-standard-input standard-input)
88668147 2811 (edebug-outside-defining-kbd-macro defining-kbd-macro)
84fc2cfa
ER
2812
2813 (edebug-outside-last-command-char last-command-char)
2814 (edebug-outside-last-command last-command)
2815 (edebug-outside-this-command this-command)
2816 (edebug-outside-last-input-char last-input-char)
1fe3d507
DL
2817
2818 (edebug-outside-unread-command-char unread-command-char)
2819
2820 (edebug-outside-last-input-event last-input-event)
2821 (edebug-outside-last-command-event last-command-event)
2822 (edebug-outside-unread-command-event unread-command-event)
2823 (edebug-outside-unread-command-events unread-command-events)
2824 (edebug-outside-last-event-frame last-event-frame)
2825 (edebug-outside-last-nonmenu-event last-nonmenu-event)
2826 (edebug-outside-track-mouse track-mouse)
84fc2cfa
ER
2827 )
2828
84fc2cfa 2829 (unwind-protect
88668147
DL
2830 (let (
2831 ;; Declare global values local but using the same global value.
2832 ;; We could set these to the values for previous edebug call.
2833 (last-command-char last-command-char)
2834 (last-command last-command)
2835 (this-command this-command)
2836 (last-input-char last-input-char)
2837
2838 ;; Assume no edebug command sets unread-command-char.
2839 (unread-command-char -1)
2840
2841 ;; More for Emacs 19
2842 (last-input-event nil)
2843 (last-command-event nil)
2844 (unread-command-event nil);; lemacs
2845 (unread-command-events nil)
2846 (last-event-frame nil)
2847 (last-nonmenu-event nil)
2848 (track-mouse nil)
2849
2850 ;; Bind again to outside values.
2851 (debug-on-error edebug-outside-debug-on-error)
2852 (debug-on-quit edebug-outside-debug-on-quit)
2853
2854 ;; Don't keep defining a kbd macro.
2855 (defining-kbd-macro
2856 (if edebug-continue-kbd-macro defining-kbd-macro))
2857
2858 ;; others??
2859 )
2860
2861 (if (fboundp 'zmacs-deactivate-region);; for lemacs
2862 (zmacs-deactivate-region))
2863 (if (and (eq edebug-execution-mode 'go)
2864 (not (memq edebug-arg-mode '(after error))))
2865 (message "Break"))
2866
2867 (setq buffer-read-only t)
1e3ab67b 2868 (setq signal-hook-function nil)
88668147
DL
2869
2870 (edebug-mode)
2871 (unwind-protect
2872 (recursive-edit) ; <<<<<<<<<< Recursive edit
2873
2874 ;; Do the following, even if quit occurs.
1e3ab67b 2875 (setq signal-hook-function 'edebug-signal)
88668147
DL
2876 (if edebug-backtrace-buffer
2877 (kill-buffer edebug-backtrace-buffer))
2878 ;; Could be an option to keep eval display up.
2879 (if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
2880
2881 ;; Remember selected-window after recursive-edit.
2882 ;; (setq edebug-inside-window (selected-window))
2883
2884 (store-match-data edebug-outside-match-data)
2885
2886 ;; Recursive edit may have changed buffers,
2887 ;; so set it back before exiting let.
2888 (if (buffer-name edebug-buffer) ; if it still exists
2889 (progn
2890 (set-buffer edebug-buffer)
2891 (if (memq edebug-execution-mode '(go Go-nonstop))
2892 (edebug-overlay-arrow))
2893 (setq buffer-read-only edebug-buffer-read-only)
2894 (use-local-map edebug-outside-map)
2895 )
2896 ;; gotta have a buffer to let its buffer local variables be set
2897 (get-buffer-create " bogus edebug buffer"))
2898 ));; inner let
2899
2900 ;; Reset global vars to outside values, in case they have been changed.
2901 (setq
2902 last-command-char edebug-outside-last-command-char
2903 last-command-event edebug-outside-last-command-event
2904 last-command edebug-outside-last-command
2905 this-command edebug-outside-this-command
2906 unread-command-char edebug-outside-unread-command-char
2907 unread-command-event edebug-outside-unread-command-event
2908 unread-command-events edebug-outside-unread-command-events
2909 last-input-char edebug-outside-last-input-char
2910 last-input-event edebug-outside-last-input-event
2911 last-event-frame edebug-outside-last-event-frame
2912 last-nonmenu-event edebug-outside-last-nonmenu-event
2913 track-mouse edebug-outside-track-mouse
2914
2915 standard-output edebug-outside-standard-output
2916 standard-input edebug-outside-standard-input
2917 defining-kbd-macro edebug-outside-defining-kbd-macro
2918 ))
2919 ))
84fc2cfa 2920
1fe3d507
DL
2921
2922;;; Display related functions
84fc2cfa
ER
2923
2924(defun edebug-adjust-window (old-start)
1fe3d507
DL
2925 ;; If pos is not visible, adjust current window to fit following context.
2926;;; (message "window: %s old-start: %s window-start: %s pos: %s"
2927;;; (selected-window) old-start (window-start) (point)) (sit-for 5)
84fc2cfa
ER
2928 (if (not (pos-visible-in-window-p))
2929 (progn
1fe3d507
DL
2930 ;; First try old-start
2931 (if old-start
2932 (set-window-start (selected-window) old-start))
84fc2cfa 2933 (if (not (pos-visible-in-window-p))
1fe3d507
DL
2934 (progn
2935;; (message "resetting window start") (sit-for 2)
2936 (set-window-start
2937 (selected-window)
2938 (save-excursion
2939 (forward-line
2940 (if (< (point) (window-start)) -1 ; one line before if in back
2941 (- (/ (window-height) 2)) ; center the line moving forward
2942 ))
2943 (beginning-of-line)
2944 (point)))))))
84fc2cfa 2945 (window-start))
1fe3d507 2946
84fc2cfa
ER
2947
2948
1fe3d507
DL
2949(defconst edebug-arrow-alist
2950 '((Continue-fast . "=")
2951 (Trace-fast . "-")
2952 (continue . ">")
2953 (trace . "->")
2954 (step . "=>")
2955 (next . "=>")
2956 (go . "<>")
2957 (Go-nonstop . "..") ; not used
2958 )
2959 "Association list of arrows for each edebug mode.")
2960
2961(defun edebug-overlay-arrow ()
2962 ;; Set up the overlay arrow at beginning-of-line in current buffer.
2963 ;; The arrow string is derived from edebug-arrow-alist and
2964 ;; edebug-execution-mode.
88668147 2965 (let ((pos (save-excursion (beginning-of-line) (point))))
1fe3d507
DL
2966 (setq overlay-arrow-string
2967 (cdr (assq edebug-execution-mode edebug-arrow-alist)))
2968 (setq overlay-arrow-position (make-marker))
2969 (set-marker overlay-arrow-position pos (current-buffer))))
84fc2cfa 2970
1fe3d507
DL
2971
2972(defun edebug-toggle-save-all-windows ()
2973 "Toggle the saving and restoring of all windows.
2974Also, each time you toggle it on, the inside and outside window
2975configurations become the same as the current configuration."
84fc2cfa 2976 (interactive)
1fe3d507
DL
2977 (setq edebug-save-windows (not edebug-save-windows))
2978 (if edebug-save-windows
84fc2cfa
ER
2979 (setq edebug-inside-windows
2980 (setq edebug-outside-windows
1fe3d507
DL
2981 (edebug-current-windows
2982 edebug-save-windows))))
2983 (message "Window saving is %s for all windows."
84fc2cfa
ER
2984 (if edebug-save-windows "on" "off")))
2985
1fe3d507
DL
2986(defmacro edebug-changing-windows (&rest body)
2987 (` (let ((window (selected-window)))
2988 (setq edebug-inside-windows (edebug-current-windows t))
2989 (edebug-set-windows edebug-outside-windows)
2990 (,@ body) ;; Code to change edebug-save-windows
2991 (setq edebug-outside-windows (edebug-current-windows
2992 edebug-save-windows))
2993 ;; Problem: what about outside windows that are deleted inside?
2994 (edebug-set-windows edebug-inside-windows))))
2995
2996(defun edebug-toggle-save-selected-window ()
2997 "Toggle the saving and restoring of the selected window.
2998Also, each time you toggle it on, the inside and outside window
2999configurations become the same as the current configuration."
3000 (interactive)
3001 (cond
3002 ((eq t edebug-save-windows)
3003 ;; Save all outside windows except the selected one.
3004 ;; Remove (selected-window) from outside-windows.
3005 (edebug-changing-windows
3006 (setq edebug-save-windows (delq window (edebug-window-list)))))
3007
3008 ((memq (selected-window) edebug-save-windows)
3009 (setq edebug-outside-windows
3010 (delq (assq (selected-window) edebug-outside-windows)
3011 edebug-outside-windows))
3012 (setq edebug-save-windows
3013 (delq (selected-window) edebug-save-windows)))
3014 (t ; Save a new window.
3015 (edebug-changing-windows
3016 (setq edebug-save-windows (cons window edebug-save-windows)))))
3017
3018 (message "Window saving is %s for %s."
3019 (if (memq (selected-window) edebug-save-windows)
3020 "on" "off")
3021 (selected-window)))
3022
3023(defun edebug-toggle-save-windows (arg)
3024 "Toggle the saving and restoring of windows.
3025With prefix, toggle for just the selected window.
3026Otherwise, toggle for all windows."
3027 (interactive "P")
3028 (if arg
3029 (edebug-toggle-save-selected-window)
3030 (edebug-toggle-save-all-windows)))
3031
84fc2cfa
ER
3032
3033(defun edebug-where ()
3034 "Show the debug windows and where we stopped in the program."
3035 (interactive)
3036 (if (not edebug-active)
1fe3d507
DL
3037 (error "Edebug is not active"))
3038 ;; Restore the window configuration to what it last was inside.
3039 ;; But it is not always set. - experiment
3040 ;;(if edebug-inside-windows
3041 ;; (edebug-set-windows edebug-inside-windows))
84fc2cfa 3042 (edebug-pop-to-buffer edebug-buffer)
1fe3d507 3043 (goto-char edebug-point))
84fc2cfa
ER
3044
3045(defun edebug-view-outside ()
3046 "Change to the outside window configuration."
3047 (interactive)
3048 (if (not edebug-active)
1fe3d507
DL
3049 (error "Edebug is not active"))
3050 (setq edebug-inside-windows
3051 (edebug-current-windows edebug-save-windows))
3052 (edebug-set-windows edebug-outside-windows)
84fc2cfa 3053 (goto-char edebug-outside-point)
1fe3d507 3054 (message "Window configuration outside of Edebug. Return with %s"
84fc2cfa
ER
3055 (substitute-command-keys "\\<global-map>\\[edebug-where]")))
3056
3057
1fe3d507
DL
3058(defun edebug-bounce-point (arg)
3059 "Bounce the point in the outside current buffer.
3060If prefix arg is supplied, sit for that many seconds before returning.
3061The default is one second."
3062 (interactive "p")
84fc2cfa 3063 (if (not edebug-active)
1fe3d507 3064 (error "Edebug is not active"))
84fc2cfa 3065 (save-excursion
1fe3d507 3066 ;; If the buffer's currently displayed, avoid set-window-configuration.
84fc2cfa
ER
3067 (save-window-excursion
3068 (edebug-pop-to-buffer edebug-outside-buffer)
84fc2cfa 3069 (goto-char edebug-outside-point)
1fe3d507
DL
3070 (message "Current buffer: %s Point: %s Mark: %s"
3071 (current-buffer) (point)
3072 (if (marker-buffer (edebug-mark-marker))
3073 (marker-position (edebug-mark-marker)) "<not set>"))
3074 (edebug-sit-for arg)
3075 (edebug-pop-to-buffer edebug-buffer (car edebug-window-data)))))
84fc2cfa 3076
84fc2cfa 3077
1fe3d507
DL
3078;; Joe Wells, here is a start at your idea of adding a buffer to the internal
3079;; display list. Still need to use this list in edebug-display.
84fc2cfa 3080
1fe3d507
DL
3081'(defvar edebug-display-buffer-list nil
3082 "List of buffers that edebug will display when it is active.")
84fc2cfa 3083
1fe3d507
DL
3084'(defun edebug-display-buffer (buffer)
3085 "Toggle display of a buffer inside of edebug."
3086 (interactive "bBuffer: ")
3087 (let ((already-displaying (memq buffer edebug-display-buffer-list)))
3088 (setq edebug-display-buffer-list
3089 (if already-displaying
3090 (delq buffer edebug-display-buffer-list)
3091 (cons buffer edebug-display-buffer-list)))
3092 (message "Displaying %s %s" buffer
3093 (if already-displaying "off" "on"))))
84fc2cfa 3094
1fe3d507 3095;;; Breakpoint related functions
84fc2cfa
ER
3096
3097(defun edebug-find-stop-point ()
1fe3d507
DL
3098 ;; Return (function . index) of the nearest edebug stop point.
3099 (let* ((edebug-def-name (edebug-form-data-symbol))
84fc2cfa 3100 (edebug-data
1fe3d507
DL
3101 (let ((data (get edebug-def-name 'edebug)))
3102 (if (or (null data) (markerp data))
3103 (error "%s is not instrumented for Edebug" edebug-def-name))
3104 data)) ; we could do it automatically, if data is a marker.
84fc2cfa 3105 ;; pull out parts of edebug-data.
1fe3d507
DL
3106 (edebug-def-mark (car edebug-data))
3107 ;; (edebug-breakpoints (car (cdr edebug-data)))
84fc2cfa 3108
1fe3d507 3109 (offset-vector (nth 2 edebug-data))
84fc2cfa
ER
3110 (offset (- (save-excursion
3111 (if (looking-at "[ \t]")
3112 ;; skip backwards until non-whitespace, or bol
3113 (skip-chars-backward " \t"))
3114 (point))
1fe3d507 3115 edebug-def-mark))
84fc2cfa
ER
3116 len i)
3117 ;; the offsets are in order so we can do a linear search
3118 (setq len (length offset-vector))
3119 (setq i 0)
3120 (while (and (< i len) (> offset (aref offset-vector i)))
3121 (setq i (1+ i)))
3122 (if (and (< i len)
3123 (<= offset (aref offset-vector i)))
3124 ;; return the relevant info
1fe3d507 3125 (cons edebug-def-name i)
84fc2cfa 3126 (message "Point is not on an expression in %s."
1fe3d507 3127 edebug-def-name)
84fc2cfa
ER
3128 )))
3129
3130
3131(defun edebug-next-breakpoint ()
3132 "Move point to the next breakpoint, or first if none past point."
3133 (interactive)
3134 (let ((edebug-stop-point (edebug-find-stop-point)))
3135 (if edebug-stop-point
1fe3d507 3136 (let* ((edebug-def-name (car edebug-stop-point))
84fc2cfa 3137 (index (cdr edebug-stop-point))
1fe3d507 3138 (edebug-data (get edebug-def-name 'edebug))
84fc2cfa
ER
3139
3140 ;; pull out parts of edebug-data
1fe3d507 3141 (edebug-def-mark (car edebug-data))
84fc2cfa 3142 (edebug-breakpoints (car (cdr edebug-data)))
1fe3d507 3143 (offset-vector (nth 2 edebug-data))
84fc2cfa
ER
3144 breakpoint)
3145 (if (not edebug-breakpoints)
3146 (message "No breakpoints in this function.")
3147 (let ((breaks edebug-breakpoints))
3148 (while (and breaks
3149 (<= (car (car breaks)) index))
3150 (setq breaks (cdr breaks)))
3151 (setq breakpoint
3152 (if breaks
3153 (car breaks)
3154 ;; goto the first breakpoint
3155 (car edebug-breakpoints)))
1fe3d507 3156 (goto-char (+ edebug-def-mark
84fc2cfa
ER
3157 (aref offset-vector (car breakpoint))))
3158
f7359658
RS
3159 (message "%s"
3160 (concat (if (nth 2 breakpoint)
84fc2cfa
ER
3161 "Temporary " "")
3162 (if (car (cdr breakpoint))
3163 (format "Condition: %s"
1fe3d507 3164 (edebug-safe-prin1-to-string
84fc2cfa
ER
3165 (car (cdr breakpoint))))
3166 "")))
3167 ))))))
3168
3169
3170(defun edebug-modify-breakpoint (flag &optional condition temporary)
3171 "Modify the breakpoint for the form at point or after it according
3172to FLAG: set if t, clear if nil. Then move to that point.
3173If CONDITION or TEMPORARY are non-nil, add those attributes to
3174the breakpoint. "
3175 (let ((edebug-stop-point (edebug-find-stop-point)))
3176 (if edebug-stop-point
1fe3d507 3177 (let* ((edebug-def-name (car edebug-stop-point))
84fc2cfa 3178 (index (cdr edebug-stop-point))
1fe3d507 3179 (edebug-data (get edebug-def-name 'edebug))
84fc2cfa
ER
3180
3181 ;; pull out parts of edebug-data
1fe3d507 3182 (edebug-def-mark (car edebug-data))
84fc2cfa 3183 (edebug-breakpoints (car (cdr edebug-data)))
1fe3d507 3184 (offset-vector (nth 2 edebug-data))
84fc2cfa
ER
3185 present)
3186 ;; delete it either way
3187 (setq present (assq index edebug-breakpoints))
3188 (setq edebug-breakpoints (delq present edebug-breakpoints))
3189 (if flag
3190 (progn
3191 ;; add it to the list and resort
3192 (setq edebug-breakpoints
3193 (edebug-sort-alist
3194 (cons
3195 (list index condition temporary)
3196 edebug-breakpoints) '<))
1fe3d507
DL
3197 (if condition
3198 (message "Breakpoint set in %s with condition: %s"
3199 edebug-def-name condition)
3200 (message "Breakpoint set in %s" edebug-def-name)))
84fc2cfa 3201 (if present
1fe3d507
DL
3202 (message "Breakpoint unset in %s" edebug-def-name)
3203 (message "No breakpoint here")))
84fc2cfa 3204
1fe3d507
DL
3205 (setcar (cdr edebug-data) edebug-breakpoints)
3206 (goto-char (+ edebug-def-mark (aref offset-vector index)))
84fc2cfa
ER
3207 ))))
3208
3209(defun edebug-set-breakpoint (arg)
3210 "Set the breakpoint of nearest sexp.
3211With prefix argument, make it a temporary breakpoint."
3212 (interactive "P")
3213 (edebug-modify-breakpoint t nil arg))
3214
3215(defun edebug-unset-breakpoint ()
3216 "Clear the breakpoint of nearest sexp."
3217 (interactive)
3218 (edebug-modify-breakpoint nil))
3219
1fe3d507
DL
3220
3221;; For emacs 18, no read-expression-history
84fc2cfa
ER
3222(defun edebug-set-conditional-breakpoint (arg condition)
3223 "Set a conditional breakpoint at nearest sexp.
3224The condition is evaluated in the outside context.
3225With prefix argument, make it a temporary breakpoint."
1fe3d507
DL
3226 ;; (interactive "P\nxCondition: ")
3227 (interactive
3228 (list
3229 current-prefix-arg
3230 ;; Edit previous condition as follows, but it is cumbersome:
3231 (let ((edebug-stop-point (edebug-find-stop-point)))
3232 (if edebug-stop-point
3233 (let* ((edebug-def-name (car edebug-stop-point))
3234 (index (cdr edebug-stop-point))
3235 (edebug-data (get edebug-def-name 'edebug))
3236 (edebug-breakpoints (car (cdr edebug-data)))
3237 (edebug-break-data (assq index edebug-breakpoints))
3238 (edebug-break-condition (car (cdr edebug-break-data))))
3239 (read-minibuffer
3240 (format "Condition in %s: " edebug-def-name)
3241 (if edebug-break-condition
3242 (format "%s" edebug-break-condition)
3243 (format ""))))))))
84fc2cfa
ER
3244 (edebug-modify-breakpoint t condition arg))
3245
1fe3d507
DL
3246
3247(defun edebug-set-global-break-condition (expression)
3248 (interactive (list (read-minibuffer
3249 "Global Condition: "
3250 (format "%s" edebug-global-break-condition))))
3251 (setq edebug-global-break-condition expression))
3252
3253
3254;;; Mode switching functions
84fc2cfa
ER
3255
3256(defun edebug-set-mode (mode shortmsg msg)
1fe3d507
DL
3257 ;; Set the edebug mode to MODE.
3258 ;; Display SHORTMSG, or MSG if not within edebug.
3259 (if (eq (1+ edebug-recursion-depth) (recursion-depth))
3260 (progn
3261 (setq edebug-execution-mode mode)
3262 (message shortmsg)
3263 ;; Continue execution
3264 (exit-recursive-edit))
3265 ;; This is not terribly useful!!
3266 (setq edebug-next-execution-mode mode)
84fc2cfa
ER
3267 (message msg)))
3268
3269
1fe3d507
DL
3270(defalias 'edebug-step-through-mode 'edebug-step-mode)
3271
3272(defun edebug-step-mode ()
3273 "Proceed to next stop point."
3274 (interactive)
3275 (edebug-set-mode 'step "" "Edebug will stop at next stop point."))
3276
3277(defun edebug-next-mode ()
3278 "Proceed to next `after' stop point."
84fc2cfa 3279 (interactive)
1fe3d507 3280 (edebug-set-mode 'next "" "Edebug will stop after next eval."))
84fc2cfa 3281
1fe3d507 3282(defun edebug-go-mode (arg)
84fc2cfa 3283 "Go, evaluating until break.
1fe3d507 3284With prefix ARG, set temporary break at current point and go."
84fc2cfa
ER
3285 (interactive "P")
3286 (if arg
3287 (edebug-set-breakpoint t))
1fe3d507 3288 (edebug-set-mode 'go "Go..." "Edebug will go until break."))
84fc2cfa 3289
1fe3d507 3290(defun edebug-Go-nonstop-mode ()
84fc2cfa
ER
3291 "Go, evaluating without debugging."
3292 (interactive)
3293 (edebug-set-mode 'Go-nonstop "Go-Nonstop..."
1fe3d507
DL
3294 "Edebug will not stop at breaks."))
3295
3296
3297(defun edebug-trace-mode ()
3298 "Begin trace mode."
3299 (interactive)
3300 (edebug-set-mode 'trace "Tracing..." "Edebug will trace with pause."))
3301
3302(defun edebug-Trace-fast-mode ()
3303 "Trace with no wait at each step."
3304 (interactive)
3305 (edebug-set-mode 'Trace-fast
3306 "Trace fast..." "Edebug will trace without pause."))
3307
3308(defun edebug-continue-mode ()
3309 "Begin continue mode."
3310 (interactive)
3311 (edebug-set-mode 'continue "Continue..."
3312 "Edebug will pause at breakpoints."))
3313
3314(defun edebug-Continue-fast-mode ()
3315 "Trace with no wait at each step."
3316 (interactive)
3317 (edebug-set-mode 'Continue-fast "Continue fast..."
3318 "Edebug will stop and go at breakpoints."))
3319
3320;; ------------------------------------------------------------
3321;; The following use the mode changing commands and breakpoints.
3322
3323
3324(defun edebug-goto-here ()
3325 "Proceed to this stop point."
3326 (interactive)
3327 (edebug-go-mode t))
3328
3329
3330(defun edebug-stop ()
3331 "Stop execution and do not continue.
3332Useful for exiting from trace or continue loop."
3333 (interactive)
3334 (message "Stop"))
3335
3336
3337'(defun edebug-forward ()
3338 "Proceed to the exit of the next expression to be evaluated."
3339 (interactive)
3340 (edebug-set-mode
3341 'forward "Forward"
3342 "Edebug will stop after exiting the next expression."))
3343
84fc2cfa
ER
3344
3345(defun edebug-forward-sexp (arg)
3346 "Proceed from the current point to the end of the ARGth sexp ahead.
3347If there are not ARG sexps ahead, then do edebug-step-out."
3348 (interactive "p")
1fe3d507 3349 (condition-case nil
84fc2cfa
ER
3350 (let ((parse-sexp-ignore-comments t))
3351 ;; Call forward-sexp repeatedly until done or failure.
3352 (forward-sexp arg)
1fe3d507 3353 (edebug-go-mode t))
84fc2cfa
ER
3354 (error
3355 (edebug-step-out)
3356 )))
3357
3358(defun edebug-step-out ()
3359 "Proceed from the current point to the end of the containing sexp.
3360If there is no containing sexp that is not the top level defun,
3361go to the end of the last sexp, or if that is the same point, then step."
3362 (interactive)
1fe3d507 3363 (condition-case nil
84fc2cfa
ER
3364 (let ((parse-sexp-ignore-comments t))
3365 (up-list 1)
3366 (save-excursion
3367 ;; Is there still a containing expression?
3368 (up-list 1))
1fe3d507 3369 (edebug-go-mode t))
84fc2cfa
ER
3370 (error
3371 ;; At top level - 1, so first check if there are more sexps at this level.
3372 (let ((start-point (point)))
3373;; (up-list 1)
3374 (down-list -1)
3375 (if (= (point) start-point)
1fe3d507
DL
3376 (edebug-step-mode) ; No more at this level, so step.
3377 (edebug-go-mode t)
84fc2cfa
ER
3378 )))))
3379
1fe3d507
DL
3380(defun edebug-instrument-function (func)
3381 ;; Func should be a function symbol.
3382 ;; Return the function symbol, or nil if not instrumented.
3383 (let ((func-marker))
3384 (setq func-marker (get func 'edebug))
3385 (cond
3386 ((markerp func-marker)
3387 ;; It is uninstrumented, so instrument it.
3388 (save-excursion
3389 (set-buffer (marker-buffer func-marker))
3390 (goto-char func-marker)
3391 (edebug-eval-top-level-form)
3392 func))
3393 ((consp func-marker)
3394 (message "%s is already instrumented." func)
3395 func)
3396 (t
3397 ;; We could try harder, e.g. do a tags search.
3398 (error "Don't know where %s is defined" func)
3399 nil))))
3400
3401(defun edebug-instrument-callee ()
3402 "Instrument the definition of the function or macro about to be called.
3403Do this when stopped before the form or it will be too late.
3404One side effect of using this command is that the next time the
3405function or macro is called, Edebug will be called there as well."
84fc2cfa 3406 (interactive)
1fe3d507
DL
3407 (if (not (looking-at "\("))
3408 (error "You must be before a list form")
3409 (let ((func
3410 (save-excursion
3411 (down-list 1)
3412 (if (looking-at "\(")
3413 (edebug-form-data-name
3414 (edebug-get-form-data-entry (point)))
88668147 3415 (edebug-original-read (current-buffer))))))
1fe3d507 3416 (edebug-instrument-function func))))
84fc2cfa 3417
84fc2cfa 3418
1fe3d507
DL
3419(defun edebug-step-in ()
3420 "Step into the definition of the function or macro about to be called.
3421This first does `edebug-instrument-callee' to ensure that it is
3422instrumented. Then it does `edebug-on-entry' and switches to `go' mode."
84fc2cfa 3423 (interactive)
1fe3d507
DL
3424 (let ((func (edebug-instrument-callee)))
3425 (if func
3426 (progn
3427 (edebug-on-entry func 'temp)
3428 (edebug-go-mode nil)))))
84fc2cfa 3429
1fe3d507
DL
3430(defun edebug-on-entry (function &optional flag)
3431 "Cause Edebug to stop when FUNCTION is called.
3432With prefix argument, make this temporary so it is automatically
3433cancelled the first time the function is entered."
3434 (interactive "aEdebug on entry to: \nP")
3435 ;; Could store this in the edebug data instead.
3436 (put function 'edebug-on-entry (if flag 'temp t)))
84fc2cfa 3437
1fe3d507
DL
3438(defun cancel-edebug-on-entry (function)
3439 (interactive "aEdebug on entry to: ")
3440 (put function 'edebug-on-entry nil))
84fc2cfa 3441
1fe3d507 3442
88668147
DL
3443(if (not (fboundp 'edebug-original-debug-on-entry))
3444 (fset 'edebug-original-debug-on-entry (symbol-function 'debug-on-entry)))
1fe3d507
DL
3445'(fset 'debug-on-entry 'edebug-debug-on-entry) ;; Should we do this?
3446;; Also need edebug-cancel-debug-on-entry
3447
3448'(defun edebug-debug-on-entry (function)
3449 "Request FUNCTION to invoke debugger each time it is called.
3450If the user continues, FUNCTION's execution proceeds.
3451Works by modifying the definition of FUNCTION,
3452which must be written in Lisp, not predefined.
3453Use `cancel-debug-on-entry' to cancel the effect of this command.
3454Redefining FUNCTION also does that.
3455
3456This version is from Edebug. If the function is instrumented for
3457Edebug, it calls `edebug-on-entry'"
3458 (interactive "aDebug on entry (to function): ")
3459 (let ((func-data (get function 'edebug)))
3460 (if (or (null func-data) (markerp func-data))
88668147 3461 (edebug-original-debug-on-entry function)
1fe3d507
DL
3462 (edebug-on-entry function))))
3463
3464
3465(defun edebug-top-level-nonstop ()
3466 "Set mode to Go-nonstop, and exit to top-level.
3467This is useful for exiting even if unwind-protect code may be executed."
84fc2cfa 3468 (interactive)
1fe3d507
DL
3469 (setq edebug-execution-mode 'Go-nonstop)
3470 (top-level))
84fc2cfa
ER
3471
3472
3473;;(defun edebug-exit-out ()
3474;; "Go until the current function exits."
3475;; (interactive)
3476;; (edebug-set-mode 'exiting "Exit..."))
3477
3478
84fc2cfa
ER
3479;;; The following initial mode setting definitions are not used yet.
3480
1fe3d507 3481'(defconst edebug-initial-mode-alist
84fc2cfa
ER
3482 '((edebug-Continue-fast . Continue-fast)
3483 (edebug-Trace-fast . Trace-fast)
3484 (edebug-continue . continue)
3485 (edebug-trace . trace)
3486 (edebug-go . go)
3487 (edebug-step-through . step)
3488 (edebug-Go-nonstop . Go-nonstop)
3489 )
3490 "Association list between commands and the modes they set.")
3491
3492
1fe3d507 3493'(defun edebug-set-initial-mode ()
84fc2cfa
ER
3494 "Ask for the initial mode of the enclosing function.
3495The mode is requested via the key that would be used to set the mode in
3496edebug-mode."
3497 (interactive)
3498 (let* ((this-function (edebug-which-function))
3499 (keymap (if (eq edebug-mode-map (current-local-map))
3500 edebug-mode-map))
3501 (old-mode (or (get this-function 'edebug-initial-mode)
3502 edebug-initial-mode))
3503 (key (read-key-sequence
3504 (format
3505 "Change initial edebug mode for %s from %s (%s) to (enter key): "
3506 this-function
3507 old-mode
3508 (where-is-internal
3509 (car (rassq old-mode edebug-initial-mode-alist))
3510 keymap 'firstonly
3511 ))))
3512 (mode (cdr (assq (key-binding key) edebug-initial-mode-alist)))
3513 )
3514 (if (and mode
3515 (or (get this-function 'edebug-initial-mode)
3516 (not (eq mode edebug-initial-mode))))
3517 (progn
3518 (put this-function 'edebug-initial-mode mode)
3519 (message "Initial mode for %s is now: %s"
3520 this-function mode))
4897b0a0 3521 (error "Key must map to one of the mode changing commands")
84fc2cfa
ER
3522 )))
3523
1fe3d507 3524;;; Evaluation of expressions
84fc2cfa 3525
1fe3d507 3526(def-edebug-spec edebug-outside-excursion t)
84fc2cfa 3527
1fe3d507
DL
3528(defmacro edebug-outside-excursion (&rest body)
3529 "Evaluate an expression list in the outside context.
3530Return the result of the last expression."
3531 (` (save-excursion ; of current-buffer
3532 (if edebug-save-windows
3533 (progn
3534 ;; After excursion, we will
3535 ;; restore to current window configuration.
3536 (setq edebug-inside-windows
3537 (edebug-current-windows edebug-save-windows))
3538 ;; Restore outside windows.
3539 (edebug-set-windows edebug-outside-windows)))
3540
3541 (set-buffer edebug-buffer) ; why?
3542 ;; (use-local-map edebug-outside-map)
3543 (store-match-data edebug-outside-match-data)
3544 ;; Restore outside context.
3545 (let (;; (edebug-inside-map (current-local-map)) ;; restore map??
3546 (last-command-char edebug-outside-last-command-char)
3547 (last-command-event edebug-outside-last-command-event)
3548 (last-command edebug-outside-last-command)
3549 (this-command edebug-outside-this-command)
3550 (unread-command-char edebug-outside-unread-command-char)
3551 (unread-command-event edebug-outside-unread-command-event)
3552 (unread-command-events edebug-outside-unread-command-events)
3553 (last-input-char edebug-outside-last-input-char)
3554 (last-input-event edebug-outside-last-input-event)
3555 (last-event-frame edebug-outside-last-event-frame)
3556 (last-nonmenu-event edebug-outside-last-nonmenu-event)
3557 (track-mouse edebug-outside-track-mouse)
1fe3d507
DL
3558 (standard-output edebug-outside-standard-output)
3559 (standard-input edebug-outside-standard-input)
88668147 3560
efcf38c7 3561 (executing-kbd-macro edebug-outside-executing-macro)
1fe3d507 3562 (defining-kbd-macro edebug-outside-defining-kbd-macro)
88668147
DL
3563 (pre-command-hook edebug-outside-pre-command-hook)
3564 (post-command-hook edebug-outside-post-command-hook)
3565
3566 ;; See edebug-display
3567 (overlay-arrow-position edebug-outside-o-a-p)
3568 (overlay-arrow-string edebug-outside-o-a-s)
3569 (cursor-in-echo-area edebug-outside-c-i-e-a)
1fe3d507
DL
3570 )
3571 (unwind-protect
3572 (save-excursion ; of edebug-buffer
3573 (set-buffer edebug-outside-buffer)
3574 (goto-char edebug-outside-point)
3575 (if (marker-buffer (edebug-mark-marker))
3576 (set-marker (edebug-mark-marker) edebug-outside-mark))
3577 (,@ body))
3578
3579 ;; Back to edebug-buffer. Restore rest of inside context.
3580 ;; (use-local-map edebug-inside-map)
3581 (if edebug-save-windows
3582 ;; Restore inside windows.
3583 (edebug-set-windows edebug-inside-windows))
88668147
DL
3584
3585 ;; Save values that may have been changed.
3586 (setq
3587 edebug-outside-last-command-char last-command-char
3588 edebug-outside-last-command-event last-command-event
3589 edebug-outside-last-command last-command
3590 edebug-outside-this-command this-command
3591 edebug-outside-unread-command-char unread-command-char
3592 edebug-outside-unread-command-event unread-command-event
3593 edebug-outside-unread-command-events unread-command-events
3594 edebug-outside-last-input-char last-input-char
3595 edebug-outside-last-input-event last-input-event
3596 edebug-outside-last-event-frame last-event-frame
3597 edebug-outside-last-nonmenu-event last-nonmenu-event
3598 edebug-outside-track-mouse track-mouse
3599 edebug-outside-standard-output standard-output
3600 edebug-outside-standard-input standard-input
3601
efcf38c7 3602 edebug-outside-executing-macro executing-kbd-macro
88668147
DL
3603 edebug-outside-defining-kbd-macro defining-kbd-macro
3604 edebug-outside-pre-command-hook pre-command-hook
3605 edebug-outside-post-command-hook post-command-hook
3606
3607 edebug-outside-o-a-p overlay-arrow-position
3608 edebug-outside-o-a-s overlay-arrow-string
3609 edebug-outside-c-i-e-a cursor-in-echo-area
3610 ))) ; let
1fe3d507
DL
3611 )))
3612
3613(defvar cl-debug-env nil) ;; defined in cl; non-nil when lexical env used.
3614
3615(defun edebug-eval (edebug-expr)
3616 ;; Are there cl lexical variables active?
3617 (if cl-debug-env
3618 (eval (cl-macroexpand-all edebug-expr cl-debug-env))
3619 (eval edebug-expr)))
3620
3621(defun edebug-safe-eval (edebug-expr)
3622 ;; Evaluate EXPR safely.
3623 ;; If there is an error, a string is returned describing the error.
3624 (condition-case edebug-err
3625 (edebug-eval edebug-expr)
3626 (error (edebug-format "%s: %s" ;; could
3627 (get (car edebug-err) 'error-message)
3628 (car (cdr edebug-err))))))
3629
f7359658
RS
3630;;; Printing
3631
1fe3d507
DL
3632;; Replace printing functions.
3633
3634;; obsolete names
3635(defalias 'edebug-install-custom-print-funcs 'edebug-install-custom-print)
3636(defalias 'edebug-reset-print-funcs 'edebug-uninstall-custom-print)
3637(defalias 'edebug-uninstall-custom-print-funcs 'edebug-uninstall-custom-print)
3638
3639(defun edebug-install-custom-print ()
3640 "Replace print functions used by Edebug with custom versions."
3641 ;; Modifying the custom print functions, or changing print-length,
3642 ;; print-level, print-circle, custom-print-list or custom-print-vector
3643 ;; have immediate effect.
84fc2cfa 3644 (interactive)
1fe3d507
DL
3645 (require 'cust-print)
3646 (defalias 'edebug-prin1 'custom-prin1)
3647 (defalias 'edebug-print 'custom-print)
3648 (defalias 'edebug-prin1-to-string 'custom-prin1-to-string)
3649 (defalias 'edebug-format 'custom-format)
3650 (defalias 'edebug-message 'custom-message)
3651 "Installed")
3652
3653(eval-and-compile
3654 (defun edebug-uninstall-custom-print ()
3655 "Replace edebug custom print functions with internal versions."
3656 (interactive)
3657 (defalias 'edebug-prin1 'prin1)
3658 (defalias 'edebug-print 'print)
3659 (defalias 'edebug-prin1-to-string 'prin1-to-string)
3660 (defalias 'edebug-format 'format)
3661 (defalias 'edebug-message 'message)
3662 "Uninstalled")
3663
3664 ;; Default print functions are the same as Emacs'.
3665 (edebug-uninstall-custom-print))
3666
3667
3668(defun edebug-report-error (edebug-value)
3669 ;; Print an error message like command level does.
3670 ;; This also prints the error name if it has no error-message.
3671 (message "%s: %s"
3672 (or (get (car edebug-value) 'error-message)
3673 (format "peculiar error (%s)" (car edebug-value)))
3674 (mapconcat (function (lambda (edebug-arg)
3675 ;; continuing after an error may
3676 ;; complain about edebug-arg. why??
3677 (prin1-to-string edebug-arg)))
3678 (cdr edebug-value) ", ")))
3679
3680;; Define here in case they are not already defined.
3681(defvar print-level nil)
3682(defvar print-circle nil)
3683(defvar print-readably) ;; defined by lemacs
3684;; Alternatively, we could change the definition of
88668147 3685;; edebug-safe-prin1-to-string to only use these if defined.
1fe3d507
DL
3686
3687(defun edebug-safe-prin1-to-string (value)
84fc2cfa 3688 (let ((print-escape-newlines t)
1fe3d507
DL
3689 (print-length (or edebug-print-length print-length))
3690 (print-level (or edebug-print-level print-level))
3691 (print-circle (or edebug-print-circle print-circle))
3692 (print-readably nil)) ;; lemacs uses this.
3693 (edebug-prin1-to-string value)))
3694
3695(defun edebug-compute-previous-result (edebug-previous-value)
3696 (setq edebug-previous-result
3697 (if (and (numberp edebug-previous-value)
3698 (< edebug-previous-value 256)
3699 (>= edebug-previous-value 0))
3700 (format "Result: %s = %s" edebug-previous-value
3701 (single-key-description edebug-previous-value))
3702 (if edebug-unwrap-results
3703 (setq edebug-previous-value
3704 (edebug-unwrap* edebug-previous-value)))
3705 (concat "Result: "
3706 (edebug-safe-prin1-to-string edebug-previous-value)))))
84fc2cfa 3707
1fe3d507
DL
3708(defun edebug-previous-result ()
3709 "Print the previous result."
3710 (interactive)
3711 (message "%s" edebug-previous-result))
84fc2cfa 3712
f7359658 3713;;; Read, Eval and Print
84fc2cfa 3714
1fe3d507
DL
3715(defun edebug-eval-expression (edebug-expr)
3716 "Evaluate an expression in the outside environment.
3717If interactive, prompt for the expression.
84fc2cfa
ER
3718Print result in minibuffer."
3719 (interactive "xEval: ")
1fe3d507
DL
3720 (princ
3721 (edebug-outside-excursion
3722 (setq values (cons (edebug-eval edebug-expr) values))
3723 (edebug-safe-prin1-to-string (car values)))))
84fc2cfa
ER
3724
3725(defun edebug-eval-last-sexp ()
3726 "Evaluate sexp before point in the outside environment;
3727print value in minibuffer."
3728 (interactive)
1fe3d507 3729 (edebug-eval-expression (edebug-last-sexp)))
84fc2cfa
ER
3730
3731(defun edebug-eval-print-last-sexp ()
3732 "Evaluate sexp before point in the outside environment;
3733print value into current buffer."
3734 (interactive)
1fe3d507
DL
3735 (let* ((edebug-form (edebug-last-sexp))
3736 (edebug-result-string
3737 (edebug-outside-excursion
3738 (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form))))
3739 (standard-output (current-buffer)))
3740 (princ "\n")
3741 ;; princ the string to get rid of quotes.
3742 (princ edebug-result-string)
3743 (princ "\n")
3744 ))
3745
f7359658 3746;;; Edebug Minor Mode
84fc2cfa 3747
1fe3d507
DL
3748;; Global GUD bindings for all emacs-lisp-mode buffers.
3749(define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode)
3750(define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode)
3751(define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode)
3752(define-key emacs-lisp-mode-map "\C-x\C-a\C-l" 'edebug-where)
3753
84fc2cfa
ER
3754
3755(defvar edebug-mode-map nil)
3756(if edebug-mode-map
3757 nil
3758 (progn
3759 (setq edebug-mode-map (copy-keymap emacs-lisp-mode-map))
3760 ;; control
1fe3d507
DL
3761 (define-key edebug-mode-map " " 'edebug-step-mode)
3762 (define-key edebug-mode-map "n" 'edebug-next-mode)
3763 (define-key edebug-mode-map "g" 'edebug-go-mode)
3764 (define-key edebug-mode-map "G" 'edebug-Go-nonstop-mode)
3765 (define-key edebug-mode-map "t" 'edebug-trace-mode)
3766 (define-key edebug-mode-map "T" 'edebug-Trace-fast-mode)
3767 (define-key edebug-mode-map "c" 'edebug-continue-mode)
3768 (define-key edebug-mode-map "C" 'edebug-Continue-fast-mode)
3769
3770 ;;(define-key edebug-mode-map "f" 'edebug-forward) not implemented
84fc2cfa
ER
3771 (define-key edebug-mode-map "f" 'edebug-forward-sexp)
3772 (define-key edebug-mode-map "h" 'edebug-goto-here)
3773
1fe3d507 3774 (define-key edebug-mode-map "I" 'edebug-instrument-callee)
84fc2cfa
ER
3775 (define-key edebug-mode-map "i" 'edebug-step-in)
3776 (define-key edebug-mode-map "o" 'edebug-step-out)
3777
1fe3d507 3778 ;; quitting and stopping
84fc2cfa 3779 (define-key edebug-mode-map "q" 'top-level)
1fe3d507 3780 (define-key edebug-mode-map "Q" 'edebug-top-level-nonstop)
84fc2cfa
ER
3781 (define-key edebug-mode-map "a" 'abort-recursive-edit)
3782 (define-key edebug-mode-map "S" 'edebug-stop)
3783
3784 ;; breakpoints
3785 (define-key edebug-mode-map "b" 'edebug-set-breakpoint)
3786 (define-key edebug-mode-map "u" 'edebug-unset-breakpoint)
3787 (define-key edebug-mode-map "B" 'edebug-next-breakpoint)
3788 (define-key edebug-mode-map "x" 'edebug-set-conditional-breakpoint)
1fe3d507 3789 (define-key edebug-mode-map "X" 'edebug-set-global-break-condition)
84fc2cfa
ER
3790
3791 ;; evaluation
1fe3d507 3792 (define-key edebug-mode-map "r" 'edebug-previous-result)
84fc2cfa
ER
3793 (define-key edebug-mode-map "e" 'edebug-eval-expression)
3794 (define-key edebug-mode-map "\C-x\C-e" 'edebug-eval-last-sexp)
3795 (define-key edebug-mode-map "E" 'edebug-visit-eval-list)
3796
3797 ;; views
3798 (define-key edebug-mode-map "w" 'edebug-where)
1fe3d507 3799 (define-key edebug-mode-map "v" 'edebug-view-outside) ;; maybe obsolete??
84fc2cfa 3800 (define-key edebug-mode-map "p" 'edebug-bounce-point)
1fe3d507 3801 (define-key edebug-mode-map "P" 'edebug-view-outside) ;; same as v
84fc2cfa 3802 (define-key edebug-mode-map "W" 'edebug-toggle-save-windows)
1fe3d507 3803
84fc2cfa
ER
3804 ;; misc
3805 (define-key edebug-mode-map "?" 'edebug-help)
3806 (define-key edebug-mode-map "d" 'edebug-backtrace)
3807
3808 (define-key edebug-mode-map "-" 'negative-argument)
1fe3d507
DL
3809
3810 ;; statistics
3811 (define-key edebug-mode-map "=" 'edebug-temp-display-freq-count)
3812
3813 ;; GUD bindings
3814 (define-key edebug-mode-map "\C-c\C-s" 'edebug-step-mode)
3815 (define-key edebug-mode-map "\C-c\C-n" 'edebug-next-mode)
3816 (define-key edebug-mode-map "\C-c\C-c" 'edebug-go-mode)
3817
3818 (define-key edebug-mode-map "\C-x " 'edebug-set-breakpoint)
3819 (define-key edebug-mode-map "\C-c\C-d" 'edebug-unset-breakpoint)
3820 (define-key edebug-mode-map "\C-c\C-t"
3821 (function (lambda () (edebug-set-breakpoint t))))
3822 (define-key edebug-mode-map "\C-c\C-l" 'edebug-where)
84fc2cfa
ER
3823 ))
3824
1fe3d507
DL
3825;; Autoloading these global bindings doesn't make sense because
3826;; they cannot be used anyway unless Edebug is already loaded and active.
3827
84fc2cfa
ER
3828(defvar global-edebug-prefix "\^XX"
3829 "Prefix key for global edebug commands, available from any buffer.")
3830
3831(defvar global-edebug-map nil
3832 "Global map of edebug commands, available from any buffer.")
3833
3834(if global-edebug-map
3835 nil
3836 (setq global-edebug-map (make-sparse-keymap))
3837
3838 (global-unset-key global-edebug-prefix)
3839 (global-set-key global-edebug-prefix global-edebug-map)
3840
1fe3d507
DL
3841 (define-key global-edebug-map " " 'edebug-step-mode)
3842 (define-key global-edebug-map "g" 'edebug-go-mode)
3843 (define-key global-edebug-map "G" 'edebug-Go-nonstop-mode)
3844 (define-key global-edebug-map "t" 'edebug-trace-mode)
3845 (define-key global-edebug-map "T" 'edebug-Trace-fast-mode)
3846 (define-key global-edebug-map "c" 'edebug-continue-mode)
3847 (define-key global-edebug-map "C" 'edebug-Continue-fast-mode)
3848
3849 ;; breakpoints
84fc2cfa 3850 (define-key global-edebug-map "b" 'edebug-set-breakpoint)
84fc2cfa 3851 (define-key global-edebug-map "u" 'edebug-unset-breakpoint)
1fe3d507
DL
3852 (define-key global-edebug-map "x" 'edebug-set-conditional-breakpoint)
3853 (define-key global-edebug-map "X" 'edebug-set-global-break-condition)
3854
3855 ;; views
84fc2cfa 3856 (define-key global-edebug-map "w" 'edebug-where)
1fe3d507
DL
3857 (define-key global-edebug-map "W" 'edebug-toggle-save-windows)
3858
3859 ;; quitting
84fc2cfa 3860 (define-key global-edebug-map "q" 'top-level)
1fe3d507
DL
3861 (define-key global-edebug-map "Q" 'edebug-top-level-nonstop)
3862 (define-key global-edebug-map "a" 'abort-recursive-edit)
84fc2cfa 3863
1fe3d507
DL
3864 ;; statistics
3865 (define-key global-edebug-map "=" 'edebug-display-freq-count)
3866 )
84fc2cfa
ER
3867
3868(defun edebug-help ()
3869 (interactive)
3870 (describe-function 'edebug-mode))
3871
84fc2cfa 3872(defun edebug-mode ()
1fe3d507
DL
3873 "Mode for Emacs Lisp buffers while in Edebug.
3874
3875In addition to all Emacs Lisp commands (except those that modify the
3876buffer) there are local and global key bindings to several Edebug
3877specific commands. E.g. `edebug-step-mode' is bound to \\[edebug-step-mode]
3878in the Edebug buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
84fc2cfa 3879
1fe3d507 3880Also see bindings for the eval list buffer, *edebug*.
84fc2cfa 3881
1fe3d507 3882The edebug buffer commands:
84fc2cfa
ER
3883\\{edebug-mode-map}
3884
1fe3d507 3885Global commands prefixed by `global-edebug-prefix':
84fc2cfa
ER
3886\\{global-edebug-map}
3887
3888Options:
1fe3d507
DL
3889edebug-setup-hook
3890edebug-all-defs
3891edebug-all-forms
84fc2cfa 3892edebug-save-windows
1fe3d507 3893edebug-save-displayed-buffer-points
84fc2cfa
ER
3894edebug-initial-mode
3895edebug-trace
1fe3d507
DL
3896edebug-test-coverage
3897edebug-continue-kbd-macro
3898edebug-print-length
3899edebug-print-level
3900edebug-print-circle
3901edebug-on-error
3902edebug-on-quit
3903edebug-on-signal
3904edebug-unwrap-results
3905edebug-global-break-condition
84fc2cfa
ER
3906"
3907 (use-local-map edebug-mode-map))
3908
f7359658 3909;;; edebug eval list mode
84fc2cfa 3910
1fe3d507 3911;; A list of expressions and their evaluations is displayed in *edebug*.
84fc2cfa
ER
3912
3913(defun edebug-eval-result-list ()
3914 "Return a list of evaluations of edebug-eval-list"
3915 ;; Assumes in outside environment.
88668147
DL
3916 ;; Don't do any edebug things now.
3917 (let ((edebug-execution-mode 'Go-nonstop)
3918 (edebug-trace nil))
3919 (mapcar 'edebug-safe-eval edebug-eval-list)))
84fc2cfa
ER
3920
3921(defun edebug-eval-display-list (edebug-eval-result-list)
3922 ;; Assumes edebug-eval-buffer exists.
3923 (let ((edebug-eval-list-temp edebug-eval-list)
3924 (standard-output edebug-eval-buffer)
1fe3d507 3925 (edebug-comment-line
84fc2cfa 3926 (format ";%s\n" (make-string (- (window-width) 2) ?-))))
1fe3d507 3927 (set-buffer edebug-eval-buffer)
84fc2cfa
ER
3928 (erase-buffer)
3929 (while edebug-eval-list-temp
3930 (prin1 (car edebug-eval-list-temp)) (terpri)
3931 (prin1 (car edebug-eval-result-list)) (terpri)
1fe3d507 3932 (princ edebug-comment-line)
84fc2cfa
ER
3933 (setq edebug-eval-list-temp (cdr edebug-eval-list-temp))
3934 (setq edebug-eval-result-list (cdr edebug-eval-result-list)))
1fe3d507 3935 (edebug-pop-to-buffer edebug-eval-buffer)
84fc2cfa
ER
3936 ))
3937
3938(defun edebug-create-eval-buffer ()
3939 (if (not (and edebug-eval-buffer (buffer-name edebug-eval-buffer)))
3940 (progn
3941 (set-buffer (setq edebug-eval-buffer (get-buffer-create "*edebug*")))
3942 (edebug-eval-mode))))
3943
3944;; Should generalize this to be callable outside of edebug
3945;; with calls in user functions, e.g. (edebug-eval-display)
3946
3947(defun edebug-eval-display (edebug-eval-result-list)
3948 "Display expressions and evaluations in EVAL-LIST.
3949It modifies the context by popping up the eval display."
3950 (if edebug-eval-result-list
3951 (progn
3952 (edebug-create-eval-buffer)
84fc2cfa
ER
3953 (edebug-eval-display-list edebug-eval-result-list)
3954 )))
3955
3956(defun edebug-eval-redisplay ()
3957 "Redisplay eval list in outside environment.
3958May only be called from within edebug-recursive-edit."
3959 (edebug-create-eval-buffer)
84fc2cfa
ER
3960 (edebug-outside-excursion
3961 (edebug-eval-display-list (edebug-eval-result-list))
3962 ))
3963
3964(defun edebug-visit-eval-list ()
3965 (interactive)
3966 (edebug-eval-redisplay)
3967 (edebug-pop-to-buffer edebug-eval-buffer))
3968
3969
3970(defun edebug-update-eval-list ()
3971 "Replace the evaluation list with the sexps now in the eval buffer."
3972 (interactive)
3973 (let ((starting-point (point))
3974 new-list)
3975 (goto-char (point-min))
3976 ;; get the first expression
3977 (edebug-skip-whitespace)
3978 (if (not (eobp))
3979 (progn
3980 (forward-sexp 1)
3981 (setq new-list (cons (edebug-last-sexp) new-list))))
3982
3983 (while (re-search-forward "^;" nil t)
3984 (forward-line 1)
3985 (skip-chars-forward " \t\n\r")
3986 (if (and (/= ?\; (following-char))
3987 (not (eobp)))
3988 (progn
3989 (forward-sexp 1)
3990 (setq new-list (cons (edebug-last-sexp) new-list)))))
3991
3992 (setq edebug-eval-list (nreverse new-list))
3993 (edebug-eval-redisplay)
3994 (goto-char starting-point)))
3995
3996
3997(defun edebug-delete-eval-item ()
3998 "Delete the item under point and redisplay."
3999 ;; could add arg to do repeatedly
4000 (interactive)
4001 (if (re-search-backward "^;" nil 'nofail)
4002 (forward-line 1))
4003 (delete-region
4004 (point) (progn (re-search-forward "^;" nil 'nofail)
4005 (beginning-of-line)
4006 (point)))
4007 (edebug-update-eval-list))
4008
4009
4010
4011(defvar edebug-eval-mode-map nil
4012 "Keymap for edebug-eval-mode. Superset of lisp-interaction-mode.")
4013
4014(if edebug-eval-mode-map
4015 nil
4016 (setq edebug-eval-mode-map (copy-keymap lisp-interaction-mode-map))
4017
4018 (define-key edebug-eval-mode-map "\C-c\C-w" 'edebug-where)
4019 (define-key edebug-eval-mode-map "\C-c\C-d" 'edebug-delete-eval-item)
4020 (define-key edebug-eval-mode-map "\C-c\C-u" 'edebug-update-eval-list)
4021 (define-key edebug-eval-mode-map "\C-x\C-e" 'edebug-eval-last-sexp)
4022 (define-key edebug-eval-mode-map "\C-j" 'edebug-eval-print-last-sexp)
4023 )
4024
4025
4026(defun edebug-eval-mode ()
1fe3d507
DL
4027 "Mode for evaluation list buffer while in Edebug.
4028
4029In addition to all Interactive Emacs Lisp commands there are local and
4030global key bindings to several Edebug specific commands. E.g.
4031`edebug-step-mode' is bound to \\[edebug-step-mode] in the Edebug
4032buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
84fc2cfa
ER
4033
4034Eval list buffer commands:
4035\\{edebug-eval-mode-map}
4036
1fe3d507 4037Global commands prefixed by global-edebug-prefix:
84fc2cfa
ER
4038\\{global-edebug-map}
4039"
4040 (lisp-interaction-mode)
4041 (setq major-mode 'edebug-eval-mode)
4042 (setq mode-name "Edebug-Eval")
4043 (use-local-map edebug-eval-mode-map))
4044
f7359658 4045;;; Interface with standard debugger.
84fc2cfa 4046
1fe3d507
DL
4047;; (setq debugger 'edebug) ; to use the edebug debugger
4048;; (setq debugger 'debug) ; use the standard debugger
84fc2cfa 4049
1fe3d507
DL
4050;; Note that debug and its utilities must be byte-compiled to work,
4051;; since they depend on the backtrace looking a certain way. But
4052;; edebug is not dependent on this, yet.
84fc2cfa 4053
1fe3d507 4054(defun edebug (&optional edebug-arg-mode &rest debugger-args)
84fc2cfa 4055 "Replacement for debug.
1fe3d507 4056If we are running an edebugged function,
84fc2cfa 4057show where we last were. Otherwise call debug normally."
1fe3d507
DL
4058;; (message "entered: %s depth: %s edebug-recursion-depth: %s"
4059;; edebug-entered (recursion-depth) edebug-recursion-depth) (sit-for 1)
4060 (if (and edebug-entered ; anything active?
4061 (eq (recursion-depth) edebug-recursion-depth))
4062 (let (;; Where were we before the error occurred?
4063 (edebug-offset-index (car edebug-offset-indices))
4064 ;; Bind variables required by edebug-display
4065 (edebug-value (car debugger-args))
4066 edebug-breakpoints
4067 edebug-break-data
4068 edebug-break-condition
4069 edebug-global-break
4070 (edebug-break (null edebug-arg-mode)) ;; if called explicitly
4071 )
84fc2cfa 4072 (edebug-display)
1fe3d507
DL
4073 (if (eq edebug-arg-mode 'error)
4074 nil
4075 edebug-value))
84fc2cfa
ER
4076
4077 ;; Otherwise call debug normally.
4078 ;; Still need to remove extraneous edebug calls from stack.
1fe3d507 4079 (apply 'debug edebug-arg-mode debugger-args)
84fc2cfa
ER
4080 ))
4081
4082
4083(defun edebug-backtrace ()
4084 "Display a non-working backtrace. Better than nothing..."
4085 (interactive)
1fe3d507
DL
4086 (if (or (not edebug-backtrace-buffer)
4087 (null (buffer-name edebug-backtrace-buffer)))
4088 (setq edebug-backtrace-buffer
4089 (generate-new-buffer "*Backtrace*"))
4090 ;; else, could just display edebug-backtrace-buffer
4091 )
4092 (with-output-to-temp-buffer (buffer-name edebug-backtrace-buffer)
4093 (setq edebug-backtrace-buffer standard-output)
4094 (let ((print-escape-newlines t)
84fc2cfa 4095 (print-length 50)
1fe3d507 4096 last-ok-point)
84fc2cfa
ER
4097 (backtrace)
4098
1fe3d507
DL
4099 ;; Clean up the backtrace.
4100 ;; Not quite right for current edebug scheme.
4101 (set-buffer edebug-backtrace-buffer)
4102 (setq truncate-lines t)
84fc2cfa 4103 (goto-char (point-min))
84fc2cfa 4104 (setq last-ok-point (point))
1fe3d507 4105 (if t (progn
84fc2cfa
ER
4106
4107 ;; Delete interspersed edebug internals.
1fe3d507
DL
4108 (while (re-search-forward "^ \(?edebug" nil t)
4109 (beginning-of-line)
4110 (cond
4111 ((looking-at "^ \(edebug-after")
4112 ;; Previous lines may contain code, so just delete this line
4113 (setq last-ok-point (point))
4114 (forward-line 1)
4115 (delete-region last-ok-point (point)))
4116
4117 ((looking-at "^ edebug")
4118 (forward-line 1)
4119 (delete-region last-ok-point (point))
4120 )))
4121 )))))
84fc2cfa
ER
4122
4123\f
f7359658 4124;;; Trace display
84fc2cfa
ER
4125
4126(defun edebug-trace-display (buf-name fmt &rest args)
4127 "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
4128The buffer is created if it does not exist.
1fe3d507
DL
4129You must include newlines in FMT to break lines, but one newline is appended."
4130;; e.g.
4131;; (edebug-trace-display "*trace-point*"
4132;; "saving: point = %s window-start = %s"
4133;; (point) (window-start))
dc0e03f3
RS
4134 (let* ((oldbuf (current-buffer))
4135 (selected-window (selected-window))
84fc2cfa 4136 (buffer (get-buffer-create buf-name))
1fe3d507
DL
4137 buf-window)
4138;; (message "before pop-to-buffer") (sit-for 1)
84fc2cfa 4139 (edebug-pop-to-buffer buffer)
1fe3d507
DL
4140 (setq truncate-lines t)
4141 (setq buf-window (selected-window))
4142 (goto-char (point-max))
4143 (insert (apply 'edebug-format fmt args) "\n")
4144 ;; Make it visible.
4145 (vertical-motion (- 1 (window-height)))
4146 (set-window-start buf-window (point))
4147 (goto-char (point-max))
4148;; (set-window-point buf-window (point))
4149;; (edebug-sit-for 0)
4150 (bury-buffer buffer)
dc0e03f3
RS
4151 (select-window selected-window)
4152 (set-buffer oldbuf))
1fe3d507
DL
4153 buf-name)
4154
4155
4156(defun edebug-trace (fmt &rest args)
4157 "Convenience call to edebug-trace-display using edebug-trace-buffer"
4158 (apply 'edebug-trace-display edebug-trace-buffer fmt args))
4159
4160\f
f7359658 4161;;; Frequency count and coverage
1fe3d507
DL
4162
4163(defun edebug-display-freq-count ()
4164 "Display the frequency count data for each line of the current
4165definition. The frequency counts are inserted as comment lines after
4166each line, and you can undo all insertions with one `undo' command.
4167
4168The counts are inserted starting under the `(' before an expression
4169or the `)' after an expression, or on the last char of a symbol.
4170The counts are only displayed when they differ from previous counts on
4171the same line.
4172
4173If coverage is being tested, whenever all known results of an expression
4174are `eq', the char `=' will be appended after the count
4175for that expression. Note that this is always the case for an
4176expression only evaluated once.
4177
4178To clear the frequency count and coverage data for a definition,
4179reinstrument it."
4180 (interactive)
4181 (let* ((function (edebug-form-data-symbol))
4182 (counts (get function 'edebug-freq-count))
4183 (coverages (get function 'edebug-coverage))
4184 (data (get function 'edebug))
4185 (def-mark (car data)) ; mark at def start
4186 (edebug-points (nth 2 data))
4187 (i (1- (length edebug-points)))
4188 (last-index)
4189 (first-index)
4190 (start-of-line)
4191 (start-of-count-line)
4192 (last-count)
4193 )
84fc2cfa 4194 (save-excursion
1fe3d507
DL
4195 ;; Traverse in reverse order so offsets are correct.
4196 (while (<= 0 i)
4197 ;; Start at last expression in line.
4198 (goto-char (+ def-mark (aref edebug-points i)))
4199 (beginning-of-line)
4200 (setq start-of-line (- (point) def-mark)
4201 last-index i)
4202
4203 ;; Find all indexes on same line.
4204 (while (and (<= 0 (setq i (1- i)))
4205 (<= start-of-line (aref edebug-points i))))
4206 ;; Insert all the indices for this line.
4207 (forward-line 1)
4208 (setq start-of-count-line (point)
4209 first-index i ; really last index for line above this one.
4210 last-count -1) ; cause first count to always appear.
4211 (insert ";#")
4212 ;; i == first-index still
4213 (while (<= (setq i (1+ i)) last-index)
4214 (let ((count (aref counts i))
4215 (coverage (aref coverages i))
4216 (col (save-excursion
4217 (goto-char (+ (aref edebug-points i) def-mark))
4218 (- (current-column)
4219 (if (= ?\( (following-char)) 0 1)))))
4220 (insert (make-string
4221 (max 0 (- col (- (point) start-of-count-line))) ?\ )
4222 (if (and (< 0 count)
4223 (not (memq coverage
4224 '(unknown ok-coverage))))
4225 "=" "")
4226 (if (= count last-count) "" (int-to-string count))
4227 " ")
4228 (setq last-count count)))
4229 (insert "\n")
4230 (setq i first-index)))))
4231
4232(defun edebug-temp-display-freq-count ()
4233 "Temporarily display the frequency count data for the current definition.
4234It is removed when you hit any char."
4235 ;; This seems not to work with Emacs 18.59. It undoes too far.
4236 (interactive)
4237 (let ((buffer-read-only nil))
4238 (undo-boundary)
4239 (edebug-display-freq-count)
4240 (setq unread-command-char (read-char))
4241 (undo)))
4242
4243\f
f7359658 4244;;; Menus
1fe3d507
DL
4245
4246(defun edebug-toggle (variable)
4247 (set variable (not (eval variable)))
4248 (message "%s: %s" variable (eval variable)))
4249
4250;; We have to require easymenu (even for Emacs 18) just so
4251;; the easy-menu-define macro call is compiled correctly.
4252(require 'easymenu)
4253
4254(defconst edebug-mode-menus
4255 '("Edebug"
4256 "----"
4257 ["Stop" edebug-stop t]
4258 ["Step" edebug-step-mode t]
4259 ["Next" edebug-next-mode t]
4260 ["Trace" edebug-trace-mode t]
4261 ["Trace Fast" edebug-Trace-fast-mode t]
4262 ["Continue" edebug-continue-mode t]
4263 ["Continue Fast" edebug-Continue-fast-mode t]
4264 ["Go" edebug-go-mode t]
4265 ["Go Nonstop" edebug-Go-nonstop-mode t]
4266 "----"
4267 ["Help" edebug-help t]
4268 ["Abort" abort-recursive-edit t]
4269 ["Quit to Top Level" top-level t]
4270 ["Quit Nonstop" edebug-top-level-nonstop t]
4271 "----"
4272 ("Jumps"
4273 ["Forward Sexp" edebug-forward-sexp t]
4274 ["Step In" edebug-step-in t]
4275 ["Step Out" edebug-step-out t]
4276 ["Goto Here" edebug-goto-here t])
4277
4278 ("Breaks"
4279 ["Set Breakpoint" edebug-set-breakpoint t]
4280 ["Unset Breakpoint" edebug-unset-breakpoint t]
4281 ["Set Conditional Breakpoint" edebug-set-conditional-breakpoint t]
4282 ["Set Global Break Condition" edebug-set-global-break-condition t]
4283 ["Show Next Breakpoint" edebug-next-breakpoint t])
4284
4285 ("Views"
4286 ["Where am I?" edebug-where t]
4287 ["Bounce to Current Point" edebug-bounce-point t]
4288 ["View Outside Windows" edebug-view-outside t]
4289 ["Previous Result" edebug-previous-result t]
4290 ["Show Backtrace" edebug-backtrace t]
4291 ["Display Freq Count" edebug-display-freq-count t])
4292
4293 ("Eval"
4294 ["Expression" edebug-eval-expression t]
4295 ["Last Sexp" edebug-eval-last-sexp t]
4296 ["Visit Eval List" edebug-visit-eval-list t])
4297
4298 ("Options"
4299 ["Edebug All Defs" edebug-all-defs t]
4300 ["Edebug All Forms" edebug-all-forms t]
4301 "----"
4302 ["Toggle Tracing" (edebug-toggle 'edebug-trace) t]
4303 ["Toggle Coverage Testing" (edebug-toggle 'edebug-test-coverage) t]
4304 ["Toggle Window Saving" edebug-toggle-save-windows t]
4305 ["Toggle Point Saving"
4306 (edebug-toggle 'edebug-save-displayed-buffer-points) t]
4307 ))
4308 "Lemacs style menus for Edebug.")
4309
4310\f
f7359658
RS
4311;;; Emacs version specific code
4312
1fe3d507
DL
4313;;; The default for all above is Emacs 18, because it is easier to compile
4314;;; Emacs 18 code in Emacs 19 than vice versa. This default will
4315;;; change once most people are using Emacs 19 or derivatives.
4316
4317;; Epoch specific code is in a separate file: edebug-epoch.el.
4318
4319;; The byte-compiler will complain about changes in number of arguments
4320;; to functions like mark and read-from-minibuffer. These warnings
4321;; may be ignored because the right call should always be made.
4322
100aa77c 4323(defun edebug-emacs-19-specific ()
1fe3d507
DL
4324
4325 (defalias 'edebug-window-live-p 'window-live-p)
4326
4327 ;; Mark takes an argument in Emacs 19.
4328 (defun edebug-mark ()
4329 (mark t));; Does this work for lemacs too?
4330
1fe3d507
DL
4331 (defun edebug-set-conditional-breakpoint (arg condition)
4332 "Set a conditional breakpoint at nearest sexp.
4333The condition is evaluated in the outside context.
4334With prefix argument, make it a temporary breakpoint."
4335 ;; (interactive "P\nxCondition: ")
4336 (interactive
4337 (list
4338 current-prefix-arg
4339 ;; Read condition as follows; getting previous condition is cumbersome:
4340 (let ((edebug-stop-point (edebug-find-stop-point)))
4341 (if edebug-stop-point
4342 (let* ((edebug-def-name (car edebug-stop-point))
4343 (index (cdr edebug-stop-point))
4344 (edebug-data (get edebug-def-name 'edebug))
4345 (edebug-breakpoints (car (cdr edebug-data)))
4346 (edebug-break-data (assq index edebug-breakpoints))
4347 (edebug-break-condition (car (cdr edebug-break-data)))
4348 (edebug-expression-history
4349 ;; Prepend the current condition, if any.
4350 (if edebug-break-condition
4351 (cons edebug-break-condition read-expression-history)
4352 read-expression-history)))
4353 (prog1
4354 (read-from-minibuffer
4355 "Condition: " nil read-expression-map t
4356 'edebug-expression-history)
4357 (setq read-expression-history edebug-expression-history)
4358 ))))))
4359 (edebug-modify-breakpoint t condition arg))
4360
4361 (defun edebug-eval-expression (edebug-expr)
4362 "Evaluate an expression in the outside environment.
4363If interactive, prompt for the expression.
4364Print result in minibuffer."
4365 (interactive (list (read-from-minibuffer
4366 "Eval: " nil read-expression-map t
4367 'read-expression-history)))
4368 (princ
4369 (edebug-outside-excursion
4370 (setq values (cons (edebug-eval edebug-expr) values))
4371 (edebug-safe-prin1-to-string (car values)))))
4372
f7359658
RS
4373 (easy-menu-define edebug-menu edebug-mode-map "Edebug menus" edebug-mode-menus)
4374 (if window-system
4375 (x-popup-menu nil (lookup-key edebug-mode-map [menu-bar Edebug])))
1fe3d507
DL
4376 )
4377
4378
4379(defun edebug-lemacs-specific ()
4380
4381 ;; We need to bind zmacs-regions to nil around all calls to `mark' and
4382 ;; `mark-marker' but don't bind it to nil before entering a recursive edit,
4383 ;; that is, don't interfere with the binding the user might see while
4384 ;; executing a command.
4385
4386 (defvar zmacs-regions)
4387
4388 (defun edebug-mark ()
4389 (let ((zmacs-regions nil))
4390 (mark)))
4391
4392 (defun edebug-mark-marker ()
4393 (let ((zmacs-regions nil));; for lemacs
4394 (mark-marker)))
4395
4396
4397 (defun edebug-mode-menu (event)
4398 (interactive "@event")
4399 (popup-menu edebug-mode-menus))
4400
4401 (define-key edebug-mode-map 'button3 'edebug-mode-menu)
4402 )
4403
4404(defun edebug-emacs-version-specific ()
4405 (cond
100aa77c 4406 ((string-match "Lucid" emacs-version);; Lucid Emacs
1fe3d507
DL
4407 (edebug-lemacs-specific))
4408
1fe3d507 4409 ((and (boundp 'epoch::version) epoch::version)
100aa77c
RS
4410 (require 'edebug-epoch))
4411
4412 ((not (string-match "^18" emacs-version))
4413 (edebug-emacs-19-specific))))
1fe3d507
DL
4414
4415(edebug-emacs-version-specific)
4416
4417\f
f7359658
RS
4418;;; Byte-compiler
4419
1fe3d507
DL
4420;; Extension for bytecomp to resolve undefined function references.
4421;; Requires new byte compiler.
4422
4423;; Reenable byte compiler warnings about unread-command-char and -event.
4424;; Disabled before edebug-recursive-edit.
4425(eval-when-compile
4426 (if edebug-unread-command-char-warning
4427 (put 'unread-command-char 'byte-obsolete-variable
4428 edebug-unread-command-char-warning))
4429 (if edebug-unread-command-event-warning
4430 (put 'unread-command-event 'byte-obsolete-variable
4431 edebug-unread-command-event-warning)))
4432
4433(eval-when-compile
4434 ;; The body of eval-when-compile seems to get evaluated with eval-defun.
4435 ;; We only want to evaluate when actually byte compiling.
4436 ;; But it is OK to evaluate as long as byte-compiler has been loaded.
4437 (if (featurep 'byte-compile) (progn
4438
4439 (defun byte-compile-resolve-functions (funcs)
4440 "Say it is OK for the named functions to be unresolved."
4441 (mapcar
4442 (function
4443 (lambda (func)
4444 (setq byte-compile-unresolved-functions
4445 (delq (assq func byte-compile-unresolved-functions)
4446 byte-compile-unresolved-functions))))
4447 funcs)
4448 nil)
4449
4450 '(defun byte-compile-resolve-free-references (vars)
4451 "Say it is OK for the named variables to be referenced."
4452 (mapcar
4453 (function
4454 (lambda (var)
4455 (setq byte-compile-free-references
4456 (delq var byte-compile-free-references))))
4457 vars)
4458 nil)
4459
4460 '(defun byte-compile-resolve-free-assignments (vars)
4461 "Say it is OK for the named variables to be assigned."
4462 (mapcar
4463 (function
4464 (lambda (var)
4465 (setq byte-compile-free-assignments
4466 (delq var byte-compile-free-assignments))))
4467 vars)
4468 nil)
4469
4470 (byte-compile-resolve-functions
4471 '(reporter-submit-bug-report
f7359658 4472 edebug-gensym ;; also in cl.el
1fe3d507
DL
4473 ;; Interfaces to standard functions.
4474 edebug-original-eval-defun
4475 edebug-original-read
4476 edebug-get-buffer-window
4477 edebug-mark
4478 edebug-mark-marker
4479 edebug-input-pending-p
4480 edebug-sit-for
4481 edebug-prin1-to-string
4482 edebug-format
1fe3d507
DL
4483 ;; lemacs
4484 zmacs-deactivate-region
4485 popup-menu
4486 ;; CL
4487 cl-macroexpand-all
f7359658 4488 ;; And believe it or not, the byte compiler doesn't know about:
1fe3d507
DL
4489 byte-compile-resolve-functions
4490 ))
4491
4492 '(byte-compile-resolve-free-references
4493 '(read-expression-history
4494 read-expression-map))
4495
4496 '(byte-compile-resolve-free-assignments
4497 '(read-expression-history))
4498
4499 )))
4500
4501\f
f7359658 4502;;; Autoloading of Edebug accessories
1fe3d507
DL
4503
4504(if (featurep 'cl)
4505 (add-hook 'edebug-setup-hook
4506 (function (lambda () (require 'cl-specs))))
4507 ;; The following causes cl-specs to be loaded if you load cl.el.
4508 (add-hook 'cl-load-hook
4509 (function (lambda () (require 'cl-specs)))))
4510
f7359658 4511;;; edebug-cl-read and cl-read are available from liberte@cs.uiuc.edu
1fe3d507
DL
4512(if (featurep 'cl-read)
4513 (add-hook 'edebug-setup-hook
4514 (function (lambda () (require 'edebug-cl-read))))
4515 ;; The following causes edebug-cl-read to be loaded when you load cl-read.el.
4516 (add-hook 'cl-read-load-hooks
4517 (function (lambda () (require 'edebug-cl-read)))))
4518
4519\f
f7359658 4520;;; Finalize Loading
1fe3d507
DL
4521
4522;;; Finally, hook edebug into the rest of Emacs.
4523;;; There are probably some other things that could go here.
4524
4525;; Install edebug read and eval functions.
4526(edebug-install-read-eval-functions)
84fc2cfa 4527
e8544af2
RS
4528(provide 'edebug)
4529
84fc2cfa 4530;;; edebug.el ends here