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