sync to xemacs-21.2.37 but STILL BUGGY
[chise/xemacs-chise.git-] / info / lispref.info-14
1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
2 lispref/lispref.texi.
3
4 INFO-DIR-SECTION XEmacs Editor
5 START-INFO-DIR-ENTRY
6 * Lispref: (lispref).           XEmacs Lisp Reference Manual.
7 END-INFO-DIR-ENTRY
8
9    Edition History:
10
11    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
20
21    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
24
25    Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
28
29    Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
33
34    Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
38
39    Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
45
46    Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
51
52 \1f
53 File: lispref.info,  Node: Jumping,  Next: Edebug Misc,  Prev: Edebug Execution Modes,  Up: Edebug
54
55 Jumping
56 -------
57
58    Commands described here let you jump to a specified location.  All,
59 except `i', use temporary breakpoints to establish the stop point and
60 then switch to `go' mode.  Any other breakpoint reached before the
61 intended stop point will also stop execution.  See *Note Breakpoints::
62 for the details on breakpoints.
63
64 `f'
65      Run the program forward over one expression
66      (`edebug-forward-sexp').  More precisely, set a temporary
67      breakpoint at the position that `C-M-f' would reach, then execute
68      in `go' mode so that the program will stop at breakpoints.
69
70      With a prefix argument N, the temporary breakpoint is placed N
71      sexps beyond point.  If the containing list ends before N more
72      elements, then the place to stop is after the containing
73      expression.
74
75      Be careful that the position `C-M-f' finds is a place that the
76      program will really get to; this may not be true in a `cond', for
77      example.
78
79      This command does `forward-sexp' starting at point rather than the
80      stop point.  If you want to execute one expression from the
81      current stop point, type `w' first, to move point there.
82
83 `o'
84      Continue "out of" an expression (`edebug-step-out').  It places a
85      temporary breakpoint at the end of the sexp containing point.
86
87      If the containing sexp is a function definition itself, it
88      continues until just before the last sexp in the definition.  If
89      that is where you are now, it returns from the function and then
90      stops.  In other words, this command does not exit the currently
91      executing function unless you are positioned after the last sexp.
92
93 `I'
94      Step into the function or macro after point after first ensuring
95      that it is instrumented.  It does this by calling
96      `edebug-on-entry' and then switching to `go' mode.
97
98      Although the automatic instrumentation is convenient, it is not
99      later automatically uninstrumented.
100
101 `h'
102      Proceed to the stop point near where point is using a temporary
103      breakpoint (`edebug-goto-here').
104
105    All the commands in this section may fail to work as expected in case
106 of nonlocal exit, because a nonlocal exit can bypass the temporary
107 breakpoint where you expected the program to stop.
108
109 \1f
110 File: lispref.info,  Node: Edebug Misc,  Next: Breakpoints,  Prev: Jumping,  Up: Edebug
111
112 Miscellaneous
113 -------------
114
115    Some miscellaneous commands are described here.
116
117 `?'
118      Display the help message for Edebug (`edebug-help').
119
120 `C-]'
121      Abort one level back to the previous command level
122      (`abort-recursive-edit').
123
124 `q'
125      Return to the top level editor command loop (`top-level').  This
126      exits all recursive editing levels, including all levels of Edebug
127      activity.  However, instrumented code protected with
128      `unwind-protect' or `condition-case' forms may resume debugging.
129
130 `Q'
131      Like `q' but don't stop even for protected code
132      (`top-level-nonstop').
133
134 `r'
135      Redisplay the most recently known expression result in the echo
136      area (`edebug-previous-result').
137
138 `d'
139      Display a backtrace, excluding Edebug's own functions for clarity
140      (`edebug-backtrace').
141
142      You cannot use debugger commands in the backtrace buffer in Edebug
143      as you would in the standard debugger.
144
145      The backtrace buffer is killed automatically when you continue
146      execution.
147
148    From the Edebug recursive edit, you may invoke commands that activate
149 Edebug again recursively.  Any time Edebug is active, you can quit to
150 the top level with `q' or abort one recursive edit level with `C-]'.
151 You can display a backtrace of all the pending evaluations with `d'.
152
153 \1f
154 File: lispref.info,  Node: Breakpoints,  Next: Trapping Errors,  Prev: Edebug Misc,  Up: Edebug
155
156 Breakpoints
157 -----------
158
159    There are three more ways to stop execution once it has started:
160 breakpoints, the global break condition, and embedded breakpoints.
161
162    While using Edebug, you can specify "breakpoints" in the program you
163 are testing: points where execution should stop.  You can set a
164 breakpoint at any stop point, as defined in *Note Using Edebug::.  For
165 setting and unsetting breakpoints, the stop point that is affected is
166 the first one at or after point in the source code buffer.  Here are the
167 Edebug commands for breakpoints:
168
169 `b'
170      Set a breakpoint at the stop point at or after point
171      (`edebug-set-breakpoint').  If you use a prefix argument, the
172      breakpoint is temporary (it turns off the first time it stops the
173      program).
174
175 `u'
176      Unset the breakpoint (if any) at the stop point at or after the
177      current point (`edebug-unset-breakpoint').
178
179 `x CONDITION <RET>'
180      Set a conditional breakpoint which stops the program only if
181      CONDITION evaluates to a non-`nil' value
182      (`edebug-set-conditional-breakpoint').  If you use a prefix
183      argument, the breakpoint is temporary (it turns off the first time
184      it stops the program).
185
186 `B'
187      Move point to the next breakpoint in the definition
188      (`edebug-next-breakpoint').
189
190    While in Edebug, you can set a breakpoint with `b' and unset one
191 with `u'.  First you must move point to a position at or before the
192 desired Edebug stop point, then hit the key to change the breakpoint.
193 Unsetting a breakpoint that has not been set does nothing.
194
195    Reevaluating or reinstrumenting a definition clears all its
196 breakpoints.
197
198    A "conditional breakpoint" tests a condition each time the program
199 gets there.  To set a conditional breakpoint, use `x', and specify the
200 condition expression in the minibuffer.  Setting a conditional
201 breakpoint at a stop point that already has a conditional breakpoint
202 puts the current condition expression in the minibuffer so you can edit
203 it.
204
205    You can make both conditional and unconditional breakpoints
206 "temporary" by using a prefix arg to the command to set the breakpoint.
207 After breaking at a temporary breakpoint, it is automatically cleared.
208
209    Edebug always stops or pauses at a breakpoint except when the Edebug
210 mode is `Go-nonstop'.  In that mode, it ignores breakpoints entirely.
211
212    To find out where your breakpoints are, use `B', which moves point
213 to the next breakpoint in the definition following point, or to the
214 first breakpoint if there are no following breakpoints.  This command
215 does not continue execution--it just moves point in the buffer.
216
217 * Menu:
218
219 * Global Break Condition::      Breaking on an event.
220 * Embedded Breakpoints::        Embedding breakpoints in code.
221
222 \1f
223 File: lispref.info,  Node: Global Break Condition,  Next: Embedded Breakpoints,  Up: Breakpoints
224
225 Global Break Condition
226 ......................
227
228    In contrast to breaking when execution reaches specified locations,
229 you can also cause a break when a certain event occurs.  The "global
230 break condition" is a condition that is repeatedly evaluated at every
231 stop point.  If it evaluates to a non-`nil' value, then execution is
232 stopped or paused depending on the execution mode, just like a
233 breakpoint.  Any errors that might occur as a result of evaluating the
234 condition are ignored, as if the result were `nil'.
235
236    You can set or edit the condition expression, stored in
237 `edebug-global-break-condition', using `X'
238 (`edebug-set-global-break-condition').
239
240    Using the global break condition is perhaps the fastest way to find
241 where in your code some event occurs, but since it is rather expensive
242 you should reset the condition to `nil' when not in use.
243
244 \1f
245 File: lispref.info,  Node: Embedded Breakpoints,  Prev: Global Break Condition,  Up: Breakpoints
246
247 Embedded Breakpoints
248 ....................
249
250    Since all breakpoints in a definition are cleared each time you
251 reinstrument it, you might rather create an "embedded breakpoint" which
252 is simply a call to the function `edebug'.  You can, of course, make
253 such a call conditional.  For example, in the `fac' function, insert
254 the first line as shown below to stop when the argument reaches zero:
255
256      (defun fac (n)
257        (if (= n 0) (edebug))
258        (if (< 0 n)
259            (* n (fac (1- n)))
260          1))
261
262    When the `fac' definition is instrumented and the function is
263 called, Edebug will stop before the call to `edebug'.  Depending on the
264 execution mode, Edebug will stop or pause.
265
266    However, if no instrumented code is being executed, calling `edebug'
267 will instead invoke `debug'.  Calling `debug' will always invoke the
268 standard backtrace debugger.
269
270 \1f
271 File: lispref.info,  Node: Trapping Errors,  Next: Edebug Views,  Prev: Breakpoints,  Up: Edebug
272
273 Trapping Errors
274 ---------------
275
276    An error may be signaled by subroutines or XEmacs Lisp code.  If a
277 signal is not handled by a `condition-case', this indicates an
278 unrecognized situation has occurred.  If Edebug is not active when an
279 unhandled error is signaled, `debug' is run normally (if
280 `debug-on-error' is non-`nil').  But while Edebug is active,
281 `debug-on-error' and `debug-on-quit' are bound to `edebug-on-error' and
282 `edebug-on-quit', which are both `t' by default.  Actually, if
283 `debug-on-error' already has a non-`nil' value, that value is still
284 used.
285
286    It is best to change the values of `edebug-on-error' or
287 `edebug-on-quit' when Edebug is not active since their values won't be
288 used until the next time Edebug is invoked at a deeper command level.
289 If you only change `debug-on-error' or `debug-on-quit' while Edebug is
290 active, these changes will be forgotten when Edebug becomes inactive.
291 Furthermore, during Edebug's recursive edit, these variables are bound
292 to the values they had outside of Edebug.
293
294    Edebug shows you the last stop point that it knew about before the
295 error was signaled.  This may be the location of a call to a function
296 which was not instrumented, within which the error actually occurred.
297 For an unbound variable error, the last known stop point might be quite
298 distant from the offending variable.  If the cause of the error is not
299 obvious at first, note that you can also get a full backtrace inside of
300 Edebug (see *Note Edebug Misc::).
301
302    Edebug can also trap signals even if they are handled.  If
303 `debug-on-error' is a list of signal names, Edebug will stop when any
304 of these errors are signaled.  Edebug shows you the last known stop
305 point just as for unhandled errors.  After you continue execution, the
306 error is signaled again (but without being caught by Edebug).  Edebug
307 can only trap errors that are handled if they are signaled in Lisp code
308 (not subroutines) since it does so by temporarily replacing the
309 `signal' function.
310
311 \1f
312 File: lispref.info,  Node: Edebug Views,  Next: Edebug Eval,  Prev: Trapping Errors,  Up: Edebug
313
314 Edebug Views
315 ------------
316
317    The following Edebug commands let you view aspects of the buffer and
318 window status that obtained before entry to Edebug.
319
320 `v'
321      View the outside window configuration (`edebug-view-outside').
322
323 `p'
324      Temporarily display the outside current buffer with point at its
325      outside position (`edebug-bounce-point'). If prefix arg is
326      supplied, sit for that many seconds instead.
327
328 `w'
329      Move point back to the current stop point (`edebug-where') in the
330      source code buffer.  Also, if you use this command in another
331      window displaying the same buffer, this window will be used
332      instead to display the buffer in the future.
333
334 `W'
335      Toggle the `edebug-save-windows' variable which indicates whether
336      the outside window configuration is saved and restored
337      (`edebug-toggle-save-windows').  Also, each time it is toggled on,
338      make the outside window configuration the same as the current
339      window configuration.
340
341      With a prefix argument, `edebug-toggle-save-windows' only toggles
342      saving and restoring of the selected window.  To specify a window
343      that is not displaying the source code buffer, you must use
344      `C-xXW' from the global keymap.
345
346    You can view the outside window configuration with `v' or just
347 bounce to the current point in the current buffer with `p', even if it
348 is not normally displayed.  After moving point, you may wish to pop
349 back to the stop point with `w' from a source code buffer.
350
351    By using `W' twice, Edebug again saves and restores the outside
352 window configuration, but to the current configuration.  This is a
353 convenient way to, for example, add another buffer to be displayed
354 whenever Edebug is active.  However, the automatic redisplay of
355 `*edebug*' and `*edebug-trace*' may conflict with the buffers you wish
356 to see unless you have enough windows open.
357
358 \1f
359 File: lispref.info,  Node: Edebug Eval,  Next: Eval List,  Prev: Edebug Views,  Up: Edebug
360
361 Evaluation
362 ----------
363
364    While within Edebug, you can evaluate expressions "as if" Edebug were
365 not running.  Edebug tries to be invisible to the expression's
366 evaluation and printing.  Evaluation of expressions that cause side
367 effects will work as expected except for things that Edebug explicitly
368 saves and restores.  See *Note The Outside Context:: for details on this
369 process.  Also see *Note Reading in Edebug:: and *Note Printing in
370 Edebug:: for topics related to evaluation.
371
372 `e EXP <RET>'
373      Evaluate expression EXP in the context outside of Edebug
374      (`edebug-eval-expression').  In other words, Edebug tries to avoid
375      altering the effect of EXP.
376
377 `M-<ESC> EXP <RET>'
378      Evaluate expression EXP in the context of Edebug itself.
379
380 `C-x C-e'
381      Evaluate the expression before point, in the context outside of
382      Edebug (`edebug-eval-last-sexp').
383
384    Edebug supports evaluation of expressions containing references to
385 lexically bound symbols created by the following constructs in `cl.el'
386 (version 2.03 or later): `lexical-let', `macrolet', and
387 `symbol-macrolet'.
388
389 \1f
390 File: lispref.info,  Node: Eval List,  Next: Reading in Edebug,  Prev: Edebug Eval,  Up: Edebug
391
392 Evaluation List Buffer
393 ----------------------
394
395    You can use the "evaluation list buffer", called `*edebug*', to
396 evaluate expressions interactively.  You can also set up the
397 "evaluation list" of expressions to be evaluated automatically each
398 time Edebug updates the display.
399
400 `E'
401      Switch to the evaluation list buffer `*edebug*'
402      (`edebug-visit-eval-list').
403
404    In the `*edebug*' buffer you can use the commands of Lisp
405 Interaction as well as these special commands:
406
407 `LFD'
408      Evaluate the expression before point, in the outside context, and
409      insert the value in the buffer (`edebug-eval-print-last-sexp').
410
411 `C-x C-e'
412      Evaluate the expression before point, in the context outside of
413      Edebug (`edebug-eval-last-sexp').
414
415 `C-c C-u'
416      Build a new evaluation list from the first expression of each
417      group, reevaluate and redisplay (`edebug-update-eval-list').
418      Groups are separated by comment lines.
419
420 `C-c C-d'
421      Delete the evaluation list group that point is in
422      (`edebug-delete-eval-item').
423
424 `C-c C-w'
425      Switch back to the source code buffer at the current stop point
426      (`edebug-where').
427
428    You can evaluate expressions in the evaluation list window with
429 `LFD' or `C-x C-e', just as you would in `*scratch*'; but they are
430 evaluated in the context outside of Edebug.
431
432    The expressions you enter interactively (and their results) are lost
433 when you continue execution unless you add them to the evaluation list
434 with `C-c C-u'.  This command builds a new list from the first
435 expression of each "evaluation list group".  Groups are separated by
436 comment lines.  Be careful not to add expressions that execute
437 instrumented code otherwise an infinite loop will result.
438
439    When the evaluation list is redisplayed, each expression is displayed
440 followed by the result of evaluating it, and a comment line.  If an
441 error occurs during an evaluation, the error message is displayed in a
442 string as if it were the result.  Therefore expressions that, for
443 example, use variables not currently valid do not interrupt your
444 debugging.
445
446    Here is an example of what the evaluation list window looks like
447 after several expressions have been added to it:
448
449      (current-buffer)
450      #<buffer *scratch*>
451      ;---------------------------------------------------------------
452      (selected-window)
453      #<window 16 on *scratch*>
454      ;---------------------------------------------------------------
455      (point)
456      196
457      ;---------------------------------------------------------------
458      bad-var
459      "Symbol's value as variable is void: bad-var"
460      ;---------------------------------------------------------------
461      (recursion-depth)
462      0
463      ;---------------------------------------------------------------
464      this-command
465      eval-last-sexp
466      ;---------------------------------------------------------------
467
468    To delete a group, move point into it and type `C-c C-d', or simply
469 delete the text for the group and update the evaluation list with `C-c
470 C-u'.  When you add a new group, be sure it is separated from its
471 neighbors by a comment line.
472
473    After selecting `*edebug*', you can return to the source code buffer
474 with `C-c C-w'.  The `*edebug*' buffer is killed when you continue
475 execution, and recreated next time it is needed.
476
477 \1f
478 File: lispref.info,  Node: Reading in Edebug,  Next: Printing in Edebug,  Prev: Eval List,  Up: Edebug
479
480 Reading in Edebug
481 -----------------
482
483    To instrument a form, Edebug first reads the whole form.  Edebug
484 replaces the standard Lisp Reader with its own reader that remembers the
485 positions of expressions.  This reader is used by the Edebug
486 replacements for `eval-region', `eval-defun', `eval-buffer', and
487 `eval-current-buffer'.
488
489    Another package, `cl-read.el', replaces the standard reader with one
490 that understands Common Lisp reader macros.  If you use that package,
491 Edebug will automatically load `edebug-cl-read.el' to provide
492 corresponding reader macros that remember positions of expressions.  If
493 you define new reader macros, you will have to define similar reader
494 macros for Edebug.
495
496 \1f
497 File: lispref.info,  Node: Printing in Edebug,  Next: Tracing,  Prev: Reading in Edebug,  Up: Edebug
498
499 Printing in Edebug
500 ------------------
501
502    If the result of an expression in your program contains a circular
503 reference, you may get an error when Edebug attempts to print it.  You
504 can set `print-length' to a non-zero value to limit the print length of
505 lists (the number of cdrs), and in Emacs 19, set `print-level' to a
506 non-zero value to limit the print depth of lists.  But you can print
507 such circular structures and structures that share elements more
508 informatively by using the `cust-print' package.
509
510    To load `cust-print' and activate custom printing only for Edebug,
511 simply use the command `M-x edebug-install-custom-print'.  To restore
512 the standard print functions, use `M-x edebug-uninstall-custom-print'.
513 You can also activate custom printing for printing in any Lisp code;
514 see the package for details.
515
516    Here is an example of code that creates a circular structure:
517
518      (progn
519        (edebug-install-custom-print)
520        (setq a '(x y))
521        (setcar a a))
522
523    Edebug will print the result of the `setcar' as `Result: #1=(#1#
524 y)'.  The `#1=' notation names the structure that follows it, and the
525 `#1#' notation references the previously named structure.  This
526 notation is used for any shared elements of lists or vectors.
527
528    Independent of whether `cust-print' is active, while printing
529 results Edebug binds `print-length', `print-level', and `print-circle'
530 to `edebug-print-length' (`50'), `edebug-print-level' (`50'), and
531 `edebug-print-circle' (`t') respectively, if these values are
532 non-`nil'.  Also, `print-readably' is bound to `nil' since some objects
533 simply cannot be printed readably.
534
535 \1f
536 File: lispref.info,  Node: Tracing,  Next: Coverage Testing,  Prev: Printing in Edebug,  Up: Edebug
537
538 Tracing
539 -------
540
541    In addition to automatic stepping through source code, which is also
542 called _tracing_ (see *Note Edebug Execution Modes::), Edebug can
543 produce a traditional trace listing of execution in a separate buffer,
544 `*edebug-trace*'.
545
546    If the variable `edebug-trace' is non-`nil', each function entry and
547 exit adds lines to the trace buffer.  On function entry, Edebug prints
548 `::::{' followed by the function name and argument values.  On function
549 exit, Edebug prints `::::}' followed by the function name and result of
550 the function.  The number of `:'s is computed from the recursion depth.
551 The balanced braces in the trace buffer can be used to find the
552 matching beginning or end of function calls. These displays may be
553 customized by replacing the functions `edebug-print-trace-before' and
554 `edebug-print-trace-after', which take an arbitrary message string to
555 print.
556
557    The macro `edebug-tracing' provides tracing similar to function
558 enter and exit tracing, but for arbitrary expressions.  This macro
559 should be explicitly inserted by you around expressions you wish to
560 trace the execution of.  The first argument is a message string
561 (evaluated), and the rest are expressions to evaluate.  The result of
562 the last expression is returned.
563
564    Finally, you can insert arbitrary strings into the trace buffer with
565 explicit calls to `edebug-trace'.  The arguments of this function are
566 the same as for `message', but a newline is always inserted after each
567 string printed in this way.
568
569    `edebug-tracing' and `edebug-trace' insert lines in the trace buffer
570 even if Edebug is not active.  Every time the trace buffer is added to,
571 the window is scrolled to show the last lines inserted.  (There may be
572 some display problems if you use tracing along with the evaluation
573 list.)
574
575 \1f
576 File: lispref.info,  Node: Coverage Testing,  Next: The Outside Context,  Prev: Tracing,  Up: Edebug
577
578 Coverage Testing
579 ----------------
580
581    Edebug provides a rudimentary coverage tester and display of
582 execution frequency.  Frequency counts are always accumulated, both
583 before and after evaluation of each instrumented expression, even if
584 the execution mode is `Go-nonstop'.  Coverage testing is only done if
585 the option `edebug-test-coverage' is non-`nil' because this is
586 relatively expensive.  Both data sets are displayed by `M-x
587 edebug-display-freq-count'.
588
589  - Command: edebug-display-freq-count
590      Display the frequency count data for each line of the current
591      definition.  The frequency counts are inserted as comment lines
592      after each line, and you can undo all insertions with one `undo'
593      command.  The counts are inserted starting under the `(' before an
594      expression or the `)' after an expression, or on the last char of
595      a symbol.  The counts are only displayed when they differ from
596      previous counts on the same line.
597
598      If coverage is being tested, whenever all known results of an
599      expression are `eq', the char `=' will be appended after the count
600      for that expression.  Note that this is always the case for an
601      expression only evaluated once.
602
603      To clear the frequency count and coverage data for a definition,
604      reinstrument it.
605
606
607    For example, after evaluating `(fac 5)' with an embedded breakpoint,
608 and setting `edebug-test-coverage' to `t', when the breakpoint is
609 reached, the frequency data is looks like this:
610
611      (defun fac (n)
612        (if (= n 0) (edebug))
613      ;#6           1      0 =5
614        (if (< 0 n)
615      ;#5         =
616            (* n (fac (1- n)))
617      ;#    5               0
618          1))
619      ;#   0
620
621    The comment lines show that `fac' has been called 6 times.  The
622 first `if' statement has returned 5 times with the same result each
623 time, and the same is true for the condition on the second `if'.  The
624 recursive call of `fac' has not returned at all.
625
626 \1f
627 File: lispref.info,  Node: The Outside Context,  Next: Instrumenting Macro Calls,  Prev: Coverage Testing,  Up: Edebug
628
629 The Outside Context
630 -------------------
631
632    Edebug tries to be transparent to the program you are debugging.  In
633 addition, most evaluations you do within Edebug (see *Note Edebug
634 Eval::) occur in the same outside context which is temporarily restored
635 for the evaluation.  But Edebug is not completely successful and this
636 section explains precisely how it fails.  Edebug operation unavoidably
637 alters some data in XEmacs, and this can interfere with debugging
638 certain programs.  Also notice that Edebug's protection against change
639 of outside data means that any side effects _intended_ by the user in
640 the course of debugging will be defeated.
641
642 * Menu:
643
644 * Checking Whether to Stop::    When Edebug decides what to do.
645 * Edebug Display Update::       When Edebug updates the display.
646 * Edebug Recursive Edit::       When Edebug stops execution.
647
648 \1f
649 File: lispref.info,  Node: Checking Whether to Stop,  Next: Edebug Display Update,  Up: The Outside Context
650
651 Checking Whether to Stop
652 ........................
653
654    Whenever Edebug is entered just to think about whether to take some
655 action, it needs to save and restore certain data.
656
657    * `max-lisp-eval-depth' and `max-specpdl-size' are both incremented
658      one time to reduce Edebug's impact on the stack.  You could,
659      however, still run out of stack space when using Edebug.
660
661    * The state of keyboard macro execution is saved and restored.  While
662      Edebug is active, `executing-macro' is bound to
663      `edebug-continue-kbd-macro'.
664
665
666 \1f
667 File: lispref.info,  Node: Edebug Display Update,  Next: Edebug Recursive Edit,  Prev: Checking Whether to Stop,  Up: The Outside Context
668
669 Edebug Display Update
670 .....................
671
672    When Edebug needs to display something (e.g., in trace mode), it
673 saves the current window configuration from "outside" Edebug.  When you
674 exit Edebug (by continuing the program), it restores the previous window
675 configuration.
676
677    XEmacs redisplays only when it pauses.  Usually, when you continue
678 execution, the program comes back into Edebug at a breakpoint or after
679 stepping without pausing or reading input in between.  In such cases,
680 XEmacs never gets a chance to redisplay the "outside" configuration.
681 What you see is the same window configuration as the last time Edebug
682 was active, with no interruption.
683
684    Entry to Edebug for displaying something also saves and restores the
685 following data, but some of these are deliberately not restored if an
686 error or quit signal occurs.
687
688    * Which buffer is current, and where point and mark are in the
689      current buffer are saved and restored.
690
691    * The Edebug Display Update, is saved and restored if
692      `edebug-save-windows' is non-`nil'.  It is not restored on error
693      or quit, but the outside selected window _is_ reselected even on
694      error or quit in case a `save-excursion' is active.  If the value
695      of `edebug-save-windows' is a list, only the listed windows are
696      saved and restored.
697
698      The window start and horizontal scrolling of the source code
699      buffer are not restored, however, so that the display remains
700      coherent.
701
702    * The value of point in each displayed buffer is saved and restored
703      if `edebug-save-displayed-buffer-points' is non-`nil'.
704
705    * The variables `overlay-arrow-position' and `overlay-arrow-string'
706      are saved and restored.  So you can safely invoke Edebug from the
707      recursive edit elsewhere in the same buffer.
708
709    * `cursor-in-echo-area' is locally bound to `nil' so that the cursor
710      shows up in the window.
711
712
713 \1f
714 File: lispref.info,  Node: Edebug Recursive Edit,  Prev: Edebug Display Update,  Up: The Outside Context
715
716 Edebug Recursive Edit
717 .....................
718
719    When Edebug is entered and actually reads commands from the user, it
720 saves (and later restores) these additional data:
721
722    * The current match data, for whichever buffer was current.
723
724    * `last-command', `this-command', `last-command-char',
725      `last-input-char', `last-input-event', `last-command-event',
726      `last-event-frame', `last-nonmenu-event', and `track-mouse' .
727      Commands used within Edebug do not affect these variables outside
728      of Edebug.
729
730      The key sequence returned by `this-command-keys' is changed by
731      executing commands within Edebug and there is no way to reset the
732      key sequence from Lisp.
733
734      For Emacs 18, Edebug cannot save and restore the value of
735      `unread-command-char'.  Entering Edebug while this variable has a
736      nontrivial value can interfere with execution of the program you
737      are debugging.
738
739    * Complex commands executed while in Edebug are added to the variable
740      `command-history'.  In rare cases this can alter execution.
741
742    * Within Edebug, the recursion depth appears one deeper than the
743      recursion depth outside Edebug.  This is not true of the
744      automatically updated evaluation list window.
745
746    * `standard-output' and `standard-input' are bound to `nil' by the
747      `recursive-edit', but Edebug temporarily restores them during
748      evaluations.
749
750    * The state of keyboard macro definition is saved and restored.
751      While Edebug is active, `defining-kbd-macro' is bound to
752      `edebug-continue-kbd-macro'.
753
754
755 \1f
756 File: lispref.info,  Node: Instrumenting Macro Calls,  Next: Edebug Options,  Prev: The Outside Context,  Up: Edebug
757
758 Instrumenting Macro Calls
759 -------------------------
760
761    When Edebug instruments an expression that calls a Lisp macro, it
762 needs additional advice to do the job properly.  This is because there
763 is no way to tell which subexpressions of the macro call may be
764 evaluated.  (Evaluation may occur explicitly in the macro body, or when
765 the resulting expansion is evaluated, or any time later.)  You must
766 explain the format of macro call arguments by using `def-edebug-spec' to
767 define an "Edebug specification" for each macro.
768
769  - Macro: def-edebug-spec macro specification
770      Specify which expressions of a call to macro MACRO are forms to be
771      evaluated.  For simple macros, the SPECIFICATION often looks very
772      similar to the formal argument list of the macro definition, but
773      specifications are much more general than macro arguments.
774
775      The MACRO argument may actually be any symbol, not just a macro
776      name.
777
778      Unless you are using Emacs 19 or XEmacs, this macro is only defined
779      in Edebug, so you may want to use the following which is
780      equivalent: `(put 'MACRO 'edebug-form-spec 'SPECIFICATION)'
781
782    Here is a simple example that defines the specification for the
783 `for' macro described in the XEmacs Lisp Reference Manual, followed by
784 an alternative, equivalent specification.
785
786      (def-edebug-spec for
787        (symbolp "from" form "to" form "do" &rest form))
788      
789      (def-edebug-spec for
790        (symbolp ['from form] ['to form] ['do body]))
791
792    Here is a table of the possibilities for SPECIFICATION and how each
793 directs processing of arguments.
794
795 *`t'
796      All arguments are instrumented for evaluation.
797
798 *`0'
799      None of the arguments is instrumented.
800
801 *a symbol
802      The symbol must have an Edebug specification which is used instead.
803      This indirection is repeated until another kind of specification is
804      found.  This allows you to inherit the specification for another
805      macro.
806
807 *a list
808      The elements of the list describe the types of the arguments of a
809      calling form.  The possible elements of a specification list are
810      described in the following sections.
811
812 * Menu:
813
814 * Specification List::          How to specify complex patterns of evaluation.
815 * Backtracking::                What Edebug does when matching fails.
816 * Debugging Backquote:: Debugging Backquote
817 * Specification Examples::      To help understand specifications.
818
819 \1f
820 File: lispref.info,  Node: Specification List,  Next: Backtracking,  Up: Instrumenting Macro Calls
821
822 Specification List
823 ..................
824
825    A "specification list" is required for an Edebug specification if
826 some arguments of a macro call are evaluated while others are not.  Some
827 elements in a specification list match one or more arguments, but others
828 modify the processing of all following elements.  The latter, called
829 "keyword specifications", are symbols beginning with ``&'' (e.g.
830 `&optional').
831
832    A specification list may contain sublists which match arguments that
833 are themselves lists, or it may contain vectors used for grouping.
834 Sublists and groups thus subdivide the specification list into a
835 hierarchy of levels.  Keyword specifications only apply to the
836 remainder of the sublist or group they are contained in and there is an
837 implicit grouping around a keyword specification and all following
838 elements in the sublist or group.
839
840    If a specification list fails at some level, then backtracking may
841 be invoked to find some alternative at a higher level, or if no
842 alternatives remain, an error will be signaled.  See *Note
843 Backtracking:: for more details.
844
845    Edebug specifications provide at least the power of regular
846 expression matching.  Some context-free constructs are also supported:
847 the matching of sublists with balanced parentheses, recursive
848 processing of forms, and recursion via indirect specifications.
849
850    Each element of a specification list may be one of the following,
851 with the corresponding type of argument:
852
853 `sexp'
854      A single unevaluated expression.
855
856 `form'
857      A single evaluated expression, which is instrumented.
858
859 `place'
860      A place as in the Common Lisp `setf' place argument.  It will be
861      instrumented just like a form, but the macro is expected to strip
862      the instrumentation.  Two functions, `edebug-unwrap' and
863      `edebug-unwrap*', are provided to strip the instrumentation one
864      level or recursively at all levels.
865
866 `body'
867      Short for `&rest form'.  See `&rest' below.
868
869 `function-form'
870      A function form: either a quoted function symbol, a quoted lambda
871      expression, or a form (that should evaluate to a function symbol
872      or lambda expression).  This is useful when function arguments
873      might be quoted with `quote' rather than `function' since the body
874      of a lambda expression will be instrumented either way.
875
876 `lambda-expr'
877      An unquoted anonymous lambda expression.
878
879 `&optional'
880      All following elements in the specification list are optional; as
881      soon as one does not match, Edebug stops matching at this level.
882
883      To make just a few elements optional followed by non-optional
884      elements, use `[&optional SPECS...]'.  To specify that several
885      elements should all succeed together, use `&optional [SPECS...]'.
886      See the `defun' example below.
887
888 `&rest'
889      All following elements in the specification list are repeated zero
890      or more times.  All the elements need not match in the last
891      repetition, however.
892
893      To repeat only a few elements, use `[&rest SPECS...]'.  To specify
894      all elements must match on every repetition, use `&rest
895      [SPECS...]'.
896
897 `&or'
898      Each of the following elements in the specification list is an
899      alternative, processed left to right until one matches.  One of the
900      alternatives must match otherwise the `&or' specification fails.
901
902      Each list element following `&or' is a single alternative even if
903      it is a keyword specification. (This breaks the implicit grouping
904      rule.)  To group two or more list elements as a single
905      alternative, enclose them in `[...]'.
906
907 `&not'
908      Each of the following elements is matched as alternatives as if by
909      using `&or', but if any of them match, the specification fails.
910      If none of them match, nothing is matched, but the `&not'
911      specification succeeds.
912
913 `&define'
914      Indicates that the specification is for a defining form.  The
915      defining form itself is not instrumented (i.e. Edebug does not
916      stop before and after the defining form), but forms inside it
917      typically will be instrumented.  The `&define' keyword should be
918      the first element in a list specification.
919
920      Additional specifications that may only appear after `&define' are
921      described here.  See the `defun' example below.
922
923     `name'
924           The argument, a symbol, is the name of the defining form.
925           But a defining form need not be named at all, in which case a
926           unique name will be created for it.
927
928           The `name' specification may be used more than once in the
929           specification and each subsequent use will append the
930           corresponding symbol argument to the previous name with ``@''
931           between them.  This is useful for generating unique but
932           meaningful names for definitions such as `defadvice' and
933           `defmethod'.
934
935     `:name'
936           The element following `:name' should be a symbol; it is used
937           as an additional name component for the definition.  This is
938           useful to add a unique, static component to the name of the
939           definition.  It may be used more than once.  No argument is
940           matched.
941
942     `arg'
943           The argument, a symbol, is the name of an argument of the
944           defining form.  However, lambda list keywords (symbols
945           starting with ``&'') are not allowed.  See `lambda-list' and
946           the example below.
947
948     `lambda-list'
949           This matches the whole argument list of an XEmacs Lisp lambda
950           expression, which is a list of symbols and the keywords
951           `&optional' and `&rest'
952
953     `def-body'
954           The argument is the body of code in a definition.  This is
955           like `body', described above, but a definition body must be
956           instrumented with a different Edebug call that looks up
957           information associated with the definition.  Use `def-body'
958           for the highest level list of forms within the definition.
959
960     `def-form'
961           The argument is a single, highest-level form in a definition.
962           This is like `def-body', except use this to match a single
963           form rather than a list of forms.  As a special case,
964           `def-form' also means that tracing information is not output
965           when the form is executed.  See the `interactive' example
966           below.
967
968 `nil'
969      This is successful when there are no more arguments to match at the
970      current argument list level; otherwise it fails.  See sublist
971      specifications and the backquote example below.
972
973 `gate'
974      No argument is matched but backtracking through the gate is
975      disabled while matching the remainder of the specifications at
976      this level.  This is primarily used to generate more specific
977      syntax error messages.  See *Note Backtracking:: for more details.
978      Also see the `let' example below.
979
980 `OTHER-SYMBOL'
981      Any other symbol in a specification list may be a predicate or an
982      indirect specification.
983
984      If the symbol has an Edebug specification, this "indirect
985      specification" should be either a list specification that is used
986      in place of the symbol, or a function that is called to process the
987      arguments.  The specification may be defined with `def-edebug-spec'
988      just as for macros. See the `defun' example below.
989
990      Otherwise, the symbol should be a predicate.  The predicate is
991      called with the argument and the specification fails if the
992      predicate fails.  The argument is not instrumented.
993
994      Predicates that may be used include: `symbolp', `integerp',
995      `stringp', `vectorp', `atom' (which matches a number, string,
996      symbol, or vector), `keywordp', and `lambda-list-keywordp'.  The
997      last two, defined in `edebug.el', test whether the argument is a
998      symbol starting with ``:'' and ``&'' respectively.
999
1000 `[ELEMENTS...]'
1001      Rather than matching a vector argument, a vector treats the
1002      ELEMENTS as a single "group specification".
1003
1004 `"STRING"'
1005      The argument should be a symbol named STRING.  This specification
1006      is equivalent to the quoted symbol, `'SYMBOL', where the name of
1007      SYMBOL is the STRING, but the string form is preferred.
1008
1009 `'SYMBOL or (quote SYMBOL)'
1010      The argument should be the symbol SYMBOL.  But use a string
1011      specification instead.
1012
1013 `(vector ELEMENTS...)'
1014      The argument should be a vector whose elements must match the
1015      ELEMENTS in the specification.  See the backquote example below.
1016
1017 `(ELEMENTS...)'
1018      Any other list is a "sublist specification" and the argument must
1019      be a list whose elements match the specification ELEMENTS.
1020
1021      A sublist specification may be a dotted list and the corresponding
1022      list argument may then be a dotted list.  Alternatively, the last
1023      cdr of a dotted list specification may be another sublist
1024      specification (via a grouping or an indirect specification, e.g.
1025      `(spec .  [(more specs...)])') whose elements match the non-dotted
1026      list arguments.  This is useful in recursive specifications such
1027      as in the backquote example below.  Also see the description of a
1028      `nil' specification above for terminating such recursion.
1029
1030      Note that a sublist specification of the form `(specs .  nil)'
1031      means the same as `(specs)', and `(specs .
1032      (sublist-elements...))' means the same as `(specs
1033      sublist-elements...)'.
1034
1035 \1f
1036 File: lispref.info,  Node: Backtracking,  Next: Debugging Backquote,  Prev: Specification List,  Up: Instrumenting Macro Calls
1037
1038 Backtracking
1039 ............
1040
1041    If a specification fails to match at some point, this does not
1042 necessarily mean a syntax error will be signaled; instead,
1043 "backtracking" will take place until all alternatives have been
1044 exhausted.  Eventually every element of the argument list must be
1045 matched by some element in the specification, and every required element
1046 in the specification must match some argument.
1047
1048    Backtracking is disabled for the remainder of a sublist or group when
1049 certain conditions occur, described below.  Backtracking is reenabled
1050 when a new alternative is established by `&optional', `&rest', or
1051 `&or'.  It is also reenabled initially when processing a sublist or
1052 group specification or an indirect specification.
1053
1054    You might want to disable backtracking to commit to some alternative
1055 so that Edebug can provide a more specific syntax error message.
1056 Normally, if no alternative matches, Edebug reports that none matched,
1057 but if one alternative is committed to, Edebug can report how it failed
1058 to match.
1059
1060    First, backtracking is disabled while matching any of the form
1061 specifications (i.e. `form', `body', `def-form', and `def-body').
1062 These specifications will match any form so any error must be in the
1063 form itself rather than at a higher level.
1064
1065    Second, backtracking is disabled after successfully matching a quoted
1066 symbol or string specification, since this usually indicates a
1067 recognized construct.  If you have a set of alternative constructs that
1068 all begin with the same symbol, you can usually work around this
1069 constraint by factoring the symbol out of the alternatives, e.g.,
1070 `["foo" &or [first case] [second case] ...]'.
1071
1072    Third, backtracking may be explicitly disabled by using the `gate'
1073 specification.  This is useful when you know that no higher
1074 alternatives may apply.
1075
1076 \1f
1077 File: lispref.info,  Node: Debugging Backquote,  Next: Specification Examples,  Prev: Backtracking,  Up: Instrumenting Macro Calls
1078
1079 Debugging Backquote
1080 ...................
1081
1082    Backquote (``') is a macro that results in an expression that may or
1083 may not be evaluated.  It is often used to simplify the definition of a
1084 macro to return an expression that is evaluated, but Edebug does not
1085 know when this is the case.  However, the forms inside unquotes (`,' and
1086 `,@') are evaluated and Edebug instruments them.
1087
1088    Nested backquotes are supported by Edebug, but there is a limit on
1089 the support of quotes inside of backquotes.  Quoted forms (with `'')
1090 are not normally evaluated, but if the quoted form appears immediately
1091 within `,' and `,@' forms, Edebug treats this as a backquoted form at
1092 the next higher level (even if there is not a next higher level - this
1093 is difficult to fix).
1094
1095    If the backquoted forms happen to be code intended to be evaluated,
1096 you can have Edebug instrument them by using `edebug-`' instead of the
1097 regular ``'.  Unquoted forms can always appear inside `edebug-`'
1098 anywhere a form is normally allowed.  But `(, FORM)' may be used in two
1099 other places specially recognized by Edebug: wherever a predicate
1100 specification would match, and at the head of a list form in place of a
1101 function name or lambda expression.  The FORM inside a spliced unquote,
1102 `(,@ FORM)', will be wrapped, but the unquote form itself will not be
1103 wrapped since this would interfere with the splicing.
1104
1105    There is one other complication with using `edebug-`'.  If the
1106 `edebug-`' call is in a macro and the macro may be called from code
1107 that is also instrumented, and if unquoted forms contain any macro
1108 arguments bound to instrumented forms, then you should modify the
1109 specification for the macro as follows: the specifications for those
1110 arguments must use `def-form' instead of `form'.  (This is to
1111 reestablish the Edebugging context for those external forms.)
1112
1113    For example, the `for' macro (*note Problems with Macros: ()Problems
1114 with Macros.) is shown here but with `edebug-`' substituted for regular
1115 ``'.
1116
1117      (defmacro inc (var)
1118        (list 'setq var (list '1+ var)))
1119      
1120      (defmacro for (var from init to final do &rest body)
1121        (let ((tempvar (make-symbol "max")))
1122          (edebug-` (let (((, var) (, init))
1123                          ((, tempvar) (, final)))
1124                      (while (<= (, var) (, tempvar))
1125                        (, body)
1126                        (inc (, var)))))))
1127
1128    Here is the corresponding modified Edebug specification and some code
1129 that calls the macro:
1130
1131      (def-edebug-spec for
1132        (symbolp "from" def-form "to" def-form "do" &rest def-form))
1133      
1134      (let ((n 5))
1135        (for i from n to (* n (+ n 1)) do
1136          (message "%s" i)))
1137
1138    After instrumenting the `for' macro and the macro call, Edebug first
1139 steps to the beginning of the macro call, then into the macro body,
1140 then through each of the unquoted expressions in the backquote showing
1141 the expressions that will be embedded in the backquote form.  Then when
1142 the macro expansion is evaluated, Edebug will step through the `let'
1143 form and each time it gets to an unquoted form, it will jump back to an
1144 argument of the macro call to step through that expression.  Finally
1145 stepping will continue after the macro call.  Even more convoluted
1146 execution paths may result when using anonymous functions.
1147
1148    When the result of an expression is an instrumented expression, it is
1149 difficult to see the expression inside the instrumentation.  So you may
1150 want to set the option `edebug-unwrap-results' to a non-`nil' value
1151 while debugging such expressions, but it would slow Edebug down to
1152 always do this.
1153
1154 \1f
1155 File: lispref.info,  Node: Specification Examples,  Prev: Debugging Backquote,  Up: Instrumenting Macro Calls
1156
1157 Specification Examples
1158 ......................
1159
1160    Here we provide several examples of Edebug specifications to show
1161 many of its capabilities.
1162
1163    A `let' special form has a sequence of bindings and a body.  Each of
1164 the bindings is either a symbol or a sublist with a symbol and optional
1165 value.  In the specification below, notice the `gate' inside of the
1166 sublist to prevent backtracking.
1167
1168      (def-edebug-spec let
1169        ((&rest
1170          &or symbolp (gate symbolp &optional form))
1171         body))
1172
1173    Edebug uses the following specifications for `defun' and `defmacro'
1174 and the associated argument list and `interactive' specifications.  It
1175 is necessary to handle the expression argument of an interactive form
1176 specially since it is actually evaluated outside of the function body.
1177
1178      (def-edebug-spec defmacro defun)      ; Indirect ref to `defun' spec
1179      (def-edebug-spec defun
1180        (&define name lambda-list
1181                 [&optional stringp]        ; Match the doc string, if present.
1182                 [&optional ("interactive" interactive)]
1183                 def-body))
1184      
1185      (def-edebug-spec lambda-list
1186        (([&rest arg]
1187          [&optional ["&optional" arg &rest arg]]
1188          &optional ["&rest" arg]
1189          )))
1190      
1191      (def-edebug-spec interactive
1192        (&optional &or stringp def-form))    ; Notice: `def-form'
1193
1194    The specification for backquote below illustrates how to match
1195 dotted lists and use `nil' to terminate recursion.  It also illustrates
1196 how components of a vector may be matched.  (The actual specification
1197 provided by Edebug does not support dotted lists because doing so
1198 causes very deep recursion that could fail.)
1199
1200      (def-edebug-spec ` (backquote-form))  ;; alias just for clarity
1201      
1202      (def-edebug-spec backquote-form
1203        (&or ([&or "," ",@"] &or ("quote" backquote-form) form)
1204             (backquote-form . [&or nil backquote-form])
1205             (vector &rest backquote-form)
1206             sexp))
1207