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