Merge r21-2-24-utf-2000-0_13-0.
[chise/xemacs-chise.git-] / info / lispref.info-14
1 This is ../info/lispref.info, produced by makeinfo version 3.12s 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: 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
448 \1f
449 File: lispref.info,  Node: Edebug Display Update,  Next: Edebug Recursive Edit,  Prev: Checking Whether to Stop,  Up: The Outside Context
450
451 Edebug Display Update
452 .....................
453
454    When Edebug needs to display something (e.g., in trace mode), it
455 saves the current window configuration from "outside" Edebug.  When you
456 exit Edebug (by continuing the program), it restores the previous window
457 configuration.
458
459    XEmacs redisplays only when it pauses.  Usually, when you continue
460 execution, the program comes back into Edebug at a breakpoint or after
461 stepping without pausing or reading input in between.  In such cases,
462 XEmacs never gets a chance to redisplay the "outside" configuration.
463 What you see is the same window configuration as the last time Edebug
464 was active, with no interruption.
465
466    Entry to Edebug for displaying something also saves and restores the
467 following data, but some of these are deliberately not restored if an
468 error or quit signal occurs.
469
470    * Which buffer is current, and where point and mark are in the
471      current buffer are saved and restored.
472
473    * The Edebug Display Update, is saved and restored if
474      `edebug-save-windows' is non-`nil'.  It is not restored on error
475      or quit, but the outside selected window _is_ reselected even on
476      error or quit in case a `save-excursion' is active.  If the value
477      of `edebug-save-windows' is a list, only the listed windows are
478      saved and restored.
479
480      The window start and horizontal scrolling of the source code
481      buffer are not restored, however, so that the display remains
482      coherent.
483
484    * The value of point in each displayed buffer is saved and restored
485      if `edebug-save-displayed-buffer-points' is non-`nil'.
486
487    * The variables `overlay-arrow-position' and `overlay-arrow-string'
488      are saved and restored.  So you can safely invoke Edebug from the
489      recursive edit elsewhere in the same buffer.
490
491    * `cursor-in-echo-area' is locally bound to `nil' so that the cursor
492      shows up in the window.
493
494
495 \1f
496 File: lispref.info,  Node: Edebug Recursive Edit,  Prev: Edebug Display Update,  Up: The Outside Context
497
498 Edebug Recursive Edit
499 .....................
500
501    When Edebug is entered and actually reads commands from the user, it
502 saves (and later restores) these additional data:
503
504    * The current match data, for whichever buffer was current.
505
506    * `last-command', `this-command', `last-command-char',
507      `last-input-char', `last-input-event', `last-command-event',
508      `last-event-frame', `last-nonmenu-event', and `track-mouse' .
509      Commands used within Edebug do not affect these variables outside
510      of Edebug.
511
512      The key sequence returned by `this-command-keys' is changed by
513      executing commands within Edebug and there is no way to reset the
514      key sequence from Lisp.
515
516      For Emacs 18, Edebug cannot save and restore the value of
517      `unread-command-char'.  Entering Edebug while this variable has a
518      nontrivial value can interfere with execution of the program you
519      are debugging.
520
521    * Complex commands executed while in Edebug are added to the variable
522      `command-history'.  In rare cases this can alter execution.
523
524    * Within Edebug, the recursion depth appears one deeper than the
525      recursion depth outside Edebug.  This is not true of the
526      automatically updated evaluation list window.
527
528    * `standard-output' and `standard-input' are bound to `nil' by the
529      `recursive-edit', but Edebug temporarily restores them during
530      evaluations.
531
532    * The state of keyboard macro definition is saved and restored.
533      While Edebug is active, `defining-kbd-macro' is bound to
534      `edebug-continue-kbd-macro'.
535
536
537 \1f
538 File: lispref.info,  Node: Instrumenting Macro Calls,  Next: Edebug Options,  Prev: The Outside Context,  Up: Edebug
539
540 Instrumenting Macro Calls
541 -------------------------
542
543    When Edebug instruments an expression that calls a Lisp macro, it
544 needs additional advice to do the job properly.  This is because there
545 is no way to tell which subexpressions of the macro call may be
546 evaluated.  (Evaluation may occur explicitly in the macro body, or when
547 the resulting expansion is evaluated, or any time later.)  You must
548 explain the format of macro call arguments by using `def-edebug-spec' to
549 define an "Edebug specification" for each macro.
550
551  - Macro: def-edebug-spec macro specification
552      Specify which expressions of a call to macro MACRO are forms to be
553      evaluated.  For simple macros, the SPECIFICATION often looks very
554      similar to the formal argument list of the macro definition, but
555      specifications are much more general than macro arguments.
556
557      The MACRO argument may actually be any symbol, not just a macro
558      name.
559
560      Unless you are using Emacs 19 or XEmacs, this macro is only defined
561      in Edebug, so you may want to use the following which is
562      equivalent: `(put 'MACRO 'edebug-form-spec 'SPECIFICATION)'
563
564    Here is a simple example that defines the specification for the
565 `for' macro described in the XEmacs Lisp Reference Manual, followed by
566 an alternative, equivalent specification.
567
568      (def-edebug-spec for
569        (symbolp "from" form "to" form "do" &rest form))
570      
571      (def-edebug-spec for
572        (symbolp ['from form] ['to form] ['do body]))
573
574    Here is a table of the possibilities for SPECIFICATION and how each
575 directs processing of arguments.
576
577 *`t'
578      All arguments are instrumented for evaluation.
579
580 *`0'
581      None of the arguments is instrumented.
582
583 *a symbol
584      The symbol must have an Edebug specification which is used instead.
585      This indirection is repeated until another kind of specification is
586      found.  This allows you to inherit the specification for another
587      macro.
588
589 *a list
590      The elements of the list describe the types of the arguments of a
591      calling form.  The possible elements of a specification list are
592      described in the following sections.
593
594 * Menu:
595
596 * Specification List::          How to specify complex patterns of evaluation.
597 * Backtracking::                What Edebug does when matching fails.
598 * Debugging Backquote:: Debugging Backquote
599 * Specification Examples::      To help understand specifications.
600
601 \1f
602 File: lispref.info,  Node: Specification List,  Next: Backtracking,  Up: Instrumenting Macro Calls
603
604 Specification List
605 ..................
606
607    A "specification list" is required for an Edebug specification if
608 some arguments of a macro call are evaluated while others are not.  Some
609 elements in a specification list match one or more arguments, but others
610 modify the processing of all following elements.  The latter, called
611 "keyword specifications", are symbols beginning with ``&'' (e.g.
612 `&optional').
613
614    A specification list may contain sublists which match arguments that
615 are themselves lists, or it may contain vectors used for grouping.
616 Sublists and groups thus subdivide the specification list into a
617 hierarchy of levels.  Keyword specifications only apply to the
618 remainder of the sublist or group they are contained in and there is an
619 implicit grouping around a keyword specification and all following
620 elements in the sublist or group.
621
622    If a specification list fails at some level, then backtracking may
623 be invoked to find some alternative at a higher level, or if no
624 alternatives remain, an error will be signaled.  See *Note
625 Backtracking:: for more details.
626
627    Edebug specifications provide at least the power of regular
628 expression matching.  Some context-free constructs are also supported:
629 the matching of sublists with balanced parentheses, recursive
630 processing of forms, and recursion via indirect specifications.
631
632    Each element of a specification list may be one of the following,
633 with the corresponding type of argument:
634
635 `sexp'
636      A single unevaluated expression.
637
638 `form'
639      A single evaluated expression, which is instrumented.
640
641 `place'
642      A place as in the Common Lisp `setf' place argument.  It will be
643      instrumented just like a form, but the macro is expected to strip
644      the instrumentation.  Two functions, `edebug-unwrap' and
645      `edebug-unwrap*', are provided to strip the instrumentation one
646      level or recursively at all levels.
647
648 `body'
649      Short for `&rest form'.  See `&rest' below.
650
651 `function-form'
652      A function form: either a quoted function symbol, a quoted lambda
653      expression, or a form (that should evaluate to a function symbol
654      or lambda expression).  This is useful when function arguments
655      might be quoted with `quote' rather than `function' since the body
656      of a lambda expression will be instrumented either way.
657
658 `lambda-expr'
659      An unquoted anonymous lambda expression.
660
661 `&optional'
662      All following elements in the specification list are optional; as
663      soon as one does not match, Edebug stops matching at this level.
664
665      To make just a few elements optional followed by non-optional
666      elements, use `[&optional SPECS...]'.  To specify that several
667      elements should all succeed together, use `&optional [SPECS...]'.
668      See the `defun' example below.
669
670 `&rest'
671      All following elements in the specification list are repeated zero
672      or more times.  All the elements need not match in the last
673      repetition, however.
674
675      To repeat only a few elements, use `[&rest SPECS...]'.  To specify
676      all elements must match on every repetition, use `&rest
677      [SPECS...]'.
678
679 `&or'
680      Each of the following elements in the specification list is an
681      alternative, processed left to right until one matches.  One of the
682      alternatives must match otherwise the `&or' specification fails.
683
684      Each list element following `&or' is a single alternative even if
685      it is a keyword specification. (This breaks the implicit grouping
686      rule.)  To group two or more list elements as a single
687      alternative, enclose them in `[...]'.
688
689 `&not'
690      Each of the following elements is matched as alternatives as if by
691      using `&or', but if any of them match, the specification fails.
692      If none of them match, nothing is matched, but the `&not'
693      specification succeeds.
694
695 `&define'
696      Indicates that the specification is for a defining form.  The
697      defining form itself is not instrumented (i.e. Edebug does not
698      stop before and after the defining form), but forms inside it
699      typically will be instrumented.  The `&define' keyword should be
700      the first element in a list specification.
701
702      Additional specifications that may only appear after `&define' are
703      described here.  See the `defun' example below.
704
705     `name'
706           The argument, a symbol, is the name of the defining form.
707           But a defining form need not be named at all, in which case a
708           unique name will be created for it.
709
710           The `name' specification may be used more than once in the
711           specification and each subsequent use will append the
712           corresponding symbol argument to the previous name with ``@''
713           between them.  This is useful for generating unique but
714           meaningful names for definitions such as `defadvice' and
715           `defmethod'.
716
717     `:name'
718           The element following `:name' should be a symbol; it is used
719           as an additional name component for the definition.  This is
720           useful to add a unique, static component to the name of the
721           definition.  It may be used more than once.  No argument is
722           matched.
723
724     `arg'
725           The argument, a symbol, is the name of an argument of the
726           defining form.  However, lambda list keywords (symbols
727           starting with ``&'') are not allowed.  See `lambda-list' and
728           the example below.
729
730     `lambda-list'
731           This matches the whole argument list of an XEmacs Lisp lambda
732           expression, which is a list of symbols and the keywords
733           `&optional' and `&rest'
734
735     `def-body'
736           The argument is the body of code in a definition.  This is
737           like `body', described above, but a definition body must be
738           instrumented with a different Edebug call that looks up
739           information associated with the definition.  Use `def-body'
740           for the highest level list of forms within the definition.
741
742     `def-form'
743           The argument is a single, highest-level form in a definition.
744           This is like `def-body', except use this to match a single
745           form rather than a list of forms.  As a special case,
746           `def-form' also means that tracing information is not output
747           when the form is executed.  See the `interactive' example
748           below.
749
750 `nil'
751      This is successful when there are no more arguments to match at the
752      current argument list level; otherwise it fails.  See sublist
753      specifications and the backquote example below.
754
755 `gate'
756      No argument is matched but backtracking through the gate is
757      disabled while matching the remainder of the specifications at
758      this level.  This is primarily used to generate more specific
759      syntax error messages.  See *Note Backtracking:: for more details.
760      Also see the `let' example below.
761
762 `OTHER-SYMBOL'
763      Any other symbol in a specification list may be a predicate or an
764      indirect specification.
765
766      If the symbol has an Edebug specification, this "indirect
767      specification" should be either a list specification that is used
768      in place of the symbol, or a function that is called to process the
769      arguments.  The specification may be defined with `def-edebug-spec'
770      just as for macros. See the `defun' example below.
771
772      Otherwise, the symbol should be a predicate.  The predicate is
773      called with the argument and the specification fails if the
774      predicate fails.  The argument is not instrumented.
775
776      Predicates that may be used include: `symbolp', `integerp',
777      `stringp', `vectorp', `atom' (which matches a number, string,
778      symbol, or vector), `keywordp', and `lambda-list-keywordp'.  The
779      last two, defined in `edebug.el', test whether the argument is a
780      symbol starting with ``:'' and ``&'' respectively.
781
782 `[ELEMENTS...]'
783      Rather than matching a vector argument, a vector treats the
784      ELEMENTS as a single "group specification".
785
786 `"STRING"'
787      The argument should be a symbol named STRING.  This specification
788      is equivalent to the quoted symbol, `'SYMBOL', where the name of
789      SYMBOL is the STRING, but the string form is preferred.
790
791 `'SYMBOL or (quote SYMBOL)'
792      The argument should be the symbol SYMBOL.  But use a string
793      specification instead.
794
795 `(vector ELEMENTS...)'
796      The argument should be a vector whose elements must match the
797      ELEMENTS in the specification.  See the backquote example below.
798
799 `(ELEMENTS...)'
800      Any other list is a "sublist specification" and the argument must
801      be a list whose elements match the specification ELEMENTS.
802
803      A sublist specification may be a dotted list and the corresponding
804      list argument may then be a dotted list.  Alternatively, the last
805      cdr of a dotted list specification may be another sublist
806      specification (via a grouping or an indirect specification, e.g.
807      `(spec .  [(more specs...)])') whose elements match the non-dotted
808      list arguments.  This is useful in recursive specifications such
809      as in the backquote example below.  Also see the description of a
810      `nil' specification above for terminating such recursion.
811
812      Note that a sublist specification of the form `(specs .  nil)'
813      means the same as `(specs)', and `(specs .
814      (sublist-elements...))' means the same as `(specs
815      sublist-elements...)'.
816
817 \1f
818 File: lispref.info,  Node: Backtracking,  Next: Debugging Backquote,  Prev: Specification List,  Up: Instrumenting Macro Calls
819
820 Backtracking
821 ............
822
823    If a specification fails to match at some point, this does not
824 necessarily mean a syntax error will be signaled; instead,
825 "backtracking" will take place until all alternatives have been
826 exhausted.  Eventually every element of the argument list must be
827 matched by some element in the specification, and every required element
828 in the specification must match some argument.
829
830    Backtracking is disabled for the remainder of a sublist or group when
831 certain conditions occur, described below.  Backtracking is reenabled
832 when a new alternative is established by `&optional', `&rest', or
833 `&or'.  It is also reenabled initially when processing a sublist or
834 group specification or an indirect specification.
835
836    You might want to disable backtracking to commit to some alternative
837 so that Edebug can provide a more specific syntax error message.
838 Normally, if no alternative matches, Edebug reports that none matched,
839 but if one alternative is committed to, Edebug can report how it failed
840 to match.
841
842    First, backtracking is disabled while matching any of the form
843 specifications (i.e. `form', `body', `def-form', and `def-body').
844 These specifications will match any form so any error must be in the
845 form itself rather than at a higher level.
846
847    Second, backtracking is disabled after successfully matching a quoted
848 symbol or string specification, since this usually indicates a
849 recognized construct.  If you have a set of alternative constructs that
850 all begin with the same symbol, you can usually work around this
851 constraint by factoring the symbol out of the alternatives, e.g.,
852 `["foo" &or [first case] [second case] ...]'.
853
854    Third, backtracking may be explicitly disabled by using the `gate'
855 specification.  This is useful when you know that no higher
856 alternatives may apply.
857
858 \1f
859 File: lispref.info,  Node: Debugging Backquote,  Next: Specification Examples,  Prev: Backtracking,  Up: Instrumenting Macro Calls
860
861 Debugging Backquote
862 ...................
863
864    Backquote (``') is a macro that results in an expression that may or
865 may not be evaluated.  It is often used to simplify the definition of a
866 macro to return an expression that is evaluated, but Edebug does not
867 know when this is the case.  However, the forms inside unquotes (`,' and
868 `,@') are evaluated and Edebug instruments them.
869
870    Nested backquotes are supported by Edebug, but there is a limit on
871 the support of quotes inside of backquotes.  Quoted forms (with `'')
872 are not normally evaluated, but if the quoted form appears immediately
873 within `,' and `,@' forms, Edebug treats this as a backquoted form at
874 the next higher level (even if there is not a next higher level - this
875 is difficult to fix).
876
877    If the backquoted forms happen to be code intended to be evaluated,
878 you can have Edebug instrument them by using `edebug-`' instead of the
879 regular ``'.  Unquoted forms can always appear inside `edebug-`'
880 anywhere a form is normally allowed.  But `(, FORM)' may be used in two
881 other places specially recognized by Edebug: wherever a predicate
882 specification would match, and at the head of a list form in place of a
883 function name or lambda expression.  The FORM inside a spliced unquote,
884 `(,@ FORM)', will be wrapped, but the unquote form itself will not be
885 wrapped since this would interfere with the splicing.
886
887    There is one other complication with using `edebug-`'.  If the
888 `edebug-`' call is in a macro and the macro may be called from code
889 that is also instrumented, and if unquoted forms contain any macro
890 arguments bound to instrumented forms, then you should modify the
891 specification for the macro as follows: the specifications for those
892 arguments must use `def-form' instead of `form'.  (This is to
893 reestablish the Edebugging context for those external forms.)
894
895    For example, the `for' macro (*note Problems with Macros: ()Problems
896 with Macros.) is shown here but with `edebug-`' substituted for regular
897 ``'.
898
899      (defmacro inc (var)
900        (list 'setq var (list '1+ var)))
901      
902      (defmacro for (var from init to final do &rest body)
903        (let ((tempvar (make-symbol "max")))
904          (edebug-` (let (((, var) (, init))
905                          ((, tempvar) (, final)))
906                      (while (<= (, var) (, tempvar))
907                        (, body)
908                        (inc (, var)))))))
909
910    Here is the corresponding modified Edebug specification and some code
911 that calls the macro:
912
913      (def-edebug-spec for
914        (symbolp "from" def-form "to" def-form "do" &rest def-form))
915      
916      (let ((n 5))
917        (for i from n to (* n (+ n 1)) do
918          (message "%s" i)))
919
920    After instrumenting the `for' macro and the macro call, Edebug first
921 steps to the beginning of the macro call, then into the macro body,
922 then through each of the unquoted expressions in the backquote showing
923 the expressions that will be embedded in the backquote form.  Then when
924 the macro expansion is evaluated, Edebug will step through the `let'
925 form and each time it gets to an unquoted form, it will jump back to an
926 argument of the macro call to step through that expression.  Finally
927 stepping will continue after the macro call.  Even more convoluted
928 execution paths may result when using anonymous functions.
929
930    When the result of an expression is an instrumented expression, it is
931 difficult to see the expression inside the instrumentation.  So you may
932 want to set the option `edebug-unwrap-results' to a non-`nil' value
933 while debugging such expressions, but it would slow Edebug down to
934 always do this.
935
936 \1f
937 File: lispref.info,  Node: Specification Examples,  Prev: Debugging Backquote,  Up: Instrumenting Macro Calls
938
939 Specification Examples
940 ......................
941
942    Here we provide several examples of Edebug specifications to show
943 many of its capabilities.
944
945    A `let' special form has a sequence of bindings and a body.  Each of
946 the bindings is either a symbol or a sublist with a symbol and optional
947 value.  In the specification below, notice the `gate' inside of the
948 sublist to prevent backtracking.
949
950      (def-edebug-spec let
951        ((&rest
952          &or symbolp (gate symbolp &optional form))
953         body))
954
955    Edebug uses the following specifications for `defun' and `defmacro'
956 and the associated argument list and `interactive' specifications.  It
957 is necessary to handle the expression argument of an interactive form
958 specially since it is actually evaluated outside of the function body.
959
960      (def-edebug-spec defmacro defun)      ; Indirect ref to `defun' spec
961      (def-edebug-spec defun
962        (&define name lambda-list
963                 [&optional stringp]        ; Match the doc string, if present.
964                 [&optional ("interactive" interactive)]
965                 def-body))
966      
967      (def-edebug-spec lambda-list
968        (([&rest arg]
969          [&optional ["&optional" arg &rest arg]]
970          &optional ["&rest" arg]
971          )))
972      
973      (def-edebug-spec interactive
974        (&optional &or stringp def-form))    ; Notice: `def-form'
975
976    The specification for backquote below illustrates how to match
977 dotted lists and use `nil' to terminate recursion.  It also illustrates
978 how components of a vector may be matched.  (The actual specification
979 provided by Edebug does not support dotted lists because doing so
980 causes very deep recursion that could fail.)
981
982      (def-edebug-spec ` (backquote-form))  ;; alias just for clarity
983      
984      (def-edebug-spec backquote-form
985        (&or ([&or "," ",@"] &or ("quote" backquote-form) form)
986             (backquote-form . [&or nil backquote-form])
987             (vector &rest backquote-form)
988             sexp))
989
990 \1f
991 File: lispref.info,  Node: Edebug Options,  Prev: Instrumenting Macro Calls,  Up: Edebug
992
993 Edebug Options
994 --------------
995
996    These options affect the behavior of Edebug:
997
998  - User Option: edebug-setup-hook
999      Functions to call before Edebug is used.  Each time it is set to a
1000      new value, Edebug will call those functions once and then
1001      `edebug-setup-hook' is reset to `nil'.  You could use this to load
1002      up Edebug specifications associated with a package you are using
1003      but only when you also use Edebug.  See *Note Instrumenting::.
1004
1005  - User Option: edebug-all-defs
1006      If non-`nil', normal evaluation of any defining forms (e.g.
1007      `defun' and `defmacro') will instrument them for Edebug.  This
1008      applies to `eval-defun', `eval-region', and `eval-current-buffer'.
1009
1010      Use the command `M-x edebug-all-defs' to toggle the value of this
1011      variable. You may want to make this variable local to each buffer
1012      by calling `(make-local-variable 'edebug-all-defs)' in your
1013      `emacs-lisp-mode-hook'.  See *Note Instrumenting::.
1014
1015  - User Option: edebug-all-forms
1016      If non-`nil', normal evaluation of any forms by `eval-defun',
1017      `eval-region', and `eval-current-buffer' will instrument them for
1018      Edebug.
1019
1020      Use the command `M-x edebug-all-forms' to toggle the value of this
1021      option.  See *Note Instrumenting::.
1022
1023  - User Option: edebug-save-windows
1024      If non-`nil', save and restore window configuration on Edebug
1025      calls.  It takes some time to do this, so if your program does not
1026      care what happens to data about windows, you may want to set this
1027      variable to `nil'.
1028
1029      If the value is a list, only the listed windows are saved and
1030      restored.
1031
1032      `M-x edebug-toggle-save-windows' may be used to change this
1033      variable.  This command is bound to `W' in source code buffers.
1034      See *Note Edebug Display Update::.
1035
1036  - User Option: edebug-save-displayed-buffer-points
1037      If non-`nil', save and restore point in all displayed buffers.
1038      This is necessary if you are debugging code that changes the point
1039      of a buffer which is displayed in a non-selected window.  If
1040      Edebug or the user then selects the window, the buffer's point
1041      will be changed to the window's point.
1042
1043      This is an expensive operation since it visits each window and
1044      therefore each displayed buffer twice for each Edebug activation,
1045      so it is best to avoid it if you can.  See *Note Edebug Display
1046      Update::.
1047
1048  - User Option: edebug-initial-mode
1049      If this variable is non-`nil', it specifies the initial execution
1050      mode for Edebug when it is first activated.  Possible values are
1051      `step', `next', `go', `Go-nonstop', `trace', `Trace-fast',
1052      `continue', and `Continue-fast'.
1053
1054      The default value is `step'.  See *Note Edebug Execution Modes::.
1055
1056  - User Option: edebug-trace
1057      Non-`nil' means display a trace of function entry and exit.
1058      Tracing output is displayed in a buffer named `*edebug-trace*', one
1059      function entry or exit per line, indented by the recursion level.
1060
1061      The default value is `nil'.
1062
1063      Also see `edebug-tracing'.  See *Note Tracing::.
1064
1065  - User Option: edebug-test-coverage
1066      If non-`nil', Edebug tests coverage of all expressions debugged.
1067      This is done by comparing the result of each expression with the
1068      previous result. Coverage is considered OK if two different
1069      results are found.  So to sufficiently test the coverage of your
1070      code, try to execute it under conditions that evaluate all
1071      expressions more than once, and produce different results for each
1072      expression.
1073
1074      Use `M-x edebug-display-freq-count' to display the frequency count
1075      and coverage information for a definition.  See *Note Coverage
1076      Testing::.
1077
1078  - User Option: edebug-continue-kbd-macro
1079      If non-`nil', continue defining or executing any keyboard macro
1080      that is executing outside of Edebug.   Use this with caution since
1081      it is not debugged.  See *Note Edebug Execution Modes::.
1082
1083  - User Option: edebug-print-length
1084      If non-`nil', bind `print-length' to this while printing results
1085      in Edebug.  The default value is `50'.  See *Note Printing in
1086      Edebug::.
1087
1088  - User Option: edebug-print-level
1089      If non-`nil', bind `print-level' to this while printing results in
1090      Edebug.  The default value is `50'.
1091
1092  - User Option: edebug-print-circle
1093      If non-`nil', bind `print-circle' to this while printing results
1094      in Edebug.  The default value is `nil'.
1095
1096  - User Option: edebug-on-error
1097      `debug-on-error' is bound to this while Edebug is active.  See
1098      *Note Trapping Errors::.
1099
1100  - User Option: edebug-on-quit
1101      `debug-on-quit' is bound to this while Edebug is active.  See
1102      *Note Trapping Errors::.
1103
1104  - User Option: edebug-unwrap-results
1105      Non-`nil' if Edebug should unwrap results of expressions.  This is
1106      useful when debugging macros where the results of expressions are
1107      instrumented expressions.  But don't do this when results might be
1108      circular or an infinite loop will result.  See *Note Debugging
1109      Backquote::.
1110
1111  - User Option: edebug-global-break-condition
1112      If non-`nil', an expression to test for at every stop point.  If
1113      the result is non-nil, then break.  Errors are ignored.  See *Note
1114      Global Break Condition::.
1115
1116 \1f
1117 File: lispref.info,  Node: Read and Print,  Next: Minibuffers,  Prev: Debugging,  Up: Top
1118
1119 Reading and Printing Lisp Objects
1120 *********************************
1121
1122    "Printing" and "reading" are the operations of converting Lisp
1123 objects to textual form and vice versa.  They use the printed
1124 representations and read syntax described in *Note Lisp Data Types::.
1125
1126    This chapter describes the Lisp functions for reading and printing.
1127 It also describes "streams", which specify where to get the text (if
1128 reading) or where to put it (if printing).
1129
1130 * Menu:
1131
1132 * Streams Intro::     Overview of streams, reading and printing.
1133 * Input Streams::     Various data types that can be used as input streams.
1134 * Input Functions::   Functions to read Lisp objects from text.
1135 * Output Streams::    Various data types that can be used as output streams.
1136 * Output Functions::  Functions to print Lisp objects as text.
1137 * Output Variables::  Variables that control what the printing functions do.
1138
1139 \1f
1140 File: lispref.info,  Node: Streams Intro,  Next: Input Streams,  Up: Read and Print
1141
1142 Introduction to Reading and Printing
1143 ====================================
1144
1145    "Reading" a Lisp object means parsing a Lisp expression in textual
1146 form and producing a corresponding Lisp object.  This is how Lisp
1147 programs get into Lisp from files of Lisp code.  We call the text the
1148 "read syntax" of the object.  For example, the text `(a . 5)' is the
1149 read syntax for a cons cell whose CAR is `a' and whose CDR is the
1150 number 5.
1151
1152    "Printing" a Lisp object means producing text that represents that
1153 object--converting the object to its printed representation.  Printing
1154 the cons cell described above produces the text `(a . 5)'.
1155
1156    Reading and printing are more or less inverse operations: printing
1157 the object that results from reading a given piece of text often
1158 produces the same text, and reading the text that results from printing
1159 an object usually produces a similar-looking object.  For example,
1160 printing the symbol `foo' produces the text `foo', and reading that text
1161 returns the symbol `foo'.  Printing a list whose elements are `a' and
1162 `b' produces the text `(a b)', and reading that text produces a list
1163 (but not the same list) with elements `a' and `b'.
1164
1165    However, these two operations are not precisely inverses.  There are
1166 three kinds of exceptions:
1167
1168    * Printing can produce text that cannot be read.  For example,
1169      buffers, windows, frames, subprocesses and markers print into text
1170      that starts with `#'; if you try to read this text, you get an
1171      error.  There is no way to read those data types.
1172
1173    * One object can have multiple textual representations.  For example,
1174      `1' and `01' represent the same integer, and `(a b)' and `(a .
1175      (b))' represent the same list.  Reading will accept any of the
1176      alternatives, but printing must choose one of them.
1177
1178    * Comments can appear at certain points in the middle of an object's
1179      read sequence without affecting the result of reading it.
1180