home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / elisp / elisp-11 < prev    next >
Encoding:
GNU Info File  |  1993-05-31  |  47.9 KB  |  1,284 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  5. Emacs Version 19.
  6.  
  7.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26. 
  27. File: elisp,  Node: Syntax Errors,  Next: Compilation Errors,  Prev: Debugger,  Up: Debugging
  28.  
  29. Debugging Invalid Lisp Syntax
  30. =============================
  31.  
  32.    The Lisp reader reports invalid syntax, but cannot say where the real
  33. problem is.  For example, the error "End of file during parsing" in
  34. evaluating an expression indicates an excess of open parentheses (or
  35. square brackets).  The reader detects this imbalance at the end of the
  36. file, but it cannot figure out where the close parenthesis should have
  37. been.  Likewise, "Invalid read syntax: ")"" indicates an excess close
  38. parenthesis or missing open parenthesis, but not where the missing
  39. parenthesis belongs.  How, then, to find what to change?
  40.  
  41.    If the problem is not simply an imbalance of parentheses, a useful
  42. technique is to try `C-M-e' at the beginning of each defun, and see if
  43. it goes to the place where that defun appears to end.  If it does not,
  44. there is a problem in that defun.
  45.  
  46.    However, unmatched parentheses are the most common syntax errors in
  47. Lisp, and we can give further advice for those cases.
  48.  
  49. * Menu:
  50.  
  51. * Excess Open::     How to find a spurious open paren or missing close.
  52. * Excess Close::    How to find a spurious close paren or missing open.
  53.  
  54. 
  55. File: elisp,  Node: Excess Open,  Next: Excess Close,  Up: Syntax Errors
  56.  
  57. Excess Open Parentheses
  58. -----------------------
  59.  
  60.    The first step is to find the defun that is unbalanced.  If there is
  61. an excess open parenthesis, the way to do this is to insert a close
  62. parenthesis at the end of the file and type `C-M-b' (`backward-sexp').
  63. This will move you to the beginning of the defun that is unbalanced.
  64. (Then type `C-SPC C-_ C-u C-SPC' to set the mark there, undo the
  65. insertion of the close parenthesis, and finally return to the mark.)
  66.  
  67.    The next step is to determine precisely what is wrong.  There is no
  68. way to be sure of this except to study the program, but often the
  69. existing indentation is a clue to where the parentheses should have
  70. been.  The easiest way to use this clue is to reindent with `C-M-q' and
  71. see what moves.
  72.  
  73.    Before you do this, make sure the defun has enough close parentheses.
  74. Otherwise, `C-M-q' will get an error, or will reindent all the rest of
  75. the file until the end.  So move to the end of the defun and insert a
  76. close parenthesis there.  Don't use `C-M-e' to move there, since that
  77. too will fail to work until the defun is balanced.
  78.  
  79.    Then go to the beginning of the defun and type `C-M-q'.  Usually all
  80. the lines from a certain point to the end of the function will shift to
  81. the right.  There is probably a missing close parenthesis, or a
  82. superfluous open parenthesis, near that point.  (However, don't assume
  83. this is true; study the code to make sure.)  Once you have found the
  84. discrepancy, undo the `C-M-q', since the old indentation is probably
  85. appropriate to the intended parentheses.
  86.  
  87.    After you think you have fixed the problem, use `C-M-q' again.  It
  88. should not change anything, if the problem is really fixed.
  89.  
  90. 
  91. File: elisp,  Node: Excess Close,  Prev: Excess Open,  Up: Syntax Errors
  92.  
  93. Excess Close Parentheses
  94. ------------------------
  95.  
  96.    To deal with an excess close parenthesis, first insert an open
  97. parenthesis at the beginning of the file and type `C-M-f' to find the
  98. end of the unbalanced defun.  (Then type `C-SPC C-_ C-u C-SPC' to set
  99. the mark there, undo the insertion of the open parenthesis, and finally
  100. return to the mark.)
  101.  
  102.    Then find the actual matching close parenthesis by typing `C-M-f' at
  103. the beginning of the defun.  This will leave you somewhere short of the
  104. place where the defun ought to end.  It is possible that you will find
  105. a spurious close parenthesis in that vicinity.
  106.  
  107.    If you don't see a problem at that point, the next thing to do is to
  108. type `C-M-q' at the beginning of the defun.  A range of lines will
  109. probably shift left; if so, the missing open parenthesis or spurious
  110. close parenthesis is probably near the first of those lines.  (However,
  111. don't assume this is true; study the code to make sure.)  Once you have
  112. found the discrepancy, undo the `C-M-q', since the old indentation is
  113. probably appropriate to the intended parentheses.
  114.  
  115. 
  116. File: elisp,  Node: Compilation Errors,  Next: Edebug,  Prev: Syntax Errors,  Up: Debugging
  117.  
  118. Debugging Problems in Compilation
  119. =================================
  120.  
  121.    When an error happens during byte compilation, it is normally due to
  122. invalid syntax in the program you are compiling.  The compiler prints a
  123. suitable error message in the `*Compile-Log*' buffer, and then stops.
  124. The message may state a function name in which the error was found, or
  125. it may not.  Regardless, here is how to find out where in the file the
  126. error occurred.
  127.  
  128.    What you should do is switch to the buffer ` *Compiler Input*'.
  129. (Note that the buffer name starts with a space, so it does not show up
  130. in `M-x list-buffers'.)  This buffer contains the program being
  131. compiled, and point shows how far the byte compiler was able to read.
  132.  
  133.    If the error was due to invalid Lisp syntax, point shows exactly
  134. where the invalid syntax was *detected*.  The cause of the error is not
  135. necessarily near by!  Use the techniques in the previous section to find
  136. the error.
  137.  
  138.    If the error was detected while compiling a form that had been read
  139. successfully, then point is located at the end of the form.  In this
  140. case, it can't localize the error precisely, but can still show you
  141. which function to check.
  142.  
  143. 
  144. File: elisp,  Node: Edebug,  Prev: Compilation Errors,  Up: Debugging
  145.  
  146. Edebug
  147. ======
  148.  
  149.    Edebug is a source-level debugger for Emacs Lisp programs that
  150. provides the following features:
  151.  
  152.    * Step through evaluation, stopping before and after each expression.
  153.  
  154.    * Set conditional or unconditional breakpoints.
  155.  
  156.    * Trace slow or fast stopping briefly at each stop point, or each
  157.      breakpoint.
  158.  
  159.    * Evaluate expressions as if outside of Edebug.
  160.  
  161.    * Automatically reevaluate a list of expressions and display their
  162.      results each time Edebug updates the display.
  163.  
  164.    * Output trace info on function enter and exit.
  165.  
  166.    The first three sections of this chapter should tell you enough about
  167. Edebug to enable you to use it.
  168.  
  169. * Menu:
  170.  
  171. * Using Edebug::        Introduction to use of Edebug.
  172. * Prepare: Edebug Prepare.    You must prepare a function or macro definition
  173.                   in order to debug it with Edebug.
  174. * Edebug Modes::        Execution modes, stopping more or less often.
  175. * Stepping::            Commands to step to a specified place.
  176. * Breakpoints::            Setting breakpoints to make the program stop.
  177. * Views::            Viewing the outside buffer and window status.
  178. * Eval: Edebug Eval.        Evaluating expressions within Edebug.
  179. * Eval List::            Expressions whose values are displayed
  180.                   each time you enter Edebug.
  181. * Misc: Edebug Misc.        Miscellaneous
  182. * Printing::            Printing circular structure in Edebug.
  183. * The Outside Context::        Data that Edebug saves and restores.
  184. * Macro Calls::            Explaining how to handle macro calls.
  185. * Options: Edebug Options.    Option variables for customizing Edebug.
  186.  
  187. 
  188. File: elisp,  Node: Using Edebug,  Next: Edebug Prepare,  Up: Edebug
  189.  
  190. Using Edebug
  191. ------------
  192.  
  193.    To debug a Lisp program with Edebug, you must first "prepare" the
  194. Lisp functions that you want to debug.  *Note Edebug Prepare::.
  195.  
  196.    Once a function is prepared, any call to the function activates
  197. Edebug.  This involves entering a recursive edit which is a level of
  198. Edebug activation.
  199.  
  200.    Activating Edebug may stop execution and let you step through the
  201. function, or it may continue execution while checking for debugging
  202. commands, depending on the selected Edebug execution mode.  *Note
  203. Edebug Modes::.
  204.  
  205.    Within Edebug, you normally view an Emacs buffer showing the source
  206. of the Lisp function you are debugging.  We call this the "Edebug
  207. buffer"--but note that it is not always the same buffer, and it is not
  208. reserved for Edebug use.
  209.  
  210.    An arrow at the left margin indicates the line where the function is
  211. executing.  Point initially shows where within the line the function is
  212. executing, but this ceases to be true if you move point yourself.
  213.  
  214.    If you prepare the definition of `fac' (shown below) for Edebug and
  215. then execute `(fac 3)', here is what you normally see.  Point is at the
  216. open-parenthesis before `if'.
  217.  
  218.      (defun fac (n)
  219.      =>-!-(if (< 0 n)
  220.            (* n (fac (1- n)))
  221.          1))
  222.  
  223.    The places within a function where Edebug can stop execution are
  224. called "stop points".  These occur both before and after each
  225. subexpression that is a list, and also after each variable reference.
  226. Stop points before variables are optional, under the control of the
  227. value of `edebug-stop-before-symbols'.  Here we show with periods the
  228. stop points normally found in the function `fac':
  229.  
  230.      (defun fac (n)
  231.        .(if .(< 0 n.).
  232.            .(* n. .(fac (1- n.).).).
  233.          1).)
  234.  
  235.    While a buffer is the Edebug buffer, the special commands of Edebug
  236. are available in it, instead of many usual editing commands.  Type `?'
  237. to display a list of Edebug commands.  In particular, you can exit the
  238. innermost Edebug activation level with `C-]', and you can return all
  239. the way to top level with `q'.
  240.  
  241.    For example, you can type the Edebug command SPC to execute until
  242. the next stop point.  If you type SPC once after entry to `fac', here
  243. is the state that you get:
  244.  
  245.      (defun fac (n)
  246.      =>(if -!-(< 0 n)
  247.            (* n (fac (1- n)))
  248.          1))
  249.  
  250.    When Edebug stops execution after an expression, it displays the
  251. expression's value in the echo area.  Use the `r' command to display
  252. the value again later.
  253.  
  254.    While Edebug is active, it catches all errors (if `debug-on-error' is
  255. non-`nil') and quits (if `debug-on-quit' is non-`nil') instead of the
  256. standard debugger.  When this happens, Edebug displays the last stop
  257. point that it knows about.  This may be the location of a call to a
  258. function which was not prepared for Edebug debugging, within which the
  259. error actually occurred.
  260.  
  261. 
  262. File: elisp,  Node: Edebug Prepare,  Next: Edebug Modes,  Prev: Using Edebug,  Up: Edebug
  263.  
  264. Preparing Functions for Edebug
  265. ------------------------------
  266.  
  267.    In order to use Edebug to debug a function, you must first "prepare"
  268. the function.  Preparing a function inserts additional code into it
  269. which invokes Edebug at the proper places.
  270.  
  271.    Any call to an Edebug-prepared function activates Edebug.  This may
  272. or may not stop execution, depending on the Edebug execution mode in
  273. use.  Some Edebug modes only update the display to indicate the
  274. progress of the evaluation without stopping execution.  The default
  275. initial Edebug mode is `step' which does stop execution.  *Note Edebug
  276. Modes::.
  277.  
  278.    Once you have loaded Edebug, the command `C-M-x' is redefined so
  279. that when used on a function or macro definition, it prepares the
  280. function or macro if given a prefix argument.  If the variable
  281. `edebug-all-defuns' is non-`nil', that inverts the meaning of the
  282. prefix argument: then `C-M-x' prepares the function or macro *unless*
  283. it has a prefix argument.  The default value of `edebug-all-defuns' is
  284. `nil'.  The command `M-x edebug-all-defuns' toggles the value of the
  285. variable `edebug-all-defuns'.
  286.  
  287.    If `edebug-all-defuns' is non-`nil', then the commands `eval-region'
  288. and `eval-current-buffer' also prepare any functions and macros whose
  289. definitions they evaluate.
  290.  
  291.    Loading a file does not prepare functions and macros for Edebug.
  292.  
  293.    See *Note Evaluation:: for discussion of other evaluation functions
  294. available inside of Edebug.
  295.  
  296. 
  297. File: elisp,  Node: Edebug Modes,  Next: Stepping,  Prev: Edebug Prepare,  Up: Edebug
  298.  
  299. Edebug Modes
  300. ------------
  301.  
  302.    Edebug supports several execution modes for running the program you
  303. are debugging.  We call these alternatives "Edebug modes"; do not
  304. confuse them with major modes or minor modes.  The current Edebug mode
  305. determines how Edebug displays the progress of the evaluation, whether
  306. it stops at each stop point, or continues to the next breakpoint, for
  307. example.
  308.  
  309.    Normally, you specify the Edebug mode for execution by typing a
  310. command to continue the program in a certain mode.  Here is a table of
  311. these commands.  All except for `S' resume execution of the program, at
  312. least for a certain distance.
  313.  
  314. `S'
  315.      Stop: don't execute any more of the program for now, just wait for
  316.      more Edebug commands.
  317.  
  318. `SPC'
  319.      Step: stop at the next stop point encountered.
  320.  
  321. `t'
  322.      Trace: pause one second at each Edebug stop point.
  323.  
  324. `T'
  325.      Rapid trace: mention each stop point, but don't actually pause.
  326.  
  327. `g'
  328.      Go: run until the next breakpoint.  *Note Breakpoints::.
  329.  
  330. `c'
  331.      Continue: pause for one second at each breakpoint, but don't stop.
  332.  
  333. `C'
  334.      Continue: mention each breakpoint, but don't actually pause.
  335.  
  336. `G'
  337.      Non-stop: ignore breakpoints.  You can still stop the program by
  338.      typing `S'.
  339.  
  340.    In general, the execution modes earlier in the above list run the
  341. program more slowly or stop sooner.
  342.  
  343.    When you enter a new Edebug level, the mode comes from the value of
  344. the variable `edebug-initial-mode'.  By default, this specifies "step"
  345. mode.  If the mode thus specified is not stop mode, then the Edebug
  346. level executes the program (or part of it).
  347.  
  348.    While executing or tracing, you can interrupt the execution by typing
  349. any Edebug command.  Edebug stops the program at the next stop point and
  350. then executes the command that you typed.  For example, typing `t'
  351. during execution switches to trace mode at the next stop point.
  352.  
  353.    You can use the `S' command to stop execution without doing anything
  354. else.
  355.  
  356.    If your function happens to read input, a character you hit
  357. intending to interrupt execution may be read by the function instead.
  358. You can avoid such unintended results by paying attention to when your
  359. program wants input.
  360.  
  361.    Keyboard macros containing the commands in this section do not
  362. completely work: exiting from Edebug, to resume the program, loses
  363. track of the keyboard macro.  This is not easy to fix.
  364.  
  365. 
  366. File: elisp,  Node: Stepping,  Next: Breakpoints,  Prev: Edebug Modes,  Up: Edebug
  367.  
  368. Stepping
  369. --------
  370.  
  371. `f'
  372.      Run the program forward over one expression.  More precisely, set a
  373.      temporary breakpoint at the position that `C-M-f' would reach,
  374.      then execute in go mode so that the program will stop at
  375.      breakpoints.  See *Note Breakpoints:: for the details on
  376.      breakpoints.
  377.  
  378.      With a prefix argument N, the temporary breakpoint is placed N
  379.      sexps beyond point.  If the containing list ends before N more
  380.      elements, then the place to stop is after the containing
  381.      expression.
  382.  
  383.      Be careful that the position `C-M-f' finds is a place that the
  384.      program will really get to; this may not be true in a
  385.      `condition-case', for example.
  386.  
  387.      This command does `forward-sexp' starting at point rather than the
  388.      stop point, thus providing more flexibility.  If you want to
  389.      execute one expression from the current stop point, type `w'
  390.      first, to move point there.
  391.  
  392. `o'
  393.      Run the program until the end of the containing sexp.  If the
  394.      containing sexp is the top level defun, run until just before the
  395.      function returns.  If that is where you are now, return from the
  396.      function and then stop.
  397.  
  398.      This command does not exit the currently executing function unless
  399.      you are positioned after the last sexp of the function.
  400.  
  401.      If the program does a non-local exit, it may fail to reach the
  402.      temporary breakpoint that this command sets.
  403.  
  404. `i'
  405.      Step into the function about to be called.  Use this command
  406.      before any of the arguments of the function call are evaluated,
  407.      since otherwise it is too late.
  408.  
  409.      One undesirable side effect of using `edebug-step-in' is that the
  410.      next time the stepped-into function is called, Edebug will be
  411.      called there as well.
  412.  
  413. `h'
  414.      Proceed to the stop point near where point is.  This uses a
  415.      temporary breakpoint.
  416.  
  417.    The `f' command runs the program forward over one expression.  More
  418. precisely, set a temporary breakpoint at the position that `C-M-f'
  419. would reach, then execute in go mode so that the program will stop at
  420. breakpoints.  See *Note Breakpoints:: for the details on breakpoints.
  421.  
  422.    With a prefix argument N, the temporary breakpoint is placed N sexps
  423. beyond point.  If the containing list ends before N more elements, then
  424. the place to stop is after the containing expression.
  425.  
  426.    Be careful that the position `C-M-f' finds is a place that the
  427. program will really get to; this may not be true in a `condition-case',
  428. for example.
  429.  
  430.    The `f' command uses the existing value of point as the basis for
  431. setting the breakpoint, because that is more flexible.  To execute one
  432. expression *from the current stop point*, type `w' and then `f'.
  433.  
  434.    The `o' command continues "out of" an expression.  It places a
  435. temporary breakpoints at the end of the containing sexp.  If the
  436. containing sexp is the top level defun, it continues until just before
  437. the function returns.  If that is where you are now, it returns from the
  438. function and then stops.
  439.  
  440.    This command does not exit the currently executing function unless
  441. you are positioned after the last sexp of the function.
  442.  
  443.    The `i' command steps into the function about to be called.  Use
  444. this command before any of the arguments of the function call are
  445. evaluated, since otherwise it is too late.
  446.  
  447.    One undesirable side effect of using `i' is that the next time the
  448. stepped-into function is called, Edebug will be called there as well.
  449.  
  450.    The `h' command proceeds to the stop point near where point is,
  451. using a temporary breakpoint.
  452.  
  453.    All the commands in this section may fail to work as expected in case
  454. of nonlocal exit, because a nonlocal exit can bypass the temporary
  455. breakpoint where you expected the program to stop.
  456.  
  457. 
  458. File: elisp,  Node: Edebug Misc,  Next: Printing,  Prev: Eval List,  Up: Edebug
  459.  
  460. Miscellaneous
  461. -------------
  462.  
  463.    Some miscellaneous commands are described here.
  464.  
  465. `C-]'
  466.      Abort one level of Edebug activity.
  467.  
  468. `q'
  469.      Return to the top level editor command loop.  This exits all
  470.      recursive editing levels, including all levels of Edebug activity.
  471.  
  472. `r'
  473.      Redisplay the result of the previous expression in the echo area.
  474.  
  475. `d'
  476.      Display a backtrace, excluding Edebug's own functions for clarity.
  477.  
  478.      You cannot use debugger commands in the backtrace buffer in Edebug
  479.      as you would in the standard debugger.
  480.  
  481.      The backtrace buffer is killed automatically when you continue
  482.      execution.
  483.  
  484. 
  485. File: elisp,  Node: Breakpoints,  Next: Views,  Prev: Stepping,  Up: Edebug
  486.  
  487. Breakpoints
  488. -----------
  489.  
  490.    While using Edebug, you can specify "breakpoints" in the program you
  491. are testing: points where execution should stop.  You can set a
  492. breakpoint at any stop point, as defined in *Note Using Edebug::--even
  493. before a symbol.  For setting and unsetting breakpoints, the stop point
  494. that is affected is the first one at or after point in the Edebug
  495. buffer.  Here are the Edebug commands for breakpoints:
  496.  
  497. `b'
  498.      Set a breakpoint at the stop point at or after point.  If you use a
  499.      prefix argument, the breakpoint is temporary (it turns off the
  500.      first time it stops the program).
  501.  
  502. `u'
  503.      Unset the breakpoint (if any) at the stop point at or after the
  504.      current point.
  505.  
  506. `x COND RET'
  507.      Set a conditional breakpoint which stops the program only if COND
  508.      evaluates to a non-`nil' value.  If you use a prefix argument, the
  509.      breakpoint is temporary (it turns off the first time it stops the
  510.      program).
  511.  
  512. `B'
  513.      Move point to the next breakpoint in the current function
  514.      definition.
  515.  
  516.    While in Edebug, you can set a breakpoint with `b'
  517. (`edebug-set-breakpoint') and unset one with `u'
  518. (`edebug-unset-breakpoint').  First you must move point to a position
  519. at or before the desired Edebug stop point, then hit the key to change
  520. the breakpoint.  Unsetting a breakpoint that has not been set does
  521. nothing.
  522.  
  523.    Reevaluating the function with `edebug-defun' clears all breakpoints
  524. in the function.
  525.  
  526.    A "conditional breakpoint" tests a condition each time the program
  527. gets there, to decide whether to stop.  To set a conditional breakpoint,
  528. use `x', and specify the condition expression in the minibuffer.
  529.  
  530.    You can make both conditional and unconditional breakpoints
  531. "temporary" by using a prefix arg to the command to set the breakpoint.
  532. After breaking at a temporary breakpoint, it is automatically cleared.
  533.  
  534.    Edebug always stops or pauses at a breakpoint except when the Edebug
  535. mode is Go-nonstop.  In that mode, it ignores breakpoints entirely.
  536.  
  537.    To find out where your breakpoints are, use the `B'
  538. (`edebug-next-breakpoint') command, which moves point to the next
  539. breakpoint in the function following point, or to the first breakpoint
  540. if there are no following breakpoints.  This command does not continue
  541. execution--it just moves point in the buffer.
  542.  
  543. 
  544. File: elisp,  Node: Views,  Next: Edebug Eval,  Prev: Breakpoints,  Up: Edebug
  545.  
  546. Views
  547. -----
  548.  
  549.    These Edebug commands let you view aspects of the buffer and window
  550. status that obtained before entry to Edebug.
  551.  
  552. `v'
  553.      View the outside window configuration.
  554.  
  555. `p'
  556.      Temporarily display the outside current buffer with point at its
  557.      outside position.
  558.  
  559. `w'
  560.      Switch back to the buffer showing the currently executing
  561.      function, and move point back to the current stop point.
  562.  
  563. `W'
  564.      Forget the saved outside window configuration--so that the current
  565.      window configuration will remain unchanged when you next exit
  566.      Edebug (by continuing the program).  Also toggle the
  567.      `edebug-save-windows' variable.
  568.  
  569. 
  570. File: elisp,  Node: Edebug Eval,  Next: Eval List,  Prev: Views,  Up: Edebug
  571.  
  572. Evaluation
  573. ----------
  574.  
  575.    While within Edebug, you can evaluate expressions "as if" Edebug were
  576. not running.  Edebug tries to be invisible to the expression's
  577. evaluation.
  578.  
  579. `e EXP RET'
  580.      Evaluate expression EXP in the context outside of Edebug.  That
  581.      is, Edebug tries to avoid altering the effect of EXP.
  582.  
  583. `M-ESC EXP RET'
  584.      Evaluate expression EXP in the context of Edebug itself.
  585.  
  586. `C-x C-e'
  587.      Evaluate the expression in the buffer before point, in the context
  588.      outside of Edebug.
  589.  
  590. 
  591. File: elisp,  Node: Eval List,  Next: Edebug Misc,  Prev: Edebug Eval,  Up: Edebug
  592.  
  593. Evaluation List Buffer
  594. ----------------------
  595.  
  596.    You can use the "evaluation list buffer", called `*edebug*', to
  597. evaluate expressions interactively.  You can also set up the
  598. "evaluation list" of expressions to be evaluated automatically each
  599. time Edebug is reentered.
  600.  
  601. `E'
  602.      Switch to the evaluation list buffer `*edebug*'.
  603.  
  604.    In the `*edebug*' buffer you can use the commands of Lisp
  605. Interaction as well as these special commands:
  606.  
  607. `LFD'
  608.      Evaluate the expression before point, in the context outside of
  609.      Edebug, and insert the value in the buffer.
  610.  
  611. `C-x C-e'
  612.      Evaluate the expression before point, in the context outside of
  613.      Edebug.
  614.  
  615. `C-c C-u'
  616.      Build a new evaluation list from the first expression of each
  617.      group, reevaluate and redisplay.  Groups are separated by a line
  618.      starting with a comment.
  619.  
  620. `C-c C-d'
  621.      Delete the evaluation list group that point is in.
  622.  
  623. `C-c C-w'
  624.      Switch back to the Edebug buffer at the current stop point.
  625.  
  626.    You can evaluate expressions in the evaluation list window with
  627. `LFD' or `C-x C-e', just as you would in `*scratch*'; but they are
  628. evaluated in the context outside of Edebug.
  629.  
  630.    The expressions you enter interactively (and their results) are lost
  631. when you continue execution of your function unless you add them to the
  632. evaluation list with `C-c C-u' (`edebug-update-eval-list').  This
  633. command builds a new list from the first expression of each "evaluation
  634. list group".  Groups are separated by a line starting with a comment.
  635.  
  636.    When the evaluation list is redisplayed, each expression is displayed
  637. followed by the result of evaluating it, and a comment line.  If an
  638. error occurs during an evaluation, the error message is displayed in a
  639. string as if it were the result.  Therefore expressions that use
  640. variables not currently valid do not interrupt your debugging.
  641.  
  642.    Here is an example of what the evaluation list window looks like
  643. after several expressions have been added to it:
  644.  
  645.      (current-buffer)
  646.      #<buffer *scratch*>
  647.      ;---------------------------------------------------------------
  648.      (point-min)
  649.      1
  650.      ;---------------------------------------------------------------
  651.      (point-max)
  652.      2
  653.      ;---------------------------------------------------------------
  654.      edebug-outside-point-max
  655.      "Symbol's value as variable is void: edebug-outside-point-max"
  656.      ;---------------------------------------------------------------
  657.      (recursion-depth)
  658.      0
  659.      ;---------------------------------------------------------------
  660.      this-command
  661.      eval-last-sexp
  662.      ;---------------------------------------------------------------
  663.  
  664.    To delete a group, move point into it and type `C-c C-d'
  665. (`edebug-delete-eval-item'), or simply delete the text for it and
  666. update the evaluation list with `C-c C-u'.  When you add a new group,
  667. be sure to add a comment at the beginning.
  668.  
  669.    After selecting `*edebug*', you can return to the source code buffer
  670. (the Edebug buffer) with `C-c C-w'.  The `*edebug*' buffer is killed
  671. when you continue execution of your function, and recreated next time
  672. it is needed.
  673.  
  674. 
  675. File: elisp,  Node: Printing,  Next: The Outside Context,  Prev: Edebug Misc,  Up: Edebug
  676.  
  677. Printing
  678. --------
  679.  
  680.    If the results of your expressions contain circular references to
  681. other parts of the same structure, you can print them more usefully
  682. with the `custom-print'.
  683.  
  684.    To load the package and activate custom printing only for Edebug,
  685. simply use the command `edebug-install-custom-print-funcs'.  Then set
  686. the variable `print-circle' to enable special handling of circular
  687. structure.  To restore the standard print functions, use
  688. `edebug-reset-print-funcs'.
  689.  
  690. 
  691. File: elisp,  Node: The Outside Context,  Next: Macro Calls,  Prev: Printing,  Up: Edebug
  692.  
  693. The Outside Context
  694. -------------------
  695.  
  696.    Edebug tries to be transparent to the program you are debugging, but
  697. it does not succeed completely.  In addition, most evaluations you do
  698. within Edebug (see *Note Evaluation::) occur in the same outside context
  699. which is temporarily restored for the evaluation.  This section explains
  700. precisely how use Edebug fails to be completely transparent.
  701.  
  702. * Menu:
  703.  
  704. * Just Checking::        Just Checking
  705. * Outside Window Configuration::  Outside Window Configuration
  706. * Recursive Edit::        Recursive Edit
  707. * Side Effects::        Side Effects
  708.  
  709. 
  710. File: elisp,  Node: Just Checking,  Next: Outside Window Configuration,  Up: The Outside Context
  711.  
  712. Just Checking
  713. .............
  714.  
  715.    Whenever Edebug is entered just to think about whether to take some
  716. action, it needs to save and restore certain data.
  717.  
  718.    * `max-lisp-eval-depth' and `max-specpdl-size' are both incremented
  719.      for each `edebug-enter' call so that your code should not be
  720.      impacted by Edebug frames on the stack.
  721.  
  722.    * The state of keyboard macro execution is saved and cleared out.
  723.  
  724. 
  725. File: elisp,  Node: Outside Window Configuration,  Next: Recursive Edit,  Prev: Just Checking,  Up: The Outside Context
  726.  
  727. Outside Window Configuration
  728. ............................
  729.  
  730.    When Edebug needs to display something (e.g., in trace mode), it
  731. saves the current window configuration from "outside" Edebug (*note
  732. Window Configurations::.).  When you exit Edebug (by continuing the
  733. program), it restores the previous window configuration.
  734.  
  735.    Emacs redisplays only when it pauses.  Usually, when you continue
  736. Edebug, the program comes back into Edebug at a breakpoint or after
  737. stepping, without pausing or reading input in between.  In such cases,
  738. Emacs never gets a chance to redisplay the "outside" configuration.
  739. What you see is the window configuration for within Edebug, with no
  740. interruption.
  741.  
  742.    The window configuration proper does not include which buffer is
  743. current or where point and mark are in the current buffer, but Edebug
  744. saves and restores these also.
  745.  
  746.    Entry to Edebug for displaying something also saves and restores the
  747. following data.  (Some of these variables are deliberately not restored
  748. if an error or quit signal occurs.)
  749.  
  750.    * The position of point in the Edebug buffer is saved and restored
  751.      if the outside current buffer is the same as the Edebug buffer.
  752.  
  753.    * The outside window configuration, as described above, is saved and
  754.      restored if `edebug-save-windows' is non-`nil'.
  755.  
  756.    * The current buffer, and point and mark in the current buffer are
  757.      normally saved and restored even if the current buffer is the same
  758.      as the Edebug buffer.
  759.  
  760.    * The value of point in each displayed buffers is saved and restored
  761.      if `edebug-save-displayed-buffer-points' is non-`nil'.
  762.  
  763.    * The variables `overlay-arrow-position' and `overlay-arrow-string'
  764.      are saved and restored.  This permits recursive use of Edebug, and
  765.      use of Edebug while using GUD.
  766.  
  767.    * `cursor-in-echo-area' is locally bound to `nil' so that the cursor
  768.      shows up in the window.
  769.  
  770. 
  771. File: elisp,  Node: Recursive Edit,  Next: Side Effects,  Prev: Outside Window Configuration,  Up: The Outside Context
  772.  
  773. Recursive Edit
  774. ..............
  775.  
  776.    When Edebug is entered and actually reads commands from the user, it
  777. saves (and later restores) these additional data:
  778.  
  779.    * The current match data, for whichever buffer was current.
  780.  
  781.    * `last-command', `this-command', `last-command-char', and
  782.      `last-input-char'.  Commands used within Edebug do not affect these
  783.      variables outside of Edebug.
  784.  
  785.      But note that it is not possible to preserve the status reported by
  786.      `(this-command-keys)' and the variable `unread-command-char'.
  787.  
  788.    * `standard-output' and `standard-input'.
  789.  
  790. 
  791. File: elisp,  Node: Side Effects,  Prev: Recursive Edit,  Up: The Outside Context
  792.  
  793. Side Effects
  794. ............
  795.  
  796.    Edebug operation unavoidably alters some data in Emacs, and this can
  797. interfere with debugging certain programs.
  798.  
  799.    * Lisp stack usage is increased, but the limits,
  800.      `max-lisp-eval-depth' and `max-specpdl-size', are also increased
  801.      proportionally.
  802.  
  803.    * The key sequence returned by `this-command-keys' is changed by
  804.      executing commands within Edebug and there appears to be no way to
  805.      reset the key sequence from Lisp.
  806.  
  807.    * Edebug cannot save and restore the value of `unread-command-char'
  808.      or `unread-command-events'.  Entering Edebug while these variables
  809.      have nontrivial values can interfere with execution of the program
  810.      you are debugging.
  811.  
  812.    * Complex commands executed while in Edebug are added to the variable
  813.      `command-history'.  In rare cases this can alter execution.
  814.  
  815.    * Within Edebug, the recursion depth appears one deeper than the
  816.      recursion depth outside Edebug.
  817.  
  818.    * Horizontal scrolling of the Edebug buffer is not recovered.
  819.  
  820. 
  821. File: elisp,  Node: Macro Calls,  Next: Edebug Options,  Prev: The Outside Context,  Up: Edebug
  822.  
  823. Macro Calls
  824. -----------
  825.  
  826.    When Edebug prepares for stepping through an expression that uses a
  827. Lisp macro, it needs additional advice to do the job properly.  This is
  828. because there is no way to tell which parts of the macro call are forms
  829. to be evaluated.  You must explain the format of calls to each macro to
  830. enable Edebug to handle it.  To do this, use `def-edebug-form-spec' to
  831. define the format of calls to a given macro.
  832.  
  833.  - Macro: def-edebug-form-spec MACRO ARGPATTERN
  834.      Specify which parts of a call to macro MACRO are subexpressions to
  835.      be evaluated.  The second argument, ARGPATTERN, details what the
  836.      argument list looks like.
  837.  
  838.    Here is a table of the possibilities for ARGPATTERN and its
  839. subexpressions:
  840.  
  841. `t'
  842.      A list of any number of evaluated arguments.
  843.  
  844. `0'
  845.      A list of unevaluated arguments.
  846.  
  847. `sexp'
  848.      A single unevaluated object.
  849.  
  850. `form'
  851.      A single evaluated expression.
  852.  
  853. `symbolp'
  854.      An unevaluated symbol.
  855.  
  856. `integerp'
  857.      An unevaluated number.
  858.  
  859. `stringp'
  860.      An unevaluated string.
  861.  
  862. `vectorp'
  863.      An unevaluated vector.
  864.  
  865. `atom'
  866.      An unevaluated object that is not a cons cell.
  867.  
  868. `function'
  869.      A function argument: a quoted symbol, a quoted lambda expression,
  870.      or a form (that should evaluate to a function or lambda
  871.      expression).  Edebug treats the body of a lambda expression
  872.      treated as evaluated.
  873.  
  874. `FUNCTION'
  875.      A function serves as a predicate--it designates the set of possible
  876.      arguments for which it would return non-`nil'.
  877.  
  878. `'OBJECT'
  879.      The precise object OBJECT, treated as unevaluated.
  880.  
  881. `(PATTERNS)'
  882.      A list whose elements are described by PATTERNS.  A sublist of the
  883.      same format as the top level, processed recursively.
  884.  
  885. `[PATTERNS]'
  886.      A sequence of arguments that are described by PATTERNS.
  887.  
  888. `&optional'
  889.      This symbol serves as a flag saying that all following elements in
  890.      the specification list at this level are optional.  They may or
  891.      may not match arguments; as soon as one does not match, processing
  892.      of the specification list at this level terminates.  To make just
  893.      one item optional, use `[&optional PATTERN]'.
  894.  
  895. `&rest'
  896.      This symbol serves as a flag saying that the following elements in
  897.      the specification list at this level may be repeated, in order,
  898.      zero or more times.  Only one `&rest' may appear at the same level
  899.      of a specification list, and `&rest' must not be followed by
  900.      `&optional'.
  901.  
  902.      To specify repetition of certain types of arguments, followed by
  903.      dissimilar arguments, use `[&rest PATTERNS...]'.
  904.  
  905. `&or'
  906.      This symbol serves as an operator saying that the following
  907.      elements in the specification list at this level are alternatives.
  908.      To group two or more list elements as one alternative, bracket
  909.      them in `[...]'.  Only one `&or' may appear in a list, and it may
  910.      not be followed by `&optional' or `&rest'.  One of the
  911.      alternatives must match, unless the `&or' is preceded by
  912.      `&optional' or `&rest'.
  913.  
  914.    If the actual arguments of a macro call fail to match the
  915. specification, taking account of alternatives, optional arguments and
  916. repeated arguments, Edebug reports a syntax error in use of the macro.
  917.  
  918.    The combination of backtracking, `&optional', `&rest', `&or', and
  919. `[...]' for grouping provides the equivalent of regular expressions.
  920. The `(...)' lists require balanced parentheses, which is the only
  921. context free (finite state with stack) construct supported.
  922.  
  923.    Here are some examples of using `def-edebug-form-spec'.  First, for
  924. the `let' special form:
  925.  
  926.      (def-edebug-form-spec let
  927.        '((&rest
  928.          &or symbolp (symbolp &optional form))
  929.         &rest form))
  930.  
  931.    Here's the spec for the `for' loop macro (*note Problems with
  932. Macros::.) and for the `case' and `do' macros in `cl.el':
  933.  
  934.      (def-edebug-form-spec for
  935.        '(symbolp 'from form 'to form 'do &rest form))
  936.      
  937.      (def-edebug-form-spec case
  938.        '(form &rest (sexp form)))
  939.      
  940.      (def-edebug-form-spec do
  941.        '((&rest &or symbolp (symbolp &optional form form))
  942.          (form &rest form)
  943.          &rest body))
  944.  
  945.    Finally, the functions `mapcar', `mapconcat', `mapatoms', `apply',
  946. and `funcall' all take function arguments, and Edebug defines
  947. specifications for them.  Here's one example:
  948.  
  949.      (def-edebug-form-spec apply '(function &rest form))
  950.  
  951.    The backquote (``') macro results in an expression that is not
  952. necessarily evaluated.  Edebug cannot step through code generated by use
  953. of backquote.
  954.  
  955. 
  956. File: elisp,  Node: Edebug Options,  Prev: Macro Calls,  Up: Edebug
  957.  
  958. Edebug Options
  959. --------------
  960.  
  961.    These options affect the behavior of Edebug:
  962.  
  963.  - User Option: edebug-all-defuns
  964.      If non-`nil', normal evaluation of `defun' and `defmacro' forms
  965.      prepares the functions and macros for stepping with Edebug.  This
  966.      applies to `eval-defun', `eval-region' and `eval-current-buffer'.
  967.  
  968.      The default value is `nil'.
  969.  
  970.  - User Option: edebug-stop-before-symbols
  971.      If non-`nil', Edebug places stop points before symbols as well as
  972.      after.
  973.  
  974.      This option takes effect for a function when you prepare it for
  975.      stepping with Edebug.  Changing the option's value during
  976.      execution of Edebug has no effect on the functions already set up
  977.      for Edebug execution.
  978.  
  979.  - User Option: edebug-save-windows
  980.      If non-`nil', save and restore window configuration on Edebug
  981.      calls.  It takes some time to save and restore, so if your program
  982.      does not care what happens to the window configurations, it is
  983.      better to set this variable to `nil'.
  984.  
  985.      The default value is `t'.
  986.  
  987.  - User Option: edebug-save-point
  988.      If non-`nil', Edebug saves and restores point and the mark in
  989.      source code buffers.  The default value is `t'.
  990.  
  991.  - User Option: edebug-save-displayed-buffer-points
  992.      If non-`nil', save and restore point in all buffers when entering
  993.      Edebug mode.
  994.  
  995.      Saving and restoring point in other buffers is necessary if you are
  996.      debugging code that changes the point of a buffer which is
  997.      displayed in a non-selected window.  If Edebug or the user then
  998.      selects the window, the buffer's point will be changed to the
  999.      window's point.
  1000.  
  1001.      Saving and restoring is an expensive operation since it visits each
  1002.      window and each displayed buffer twice for each Edebug call, so it
  1003.      is best to avoid it if you can.
  1004.  
  1005.      The default value is `nil'.
  1006.  
  1007.  - User Option: edebug-initial-mode
  1008.      If this variable is non-`nil', it specifies an Edebug mode to start
  1009.      in each time the program enters a new Edebug recursive-edit level.
  1010.      Possible values are `step', `go', `Go-nonstop', `trace',
  1011.      `Trace-fast', `continue', and `Continue-fast'.
  1012.  
  1013.      The default value is `step'.
  1014.  
  1015.  - User Option: edebug-trace
  1016.      Non-`nil' means display a trace of function entry and exit.
  1017.      Tracing output is displayed in a buffer named `*edebug-trace*', one
  1018.      function entry or exit per line, indented by the recursion level.
  1019.      You can customize this display by replacing the functions
  1020.      `edebug-print-trace-entry' and `edebug-print-trace-exit'.
  1021.  
  1022.      The default value is `nil'.
  1023.  
  1024. 
  1025. File: elisp,  Node: Streams,  Next: Minibuffers,  Prev: Debugging,  Up: Top
  1026.  
  1027. Reading and Printing Lisp Objects
  1028. *********************************
  1029.  
  1030.    "Printing" and "reading" are the operations of converting Lisp
  1031. objects to textual form and vice versa.  They use the printed
  1032. representations and read syntax described in *Note Types of Lisp
  1033. Object::.
  1034.  
  1035.    This chapter describes the Lisp functions for reading and printing.
  1036. It also describes "streams", which specify where to get the text (if
  1037. reading) or where to put it (if printing).
  1038.  
  1039. * Menu:
  1040.  
  1041. * Streams Intro::     Overview of streams, reading and printing.
  1042. * Input Streams::     Various data types that can be used as input streams.
  1043. * Input Functions::   Functions to read Lisp objects from text.
  1044. * Output Streams::    Various data types that can be used as output streams.
  1045. * Output Functions::  Functions to print Lisp objects as text.
  1046. * Output Variables::  Variables that control what the printing functions do.
  1047.  
  1048. 
  1049. File: elisp,  Node: Streams Intro,  Next: Input Streams,  Up: Streams
  1050.  
  1051. Introduction to Reading and Printing
  1052. ====================================
  1053.  
  1054.    "Reading" a Lisp object means parsing a Lisp expression in textual
  1055. form and producing a corresponding Lisp object.  This is how Lisp
  1056. programs get into Lisp from files of Lisp code.  We call the text the
  1057. "read syntax" of the object.  For example, reading the text `(a . 5)'
  1058. returns a cons cell whose CAR is `a' and whose CDR is the number 5.
  1059.  
  1060.    "Printing" a Lisp object means producing text that represents that
  1061. object--converting the object to its printed representation.  Printing
  1062. the cons cell described above produces the text `(a . 5)'.
  1063.  
  1064.    Reading and printing are more or less inverse operations: printing
  1065. the object that results from reading a given piece of text often
  1066. produces the same text, and reading the text that results from printing
  1067. an object usually produces a similar-looking object.  For example,
  1068. printing the symbol `foo' produces the text `foo', and reading that text
  1069. returns the symbol `foo'.  Printing a list whose elements are `a' and
  1070. `b' produces the text `(a b)', and reading that text produces a list
  1071. (but not the same list) with elements are `a' and `b'.
  1072.  
  1073.    However, these two operations are not precisely inverses.  There are
  1074. two kinds of exceptions:
  1075.  
  1076.    * Printing can produce text that cannot be read.  For example,
  1077.      buffers, windows, subprocesses and markers print into text that
  1078.      starts with `#'; if you try to read this text, you get an error.
  1079.      There is no way to read those data types.
  1080.  
  1081.    * One object can have multiple textual representations.  For example,
  1082.      `1' and `01' represent the same integer, and `(a b)' and `(a .
  1083.      (b))' represent the same list.  Reading will accept any of the
  1084.      alternatives, but printing must choose one of them.
  1085.  
  1086. 
  1087. File: elisp,  Node: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Streams
  1088.  
  1089. Input Streams
  1090. =============
  1091.  
  1092.    Most of the Lisp functions for reading text take an "input stream"
  1093. as an argument.  The input stream specifies where or how to get the
  1094. characters of the text to be read.  Here are the possible types of input
  1095. stream:
  1096.  
  1097. BUFFER
  1098.      The input characters are read from BUFFER, starting with the
  1099.      character directly after point.  Point advances as characters are
  1100.      read.
  1101.  
  1102. MARKER
  1103.      The input characters are read from the buffer that MARKER is in,
  1104.      starting with the character directly after the marker.  The marker
  1105.      position advances as characters are read.  The value of point in
  1106.      the buffer has no effect when the stream is a marker.
  1107.  
  1108. STRING
  1109.      The input characters are taken from STRING, starting at the first
  1110.      character in the string and using as many characters as required.
  1111.  
  1112. FUNCTION
  1113.      The input characters are generated by FUNCTION, one character per
  1114.      call.  Normally FUNCTION is called with no arguments, and should
  1115.      return a character.
  1116.  
  1117.      Occasionally FUNCTION is called with one argument (always a
  1118.      character).  When that happens, FUNCTION should save the argument
  1119.      and arrange to return it on the next call.  This is called
  1120.      "unreading" the character; it happens when the Lisp reader reads
  1121.      one character too many and want to "put it back where it came
  1122.      from".
  1123.  
  1124. `t'
  1125.      `t' used as a stream means that the input is read from the
  1126.      minibuffer.  In fact, the minibuffer is invoked once and the text
  1127.      given by the user is made into a string that is then used as the
  1128.      input stream.
  1129.  
  1130. `nil'
  1131.      `nil' used as a stream means that the value of `standard-input'
  1132.      should be used instead; that value is the "default input stream",
  1133.      and must be a non-`nil' input stream.
  1134.  
  1135. SYMBOL
  1136.      A symbol as output stream is equivalent to the symbol's function
  1137.      definition (if any).
  1138.  
  1139.    Here is an example of reading from a stream which is a buffer,
  1140. showing where point is located before and after:
  1141.  
  1142.      ---------- Buffer: foo ----------
  1143.      This-!- is the contents of foo.
  1144.      ---------- Buffer: foo ----------
  1145.      
  1146.      (read (get-buffer "foo"))
  1147.           => is
  1148.      (read (get-buffer "foo"))
  1149.           => the
  1150.      
  1151.      ---------- Buffer: foo ----------
  1152.      This is the-!- contents of foo.
  1153.      ---------- Buffer: foo ----------
  1154.  
  1155. Note that the first read skips a space at the beginning of the buffer.
  1156. Reading skips any amount of whitespace preceding the significant text.
  1157.  
  1158.    In Emacs 18, reading a symbol discarded the delimiter terminating the
  1159. symbol.  Thus, point would end up at the beginning of `contents' rather
  1160. than after `the'.  The Emacs 19 behavior is superior because it
  1161. correctly handles input such as `bar(foo)' where the delimiter that
  1162. ends one object is needed as the beginning of another object.
  1163.  
  1164.    Here is an example of reading from a stream that is a marker,
  1165. initialized to point at the beginning of the buffer shown.  The value
  1166. read is the symbol `This'.
  1167.  
  1168.  
  1169.      ---------- Buffer: foo ----------
  1170.      This is the contents of foo.
  1171.      ---------- Buffer: foo ----------
  1172.      
  1173.      (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
  1174.           => #<marker at 1 in foo>
  1175.      (read m)
  1176.           => This
  1177.      m
  1178.           => #<marker at 6 in foo>   ;; After the first space.
  1179.  
  1180.    Here we read from the contents of a string:
  1181.  
  1182.      (read "(When in) the course")
  1183.           => (When in)
  1184.  
  1185.    The following example reads from the minibuffer.  The prompt is:
  1186. `Lisp expression: '.  (That is always the prompt used when you read
  1187. from the stream `t'.)  The user's input is shown following the prompt.
  1188.  
  1189.      (read t)
  1190.           => 23
  1191.      ---------- Buffer: Minibuffer ----------
  1192.      Lisp expression: `23 RET'
  1193.      ---------- Buffer: Minibuffer ----------
  1194.  
  1195.    Finally, here is an example of a stream that is a function, named
  1196. `useless-stream'.  Before we use the stream, we initialize the variable
  1197. `useless-list' to a list of characters.  Then each call to the function
  1198. `useless-stream' obtains the next characters in the list or unreads a
  1199. character by adding it to the front of the list.
  1200.  
  1201.      (setq useless-list (append "XY()" nil))
  1202.           => (88 89 40 41)
  1203.      
  1204.      (defun useless-stream (&optional unread)
  1205.        (if unread
  1206.            (setq useless-list (cons unread useless-list))
  1207.          (prog1 (car useless-list)
  1208.                 (setq useless-list (cdr useless-list)))))
  1209.           => useless-stream
  1210.  
  1211. Now we read using the stream thus constructed:
  1212.  
  1213.      (read 'useless-stream)
  1214.           => XY
  1215.      
  1216.      useless-list
  1217.           => (41)
  1218.  
  1219. Note that the close parenthesis remains in the list.  The reader has
  1220. read it, discovered that it ended the input, and unread it.  Another
  1221. attempt to read from the stream at this point would get an error due to
  1222. the unmatched close parenthesis.
  1223.  
  1224.  - Function: get-file-char
  1225.      This function is used internally as an input stream to read from
  1226.      the input file opened by the function `load'.  Don't use this
  1227.      function yourself.
  1228.  
  1229. 
  1230. File: elisp,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Streams
  1231.  
  1232. Input Functions
  1233. ===============
  1234.  
  1235.    This section describes the Lisp functions and variables that pertain
  1236. to reading.
  1237.  
  1238.    In the functions below, STREAM stands for an input stream (see the
  1239. previous section).  If STREAM is `nil' or omitted, it defaults to the
  1240. value of `standard-input'.
  1241.  
  1242.    An `end-of-file' error results if an unterminated list or vector is
  1243. found.
  1244.  
  1245.  - Function: read &optional STREAM
  1246.      This function reads one textual Lisp expression from STREAM,
  1247.      returning it as a Lisp object.  This is the basic Lisp input
  1248.      function.
  1249.  
  1250.  - Function: read-from-string STRING &optional START END
  1251.      This function reads the first textual Lisp expression from the
  1252.      text in STRING.  It returns a cons cell whose CAR is that
  1253.      expression, and whose CDR is an integer giving the position of the
  1254.      next remaining character in the string (i.e., the first one not
  1255.      read).
  1256.  
  1257.      If START is supplied, then reading begins at index START in the
  1258.      string (where the first character is at index 0).  If END is also
  1259.      supplied, then reading stops at that index as if the rest of the
  1260.      string were not there.
  1261.  
  1262.      For example:
  1263.  
  1264.           (read-from-string "(setq x 55) (setq y 5)")
  1265.                => ((setq x 55) . 11)
  1266.           (read-from-string "\"A short string\"")
  1267.                => ("A short string" . 16)
  1268.           
  1269.           ;; Read starting at the first character.
  1270.           (read-from-string "(list 112)" 0)
  1271.                => ((list 112) . 10)
  1272.           ;; Read starting at the second character.
  1273.           (read-from-string "(list 112)" 1)
  1274.                => (list . 6)
  1275.           ;; Read starting at the seventh character,
  1276.           ;;   and stopping at the ninth.
  1277.           (read-from-string "(list 112)" 6 8)
  1278.                => (11 . 8)
  1279.  
  1280.  - Variable: standard-input
  1281.      This variable holds the default input stream: the stream that
  1282.      `read' uses when the STREAM argument is `nil'.
  1283.  
  1284.