annotate lisp/emacs-lisp/edebug.el @ 4876:8ddcaee25a73

(isearch-yank): Handle `kill' as chunk type. (isearch-yank-kill): New command, on M-y and mouse-2.
author Richard M. Stallman <rms@gnu.org>
date Sun, 24 Oct 1993 04:05:22 +0000
parents fd03ee47c0b2
children 127a513c13b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
1 ;;; edebug.el --- a source-level debugger for emacs lisp
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
3 ;; Copyright (C) 1988, 1989, 1990, 1991 Free Software Foundation, Inc
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
4
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 1821
diff changeset
6 ;; Keywords: lisp, tools, maint
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
7
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
8 ;; This is Dan's 2.5 version with some header comments rearranged to separate
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
9 ;; the Change Log from the Commentary (so the package-finder code can browse
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
10 ;; the Commentary).
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
11
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; This file is part of GNU Emacs.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
13
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY. No author or distributor
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16 ;; accepts responsibility to anyone for the consequences of using it
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; or for whether it serves any particular purpose or works at all,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
18 ;; unless he says so in writing. Refer to the GNU Emacs General Public
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; License for full details.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21 ;; Everyone is granted permission to copy, modify and redistribute
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; GNU Emacs, but only under the conditions described in the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
23 ;; GNU Emacs General Public License. A copy of this license is
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
24 ;; supposed to have been given to you along with GNU Emacs so you
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
25 ;; can know your rights and responsibilities. It should be in a
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
26 ;; file named COPYING. Among other things, the copyright notice
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
27 ;; and this notice must be preserved on all copies.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
29 ;;;; Commentary:
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
30
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
31 ;;; This minor mode allows programmers to step through Emacs Lisp source
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
32 ;;; code while executing, set breakpoints, etc. See the texinfo
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
33 ;;; document (being constructed...) for more detailed instructions
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
34 ;;; than contained here. Send me your enhancement, ideas, bugs, or
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
35 ;;; fixes.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
36
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
37 ;;; Daniel LaLiberte 217-244-0785
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
38 ;;; University of Illinois, Urbana-Champaign
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
39 ;;; Department of Computer Science
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
40 ;;; 1304 W Springfield
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
41 ;;; Urbana, IL 61801
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
42
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
43 ;;; uiucdcs!liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
44 ;;; liberte@cs.uiuc.edu
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
45
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
46 ;;; Contents:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
47 ;;; =========
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
48 ;;; Installation
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49 ;;; Change list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
50 ;;; Utilities
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51 ;;; Parser
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52 ;;; Debugger
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
55 ;;; Installation
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
56 ;;; ------------
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
57 ;; Put edebug.el in some directory in your load-path and byte-compile it.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
58
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
59 ;; Put the following forms in your .emacs file.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
60 ;; (define-key emacs-lisp-mode-map "\^Xx" 'edebug-defun)
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
61 ;; (autoload 'edebug-defun "edebug")
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
62 ;; (autoload 'edebug-debug "edebug")
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
63 ;; (setq debugger 'edebug-debug)
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
64 ;; ... other options, described in the next section.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
65
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
66 ;; Evaluate a defun for edebug with edebug-defun.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
67 ;; Evaluate your function normally.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
68 ;; Use the "?" command in edebug to describe other commands.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
69 ;; See edebug.texinfo for more instructions.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
70
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
71 ;;; Change Log:
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
72
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
73 ;;; Revision 2.5 91/07/25 13:32:53 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
74 ;;; Doc string cleanup.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
75 ;;; If edebug-form-hook is t, evaluate all arguments.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
76 ;;; If edebug-form-hook is 0, evaluate no arguments.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 ;;; If edebug-form-hook is nil, evaluate macro args according
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 ;;; to edebug-eval-macro-args.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 ;;; Save the outside value of executing macro.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 ;;; Save and restore the outside restriction.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81 ;;; Dont force update for go and Go-nonstop.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 ;;; Save and restore last-command-char, last-command,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83 ;;; this-command, last-input-char.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 ;;; For epoch, do epoch::dispatch-events before sit-for
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 ;;; and input-pending-p since X events could interfere.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 ;;; Warn about unsetting non-existent breakpoint.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 ;;; Fix edebug-forward-sexp with prefix arg.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
88 ;;; Add edebug-step-out to exit from current sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
90 ;;; Revision 2.4 91/03/18 12:35:44 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
91 ;;; Force update after go or Go-nonstop modes, so overlay arrow is correct.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
92 ;;; Support debug-on-quit. Remove edebug-on-error.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
93 ;;; Fix edebug-anonymous. Bug found by jackr@wpd.sgi.com (Jack Repenning).
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
94 ;;; Don't discard-input anymore. Easier to change modes this way.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
95 ;;; Fix max-lisp-eval-depth and max-specpdl-size incrementing.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
96 ;;; Save and restore points in all buffers, if
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 ;;; edebug-save-buffer-points is non-nil. Expensive!
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
98 ;;; Bug caught by wolfgang@wsrcc.com (Wolfgang S. Rupprecht)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
99 ;;; Save standard-output and standard-input in edebug-recursive-edit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
100 ;;; so that edebug-outside-excursion can restore them.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
101 ;;; Call set-buffer in edebug-pop-to-buffer since
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
102 ;;; select-window does not do that.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
103 ;;; Fix edebug's eval-defun to remember current buffer inside evaluations
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
104 ;;; and to evaluate top-level forms. Found by Jamie Zawinski.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
105 ;;; Add edebug-interactive-entry to support interactive forms with
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
106 ;;; non-string arg. Bug found by Jack Repenning.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
107 ;;; Simplify edebug-restore-match-data to just store-match-data.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
108 ;;; Motivated by linus@lysator.liu.se.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
109 ;;; Move the match-data call to before the outside
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
110 ;;; buffer is changed, since it assumes that.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
111 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
112 ;;; Revision 2.3 91/01/17 20:55:14 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
113 ;;; Fix bug found by hollen@megatek.uucp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
114 ;;; Current buffer was not being restored.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
115 ;;; Call edebug with (edebug begin end 'exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
116 ;;; and add additional wrapper around body of functions:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
117 ;;; (edebug-enter function body).
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 ;;; Make &optional only apply to immediate next arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
119 ;;; in edebug-form-parser (was edebug-macro-parser).
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 ;;; Catch debug errors with edebug. Yeah!
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
121 ;;; Reset edebug-mode on first function entry. Yeah!
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122 ;;; Motivated by Dion Hollenbeck.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 ;;; Add the missing bindings to the global-edebug-map.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 ;;; eval-current-buffer now uses eval-region.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 ;;; eval-region now does not narrow region.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126 ;;; Narrowing was the cause of the window-start being set wrong.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127 ;;; Reset edebug-mode only on
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
128 ;;; first entry of any function at each recursive-edit level.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129 ;;; Add edebug-backtrace, to generate cleaned up
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
130 ;;; backtrace. It doesn't "work" like the debug backtrace, however.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131 ;;; Require reselecting outside window even if
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 ;;; quit occurs, otherwise save-excursions may restore
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133 ;;; buffer to the wrong window.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
134 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
135 ;;; Revision 2.2 90/11/26 21:14:22 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
136 ;;; Shadow eval-defun and eval-region. Toggle
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
137 ;;; edebugging with edebug-all-defuns.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
138 ;;; Call edebug with (edebug 'function begin end 'exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
139 ;;; Suggested by Jamie Zawinski <jwz@lucid.com>.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140 ;;; Add edebug-form-parser to process macro args.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 ;;; Motivated by Darryl Okahata darrylo@hpnmxx.hp.com.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
142 ;;; Fix by Roland McGrath <roland@ai.mit.edu>
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
143 ;;; to wrap body of edebug-save-restriction in progn.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
144 ;;; Fix by Darryl Okahata <darrylo%hpnmd@hpcea.hp.com>
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
145 ;;; to add (set-window-hscroll (selected-window) 0) to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
146 ;;; edebug-pop-to-buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
147 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
148 ;;; Revision 2.1 90/11/16 21:55:35 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
149 ;;; Clean up.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
150 ;;; Add edebug-form-hook to edebug macro calls. Thanks to Joe Wells.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
151 ;;; edebug-forward-sexp uses step mode if no forward-sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153 ;;; Revision 2.0 90/11/14 22:30:54 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154 ;;; Handle lambda forms, function, interactive evals, defmacro.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
155 ;;; Clean up display for Epoch - save and restore screen configurations.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
156 ;;; Note: epoch 3.2 broke set-window-configuration.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157 ;;; Also, sit-for pauses do not always work in epoch.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 ;;; Display evaluations window.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
159 ;;; Display result after expression evaluation.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
160 ;;; Thanks to discussions with Shinichirou Sugou.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161 ;;; Conditional and temporary breakpoints.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
162 ;;; Change "continue" to "go" mode and add different "continue" mode.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
163 ;;; Option to stop before symbols.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
164 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
165 ;;; Fix by: Glen Ditchfield gjditchfield@violet.uwaterloo.ca
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166 ;;; to handle ?# type chars.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
168 ;;; Revision 1.5 89/05/10 02:39:27 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
169 ;;; Fix condition-case expression lists.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
170 ;;; Reorganize edebug.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
172 ;;; Revision 1.4 89/02/14 22:58:34 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 ;;; Fix broken breakpointing.
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
174 ;;; Temporarily widen Emacs Lisp buffer during edebug.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
175 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
176 ;;; Revision 1.3 89/01/30 00:26:09 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
177 ;;; More bug fixes for cond and let.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
178 ;;; Another parsing fix backquote.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
179 ;;; Fix for lambda forms inside defuns.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
180 ;;; Leave point at syntax error, mark at starting position.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
181 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
182 ;;; Revision 1.2 88/11/28 12:14:15 liberte
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
183 ;;; Bug fixes: cond construct didn't execute.
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
184 ;;; () in sexp list didn't parse
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
185 ;;; () as variable in condition-case didn't parse.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
186 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
187 ;;; Revision 1.1 88/11/28 12:11:27 liberte
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
188 ;;; Initial revision
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189 ;;;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
190
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
191 ;;; Code:
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
192
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
193
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194 ;;; Options
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
195 ;;; -------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 (defvar edebug-all-defuns nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
198 "*If non-nil, all defuns and defmacros evaluated will use edebug.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
199 eval-defun without prefix arg and eval-region will use edebug-defun.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
200
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201 If nil, eval-region evaluates normally, but eval-defun with prefix arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
202 uses edebug-defun. eval-region is called by eval-defun, eval-last-sexp,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
203 and eval-print-last-sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
204
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
205 You may wish to make this variable local to each Emacs Lisp buffer by calling
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
206 (make-local-variable 'edebug-all-defuns) in your emacs-lisp-mode-hook.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
207 You can use the function edebug-all-defuns to toggle its value.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
208
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
209
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
210 (defvar edebug-eval-macro-args nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
211 "*If non-nil, edebug will assume that all macro call arguments for
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
212 macros that have no edebug-form-hook may be evaluated, otherwise it
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
213 will not. To specify exceptions for macros that have some arguments
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
214 evaluated and some not, you should specify an edebug-form-hook")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
215
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
216 (defvar edebug-stop-before-symbols nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
217 "*Non-nil causes edebug to stop before symbols as well as after.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
218 In any case, it is possible to stop before a symbol with a breakpoint or
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
219 interrupt.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
220
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
221 (defvar edebug-save-windows t
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
222 "*If non-nil, save and restore window configuration on edebug calls.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
223 It takes some time to save and restore, so if your program does not care
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224 what happens to the window configurations, it is better to set this
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 variable to nil.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
227 (defvar edebug-save-point t
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
228 "*If non-nil, save and restore the point and mark in source code buffers.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
229
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
230 (defvar edebug-save-buffer-points nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
231 "*If non-nil, save and restore the points of all buffers, displayed or not.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
232
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
233 Saving and restoring buffer points is necessary if you are debugging
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
234 code that changes the point of a buffer which is displayed in a
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
235 non-selected window. If edebug or the user then selects the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
236 window, the buffer's point will be changed to the window's point.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
237
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
238 Saving and restoring all the points is an expensive operation since it
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
239 visits each buffer twice for each edebug call, so it is best to avoid
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
240 it if you can.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
241
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
242 (defvar edebug-initial-mode 'step
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
243 "*Global initial mode for edebug, if non-nil.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
244 This is used when edebug is first entered for each recursive-edit level.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
245 Possible values are nil (meaning keep using edebug-mode), step, go,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
246 Go-nonstop, trace, Trace-fast, continue, and Continue-fast.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
247
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
248 (defvar edebug-trace nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
249 "*Non-nil if edebug should show a trace of function entry and exit.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
250 Tracing output is displayed in a buffer named *edebug-trace*, one
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
251 function entry or exit per line, indented by the recursion level. You
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
252 can customize by replacing functions edebug-print-trace-entry and
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
253 edebug-print-trace-exit.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
254
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
255
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
256
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
257 ;;;========================================================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
258 ;;; Utilities
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
259 ;;; ---------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
260
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
261 (defun edebug-which-function ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
262 "Return the symbol of the function we are in"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
263 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
264 (end-of-defun)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
265 (beginning-of-defun)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
266 (down-list 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
267 (if (not (memq (read (current-buffer)) '(defun defmacro)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
268 (error "Not in defun or defmacro."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
269 (read (current-buffer))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
270
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
271 (defun edebug-last-sexp ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
272 "Return the last sexp before point in current buffer.
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
273 Assumes Emacs Lisp syntax is active."
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
274 (car
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
275 (read-from-string
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
276 (buffer-substring
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
277 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
278 (forward-sexp -1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
279 (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
280 (point)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
281
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
282 (defun edebug-window-list ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
283 "Return a list of windows, in order of next-window."
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
284 ;; This doesn't work for epoch.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
285 (let* ((first-window (selected-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
286 (window-list (list first-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
287 (next (next-window first-window)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
288 (while (not (eq next first-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
289 (setq window-list (cons next window-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
290 (setq next (next-window next)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
291 (nreverse window-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
292
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
293 (defun edebug-get-buffer-points ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
294 "Return a list of buffer point pairs, for all buffers."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
295 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
296 (mapcar (function (lambda (buf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
297 (set-buffer buf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
298 (cons buf (point))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
299 (buffer-list))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
300
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
301 (defun edebug-set-buffer-points ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
302 "Restore the buffer-points given by edebug-get-buffer-points."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
303 (mapcar (function (lambda (buf-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
304 (if (buffer-name (car buf-point)) ; still exists
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
305 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
306 (set-buffer (car buf-point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
307 (goto-char (cdr buf-point))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
308 edebug-buffer-points))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
309
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
310 (defun edebug-two-window-p ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
311 "Return t if there are two windows."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
312 (and (not (one-window-p))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
313 (eq (selected-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
314 (next-window (next-window (selected-window))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
315
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
316 (defun edebug-macrop (object)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
317 "Return the macro named by OBJECT, or nil if it is not a macro."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
318 (while (and (symbolp object) (fboundp object))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
319 (setq object (symbol-function object)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
320 (if (and (listp object)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
321 (eq 'macro (car object))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
322 (edebug-functionp (cdr object)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
323 object))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
324
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
325 (defun edebug-functionp (object)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
326 "Returns the function named by OBJECT, or nil if it is not a function."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
327 (while (and (symbolp object) (fboundp object))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
328 (setq object (symbol-function object)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
329 (if (or (subrp object)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
330 (and (listp object)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
331 (eq (car object) 'lambda)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
332 (listp (car (cdr object)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
333 object))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
334
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
335 (defun edebug-sort-alist (alist function)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
336 "Return the ALIST sorted with comparison function FUNCTION.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
337 This uses 'sort so the sorting is destructive."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
338 (sort alist (function
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
339 (lambda (e1 e2)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
340 (funcall function (car e1) (car e2))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
341
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
342 (put 'edebug-save-restriction 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
343 '(&rest form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
344
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
345 (defmacro edebug-save-restriction (&rest body)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
346 "Evaluate BODY while saving the current buffers restriction.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
347 BODY may change buffer outside of current restriction, unlike
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
348 save-restriction. BODY may change the current buffer,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
349 and the restriction will be restored to the original buffer,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
350 and the current buffer remains current.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
351 Return the result of the last expression in BODY."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
352 (` (let ((edebug:s-r-beg (point-min-marker))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
353 (edebug:s-r-end (point-max-marker)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
354 (unwind-protect
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
355 (progn (,@ body))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
356 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
357 (set-buffer (marker-buffer edebug:s-r-beg))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
358 (narrow-to-region edebug:s-r-beg edebug:s-r-end))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
359
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
360
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
361 ;;;=============================================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
362 ;;; Redefine eval-defun, eval-region, and eval-current-buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
363 ;;; -----------------------------------------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
364
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
365 (defun edebug-all-defuns ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
366 "Toggle edebugging of all defuns and defmacros,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
367 not including those evaluated in the minibuffer, or during load."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
368 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
369 (setq edebug-all-defuns (not edebug-all-defuns))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
370 (message "Edebugging is %s." (if edebug-all-defuns "on" "off")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
371
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
372
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
373 (if (not (fboundp 'edebug-emacs-eval-defun))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
374 (fset 'edebug-emacs-eval-defun (symbol-function 'eval-defun)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
375 ;;(fset 'eval-defun (symbol-function 'edebug-emacs-eval-defun))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
376
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
377 (defun eval-defun (edebug-debug)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
378 "Edebug replacement for eval-defun. Print value in the minibuffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
379 Evaluate the top-level form that point is in or before. Note:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
380 eval-defun normally evaluates any top-level form, not just defuns.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
381
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
382 Here are the differences from the standard eval-defun. If the prefix
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
383 argument is the same as edebug-all-defuns (nil or non-nil), evaluate
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
384 normally; otherwise edebug-defun is called to wrap edebug calls around
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
385 evaluatable expressions in the defun or defmacro body. Also, the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
386 value printed by edebug-defun is not just the function name."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
387 (interactive "P")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
388 (let ((edebug-all-defuns
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
389 (not (eq (not edebug-debug) (not edebug-all-defuns)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
390 (edebug-emacs-eval-defun nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
391 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
392
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
393
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
394 (if (not (fboundp 'edebug-emacs-eval-region))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
395 (fset 'edebug-emacs-eval-region (symbol-function 'eval-region)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
396 ;; (fset 'eval-region (symbol-function 'edebug-emacs-eval-region))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
397
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
398 (defun eval-region (edebug-e-r-start edebug-e-r-end
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
399 &optional edebug-e-r-output)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
400 "Edebug replacement for eval-defun.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
401 Like eval-region, but call edebug-defun for defuns or defmacros.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
402 Also, this eval-region does not narrow to the region and
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
403 if an error occurs, point is left at the error."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
404 ;; One other piddling difference concerns whitespace after the expression.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
405 (interactive "r")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
406 (let ((standard-output (or edebug-e-r-output 'symbolp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
407 (edebug-e-r-pnt (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
408 (edebug-e-r-buf (current-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
409 (edebug-e-r-inside-buf (current-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
410 ;; Mark the end because it may move.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
411 (edebug-e-r-end-marker (set-marker (make-marker) edebug-e-r-end))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
412 edebug-e-r-val
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
413 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
414 (goto-char edebug-e-r-start)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
415 (edebug-skip-whitespace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
416 (while (< (point) edebug-e-r-end-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
417 (if (and edebug-all-defuns
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
418 (eq 'lparen (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
419 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
420 (forward-char 1) ; skip \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
421 (memq (edebug-read-sexp) '(defun defmacro))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
422 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
423 (edebug-defun)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
424 ;; Potential problem: edebug-defun always prints name.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
425 (forward-sexp 1) ; skip the defun
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
426 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
427 (if (and (eq 'lparen (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
428 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
429 (forward-char 1) ; skip \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
430 (memq (edebug-read-sexp) '(defun defmacro))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
431 ;; If it's a defun or defmacro, but not edebug-all-defuns
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
432 ;; reset the symbols edebug property to be just a marker at
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
433 ;; the definitions source code.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
434 (put (edebug-which-function) 'edebug (point-marker)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
435
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
436 ;; Evaluate normally - after restoring the current-buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
437 (setq edebug-e-r-val (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
438 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
439 (set-buffer edebug-e-r-inside-buf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
440 (setq edebug-e-r-val (eval edebug-e-r-val))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
441 ;; Remember current buffer for next time.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
442 (setq edebug-e-r-inside-buf (current-buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
443
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
444 (if edebug-e-r-output
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
445 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
446 (setq values (cons edebug-e-r-val values))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
447 (if (eq standard-output t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
448 (prin1 edebug-e-r-val)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
449 (print edebug-e-r-val))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
450 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
451 (goto-char
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
452 (min (max edebug-e-r-end-marker (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
453 (progn (edebug-skip-whitespace) (point))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
454 ) ; while
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
455 (if (null edebug-e-r-output)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
456 ;; do the save-excursion recovery
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
457 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
458 ;; but mark is not restored
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
459 (set-buffer edebug-e-r-buf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
460 (goto-char edebug-e-r-pnt)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
461 nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
462 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
463
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
464
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
465 (defun edebug-eval-current-buffer (&optional edebug-e-c-b-output)
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
466 "Call eval-region on the whole buffer."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
467 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
468 (eval-region (point-min) (point-max) edebug-e-c-b-output))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
469
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
470 (defun edebug-eval-buffer (&optional buffer edebug-e-c-b-output)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
471 "Call eval-region on the whole buffer."
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
472 (interactive "bEval buffer: ")
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
473 (save-excursion
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
474 (set-buffer buffer)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
475 (eval-region (point-min) (point-max) edebug-e-c-b-output)))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
476
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
477 ;; The standard eval-current-buffer doesn't use eval-region.
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
478 (if (and (fboundp 'eval-current-buffer)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
479 (not (fboundp 'edebug-emacs-eval-current-buffer)))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
480 (progn
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
481 (fset 'edebug-emacs-eval-current-buffer
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
482 (symbol-function 'eval-current-buffer))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
483 (fset 'eval-current-buffer 'edebug-eval-current-buffer)))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
484 (if (and (fboundp 'eval-buffer)
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
485 (not (fboundp 'edebug-emacs-eval-buffer)))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
486 (progn
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
487 (fset 'edebug-emacs-eval-buffer
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
488 (symbol-function 'eval-buffer))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
489 (fset 'eval-buffer 'edebug-eval-buffer)))
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
490
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
491
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
492
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
493 ;;;======================================================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
494 ;;; The Parser
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
495 ;;; ----------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
496
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
497 ;;; The top level function for parsing defuns is edebug-defun; it
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
498 ;;; calls all the rest. It checks the syntax a bit and leaves point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
499 ;;; at any error it finds, but otherwise should appear to work like
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
500 ;;; eval-defun.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
501
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
502 ;;; The basic plan is to surround each expression with a call to the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
503 ;;; function edebug together with indexes into a table of positions of
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
504 ;;; all expressions. Thus an expression "exp" in function foo
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
505 ;;; becomes:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
506
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
507 ;;; (edebug 1 2 'exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
508
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
509 ;;; First point moved to to the beginning of exp (offset 1 of the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
510 ;;; current function). Then the expression is evaluated and point is
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
511 ;;; moved to offset 2, at the end of exp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
512
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
513 ;;; The top level expressions of the function are wrapped in a call to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
514 ;;; edebug-enter, which supplies the function name and the actual
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
515 ;;; arguments to the function. See functions edebug and edebug-enter
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
516 ;;; for more details.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
517
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
518
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
519 ;;;###autoload
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
520 (defun edebug-defun ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
521 "Evaluate defun or defmacro, like eval-defun, but with edebug calls.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
522 Print its name in the minibuffer and leave point after any error it finds,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
523 with mark at the original point."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
524 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
525 (let (def-kind ; whether defmacro or defun
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
526 def-name
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
527 def-args
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
528 def-docstring
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
529 defun-interactive
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
530 (edebug-offset-index 0)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
531 edebug-offset-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
532 edebug-func-mark
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
533 (starting-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
534 tmp-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
535 (parse-sexp-ignore-comments t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
536
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
537 (condition-case err
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
538 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
539 (end-of-defun)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
540 (beginning-of-defun)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
541 (down-list 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
542
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
543 (setq edebug-func-mark (point-marker))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
544 (if (not (eq 'defun (setq def-kind (edebug-read-sexp))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
545 (if (not (eq 'defmacro def-kind))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
546 (edebug-syntax-error "%s is not a defun or defmacro."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
547 def-kind)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
548 (setq def-name (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
549 (if (not (symbolp def-name))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
550 (edebug-syntax-error "Bad defun name: %s" def-name))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
551 (setq def-args (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
552 (if (not (listp def-args))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
553 (edebug-syntax-error "Bad defun arg list: %s" def-args))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
554
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
555 ;; look for doc string
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
556 (setq tmp-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
557 (if (eq 'string (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
558 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
559 (setq def-docstring (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
560 (setq tmp-point (point))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
561
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
562 ;; look for interactive form
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
563 (if (eq 'lparen (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
564 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
565 (forward-char 1) ; skip \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
566 (if (eq 'interactive (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
567 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
568 (setq defun-interactive
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
569 (cons 'interactive (edebug-interactive)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
570 (forward-char 1) ; skip \)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
571 (setq tmp-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
572 ))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
573
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
574 (goto-char tmp-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
575
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
576 ;; build the new definition
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
577 (fset def-name (` (lambda
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
578 (, def-args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
579 (, def-docstring)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
580 (, defun-interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
581 ;; the remainder is a list of sexps
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
582 (edebug-enter
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
583 (quote (, def-name))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
584 (quote (, def-args))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
585 (quote (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
586 (,@ (edebug-sexp-list t)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
587 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
588 ;; if it is a defmacro, prepend 'macro
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
589 (if (eq 'defmacro def-kind)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
590 (fset def-name (cons 'macro (symbol-function def-name))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
591
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
592 ;; recover point, like save-excursion but only if no error occurs
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
593 (goto-char starting-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
594
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
595 ;; store the offset list in functions property list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
596 (put def-name 'edebug
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
597 (list edebug-func-mark
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
598 nil ; clear breakpoints
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
599 (vconcat (nreverse edebug-offset-list))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
600 (message "edebug: %s" def-name)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
601 ) ; progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
602
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
603 (invalid-read-syntax
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
604 ;; Set mark at starting-point so user can return.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
605 ;; Leave point at error.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
606 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
607 (goto-char starting-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
608 (set-mark-command nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
609 (message "Syntax error: %s" (cdr err))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
610 ;; (signal 'invalid-read-syntax (cdr err)) ; pass it on, to who?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
611 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
612 ) ; condition-case
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
613 def-name
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
614 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
615
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
616
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
617 (defun edebug-sexp-list (debuggable)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
618 "Return an edebug form built from the sexp list following point in the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
619 current buffer. If DEBUGGABLE then wrap edebug calls around each sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
620 The sexp list does not start with a left paren; we are already in the list.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
621 Leave point at (before) the trailing right paren."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
622 (let (sexp-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
623 (while (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
624 (setq sexp-list (cons (if debuggable
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
625 (edebug-form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
626 (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
627 sexp-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
628 (nreverse sexp-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
629
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
630
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
631 (defun edebug-increment-offset ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
632 ;; accesses edebug-offset-index and edebug-offset-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
633 (setq edebug-offset-index (1+ edebug-offset-index))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
634 (setq edebug-offset-list (cons (- (point) edebug-func-mark)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
635 edebug-offset-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
636
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
637
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
638 (defun edebug-make-edebug-form (index form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
639 "Return the edebug form for the current function at offset INDEX given FORM.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
640 Looks like: (edebug def-name INDEX edebug-offset-index 'FORM).
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
641 Also increment the offset index."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
642 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
643 (list 'edebug
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
644 index
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
645 edebug-offset-index
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
646 (list 'quote form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
647 (edebug-increment-offset)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
648 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
649
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
650
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
651 (defun edebug-form ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
652 "Return the debug form for the following form. Add the point offset
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
653 to the edebug-offset-list for the function and move point to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
654 immediately after the form."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
655 (let* ((index edebug-offset-index)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
656 form class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
657 ;; The point must be added to the offset list now
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
658 ;; because edebug-list will add more offsets indirectly.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
659 (edebug-skip-whitespace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
660 (edebug-increment-offset)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
661 (setq class (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
662 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
663 ((eq 'lparen class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
664 (edebug-make-edebug-form index (edebug-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
665
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
666 ((eq 'symbol class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
667 (if (and (not (memq (setq form (edebug-read-sexp)) '(nil t)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
668 ;; note: symbol includes numbers, see parsing utilities
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
669 (not (numberp form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
670 (edebug-make-edebug-form index form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
671 form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
672 (t (edebug-read-sexp)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
673
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
674
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
675 (defun edebug-list ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
676 "Return an edebug form built from the list form that follows point.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
677 Insert debug calls as appropriate to the form. Start with point at
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
678 the left paren. Leave point after the right paren."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
679 (let ((beginning (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
680 class
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
681 head)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
682
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
683 (forward-char 1) ; skip \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
684 (setq class (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
685 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
686 ((eq 'symbol class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
687 (setq head (edebug-read-sexp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
688 ((eq 'lparen class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
689 (setq head (edebug-anonymous)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
690 ((eq 'rparen class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
691 (setq head nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
692 (t (edebug-syntax-error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
693 "Head of list must be a symbol or lambda expression.")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
694
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
695 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
696 (if head
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
697 (cons head
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
698 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
699
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
700 ;; None of the edebug-form-hooks defined below are used, for speed.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
701 ;; They are included for documentation, though the hook would not
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
702 ;; necessarily behave the same as the function it is replacing.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
703
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
704 ;;; Using the edebug-form-hooks should work, but would take more time.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
705 ;;; ((symbolp head)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
706 ;;; (let ((form (get head 'edebug-form-hook)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
707 ;;; (if form
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
708 ;;; (edebug-form-parser form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
709 ;;; (if (edebug-macrop head)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
710 ;;; (if edebug-eval-macro-args
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
711 ;;; (edebug-sexp-list t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
712 ;;; (edebug-sexp-list nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
713 ;;; ;; assume it is a function
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
714 ;;; (edebug-sexp-list t)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
715
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
716 ;; handle all special-forms with unevaluated arguments
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
717 ((memq head '(let let*)) (edebug-let))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
718 ((memq head '(setq setq-default)) (edebug-setq))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
719 ((eq head 'cond) (edebug-cond))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
720 ((eq head 'condition-case) (edebug-condition-case))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
721
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
722 ((memq head '(quote ; permits more than one arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
723 defun defvar defconst defmacro))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
724 (edebug-sexp-list nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
725 ((eq head 'function)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
726 (list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
727 (if (eq 'lparen (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
728 (edebug-anonymous)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
729 (edebug-read-sexp) ; should be just a symbol
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
730 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
731
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
732 ;; is it a lisp macro?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
733 ((edebug-macrop head)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
734 (or (and (symbolp head)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
735 (let ((form (get head 'edebug-form-hook)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
736 (if form
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
737 (if (eq form t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
738 (edebug-sexp-list t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
739 (if (eq form 0)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
740 (edebug-sexp-list nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
741 (edebug-form-parser form))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
742 (edebug-sexp-list edebug-eval-macro-args)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
743
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
744 ((eq head 'interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
745 (edebug-syntax-error "interactive not expected here."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
746
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
747 ;; otherwise it is a function call
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
748 (t (edebug-sexp-list t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
749 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
750
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
751 (if (eq 'rparen (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
752 (forward-char 1) ; skip \)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
753 (edebug-syntax-error "Too many arguments."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
754 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
755
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
756
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
757 (defun edebug-form-parser (args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
758 "Parse the macro arguments that follow based on ARGS.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
759 ARGS describes the types of the arguments of a list form. Each of the ARGS
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
760 is processed left to right, in the same order as the arguments of the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
761 list form. See the edebug documentation for more details. The ARGS
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
762 may be one of the following:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
763
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
764 symbolp - an unevaluated symbol
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
765 integerp - an unevaluated number
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
766 stringp - an unevaluated string
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
767 vectorp - an unevaluated vector
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
768 atom - an unevaluated number, string, symbol, or vector
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
769
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
770 sexp - an unevaluated sexp (atom or list); may not be empty
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
771 form - an evaluated sexp; may not be empty
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
772
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
773 foo - any other symbol should be the name of a function; this
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
774 function is called on the argument as a predicate and an error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
775 is signaled if the predicate fails.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
776
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
777 &optional - one following arg in the list may or may not appear.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
778 &rest - all following args are repeated zero or more times as a group.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
779 This is an extension of the normal meaning of &rest.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
780 &or - each of the following args are alternatives, processed left to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
781 right until one succeeds. There is no way to group
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
782 more than one list element as one alternative.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
783
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
784 (...) - a sublist, of the same format as the top level, processed recursively.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
785 Special case: if the car of the list is quote, the argument must match
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
786 the quoted sexp (see example below of 'for macro).
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
787 "
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
788
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
789 (let ((arglist args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
790 arg form form-list class
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
791 &optional &rest &or)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
792 (while (and arglist
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
793 (not (eq 'rparen (setq class (edebug-next-token-class)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
794 (catch 'no-match
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
795 (setq arg (car arglist))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
796 (setq arglist (cdr arglist))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
797 (if (and &rest (null arglist))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
798 (setq arglist &rest))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
799
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
800 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
801 ((memq arg '(&optional &rest &or))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
802 ;; remember arglist at this point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
803 (set arg arglist)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
804 (throw 'no-match nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
805
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
806 ((eq arg 'form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
807 (setq form (edebug-form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
808
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
809 ((eq arg 'sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
810 (setq form (edebug-read-sexp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
811
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
812 ((listp arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
813 (if (eq 'quote (car arg))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
814 ;; special case, match the quoted symbol
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
815 (let ((pnt (point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
816 (setq arg (car (cdr arg)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
817 (if (not (eq arg (setq form (edebug-read-sexp))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
818 (edebug-form-parser-error)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
819 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
820 (if (eq class 'lparen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
821 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
822 (forward-char 1) ; skip \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
823 (setq form (edebug-form-parser arg))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
824 (forward-char 1) ; skip \)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
825 ))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
826 ((symbolp arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
827 (let ((pnt (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
828 (pred (if (fboundp arg) (symbol-function arg))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
829 (and pred
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
830 (not (funcall pred (setq form (edebug-read-sexp))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
831 (edebug-form-parser-error)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
832 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
833 (t (throw 'no-match nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
834 ) ; cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
835 (setq &optional nil) ; only lasts for one match
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
836 (setq form-list (cons form form-list)) ; skipped by no-match throw
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
837 )) ; while
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
838
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
839 (if (and arglist (not (or &optional &rest
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
840 (memq (car arglist) '(&optional &rest)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
841 (edebug-syntax-error "Not enough arguments."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
842 (if (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
843 (if &or
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
844 (edebug-syntax-error "Unrecognized argument.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
845 (edebug-syntax-error "Too many arguments.")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
846 (nreverse form-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
847
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
848
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
849 (defun edebug-form-parser-error ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
850 (goto-char pnt)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
851 (if &or
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
852 (throw 'no-match nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
853 (if &optional
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
854 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
855 (setq &optional nil) ; only lasts for one failed match not in &or
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
856 (throw 'no-match nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
857 (edebug-syntax-error "%s is not %s" form arg))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
858
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
859 ;; for loop defined in Emacs Lisp manual
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
860 (put 'for 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
861 '(symbolp 'from form 'to form 'do &rest form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
862
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
863 ;; case and do defined in cl.el
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
864 (put 'case 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
865 '(form &rest (sexp form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
866
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
867 (put 'do 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
868 '((&rest
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
869 &or symbolp
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
870 (symbolp &optional form
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
871 &optional form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
872 (form &rest form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
873 &rest body))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
874
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
875 (put 'defvar 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
876 (put 'defconst 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
877 '(symbolp &optional form &optional stringp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
878
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
879 (put 'defun 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
880 (put 'defmacro 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
881 '(symbolp (&rest symbolp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
882 &optional stringp
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
883 &optional ('interactive &or stringp form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
884 &rest form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
885
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
886 (put 'anonymous 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
887 '(&optional 'macro 'lambda (&rest symbolp) &rest form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
888
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
889 (defun edebug-anonymous ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
890 "Return the edebug form for an anonymous lambda or macro.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
891 Point starts before the left paren and ends after it."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
892 (forward-char 1) ; skip \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
893 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
894 (let ((head (edebug-read-sexp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
895 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
896 ((eq head 'lambda)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
897 (edebug-lambda))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
898 ((eq head 'macro)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
899 (if (not (eq 'lambda (edebug-read-sexp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
900 (edebug-syntax-error "lambda expected."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
901 (cons 'macro (edebug-lambda)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
902 (t (edebug-syntax-error "Anonymous lambda or macro expected."))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
903 (forward-char 1) ; skip \)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
904 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
905
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
906
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
907 (defun edebug-lambda ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
908 "Return the edebug form for the lambda form that follows.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
909 Point starts after the lambda symbol and is moved to before the right paren."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
910 (append
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
911 (list 'lambda (edebug-read-sexp)) ; the args
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
912 (edebug-sexp-list t))) ; the body
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
913
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
914
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
915
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
916 (put 'let 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
917 (put 'let* 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
918 '((&rest
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
919 &or (symbolp &optional form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
920 symbolp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
921 &rest form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
922
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
923 (defun edebug-let ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
924 "Return the edebug form of the let or let* form.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
925 Leave point before the right paren."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
926 (let (var-value-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
927 token
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
928 class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
929 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
930 ;; first process the var/value list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
931 (if (not (eq 'lparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
932 (if (setq token (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
933 (edebug-syntax-error "Bad var list in let.") ; should be nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
934 token ; == nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
935 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
936
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
937 (forward-char 1) ; lparen
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
938 (while (not (eq 'rparen (setq class (edebug-next-token-class))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
939 (setq var-value-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
940 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
941 (if (not (eq 'lparen class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
942 (edebug-read-sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
943 (forward-char 1) ; lparen
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
944 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
945 (edebug-var-value)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
946 (if (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
947 (edebug-syntax-error "Right paren expected in let.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
948 (forward-char 1) ; rparen
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
949 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
950 var-value-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
951 (forward-char 1) ; rparen
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
952 (nreverse var-value-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
953
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
954 ;; now process the expression list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
955 (edebug-sexp-list t))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
956
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
957
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
958 (defun edebug-var-value ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
959 "Return the edebug form of the var and optional value that follow point.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
960 Leave point after the value, if there is one."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
961 (list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
962 (edebug-read-sexp) ; the variable
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
963 (and (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
964 (edebug-form))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
965
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
966
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
967 (put 'setq 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
968 (put 'setq-default 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
969 '(&rest symbolp form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
970
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
971 (defun edebug-setq ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
972 "Return the edebug form of the setq or setq-default var-value list."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
973 (let (var-value-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
974 (while (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
975 (setq var-value-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
976 (append var-value-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
977 (edebug-var-value))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
978 var-value-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
979
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
980
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
981 (put 'interactive 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
982 '(&optional &or stringp form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
983
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
984 (defun edebug-interactive ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
985 "Return the edebug form of the interactive form."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
986 (list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
987 (if (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
988 (if (eq 'string (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
989 (edebug-read-sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
990 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
991 (` (edebug-interactive-entry
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
992 (quote (, def-name))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
993 (quote ((,@ (edebug-form))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
994 (if (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
995 (edebug-syntax-error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
996 "Only first expression used in interactive form.")))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
997
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
998
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
999 (put 'cond 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1000 '(&rest (form &rest form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1001
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1002 (defun edebug-cond ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1003 "Return the edebug form of the cond form."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1004 (let (value-value-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1005 class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1006 (while (not (eq 'rparen (setq class (edebug-next-token-class))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1007 (setq value-value-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1008 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1009 (if (not (eq 'lparen class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1010 (let ((thing (edebug-read-sexp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1011 (if thing
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1012 (edebug-syntax-error "Condition expected in cond")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1013 nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1014 (forward-char 1) ; \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1015 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1016 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1017 (edebug-form)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1018 (if (eq 'rparen (edebug-next-token-class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1019 nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1020 (edebug-sexp-list t)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1021 (if (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1022 (edebug-syntax-error "Right paren expected in cond"))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1023 (forward-char 1) ; \)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1024 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1025 value-value-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1026 (nreverse value-value-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1027
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1028
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
1029 ;; Bug: this doesn't support condition name lists
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1030 (put 'condition-case 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1031 '(symbolp
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1032 form
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1033 &rest (symbolp &optional form)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1034
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1035 (defun edebug-condition-case ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1036 "Return the edebug form of the condition-case form."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1037 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1038 (let (token)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1039 ;; read the variable or nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1040 (setq token (edebug-read-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1041 (if (not (symbolp token))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1042 (edebug-syntax-error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1043 "Variable or nil required for condition-case; found: %s" token))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1044 token)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1045
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1046 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1047 (edebug-form) ; the form
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1048
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1049 ;; process handlers
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1050 (let (symb-sexp-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1051 class)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1052 (while (not (eq 'rparen (setq class (edebug-next-token-class))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1053 (setq symb-sexp-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1054 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1055 (if (not (eq 'lparen class))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1056 (edebug-syntax-error "Bad handler in condition-case.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1057 (forward-char 1) ; \(
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1058 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1059 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1060 (edebug-read-sexp) ; the error-condition
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1061 (and (not (eq 'rparen (edebug-next-token-class)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1062 (edebug-sexp-list t)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1063 (forward-char 1) ; \)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1064 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1065 symb-sexp-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1066 (nreverse symb-sexp-list)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1067
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1068
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1069
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1070 ;;------------------------------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1071 ;; Parser utilities
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1072
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1073 (defun edebug-syntax-error (msg &rest args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1074 "Signal an invalid-read-syntax with MSG and ARGS.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1075 This is caught by edebug-defun."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1076 (signal 'invalid-read-syntax (apply 'format msg args)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1077
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1078
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1079 (defun edebug-skip-whitespace ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1080 "Leave point before the next token, skipping white space and comments."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1081 (skip-chars-forward " \t\r\n\f")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1082 (while (= (following-char) ?\;)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1083 (skip-chars-forward "^\n\r") ; skip the comment
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1084 (skip-chars-forward " \t\r\n\f")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1085
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1086 (defun edebug-read-sexp ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1087 "Read one sexp from the current buffer starting at point.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1088 Leave point immediately after it. A sexp can be a list or atom.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1089 An atom is a symbol (or number), character, string, or vector."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1090 ;; This is gummed up by parser inconsistencies (bugs?)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1091 (let (token)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1092 (edebug-skip-whitespace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1093 (if (or (= (following-char) ?\[) (= (following-char) ??))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1094 ;; scan-sexps doesn't read vectors or character literals correctly,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1095 ;; but read does.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1096 (setq token (read (current-buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1097 (goto-char
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1098 (min ; use the lesser of the read and scan-sexps motion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1099 ;; read goes one too far if (quoted) string or symbol
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1100 ;; is immediately followed by non-whitespace
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1101 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1102 (setq token (read (current-buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1103 (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1104 ;; scan-sexps reads too far if a quoting character is read
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1105 (scan-sexps (point) 1))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1106 token))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1107
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1108 (defconst edebug-syntax-table
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1109 (let ((table (make-vector 256 'symbol)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1110 ;; Treat numbers as symbols, because of confusion with -, -1, and 1-.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1111 (aset table ?\( 'lparen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1112 (aset table ?\) 'rparen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1113 (aset table ?\' 'quote)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1114 (aset table ?\" 'string)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1115 (aset table ?\? 'char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1116 (aset table ?\[ 'vector)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1117 (aset table ?\. 'dot)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1118 ;; We dont care about any other chars since they wont be seen.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1119 table)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1120 "Lookup table for the token class of each character.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1121
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1122 (defun edebug-next-token-class ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1123 "Move to the next token and return its class. We only care about
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1124 lparen, rparen, dot, quote, string, char, vector, or symbol."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1125 (edebug-skip-whitespace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1126 (aref edebug-syntax-table (following-char)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1127
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1128
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1129 ;;;=================================================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1130 ;;; The debugger itself
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1131 ;;; -------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1132
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1133
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1134 (defvar edebug-active nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1135 "Non-nil when edebug is active")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1136
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1137
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1138 ;;; add minor-mode-alist entry
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1139 (or (assq 'edebug-active minor-mode-alist)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1140 (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1141 minor-mode-alist)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1142
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1143 (defvar edebug-backtrace nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1144 "Stack of active functions evaluated via edebug.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1145 Should be nil at the top level.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1146
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1147 (defvar edebug-offset-indices nil ; not used yet.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1148 "Stack of offset indices of visited edebug sexps.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1149 Should be nil at the top level.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1150
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1151 (defvar edebug-entered nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1152 "Non-nil if edebug has already been entered at this recursive edit level.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1153
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1154
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1155 (defun edebug-enter (edebug-func edebug-args edebug-body)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1156 "Entering FUNC. The arguments are ARGS, and the body is BODY.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1157 Setup edebug variables and evaluate BODY. This function is called
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1158 when a function evaluated with edebug-defun is entered. Return the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1159 result of BODY."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1160
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1161 ;; Is this the first time we are entering edebug since
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1162 ;; lower-level recursive-edit command?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1163 (if (and (not edebug-entered)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1164 edebug-initial-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1165 ;; Reset edebug-mode to the initial mode.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1166 (setq edebug-mode edebug-initial-mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1167 (let* ((edebug-entered t)
4761
fd03ee47c0b2 (edebug-enter): Don't call the current function being debugged in
Brian Fox <bfox@gnu.org>
parents: 3591
diff changeset
1168 (pre-command-hook (if (memq edebug-func pre-command-hook)
fd03ee47c0b2 (edebug-enter): Don't call the current function being debugged in
Brian Fox <bfox@gnu.org>
parents: 3591
diff changeset
1169 nil pre-command-hook))
fd03ee47c0b2 (edebug-enter): Don't call the current function being debugged in
Brian Fox <bfox@gnu.org>
parents: 3591
diff changeset
1170 (post-command-hook (if (memq edebug-func post-command-hook)
fd03ee47c0b2 (edebug-enter): Don't call the current function being debugged in
Brian Fox <bfox@gnu.org>
parents: 3591
diff changeset
1171 nil post-command-hook))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1172 (edebug-data (get edebug-func 'edebug))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1173 ;; pull out parts of the edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1174 (edebug-func-mark (car edebug-data)) ; mark at function start
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1175
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1176 (edebug-buffer (marker-buffer edebug-func-mark))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1177 (edebug-backtrace (cons edebug-func edebug-backtrace))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1178 (max-lisp-eval-depth (+ 6 max-lisp-eval-depth)) ; too much??
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1179 (max-specpdl-size (+ 10 max-specpdl-size)) ; the args and these vars
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1180 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1181 (if edebug-trace
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1182 (let ((edebug-stack-depth (1- (length edebug-backtrace)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1183 edebug-result)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1184 (edebug-print-trace-entry
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1185 "*edebug-trace*" edebug-func edebug-args edebug-stack-depth)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1186 (setq edebug-result (eval edebug-body))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1187 (edebug-print-trace-exit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1188 "*edebug-trace*" edebug-func edebug-result edebug-stack-depth)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1189 edebug-result)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1190 (eval edebug-body)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1191 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1192
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1193 (defun edebug-interactive-entry (edebug-func edebug-args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1194 "Evaluating FUNCs non-string argument of interactive form ARGS."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1195 (if (and (not edebug-entered)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1196 edebug-initial-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1197 ;; Reset edebug-mode to the initial mode.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1198 (setq edebug-mode edebug-initial-mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1199 (let* ((edebug-entered t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1200 (edebug-data (get edebug-func 'edebug))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1201 ;; pull out parts of the edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1202 (edebug-func-mark (car edebug-data)) ; mark at function start
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1203
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1204 (edebug-buffer (marker-buffer edebug-func-mark))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1205 ;; (edebug-backtrace (cons edebug-func edebug-backtrace))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1206 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1207 (eval edebug-args)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1208
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1209
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1210 (defun edebug-print-trace-entry
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1211 (edebug-stream edebug-function edebug-args edebug-stack-depth)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1212 (edebug-trace-display
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1213 edebug-stream
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1214 "%sEnter: %s\n" (make-string edebug-stack-depth ?\ ) edebug-function)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1215 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1216
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1217 (defun edebug-print-trace-exit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1218 (edebug-stream edebug-function edebug-result edebug-stack-depth)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1219 (edebug-trace-display
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1220 edebug-stream
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1221 "%sExit: %s\n" (make-string edebug-stack-depth ?\ ) edebug-function)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1222 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1223
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1224
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1225 (defun edebug (edebug-before-index edebug-after-index edebug-exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1226 "Debug current function given BEFORE and AFTER positions around EXP.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1227 BEFORE and AFTER are indexes into the position offset vector in the
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1228 functions 'edebug property. edebug is called from functions compiled
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1229 with edebug-defun."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1230 (let ((max-lisp-eval-depth (+ 5 max-lisp-eval-depth)) ; enough??
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1231 (max-specpdl-size (+ 7 max-specpdl-size)) ; the args and these vars
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1232 (edebug-offset-indices
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1233 (cons edebug-before-index edebug-offset-indices))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1234 ;; Save the outside value of executing macro.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1235 (edebug-outside-executing-macro executing-macro)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1236 ;; Don't keep reading from an executing kbd macro within edebug!
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1237 (executing-macro nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1238 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1239 (if (and (eq edebug-mode 'Go-nonstop)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1240 (not (edebug-input-pending-p)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1241 ;; Just return evalled expression.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1242 (eval edebug-exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1243 (edebug-debugger edebug-before-index 'enter edebug-exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1244 (edebug-debugger edebug-after-index 'exit (eval edebug-exp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1245 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1246
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1247
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1248 (defun edebug-debugger (edebug-offset-index edebug-arg-mode edebug-exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1249 "Determine if edebug display should be updated."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1250 (let* (
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1251 ;; This needs to be here since breakpoints may be changed.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1252 (edebug-breakpoints (car (cdr edebug-data))) ; list of breakpoints
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1253 (edebug-break-data (assq edebug-offset-index edebug-breakpoints))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1254 (edebug-break
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1255 (if edebug-break-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1256 (let ((edebug-break-condition
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1257 (car (cdr edebug-break-data))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1258 (or (not edebug-break-condition)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1259 (eval edebug-break-condition)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1260 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1261 (if (and edebug-break
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1262 (car (cdr (cdr edebug-break-data)))) ; is it temporary?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1263 ;; Delete the breakpoint.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1264 (setcdr edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1265 (cons (delq edebug-break-data edebug-breakpoints)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1266 (cdr (cdr edebug-data)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1267
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1268 ;; Dont do anything if mode is go, continue, or Continue-fast
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1269 ;; and no break, and no input.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1270 (if (or (and (not (memq edebug-mode '(go continue Continue-fast)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1271 (or edebug-stop-before-symbols
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1272 (not (and (eq edebug-arg-mode 'enter)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1273 (symbolp edebug-exp)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1274 (edebug-input-pending-p)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1275 edebug-break)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1276 (edebug-display))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1277
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1278 edebug-exp
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1279 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1280
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1281
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1282 (defvar edebug-window-start 0
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1283 "Remember where each buffers' window starts between edebug calls.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1284 This is to avoid spurious recentering.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1285
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1286 (setq-default edebug-window-start 0)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1287 (make-variable-buffer-local 'edebug-window-start)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1288
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1289 (defun edebug-display ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1290 "Setup windows for edebug, determine mode, maybe enter recursive-edit."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1291 ;; uses local variables of edebug-enter, edebug, and edebug-debugger.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1292 (let ((edebug-active t) ; for minor mode alist
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1293 edebug-stop ; should we enter recursive-edit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1294 (edebug-point (+ edebug-func-mark
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1295 (aref (car (cdr (cdr edebug-data)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1296 edebug-offset-index)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1297 (edebug-buffer-points
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1298 (if edebug-save-buffer-points (edebug-get-buffer-points)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1299 edebug-window ; window displaying edebug-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1300 edebug-inside-window ; window displayed after recursive edit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1301 (edebug-outside-window (selected-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1302 (edebug-outside-buffer (current-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1303 (edebug-outside-point (point))
2629
137117f5c44c * edebug.el (edebug-display): Call the `mark' function with the
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
1304 (edebug-outside-mark (mark t))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1305 edebug-outside-windows ; window or screen configuration
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1306 edebug-outside-edebug-point ; old point in edebug buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1307 edebug-outside-edebug-mark
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1308
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1309 edebug-eval-buffer ; declared here so we can kill it below
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1310 (edebug-eval-result-list (and edebug-eval-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1311 (edebug-eval-result-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1312 (edebug-outside-o-a-p overlay-arrow-position)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1313 (edebug-outside-o-a-s overlay-arrow-string)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1314 (edebug-outside-c-i-e-a cursor-in-echo-area)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1315
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1316 edebug-outside-point-min
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1317 edebug-outside-point-max
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1318
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1319 overlay-arrow-position
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1320 overlay-arrow-string
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1321 (cursor-in-echo-area nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1322 ;; any others??
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1323 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1324 (if (not (buffer-name edebug-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1325 (let (debug-on-error nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1326 (error "Buffer defining %s not found." edebug-func)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1327
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1328 ;; Save windows now before we modify them.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1329 (if edebug-save-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1330 (setq edebug-outside-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1331 (edebug-current-window-configuration)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1332
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1333 ;; If edebug-buffer is not currently displayed,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1334 ;; first find a window for it.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1335 (edebug-pop-to-buffer edebug-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1336 (setq edebug-window (selected-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1337
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1338 ;; Now display eval list, if any.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1339 ;; This is done after the pop to edebug-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1340 ;; so that buffer-window correspondence is correct after quit.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1341 (edebug-eval-display edebug-eval-result-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1342 (select-window edebug-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1343
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1344 (if edebug-save-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1345 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1346 (setq edebug-outside-edebug-point (point))
2629
137117f5c44c * edebug.el (edebug-display): Call the `mark' function with the
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
1347 (setq edebug-outside-edebug-mark (mark t))))
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1348
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1349 (edebug-save-restriction
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1350 (setq edebug-outside-point-min (point-min))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1351 (setq edebug-outside-point-max (point-max))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1352 (widen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1353 (goto-char edebug-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1354
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1355 (setq edebug-window-start
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1356 (edebug-adjust-window edebug-window-start))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1357
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1358 (if (edebug-input-pending-p) ; not including keyboard macros
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1359 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1360 (setq edebug-mode 'step)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1361 (setq edebug-stop t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1362 (edebug-stop)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1363 ;; (discard-input) ; is this unfriendly??
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1364 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1365 (edebug-overlay-arrow)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1366
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1367 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1368 ((eq 'exit edebug-arg-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1369 ;; Display result of previous evaluation.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1370 (setq edebug-previous-result edebug-exp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1371 (edebug-previous-result))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1372
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1373 ((eq 'error edebug-arg-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1374 ;; Display error message
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1375 (beep)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1376 (if (eq 'quit (car edebug-exp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1377 (message "Quit")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1378 (message "%s: %s"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1379 (get (car edebug-exp) 'error-message)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1380 (car (cdr edebug-exp)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1381
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1382 (edebug-break
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1383 (message "Break"))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1384 (t (message "")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1385
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1386 (if edebug-break
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1387 (if (not (memq edebug-mode '(continue Continue-fast)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1388 (setq edebug-stop t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1389 (if (eq edebug-mode 'continue)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1390 (edebug-sit-for 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1391 (edebug-sit-for 0)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1392 ;; not edebug-break
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1393 (if (eq edebug-mode 'trace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1394 (edebug-sit-for 1) ; Force update and pause.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1395 (if (eq edebug-mode 'Trace-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1396 (edebug-sit-for 0) ; Force update and continue.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1397 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1398
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1399 (unwind-protect
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1400 (if (or edebug-stop
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1401 (eq edebug-mode 'step)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1402 (eq edebug-arg-mode 'error))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1403 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1404 (setq edebug-mode 'step)
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3350
diff changeset
1405 (edebug-overlay-arrow) ; this doesn't always show up.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1406 (edebug-recursive-edit));; <<<<<< Recursive edit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1407 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1408
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1409 (if edebug-save-buffer-points
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1410 (edebug-set-buffer-points))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1411 ;; Since we may be in a save-excursion, in case of quit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1412 ;; restore the outside window only.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1413 (select-window edebug-outside-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1414 ) ; unwind-protect
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1415
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1416 ;; None of the following is done if quit or signal occurs.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1417 (if edebug-save-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1418 ;; Restore point and mark in edebug-buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1419 ;; This does the save-excursion recovery only if no quit.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1420 ;; If edebug-buffer == edebug-outside-buffer,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1421 ;; then this is redundant with outside save-excursion.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1422 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1423 (set-buffer edebug-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1424 (goto-char edebug-outside-edebug-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1425 (if (mark-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1426 (set-marker (mark-marker) edebug-outside-edebug-mark))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1427 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1428 ) ; edebug-save-restriction
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1429
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1430 ;; Restore windows, buffer, point, and mark.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1431 (if edebug-save-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1432 ;; Restore windows before continuing.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1433 (edebug-set-window-configuration edebug-outside-windows))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1434 (set-buffer edebug-outside-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1435 (goto-char edebug-outside-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1436 (if (mark-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1437 (set-marker (mark-marker) edebug-outside-mark))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1438 ;; The following is not sufficient, and sometimes annoying.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1439 ;; (if (memq edebug-mode '(go Go-nonstop))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1440 ;; (edebug-sit-for 0))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1441 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1442
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1443
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1444 (defvar edebug-depth 0
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1445 "Number of recursive edits started by edebug.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1446 Should be 0 at the top level.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1447
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1448 (defvar edebug-recursion-depth 0
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1449 "Value of recursion-depth when edebug was called.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1450
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1451
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1452 (defun edebug-recursive-edit ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1453 "Start up a recursive edit inside of edebug."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1454 ;; The current buffer is the edebug-buffer, which is put into edebug-mode.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1455 (let ((edebug-buffer-read-only buffer-read-only)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1456 ;; match-data must be done in the outside buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1457 (edebug-outside-match-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1458 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1459 (set-buffer edebug-outside-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1460 (match-data)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1461
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1462 (edebug-depth (1+ edebug-depth))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1463 (edebug-recursion-depth (recursion-depth))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1464 edebug-entered ; bind locally to nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1465 edebug-backtrace-buffer ; each recursive edit gets its own
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1466 ;; The window configuration may be saved and restored
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1467 ;; during a recursive-edit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1468 edebug-inside-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1469
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1470 (edebug-outside-map (current-local-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1471 (edebug-outside-standard-output standard-output)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1472 (edebug-outside-standard-input standard-input)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1473
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1474 (edebug-outside-last-command-char last-command-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1475 (edebug-outside-last-command last-command)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1476 (edebug-outside-this-command this-command)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1477 (edebug-outside-last-input-char last-input-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1478 ;; (edebug-outside-unread-command-char unread-command-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1479
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1480 ;; Declare the following local variables to protect global values.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1481 ;; We could set these to the values for previous edebug call.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1482 ;; But instead make it local, but use global value.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1483 (last-command-char last-command-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1484 (last-command last-command)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1485 (this-command this-command)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1486 (last-input-char last-input-char)
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 851
diff changeset
1487 ;; Assume no edebug command sets unread-command-events.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1488 ;; (unread-command-char -1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1489
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1490 (debug-on-error debug-on-error)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1491
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1492 ;; others??
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1493 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1494
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1495 (if (and (eq edebug-mode 'go)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1496 (not (memq edebug-arg-mode '(exit error))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1497 (message "Break"))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1498 (edebug-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1499 (if (boundp 'edebug-outside-debug-on-error)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1500 (setq debug-on-error edebug-outside-debug-on-error))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1501
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1502 (setq buffer-read-only t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1503 (unwind-protect
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1504 (recursive-edit) ; <<<<<<<<<< Recursive edit
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1505
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1506 ;; Do the following, even if quit occurs.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1507 (if edebug-backtrace-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1508 (kill-buffer edebug-backtrace-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1509 ;; Could be an option to keep eval display up.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1510 (if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1511
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1512 ;; Remember selected-window after recursive-edit.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1513 (setq edebug-inside-window (selected-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1514
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1515 (store-match-data edebug-outside-match-data)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1516
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1517 ;; Recursive edit may have changed buffers,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1518 ;; so set it back before exiting let.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1519 (if (buffer-name edebug-buffer) ; if it still exists
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1520 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1521 (set-buffer edebug-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1522 (if (memq edebug-mode '(go Go-nonstop))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1523 (edebug-overlay-arrow))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1524 (setq buffer-read-only edebug-buffer-read-only)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1525 (use-local-map edebug-outside-map)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1526 ;; Remember current window-start for next visit.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1527 (select-window edebug-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1528 (if (eq edebug-buffer (window-buffer edebug-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1529 (setq edebug-window-start (window-start)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1530 (select-window edebug-inside-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1531 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1532 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1533
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1534
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1535 ;;--------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1536 ;; Display related functions
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1537
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1538 (defun edebug-adjust-window (old-start)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1539 "Adjust window to fit as much as possible following point.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1540 The display should prefer to start at OLD-START if point is not visible.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1541 Return the new window-start."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1542 (if (not (pos-visible-in-window-p))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1543 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1544 (set-window-start (selected-window) old-start)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1545 (if (not (pos-visible-in-window-p))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1546 (let ((start (window-start))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1547 (pnt (point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1548 (set-window-start
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1549 (selected-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1550 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1551 (forward-line
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1552 (if (< pnt start) -1 ; one line before
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1553 (- (/ (window-height) 2)) ; center the line
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1554 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1555 (beginning-of-line)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1556 (point)))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1557 (window-start))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1558
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1559
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1560 (defconst edebug-arrow-alist
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1561 '((Continue-fast . ">")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1562 (Trace-fast . ">")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1563 (continue . ">")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1564 (trace . "->")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1565 (step . "=>")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1566 (go . "<>")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1567 (Go-nonstop . "..") ; not used
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1568 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1569 "Association list of arrows for each edebug mode.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1570 If you come up with arrows that make more sense, let me know.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1571
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1572 (defun edebug-overlay-arrow ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1573 "Set up the overlay arrow at beginning-of-line in current buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1574 The arrow string is derived from edebug-arrow-alist and edebug-mode."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1575 (let* ((pos))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1576 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1577 (beginning-of-line)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1578 (setq pos (point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1579 (setq overlay-arrow-string
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1580 (cdr (assq edebug-mode edebug-arrow-alist)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1581 (setq overlay-arrow-position (make-marker))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1582 (set-marker overlay-arrow-position pos (current-buffer))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1583
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1584
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1585 (put 'edebug-outside-excursion 'edebug-form-hook
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1586 '(&rest form))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1587
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1588 (defmacro edebug-outside-excursion (&rest body)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1589 "Evaluate an expression list in the outside context.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1590 Return the result of the last expression."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1591 (` (save-excursion ; of current-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1592 (if edebug-save-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1593 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1594 ;; After excursion, we will
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1595 ;; restore to current window configuration.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1596 (setq edebug-inside-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1597 (edebug-current-window-configuration))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1598 ;; Restore outside windows.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1599 (edebug-set-window-configuration edebug-outside-windows)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1600
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1601 (set-buffer edebug-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1602 ;; Restore outside context.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1603 (let ((edebug-inside-map (current-local-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1604 (last-command-char edebug-outside-last-command-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1605 (last-command edebug-outside-last-command)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1606 (this-command edebug-outside-this-command)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1607 ;; (unread-command-char edebug-outside-unread-command-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1608 (last-input-char edebug-outside-last-input-char)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1609 (overlay-arrow-position edebug-outside-o-a-p)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1610 (overlay-arrow-string edebug-outside-o-a-s)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1611 (cursor-in-echo-area edebug-outside-c-i-e-a)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1612 (standard-output edebug-outside-standard-output)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1613 (standard-input edebug-outside-standard-input)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1614 (executing-macro edebug-outside-executing-macro)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1615 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1616 (unwind-protect
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1617 (save-restriction
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1618 (narrow-to-region edebug-outside-point-min
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1619 edebug-outside-point-max)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1620 (save-excursion ; of edebug-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1621 (if edebug-save-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1622 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1623 (goto-char edebug-outside-edebug-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1624 (if (mark-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1625 (set-marker (mark-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1626 edebug-outside-edebug-mark))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1627 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1628 (use-local-map edebug-outside-map)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1629 (store-match-data edebug-outside-match-data)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1630 (select-window edebug-outside-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1631 (set-buffer edebug-outside-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1632 (goto-char edebug-outside-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1633 (,@ body)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1634 ) ; save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1635 ) ; save-restriction
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1636 ;; Back to edebug-buffer. Restore rest of inside context.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1637 (use-local-map edebug-inside-map)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1638 (if edebug-save-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1639 ;; Restore inside windows.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1640 (edebug-set-window-configuration edebug-inside-windows))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1641 )) ; let
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1642 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1643
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1644
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1645 (defun edebug-toggle-save-windows ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1646 "Toggle the edebug-save-windows variable.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1647 Each time you toggle it, the inside and outside window configurations
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1648 become the same as the current configuration."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1649 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1650 (if (setq edebug-save-windows (not edebug-save-windows))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1651 (setq edebug-inside-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1652 (setq edebug-outside-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1653 (edebug-current-window-configuration))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1654 (message "Window saving is %s."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1655 (if edebug-save-windows "on" "off")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1656
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1657
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1658 (defun edebug-where ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1659 "Show the debug windows and where we stopped in the program."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1660 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1661 (if (not edebug-active)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1662 (error "edebug is not active."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1663 (edebug-pop-to-buffer edebug-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1664 (goto-char edebug-point) ; from edebug
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1665 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1666
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1667 (defun edebug-view-outside ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1668 "Change to the outside window configuration."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1669 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1670 (if (not edebug-active)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1671 (error "edebug is not active."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1672 (setq edebug-inside-windows (edebug-current-window-configuration))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1673 (edebug-set-window-configuration edebug-outside-windows)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1674 (goto-char edebug-outside-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1675 (message "Window configuration outside of edebug. Return with %s"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1676 (substitute-command-keys "\\<global-map>\\[edebug-where]")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1677
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1678
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1679 (defun edebug-bounce-point ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1680 "Bounce the point in the outside current buffer."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1681 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1682 (if (not edebug-active)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1683 (error "edebug is not active."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1684 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1685 ;; If the buffer's currently displayed, avoid the set-window-configuration.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1686 (save-window-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1687 (edebug-pop-to-buffer edebug-outside-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1688 ;; (edebug-sit-for 1) ; this shouldnt be necessary
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1689 (goto-char edebug-outside-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1690 ;; (message "current buffer: %s" (current-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1691 (edebug-sit-for 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1692 (edebug-pop-to-buffer edebug-buffer))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1693
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1694
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1695
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1696 ;;--------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1697 ;; epoch related things
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1698
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1699 (defvar edebug-epoch-running (and (boundp 'epoch::version) epoch::version)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1700 "non-nil if epoch is running.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1701 Windows are handled a little differently under epoch.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1702
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1703
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1704 (defun edebug-current-window-configuration ()
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 727
diff changeset
1705 "Return the current window or frame configuration."
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1706 (if edebug-epoch-running
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1707 (edebug-current-screen-configuration)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1708 (current-window-configuration)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1709
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1710
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1711 (defun edebug-set-window-configuration (conf)
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 727
diff changeset
1712 "Set the window or frame configuration to CONF."
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1713 (if edebug-epoch-running
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1714 (edebug-set-screen-configuration conf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1715 (set-window-configuration conf)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1716
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1717
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1718 (defun edebug-get-buffer-window (buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1719 (if edebug-epoch-running
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1720 (epoch::get-buffer-window buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1721 (get-buffer-window buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1722
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1723
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1724 (defun edebug-pop-to-buffer (buffer)
778
cd00bdacc17b *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 727
diff changeset
1725 "Like pop-to-buffer, but select a frame that buffer was shown in."
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1726 (let ((edebug-window (edebug-get-buffer-window buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1727 (if edebug-window
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1728 (select-window edebug-window)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1729 ;; It is not currently displayed, so find some place to display it.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1730 (if edebug-epoch-running
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1731 ;; Select a screen that the buffer has been displayed in before
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1732 ;; or the current screen otherwise.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1733 (select-screen
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1734 ;; allowed-screens in epoch 3.2, was called screens before that
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1735 (or (car (symbol-buffer-value 'allowed-screens buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1736 (epoch::current-screen))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1737 (if (one-window-p)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1738 (split-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1739 (select-window (next-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1740 (set-window-buffer (selected-window) buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1741 (set-window-hscroll (selected-window) 0)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1742 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1743 ;; Selecting the window does not set the buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1744 (set-buffer buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1745 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1746
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1747
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1748 (defun edebug-current-screen-configuration ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1749 "Return an object recording the current configuration of Epoch screen-list.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1750 The object is a list of pairs of the form (SCREEN . CONFIGURATION)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1751 where SCREEN has window-configuration CONFIGURATION. The current
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1752 screen is the head of the list."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1753 (let ((screen-list (epoch::screen-list 'unmapped))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1754 (current-screen (epoch::get-screen))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1755 (current-buffer (current-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1756 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1757 ;; put current screen first
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1758 (setq screen-list (cons current-screen (delq current-screen screen-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1759 (prog1
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1760 (mapcar (function
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1761 (lambda (screen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1762 (cons screen
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1763 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1764 (epoch::select-screen screen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1765 (current-window-configuration)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1766 screen-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1767 (epoch::select-screen current-screen)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1768 (set-buffer current-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1769 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1770
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1771 (defun edebug-set-screen-configuration (sc)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1772 "Set the window-configuration for all the screens in SC.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1773 Set the current screen to be the head of SC."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1774 (mapcar (function
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1775 (lambda (screen-conf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1776 (if (epoch::screen-p (car screen-conf)) ; still exist?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1777 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1778 (epoch::select-screen (car screen-conf))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1779 (set-window-configuration (cdr screen-conf))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1780 sc)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1781 (if (epoch::screen-p (car (car sc)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1782 (epoch::select-screen (car (car sc))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1783 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1784
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1785
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1786 (defun edebug-sit-for (arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1787 (if edebug-epoch-running
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1788 (epoch::dispatch-events))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1789 (sit-for arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1790 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1791
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1792 (defun edebug-input-pending-p ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1793 (if edebug-epoch-running
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1794 (epoch::dispatch-events))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1795 (input-pending-p)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1796 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1797
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1798
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1799
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1800 ;;--------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1801 ;; breakpoint related functions
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1802
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1803 (defun edebug-find-stop-point ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1804 "Return (function . index) of the nearest edebug stop point."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1805 (let* ((def-name (edebug-which-function))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1806 (edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1807 (or (get def-name 'edebug)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1808 (error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1809 "%s must first be evaluated with edebug-defun." def-name)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1810 ;; pull out parts of edebug-data.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1811 (edebug-func-mark (car edebug-data))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1812 (edebug-breakpoints (car (cdr edebug-data)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1813
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1814 (offset-vector (car (cdr (cdr edebug-data))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1815 (offset (- (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1816 (if (looking-at "[ \t]")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1817 ;; skip backwards until non-whitespace, or bol
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1818 (skip-chars-backward " \t"))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1819 (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1820 edebug-func-mark))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1821 len i)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1822 ;; the offsets are in order so we can do a linear search
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1823 (setq len (length offset-vector))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1824 (setq i 0)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1825 (while (and (< i len) (> offset (aref offset-vector i)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1826 (setq i (1+ i)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1827 (if (and (< i len)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1828 (<= offset (aref offset-vector i)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1829 ;; return the relevant info
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1830 (cons def-name i)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1831 (message "Point is not on an expression in %s."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1832 def-name)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1833 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1834
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1835
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1836 (defun edebug-next-breakpoint ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1837 "Move point to the next breakpoint, or first if none past point."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1838 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1839 (let ((edebug-stop-point (edebug-find-stop-point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1840 (if edebug-stop-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1841 (let* ((def-name (car edebug-stop-point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1842 (index (cdr edebug-stop-point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1843 (edebug-data (get def-name 'edebug))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1844
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1845 ;; pull out parts of edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1846 (edebug-func-mark (car edebug-data))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1847 (edebug-breakpoints (car (cdr edebug-data)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1848 (offset-vector (car (cdr (cdr edebug-data))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1849 breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1850 (if (not edebug-breakpoints)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1851 (message "No breakpoints in this function.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1852 (let ((breaks edebug-breakpoints))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1853 (while (and breaks
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1854 (<= (car (car breaks)) index))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1855 (setq breaks (cdr breaks)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1856 (setq breakpoint
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1857 (if breaks
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1858 (car breaks)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1859 ;; goto the first breakpoint
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1860 (car edebug-breakpoints)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1861 (goto-char (+ edebug-func-mark
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1862 (aref offset-vector (car breakpoint))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1863
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1864 (message (concat (if (car (cdr (cdr breakpoint)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1865 "Temporary " "")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1866 (if (car (cdr breakpoint))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1867 (format "Condition: %s"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1868 (prin1-to-string
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1869 (car (cdr breakpoint))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1870 "")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1871 ))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1872
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1873
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1874 (defun edebug-modify-breakpoint (flag &optional condition temporary)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1875 "Modify the breakpoint for the form at point or after it according
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1876 to FLAG: set if t, clear if nil. Then move to that point.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1877 If CONDITION or TEMPORARY are non-nil, add those attributes to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1878 the breakpoint. "
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1879 (let ((edebug-stop-point (edebug-find-stop-point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1880 (if edebug-stop-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1881 (let* ((def-name (car edebug-stop-point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1882 (index (cdr edebug-stop-point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1883 (edebug-data (get def-name 'edebug))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1884
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1885 ;; pull out parts of edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1886 (edebug-func-mark (car edebug-data))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1887 (edebug-breakpoints (car (cdr edebug-data)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1888 (offset-vector (car (cdr (cdr edebug-data))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1889 present)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1890 ;; delete it either way
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1891 (setq present (assq index edebug-breakpoints))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1892 (setq edebug-breakpoints (delq present edebug-breakpoints))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1893 (if flag
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1894 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1895 ;; add it to the list and resort
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1896 (setq edebug-breakpoints
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1897 (edebug-sort-alist
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1898 (cons
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1899 (list index condition temporary)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1900 edebug-breakpoints) '<))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1901 (message "Breakpoint set in %s." def-name))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1902 (if present
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1903 (message "Breakpoint unset in %s." def-name)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1904 (message "No breakpoint here.")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1905
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1906 (setcdr edebug-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1907 (cons edebug-breakpoints (cdr (cdr edebug-data))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1908 (goto-char (+ edebug-func-mark (aref offset-vector index)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1909 ))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1910
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1911 (defun edebug-set-breakpoint (arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1912 "Set the breakpoint of nearest sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1913 With prefix argument, make it a temporary breakpoint."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1914 (interactive "P")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1915 (edebug-modify-breakpoint t nil arg))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1916
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1917 (defun edebug-unset-breakpoint ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1918 "Clear the breakpoint of nearest sexp."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1919 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1920 (edebug-modify-breakpoint nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1921
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1922 (defun edebug-set-conditional-breakpoint (arg condition)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1923 "Set a conditional breakpoint at nearest sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1924 The condition is evaluated in the outside context.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1925 With prefix argument, make it a temporary breakpoint."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1926 (interactive "P\nxCondition: ")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1927 (edebug-modify-breakpoint t condition arg))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1928
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1929
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1930 ;;--------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1931 ;; Mode switching functions
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1932
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1933 (defun edebug-set-mode (mode shortmsg msg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1934 "Set the edebug mode to MODE.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1935 Display SHORTMSG, or MSG if not within edebug."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1936 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1937 (setq edebug-mode mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1938 (if (< 0 edebug-depth)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1939 (if (eq (current-buffer) edebug-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1940 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1941 (message shortmsg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1942 (exit-recursive-edit)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1943 (message msg)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1944
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1945
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1946 (defun edebug-step-through ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1947 "Proceed to next debug step."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1948 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1949 (edebug-set-mode 'step "" "edebug will stop before next eval."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1950
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1951 (defun edebug-go (arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1952 "Go, evaluating until break.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1953 With ARG set temporary break at stop point and go."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1954 (interactive "P")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1955 (if arg
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1956 (edebug-set-breakpoint t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1957 (edebug-set-mode 'go "Go..." "edebug will go until break."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1958
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1959 (defun edebug-Go-nonstop ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1960 "Go, evaluating without debugging."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1961 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1962 (edebug-set-mode 'Go-nonstop "Go-Nonstop..."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1963 "edebug will not stop at breaks."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1964
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1965 (defun edebug-forward-sexp (arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1966 "Proceed from the current point to the end of the ARGth sexp ahead.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1967 If there are not ARG sexps ahead, then do edebug-step-out."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1968 (interactive "p")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1969 (condition-case err
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1970 (let ((parse-sexp-ignore-comments t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1971 ;; Call forward-sexp repeatedly until done or failure.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1972 (forward-sexp arg)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1973 (edebug-go t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1974 (error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1975 (edebug-step-out)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1976 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1977
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1978 (defun edebug-step-out ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1979 "Proceed from the current point to the end of the containing sexp.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1980 If there is no containing sexp that is not the top level defun,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1981 go to the end of the last sexp, or if that is the same point, then step."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1982 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1983 (condition-case err
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1984 (let ((parse-sexp-ignore-comments t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1985 (up-list 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1986 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1987 ;; Is there still a containing expression?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1988 (up-list 1))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1989 (edebug-go t))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1990 (error
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1991 ;; At top level - 1, so first check if there are more sexps at this level.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1992 (let ((start-point (point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1993 ;; (up-list 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1994 (down-list -1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1995 (if (= (point) start-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1996 (edebug-step-through) ; No more at this level, so step.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1997 (edebug-go t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1998 )))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1999
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2000
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2001 (defun edebug-goto-here ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2002 "Proceed to this stop point."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2003 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2004 (edebug-go t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2005 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2006
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2007 (defun edebug-trace ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2008 "Begin trace mode."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2009 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2010 (edebug-set-mode 'trace "Tracing..." "edebug will trace with pause."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2011
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2012 (defun edebug-Trace-fast ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2013 "Trace with no wait at each step."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2014 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2015 (edebug-set-mode 'Trace-fast
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2016 "Trace fast..." "edebug will trace without pause."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2017
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2018 (defun edebug-continue ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2019 "Begin continue mode."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2020 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2021 (edebug-set-mode 'continue "Continue..."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2022 "edebug will pause at breakpoints."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2023
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2024 (defun edebug-Continue-fast ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2025 "Trace with no wait at each step."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2026 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2027 (edebug-set-mode 'Continue-fast "Continue fast..."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2028 "edebug will stop and go at breakpoints."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2029
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2030
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2031 (defun edebug-step-in ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2032 "Step into the function about to be called.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2033 Do this before the arguments are evaluated since otherwise it will be
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2034 too late. One side effect of using edebug-step-in is that the next
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2035 time the function is called, edebug will be called there as well."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2036 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2037 (if (not (eq 'enter edebug-arg-mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2038 (error "You must be in front of a function or macro call."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2039 (let* ((func (car edebug-exp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2040 (func-marker (get func 'edebug)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2041 (cond
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2042 ((markerp func-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2043 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2044 (set-buffer (marker-buffer func-marker))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2045 (goto-char func-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2046 (edebug-defun)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2047 ((listp func-marker)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2048 ;; its already been evaluated for edebug
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2049 nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2050 (t (error "You must first evaluate %s in a buffer." func))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2051 (exit-recursive-edit))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2052
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2053
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2054 ;;(defun edebug-exit-out ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2055 ;; "Go until the current function exits."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2056 ;; (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2057 ;; (edebug-set-mode 'exiting "Exit..."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2058
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2059
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2060 (defun edebug-stop ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2061 "Useful for exiting from trace loop."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2062 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2063 (message "Stop"))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2064
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2065
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2066 ;;; The following initial mode setting definitions are not used yet.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2067
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2068 (defconst edebug-initial-mode-alist
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2069 '((edebug-Continue-fast . Continue-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2070 (edebug-Trace-fast . Trace-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2071 (edebug-continue . continue)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2072 (edebug-trace . trace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2073 (edebug-go . go)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2074 (edebug-step-through . step)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2075 (edebug-Go-nonstop . Go-nonstop)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2076 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2077 "Association list between commands and the modes they set.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2078
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2079
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2080 (defun edebug-set-initial-mode ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2081 "Ask for the initial mode of the enclosing function.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2082 The mode is requested via the key that would be used to set the mode in
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2083 edebug-mode."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2084 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2085 (let* ((this-function (edebug-which-function))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2086 (keymap (if (eq edebug-mode-map (current-local-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2087 edebug-mode-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2088 (old-mode (or (get this-function 'edebug-initial-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2089 edebug-initial-mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2090 (key (read-key-sequence
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2091 (format
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2092 "Change initial edebug mode for %s from %s (%s) to (enter key): "
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2093 this-function
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2094 old-mode
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2095 (where-is-internal
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2096 (car (rassq old-mode edebug-initial-mode-alist))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2097 keymap 'firstonly
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2098 ))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2099 (mode (cdr (assq (key-binding key) edebug-initial-mode-alist)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2100 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2101 (if (and mode
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2102 (or (get this-function 'edebug-initial-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2103 (not (eq mode edebug-initial-mode))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2104 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2105 (put this-function 'edebug-initial-mode mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2106 (message "Initial mode for %s is now: %s"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2107 this-function mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2108 (error "Key must map to one of the mode changing commands.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2109 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2110
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2111
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2112
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2113 ;;--------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2114 ;; Evaluation of expressions
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2115
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2116 (defvar edebug-previous-result nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2117 "Last result returned from an expression.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2118
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2119 (defun edebug-previous-result ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2120 "Return the previous result."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2121 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2122 (let ((print-escape-newlines t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2123 (print-length 20))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2124 (message "Result: %s" (prin1-to-string edebug-previous-result))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2125
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2126
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2127 (defun edebug-eval (expr)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2128 "Evaluate EXPR in the outside environment."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2129 (if (not edebug-active)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2130 (error "edebug is not active."))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2131 (edebug-outside-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2132 (eval expr)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2133
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2134 (defun edebug-eval-expression (expr)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2135 "Prompt and evaluate an expression in the outside environment.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2136 Print result in minibuffer."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2137 (interactive "xEval: ")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2138 (prin1 (edebug-eval expr)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2139
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2140 (defun edebug-eval-last-sexp ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2141 "Evaluate sexp before point in the outside environment;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2142 print value in minibuffer."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2143 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2144 (prin1 (edebug-eval (edebug-last-sexp))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2145
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2146 (defun edebug-eval-print-last-sexp ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2147 "Evaluate sexp before point in the outside environment;
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2148 print value into current buffer."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2149 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2150 (let ((standard-output (current-buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2151 (print
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2152 (condition-case err
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2153 (edebug-eval (edebug-last-sexp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2154 (error (format "%s: %s"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2155 (get (car err) 'error-message)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2156 (car (cdr err))))))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2157
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2158 ;;;---------------------------------
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2159 ;;; edebug minor mode initialization
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2160
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2161 (defvar edebug-mode 'step
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2162 "Current edebug mode set by user.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2163
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2164 (defvar edebug-mode-map nil)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2165 (if edebug-mode-map
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2166 nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2167 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2168 (setq edebug-mode-map (copy-keymap emacs-lisp-mode-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2169 ;; control
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2170 (define-key edebug-mode-map " " 'edebug-step-through)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2171 (define-key edebug-mode-map "g" 'edebug-go)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2172 (define-key edebug-mode-map "G" 'edebug-Go-nonstop)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2173 (define-key edebug-mode-map "t" 'edebug-trace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2174 (define-key edebug-mode-map "T" 'edebug-Trace-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2175 (define-key edebug-mode-map "c" 'edebug-continue)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2176 (define-key edebug-mode-map "C" 'edebug-Continue-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2177
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2178 (define-key edebug-mode-map "f" 'edebug-forward-sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2179 (define-key edebug-mode-map "h" 'edebug-goto-here)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2180
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2181 (define-key edebug-mode-map "r" 'edebug-previous-result)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2182
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2183 (define-key edebug-mode-map "i" 'edebug-step-in)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2184 (define-key edebug-mode-map "o" 'edebug-step-out)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2185
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2186 ;; (define-key edebug-mode-map "m" 'edebug-set-initial-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2187
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2188 (define-key edebug-mode-map "q" 'top-level)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2189 (define-key edebug-mode-map "a" 'abort-recursive-edit)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2190 (define-key edebug-mode-map "S" 'edebug-stop)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2191
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2192 ;; breakpoints
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2193 (define-key edebug-mode-map "b" 'edebug-set-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2194 (define-key edebug-mode-map "u" 'edebug-unset-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2195 (define-key edebug-mode-map "B" 'edebug-next-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2196 (define-key edebug-mode-map "x" 'edebug-set-conditional-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2197
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2198 ;; evaluation
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2199 (define-key edebug-mode-map "e" 'edebug-eval-expression)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2200 (define-key edebug-mode-map "\C-x\C-e" 'edebug-eval-last-sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2201 (define-key edebug-mode-map "E" 'edebug-visit-eval-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2202
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2203 ;; views
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2204 (define-key edebug-mode-map "w" 'edebug-where)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2205 (define-key edebug-mode-map "v" 'edebug-view-outside)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2206 (define-key edebug-mode-map "p" 'edebug-bounce-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2207 (define-key edebug-mode-map "W" 'edebug-toggle-save-windows)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2208
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2209 ;; misc
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2210 (define-key edebug-mode-map "?" 'edebug-help)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2211 (define-key edebug-mode-map "d" 'edebug-backtrace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2212
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2213 (define-key edebug-mode-map "-" 'negative-argument)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2214 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2215
2629
137117f5c44c * edebug.el (edebug-display): Call the `mark' function with the
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
2216 ;;;###autoload
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2217 (defvar global-edebug-prefix "\^XX"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2218 "Prefix key for global edebug commands, available from any buffer.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2219
2629
137117f5c44c * edebug.el (edebug-display): Call the `mark' function with the
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
2220 ;;;###autoload
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2221 (defvar global-edebug-map nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2222 "Global map of edebug commands, available from any buffer.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2223
2629
137117f5c44c * edebug.el (edebug-display): Call the `mark' function with the
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
2224 ;;;###autoload
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2225 (if global-edebug-map
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2226 nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2227 (setq global-edebug-map (make-sparse-keymap))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2228
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2229 (global-unset-key global-edebug-prefix)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2230 (global-set-key global-edebug-prefix global-edebug-map)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2231
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2232 ;; (define-key global-edebug-map "X" 'edebug-step-through)
2629
137117f5c44c * edebug.el (edebug-display): Call the `mark' function with the
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
2233 (define-key global-edebug-map "d" 'edebug-defun)
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2234 (define-key global-edebug-map " " 'edebug-step-through)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2235 (define-key global-edebug-map "g" 'edebug-go)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2236 (define-key global-edebug-map "G" 'edebug-Go-nonstop)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2237 (define-key global-edebug-map "t" 'edebug-trace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2238 (define-key global-edebug-map "T" 'edebug-Trace-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2239 (define-key global-edebug-map "c" 'edebug-continue)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2240 (define-key global-edebug-map "C" 'edebug-Continue-fast)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2241
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2242 ;; (define-key global-edebug-map "m" 'edebug-set-initial-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2243 (define-key global-edebug-map "b" 'edebug-set-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2244 (define-key global-edebug-map "x" 'edebug-set-conditional-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2245 (define-key global-edebug-map "u" 'edebug-unset-breakpoint)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2246 (define-key global-edebug-map "w" 'edebug-where)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2247 (define-key global-edebug-map "q" 'top-level)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2248 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2249
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2250
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2251 (defun edebug-help ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2252 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2253 (describe-function 'edebug-mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2254
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2255
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2256 (defun edebug-mode ()
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 778
diff changeset
2257 "Mode for Emacs Lisp buffers while in edebug. Under construction.
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2258
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2259 There are both buffer local and global key bindings to several
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2260 functions. E.g. edebug-step-through is bound to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2261 \\[edebug-step-through] in the debug buffer and
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2262 \\<global-map>\\[edebug-step-through] in any buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2263
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2264 edebug buffer commands:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2265 \\{edebug-mode-map}
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2266
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2267 Global commands prefixed by global-edbug-prefix:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2268 \\{global-edebug-map}
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2269
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2270 Options:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2271 edebug-all-defuns
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2272 edebug-eval-macro-args
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2273 edebug-stop-before-symbols
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2274 edebug-save-windows
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2275 edebug-save-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2276 edebug-save-buffer-points
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2277 edebug-initial-mode
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2278 edebug-trace
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2279 "
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2280 (use-local-map edebug-mode-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2281
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2282
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2283
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2284 ;;===============================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2285 ;; edebug eval list mode
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2286 ;; A list of expressions and their evaluations is displayed
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2287 ;; in edebug-eval-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2288
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2289 (defvar edebug-eval-list nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2290 "List of expressions to evaluate.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2291
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2292 ;;(defvar edebug-eval-buffer "*edebug*"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2293 ;; "*Declared globally so edebug-eval-display can be called independent
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2294 ;;of edebug (not implemented yet).")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2295
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2296
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2297 (defun edebug-eval-result-list ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2298 "Return a list of evaluations of edebug-eval-list"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2299 ;; Assumes in outside environment.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2300 (mapcar (function
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2301 (lambda (expr)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2302 (condition-case err
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2303 (eval expr)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2304 (error (format "%s: %s"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2305 (get (car err) 'error-message)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2306 (car (cdr err))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2307 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2308 edebug-eval-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2309
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2310 (defun edebug-eval-display-list (edebug-eval-result-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2311 ;; Assumes edebug-eval-buffer exists.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2312 (let ((edebug-eval-list-temp edebug-eval-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2313 (standard-output edebug-eval-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2314 (edebug-display-line
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2315 (format ";%s\n" (make-string (- (window-width) 2) ?-))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2316 (edebug-pop-to-buffer edebug-eval-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2317 (erase-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2318 (while edebug-eval-list-temp
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2319 (prin1 (car edebug-eval-list-temp)) (terpri)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2320 (prin1 (car edebug-eval-result-list)) (terpri)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2321 (princ edebug-display-line)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2322 (setq edebug-eval-list-temp (cdr edebug-eval-list-temp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2323 (setq edebug-eval-result-list (cdr edebug-eval-result-list)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2324 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2325
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2326 (defun edebug-create-eval-buffer ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2327 (if (not (and edebug-eval-buffer (buffer-name edebug-eval-buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2328 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2329 (set-buffer (setq edebug-eval-buffer (get-buffer-create "*edebug*")))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2330 (edebug-eval-mode))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2331
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2332 ;; Should generalize this to be callable outside of edebug
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2333 ;; with calls in user functions, e.g. (edebug-eval-display)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2334
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2335 (defun edebug-eval-display (edebug-eval-result-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2336 "Display expressions and evaluations in EVAL-LIST.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2337 It modifies the context by popping up the eval display."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2338 (if edebug-eval-result-list
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2339 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2340 (edebug-create-eval-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2341 (edebug-pop-to-buffer edebug-eval-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2342 (edebug-eval-display-list edebug-eval-result-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2343 )))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2344
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2345 (defun edebug-eval-redisplay ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2346 "Redisplay eval list in outside environment.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2347 May only be called from within edebug-recursive-edit."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2348 (edebug-create-eval-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2349 (edebug-pop-to-buffer edebug-eval-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2350 (edebug-outside-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2351 (edebug-eval-display-list (edebug-eval-result-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2352 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2353
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2354 (defun edebug-visit-eval-list ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2355 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2356 (edebug-eval-redisplay)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2357 (edebug-pop-to-buffer edebug-eval-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2358
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2359
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2360 (defun edebug-update-eval-list ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2361 "Replace the evaluation list with the sexps now in the eval buffer."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2362 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2363 (let ((starting-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2364 new-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2365 (goto-char (point-min))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2366 ;; get the first expression
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2367 (edebug-skip-whitespace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2368 (if (not (eobp))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2369 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2370 (forward-sexp 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2371 (setq new-list (cons (edebug-last-sexp) new-list))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2372
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2373 (while (re-search-forward "^;" nil t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2374 (forward-line 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2375 (skip-chars-forward " \t\n\r")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2376 (if (and (/= ?\; (following-char))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2377 (not (eobp)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2378 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2379 (forward-sexp 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2380 (setq new-list (cons (edebug-last-sexp) new-list)))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2381
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2382 (setq edebug-eval-list (nreverse new-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2383 (edebug-eval-redisplay)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2384 (goto-char starting-point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2385
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2386
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2387 (defun edebug-delete-eval-item ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2388 "Delete the item under point and redisplay."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2389 ;; could add arg to do repeatedly
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2390 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2391 (if (re-search-backward "^;" nil 'nofail)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2392 (forward-line 1))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2393 (delete-region
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2394 (point) (progn (re-search-forward "^;" nil 'nofail)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2395 (beginning-of-line)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2396 (point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2397 (edebug-update-eval-list))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2398
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2399
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2400
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2401 (defvar edebug-eval-mode-map nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2402 "Keymap for edebug-eval-mode. Superset of lisp-interaction-mode.")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2403
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2404 (if edebug-eval-mode-map
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2405 nil
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2406 (setq edebug-eval-mode-map (copy-keymap lisp-interaction-mode-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2407
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2408 (define-key edebug-eval-mode-map "\C-c\C-w" 'edebug-where)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2409 (define-key edebug-eval-mode-map "\C-c\C-d" 'edebug-delete-eval-item)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2410 (define-key edebug-eval-mode-map "\C-c\C-u" 'edebug-update-eval-list)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2411 (define-key edebug-eval-mode-map "\C-x\C-e" 'edebug-eval-last-sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2412 (define-key edebug-eval-mode-map "\C-j" 'edebug-eval-print-last-sexp)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2413 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2414
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2415
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2416 (defun edebug-eval-mode ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2417 "Mode for data display buffer while in edebug. Under construction.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2418 ... ignore the following...
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2419 There are both buffer local and global key bindings to several
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2420 functions. E.g. edebug-step-through is bound to
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2421 \\[edebug-step-through] in the debug buffer and
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2422 \\<global-map>\\[edebug-step-through] in any buffer.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2423
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2424 Eval list buffer commands:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2425 \\{edebug-eval-mode-map}
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2426
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2427 Global commands prefixed by global-edbug-prefix:
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2428 \\{global-edebug-map}
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2429 "
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2430 (lisp-interaction-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2431 (setq major-mode 'edebug-eval-mode)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2432 (setq mode-name "Edebug-Eval")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2433 (use-local-map edebug-eval-mode-map))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2434
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2435
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2436 ;;========================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2437 ;; Interface with standard debugger.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2438
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2439 (setq debugger 'edebug-debug)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2440 ;; (setq debugger 'debug) ; use the default
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2441
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2442 ;; Note that debug and its utilities must be byte-compiled to work, since
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2443 ;; they depend on the backtrace looking a certain way.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2444
727
540b047ece4d *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 661
diff changeset
2445 ;;;###autoload
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2446 (defun edebug-debug (&rest debugger-args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2447 "Replacement for debug.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2448 If an error or quit occurred and we are running an edebugged function,
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2449 show where we last were. Otherwise call debug normally."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2450 (if (and edebug-backtrace ; anything active?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2451 (eq (recursion-depth) edebug-recursion-depth)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2452 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2453
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2454 ;; Where were we before the error occurred?
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2455 (let ((edebug-offset-index (car edebug-offset-indices))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2456 (edebug-arg-mode (car debugger-args))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2457 (edebug-exp (car (cdr debugger-args)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2458 edebug-break-data
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2459 edebug-break
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2460 (edebug-outside-debug-on-eror debug-on-error)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2461 (debug-on-error nil))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2462 (edebug-display)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2463 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2464
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2465 ;; Otherwise call debug normally.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2466 ;; Still need to remove extraneous edebug calls from stack.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2467 (apply 'debug debugger-args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2468 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2469
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2470
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2471 (defun edebug-backtrace ()
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2472 "Display a non-working backtrace. Better than nothing..."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2473 (interactive)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2474 (let ((old-buf (current-buffer)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2475 (if (not edebug-backtrace-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2476 (setq edebug-backtrace-buffer
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2477 (let ((default-major-mode 'fundamental-mode))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2478 (generate-new-buffer "*Backtrace*"))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2479 (edebug-pop-to-buffer edebug-backtrace-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2480 (erase-buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2481 (let ((standard-output (current-buffer))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2482 (print-escape-newlines t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2483 (print-length 50)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2484 last-ok-point
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2485 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2486 (setq truncate-lines t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2487 (backtrace)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2488
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2489 ;; Clean up the backtrace.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2490 (goto-char (point-min))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2491 (delete-region
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2492 (point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2493 (progn
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2494 ;; Everything up to the first edebug is internal.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2495 (re-search-forward "^ edebug(")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2496 (forward-line 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2497 (point)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2498 (forward-line 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2499 (setq last-ok-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2500
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2501 ;; Delete interspersed edebug internals.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2502 (while (re-search-forward "^ edebug" nil t)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2503 (if (looking-at "-enter")
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2504 ;; delete extraneous progn at top level of function body
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2505 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2506 (goto-char last-ok-point)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2507 (forward-line -1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2508 (setq last-ok-point (point))))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2509 (forward-line 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2510 (delete-region last-ok-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2511 (forward-line 1) ; skip past the good line
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2512 (setq last-ok-point (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2513 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2514 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2515 (edebug-pop-to-buffer old-buf)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2516 ))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2517
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2518
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2519 ;;========================================================================
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2520 ;; Trace display - append text to a buffer, and update display.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2521 ;;; e.g.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2522 ;;; (edebug-trace-display
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2523 ;;; "*trace-point*"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2524 ;;; "saving: point = %s window-start = %s\n"
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2525 ;;; (point) (window-start))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2526
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2527 (defun edebug-trace-display (buf-name fmt &rest args)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2528 "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2529 The buffer is created if it does not exist.
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2530 You must include newlines in FMT to break lines."
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2531 (let* ((selected-window (selected-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2532 (buffer (get-buffer-create buf-name))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2533 (buf-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2534 (edebug-pop-to-buffer buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2535 (save-excursion
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2536 (setq buf-window (selected-window))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2537 (set-buffer buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2538 (goto-char (point-max))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2539 (insert (apply 'format fmt args))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2540 (set-window-point buf-window (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2541 (forward-line (- 1 (window-height buf-window)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2542 (set-window-start buf-window (point))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2543 ;; (edebug-sit-for 1)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2544 (bury-buffer buffer)
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2545 )
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2546 (select-window selected-window)))
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2547
3350
c9689f8d0574 Provide edebug.
Richard M. Stallman <rms@gnu.org>
parents: 2629
diff changeset
2548 (provide 'edebug)
c9689f8d0574 Provide edebug.
Richard M. Stallman <rms@gnu.org>
parents: 2629
diff changeset
2549
661
36fbc3f71803 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2550 ;;; edebug.el ends here