home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / emacsinf.zip / elisp.INF (.txt) next >
OS/2 Help File  |  1994-01-21  |  596KB  |  22,635 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Title page ΓòÉΓòÉΓòÉ
  3.  
  4.                          GNU Emacs Lisp Reference Manual
  5.  
  6.                               GNU Emacs Version 18
  7.  
  8.                                  for Unix Users
  9.  
  10.                            Edition 1.03, December 1990
  11.  
  12.               by Bil Lewis, Dan LaLiberte, and the GNU Manual Group
  13.  
  14. Copyright (C) 1990 Free Software Foundation, Inc. 
  15.  
  16. This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for Emacs Version 
  17. 18, 
  18. December 1990. 
  19. ISBN 1-882114-10-8. 
  20.  
  21. Published by the Free Software Foundation, 
  22. 675 Massachusetts Avenue, 
  23. Cambridge, MA 02139 USA 
  24.  
  25. Permission is granted to make and distribute verbatim copies of this manual 
  26. provided the copyright notice and this permission notice are preserved on all 
  27. copies. 
  28.  
  29. Permission is granted to copy and distribute modified versions of this manual 
  30. under the conditions for verbatim copying, provided that the entire resulting 
  31. derived work is distributed under the terms of a permission notice identical to 
  32. this one. 
  33.  
  34. Permission is granted to copy and distribute translations of this manual into 
  35. another language, under the above conditions for modified versions, except that 
  36. this permission notice may be stated in a translation approved by the 
  37. Foundation. 
  38.  
  39. Cover art by Etienne Suvasa. 
  40.  
  41.  
  42. ΓòÉΓòÉΓòÉ 2. Top ΓòÉΓòÉΓòÉ
  43.  
  44. This Info file contains edition 1.03 of the GNU Emacs Lisp Reference Manual. 
  45.  
  46.  
  47. ΓòÉΓòÉΓòÉ 3. GNU Emacs General Public License ΓòÉΓòÉΓòÉ
  48.  
  49.                              (Clarified 11 Feb 1988)
  50.  
  51.  The license agreements of most software companies keep you at the mercy of 
  52. those companies.  By contrast, our general public license is intended to give 
  53. everyone the right to share GNU Emacs.  To make sure that you get the rights we 
  54. want you to have, we need to make restrictions that forbid anyone to deny you 
  55. these rights or to ask you to surrender the rights.  Hence this license 
  56. agreement. 
  57.  
  58.  Specifically, we want to make sure that you have the right to give away copies 
  59. of Emacs, that you receive source code or else can get it if you want it, that 
  60. you can change Emacs or use pieces of it in new free programs, and that you 
  61. know you can do these things. 
  62.  
  63.  To make sure that everyone has such rights, we have to forbid you to deprive 
  64. anyone else of these rights.  For example, if you distribute copies of Emacs, 
  65. you must give the recipients all the rights that you have.  You must make sure 
  66. that they, too, receive or can get the source code.  And you must tell them 
  67. their rights. 
  68.  
  69.  Also, for our own protection, we must make certain that everyone finds out 
  70. that there is no warranty for GNU Emacs.  If Emacs is modified by someone else 
  71. and passed on, we want its recipients to know that what they have is not what 
  72. we distributed, so that any problems introduced by others will not reflect on 
  73. our reputation. 
  74.  
  75.  Therefore we (Richard Stallman and the Free Software Foundation, Inc.) make 
  76. the following terms which say what you must do to be allowed to distribute or 
  77. change GNU Emacs. 
  78.  
  79.  
  80. ΓòÉΓòÉΓòÉ 3.1. Copying Policies ΓòÉΓòÉΓòÉ
  81.  
  82.  1. You may copy and distribute verbatim copies of GNU Emacs source code as you 
  83.     receive it, in any medium, provided that you conspicuously and 
  84.     appropriately publish on each file a valid copyright notice ``Copyright (C) 
  85.     1988 Free Software Foundation, Inc.'' (or with whatever year is 
  86.     appropriate); keep intact the notices on all files that refer to this 
  87.     License Agreement and to the absence of any warranty; and give any other 
  88.     recipients of the GNU Emacs program a copy of this License Agreement along 
  89.     with the program.  You may charge a distribution fee for the physical act 
  90.     of transferring a copy. 
  91.  
  92.  2. You may modify your copy or copies of GNU Emacs source code or any portion 
  93.     of it, and copy and distribute such modifications under the terms of 
  94.     Paragraph 1 above, provided that you also do the following: 
  95.  
  96.    o cause the modified files to carry prominent notices stating who last 
  97.      changed such files and the date of any change; and 
  98.  
  99.    o cause the whole of any work that you distribute or publish, that in whole 
  100.      or in part contains or is a derivative of GNU Emacs or any part thereof, 
  101.      to be licensed at no charge to all third parties on terms identical to 
  102.      those contained in this License Agreement (except that you may choose to 
  103.      grant more extensive warranty protection to some or all third parties, at 
  104.      your option). 
  105.  
  106.    o if the modified program serves as a text editor, cause it, when started 
  107.      running in the simplest and usual way, to print an announcement including 
  108.      a valid copyright notice ``Copyright (C) 1988 Free Software Foundation, 
  109.      Inc.'' (or with the year that is appropriate), saying that there is no 
  110.      warranty (or else, saying that you provide a warranty) and that users may 
  111.      redistribute the program under these conditions, and telling the user how 
  112.      to view a copy of this License Agreement. 
  113.  
  114.    o You may charge a distribution fee for the physical act of transferring a 
  115.      copy, and you may at your option offer warranty protection in exchange for 
  116.      a fee. 
  117.  
  118.     Mere aggregation of another unrelated program with this program (or its 
  119.     derivative) on a volume of a storage or distribution medium does not bring 
  120.     the other program under the scope of these terms. 
  121.  
  122.  3. You may copy and distribute GNU Emacs (or a portion or derivative of it, 
  123.     under Paragraph 2) in object code or executable form under the terms of 
  124.     Paragraphs 1 and 2 above provided that you also do one of the following: 
  125.  
  126.    o accompany it with the complete corresponding machine-readable source code, 
  127.      which must be distributed under the terms of Paragraphs 1 and 2 above; or, 
  128.  
  129.    o accompany it with a written offer, valid for at least three years, to give 
  130.      any third party free (except for a nominal shipping charge) a complete 
  131.      machine-readable copy of the corresponding source code, to be distributed 
  132.      under the terms of Paragraphs 1 and 2 above; or, 
  133.  
  134.    o accompany it with the information you received as to where the 
  135.      corresponding source code may be obtained.  (This alternative is allowed 
  136.      only for noncommercial distribution and only if you received the program 
  137.      in object code or executable form alone.) 
  138.  
  139.     For an executable file, complete source code means all the source code for 
  140.     all modules it contains; but, as a special exception, it need not include 
  141.     source code for modules which are standard libraries that accompany the 
  142.     operating system on which the executable file runs. 
  143.  
  144.  4. You may not copy, sublicense, distribute or transfer GNU Emacs except as 
  145.     expressly provided under this License Agreement.  Any attempt otherwise to 
  146.     copy, sublicense, distribute or transfer GNU Emacs is void and your rights 
  147.     to use GNU Emacs under this License agreement shall be automatically 
  148.     terminated.  However, parties who have received computer software programs 
  149.     from you with this License Agreement will not have their licenses 
  150.     terminated so long as such parties remain in full compliance. 
  151.  
  152.  5. If you wish to incorporate parts of GNU Emacs into other free programs 
  153.     whose distribution conditions are different, write to the Free Software 
  154.     Foundation.  We have not yet worked out a simple rule that can be stated 
  155.     here, but we will often permit this.  We will be guided by the two goals of 
  156.     preserving the free status of all derivatives of our free software and of 
  157.     promoting the sharing and reuse of software. 
  158.  
  159. Your comments and suggestions about our licensing policies and our software are 
  160. welcome!  Please contact the Free Software Foundation, Inc., 675 Mass Ave, 
  161. Cambridge, MA 02139. 
  162.  
  163.  
  164. ΓòÉΓòÉΓòÉ 3.2. NO WARRANTY ΓòÉΓòÉΓòÉ
  165.  
  166.  BECAUSE GNU EMACS IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO 
  167. WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT WHEN 
  168. OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD M. STALLMAN 
  169. AND/OR OTHER PARTIES PROVIDE GNU EMACS ``AS IS'' WITHOUT WARRANTY OF ANY KIND, 
  170. EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  171. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE 
  172. RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE 
  173. GNU EMACS PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY 
  174. SERVICING, REPAIR OR CORRECTION. 
  175.  
  176.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL FREE SOFTWARE FOUNDATION, 
  177. INC., RICHARD M. STALLMAN, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND 
  178. REDISTRIBUTE GNU EMACS AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 
  179. INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR 
  180. CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE (INCLUDING BUT 
  181. NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES 
  182. SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS 
  183. NOT DISTRIBUTED BY FREE SOFTWARE FOUNDATION, INC.) THE PROGRAM, EVEN IF YOU 
  184. HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY 
  185. OTHER PARTY. 
  186.  
  187.  
  188. ΓòÉΓòÉΓòÉ 4. Introduction ΓòÉΓòÉΓòÉ
  189.  
  190.  Most of the GNU Emacs text editor is written in the programming language 
  191. called Emacs Lisp.  You can write new code in Emacs Lisp and install it as an 
  192. extension to the editor.  However, Emacs Lisp is more than a mere ``extension 
  193. language''; it is a full computer programming language in its own right.  You 
  194. can use it as you would any other programming language. 
  195.  
  196.  Because Emacs Lisp is designed for use in an editor, it has special features 
  197. for scanning and parsing text as well as features for handling files, buffers, 
  198. displays, subprocesses, and so on.  Emacs Lisp is closely integrated with the 
  199. editing facilities; thus, editing commands are functions that can also 
  200. conveniently be called from Lisp programs, and parameters for customization are 
  201. ordinary Lisp variables. 
  202.  
  203.  This manual describes Emacs Lisp, presuming considerable familiarity with the 
  204. use of Emacs for editing.  (See The GNU Emacs Manual, for this basic 
  205. information.)  Generally speaking, the earlier chapters describe features of 
  206. Emacs Lisp that have counterparts in many programming languages, and later 
  207. chapters describe features that are peculiar to Emacs Lisp or relate 
  208. specifically to editing. 
  209.  
  210.  This is edition 1.02. 
  211.  
  212.  
  213. ΓòÉΓòÉΓòÉ 4.1. Caveats ΓòÉΓòÉΓòÉ
  214.  
  215.  This manual has gone through numerous drafts.  It is nearly complete but not 
  216. flawless.  There are a few sections which are not included, either because we 
  217. consider them secondary (such as most of the individual modes) or because they 
  218. are yet to be written. 
  219.  
  220.  Because we are not able to deal with them completely, we have left out several 
  221. parts intentionally.  This includes most references to VMS and all information 
  222. relating to X Windows and Sunview.  The functions for using X Windows will in 
  223. any case be entirely different in version 19. (The Free Software Foundation 
  224. expends no effort on support for Sunview, since we believe users should use 
  225. free X Windows rather than proprietary window systems.) 
  226.  
  227.  The manual should be fully correct in what it does cover, and it is therefore 
  228. open to criticism on anything it says---from specific examples and descriptive 
  229. text, to the ordering of chapters and sections.  If something is confusing, or 
  230. you find that you have to look at the sources or experiment to learn something 
  231. not covered in the manual, then perhaps the manual should be fixed.  Please let 
  232. us know. 
  233.  
  234. As you use this manual, we ask that you send corrections as soon as you find 
  235. them.  If you think of a simple, real life example for a function or group of 
  236. functions, please make an effort to write it up and send it in.  Please 
  237. reference any comments to the node name and function or variable name, as 
  238. appropriate. 
  239.  
  240. Please mail comments and corrections to lisp-manual-bugs@prep.ai.mit.edu. 
  241.  
  242.  --Bil Lewis, Dan LaLiberte, Richard Stallman
  243.  
  244.  
  245. ΓòÉΓòÉΓòÉ 4.2. Lisp History ΓòÉΓòÉΓòÉ
  246.  
  247.  Lisp (LISt Processing language) was first developed in the late 1950s at the 
  248. Massachusetts Institute of Technology for research in artificial intelligence. 
  249. The great power of the Lisp language makes it superior for other purposes as 
  250. well, such as writing editing commands. 
  251.  
  252.  Dozens of Lisp implementations have been built over the years, each with its 
  253. own idiosyncrasies.  Many of them were inspired by Maclisp, which was written 
  254. in the 1960's at MIT's Project MAC.  Eventually the implementors of the 
  255. descendents of Maclisp came together and developed a standard for Lisp systems, 
  256. called Common Lisp. 
  257.  
  258.  GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common Lisp. 
  259. If you know Common Lisp, you will notice many similarities. However, many of 
  260. the features of Common Lisp have been omitted or simplified in order to reduce 
  261. the memory requirements of GNU Emacs. Sometimes the simplifications are so 
  262. drastic that a Common Lisp user might be very confused.  We will occasionally 
  263. point out how GNU Emacs Lisp differs from Common Lisp.  If you don't know 
  264. Common Lisp, don't worry about it; this manual is self-contained. 
  265.  
  266.  
  267. ΓòÉΓòÉΓòÉ 4.3. Conventions ΓòÉΓòÉΓòÉ
  268.  
  269. This section explains the notational conventions that are used in this manual. 
  270. You may want to skip this section and refer back to it later. 
  271.  
  272.  
  273. ΓòÉΓòÉΓòÉ 4.3.1. Some Terms ΓòÉΓòÉΓòÉ
  274.  
  275.  Throughout this manual, the phrases ``the Lisp reader'' and ``the Lisp 
  276. printer'' are used to refer to those routines in Lisp that convert textual 
  277. representations of Lisp objects into actual objects, and vice versa.  See 
  278. Printed Representation, for more details.  You, the person reading this manual, 
  279. are assumed to be ``the programmer'' and are addressed as ``you''.  ``The 
  280. user'' is the person who uses the code that you write. 
  281.  
  282.  Examples of Lisp code appear in this font or form: (list 1 2 3).  Names that 
  283. represent arguments or metasyntactic variables appear in this font or form: 
  284. first-number. 
  285.  
  286.  
  287. ΓòÉΓòÉΓòÉ 4.3.2. nil and t ΓòÉΓòÉΓòÉ
  288.  
  289.  In Lisp, the symbol nil is overloaded with three meanings: it is a symbol with 
  290. the name `nil'; it is the logical truth value false; and it is the empty 
  291. list---the list of zero elements. When used as a variable, nil always has the 
  292. value nil. 
  293.  
  294.  As far as the Lisp reader is concerned, `()' and `nil' are identical: they 
  295. stand for the same object, the symbol nil.  The different ways of writing the 
  296. symbol are intended entirely for human readers.  After the Lisp reader has read 
  297. either `()' or `nil', there is no way to determine which representation was 
  298. actually written by the programmer. 
  299.  
  300.  In this manual, we use () when we wish to emphasize that it means the empty 
  301. list, and we use nil when we wish to emphasize that it means the truth value 
  302. false.  That is a good convention to use in Lisp programs also. 
  303.  
  304. (cons 'foo ())                ; Emphasize the empty list
  305. (not nil)                     ; Emphasize the truth value false
  306.  
  307.  In context where a truth value is expected, any non-nil value is considered to 
  308. be true.  However, t is the preferred way to represent the truth value true. 
  309. When you need to choose a value which represents true, and there is no other 
  310. basis for choosing, use t.  The symbol t always has value t. 
  311.  
  312.  In Emacs Lisp, nil and t are special symbols that always evaluate to 
  313. themselves.  This is so that you do not need to quote them to use them as 
  314. constants in a program.  An attempt to change their values results in a 
  315. setting-constant error. See Accessing Variables. 
  316.  
  317.  
  318. ΓòÉΓòÉΓòÉ 4.3.3. Evaluation Notation ΓòÉΓòÉΓòÉ
  319.  
  320.  When you evaluate a piece of Lisp code, it produces a result.  In the examples 
  321. in this manual, this is indicated with `=>': 
  322.  
  323. (car '(1 2))
  324.      => 1
  325.  
  326. You can read this as ``(car '(1 2)) evaluates to 1''. 
  327.  
  328.  When a form is a macro call, it expands into a new form for Lisp to evaluate. 
  329. We show the result of the expansion with `->'.  We may or may not show the 
  330. actual result of the evaluation of the expanded form. 
  331.  
  332. (third '(a b c))
  333.      -> (car (cdr (cdr '(a b c))))
  334.      => c
  335.  
  336.  Sometimes to help describe one form we show another form which produces 
  337. identical results.  The exact equivalence of two forms is indicated with `=='. 
  338.  
  339. (make-sparse-keymap) == (list 'keymap)
  340.  
  341.  
  342. ΓòÉΓòÉΓòÉ 4.3.4. Printing Notation ΓòÉΓòÉΓòÉ
  343.  
  344.  Many of the examples in this manual print text when they are evaluated.  If 
  345. you execute the code from an example in a Lisp Interaction buffer (such as the 
  346. buffer `*scratch*'), the printed text is inserted into the buffer.  If the 
  347. example is executed by other means (such as by evaluating the function 
  348. eval-region), the text printed is usually displayed in the echo area.  You 
  349. should be aware that text displayed in the echo area is truncated to a single 
  350. line. 
  351.  
  352.  In examples that print text, the printed text is indicated with `-|', 
  353. irrespective of how the form is executed.  The value returned by evaluating the 
  354. form (here bar) follows on a separate line. 
  355.  
  356. (progn (print 'foo) (print 'bar))
  357.      -| foo
  358.      -| bar
  359.      => bar
  360.  
  361.  
  362. ΓòÉΓòÉΓòÉ 4.3.5. Error Messages ΓòÉΓòÉΓòÉ
  363.  
  364.  Some examples cause errors to be signaled.  In them, the error message (which 
  365. always appears in the echo area) is shown on a line starting with `error-->'. 
  366. Note that `error-->' itself does not appear in the echo area. 
  367.  
  368. (+ 23 'x)
  369. error--> Wrong type argument: integer-or-marker-p, x
  370.  
  371.  
  372. ΓòÉΓòÉΓòÉ 4.3.6. Buffer Text Notation ΓòÉΓòÉΓòÉ
  373.  
  374.  Some examples show modifications to text in a buffer, with ``before'' and 
  375. ``after'' versions of the text.  In such cases, the entire contents of the 
  376. buffer in question are included between two lines of dashes containing the 
  377. buffer name.  In addition, the location of point is shown as `-!-'.  (The 
  378. symbol for point, of course, is not part of the text in the buffer; it 
  379. indicates the place between two characters where point is located.) 
  380.  
  381. ---------- Buffer: foo ----------
  382. This is the -!-contents of foo.
  383. ---------- Buffer: foo ----------
  384.  
  385. (insert "changed ")
  386.      => nil
  387. ---------- Buffer: foo ----------
  388. This is the changed -!-contents of foo.
  389. ---------- Buffer: foo ----------
  390.  
  391.  
  392. ΓòÉΓòÉΓòÉ 4.3.7. Format of Descriptions ΓòÉΓòÉΓòÉ
  393.  
  394.  Functions, variables, macros, commands, user options, and special forms are 
  395. described in this manual in a uniform format.  The first line of a description 
  396. contains the name of the item followed by its arguments, if any. The 
  397. category---function, variable, or whatever---appears at the beginning of the 
  398. line. The description follows on succeeding lines, sometimes with examples. 
  399.  
  400.  
  401. ΓòÉΓòÉΓòÉ 4.3.7.1. A Sample Function Description ΓòÉΓòÉΓòÉ
  402.  
  403.  In a function description, the name of the function being described appears 
  404. first.  It is followed on the same line by a list of parameters. The names used 
  405. for the parameters are also used in the body of the description. 
  406.  
  407.  The appearance of the keyword &optional in the parameter list indicates that 
  408. the arguments for subsequent parameters may be omitted (omitted parameters 
  409. default to nil).  Do not write &optional when you call the function. 
  410.  
  411.  The keyword &rest (which will always be followed by a single parameter) 
  412. indicates that any number of arguments can follow.  The value of the single 
  413. following parameter will be a list of all these arguments. Do not write &rest 
  414. when you call the function. 
  415.  
  416.  Here is a description of an imaginary function foo: 
  417.  
  418. -- Function: foo integer1 &optional integer2 &rest integers 
  419.  The function foo subtracts integer1 from integer2, then adds all the rest of 
  420. the arguments to the result.  If integer2 is not supplied, then the number 19 
  421. is used by default. 
  422.  
  423. (foo 1 5 3 9)
  424.      => 16
  425. (foo 5)
  426.      => 14
  427.  
  428. More generally, 
  429.  
  430. (foo w x y...)
  431. ==
  432. (+ (- x w) y...)
  433.  
  434.  Any parameter whose name contains the name of a type (e.g., integer, integer1 
  435. or buffer) is expected to be of that type.  A plural of a type (such as 
  436. buffers) often means a list of objects of that type.  Parameters named object 
  437. may be of any type. (See Types of Lisp Object, for a list of Emacs object 
  438. types.) Parameters with other sorts of names (e.g., new-file) are discussed 
  439. specifically in the description of the function.  In some sections, features 
  440. common to parameters of several functions are described at the beginning. 
  441.  
  442.  See Lambda Expressions, for a more complete description of optional and rest 
  443. arguments. 
  444.  
  445.  Command, macro, and special form descriptions have the same format, but the 
  446. word `Function' is replaced by `Command', `Macro', or `Special Form', 
  447. respectively.  Commands are simply functions that may be called interactively; 
  448. macros process their arguments differently from functions (the arguments are 
  449. not evaluated), but are presented the same way. 
  450.  
  451.  Special form descriptions use a more complex notation to specify optional and 
  452. repeated parameters because they can break the argument list down into separate 
  453. arguments in more complicated ways. `[optional-arg]' means that optional-arg is 
  454. optional and `repeated-args...' stands for zero or more arguments.  Parentheses 
  455. are used when several arguments are grouped into additional levels of list 
  456. structure.  Here is an example: 
  457.  
  458. -- Special Form: count-loop (var [from to [inc]]) body... 
  459. This imaginary special form implements a loop that executes the body forms and 
  460. then increments the variable var on each iteration.  On the first iteration, 
  461. the variable has the value from; on subsequent iterations, it is incremented by 
  462. 1 (or by inc if that is given).  The loop exits before executing body if var 
  463. equals to.  Here is an example: 
  464.  
  465. (count-loop (i 0 10)
  466.   (prin1 i) (princ " ")
  467.   (prin1 (aref vector i)) (terpri))
  468.  
  469. If from and to are omitted, then var is bound to nil before the loop begins, 
  470. and the loop exits if var is non-nil at the beginning of an iteration.  Here is 
  471. an example: 
  472.  
  473. (count-loop (done)
  474.   (if (pending)
  475.       (fixit)
  476.     (setq done t)))
  477.  
  478. In this special form, the arguments from and to are optional, but must both be 
  479. present or both absent.  If they are present, inc may optionally be specified 
  480. as well.  These arguments are grouped with the argument var into a list, to 
  481. distinguish them from body, which includes all remaining elements of the form. 
  482.  
  483.  
  484. ΓòÉΓòÉΓòÉ 4.3.7.2. A Sample Variable Description ΓòÉΓòÉΓòÉ
  485.  
  486.  A variable is a name that can hold a value.  Although any variable can be set 
  487. by the user, certain variables that exist specifically so that users can change 
  488. them are called user options.  Ordinary variables and user options are 
  489. described using a format like that for functions except that there are no 
  490. arguments. 
  491.  
  492.  Here is a description of the imaginary electric-future-map variable. 
  493.  
  494. -- Variable: electric-future-map 
  495.  The value of this variable is a full keymap used by electric command future 
  496. mode.  The functions in this map will allow you to edit commands you have not 
  497. yet thought about executing. 
  498.  
  499.  User option descriptions have the same format, but `Variable' is replaced by 
  500. `User Option'. 
  501.  
  502.  
  503. ΓòÉΓòÉΓòÉ 4.4. Acknowledgements ΓòÉΓòÉΓòÉ
  504.  
  505.  This manual was written by Robert Krawitz, Bil Lewis, Dan LaLiberte, Richard 
  506. M. Stallman and Chris Welty, the volunteers of the GNU manual group, in an 
  507. effort extending over several years.  Robert J. Chassell helped to review and 
  508. edit the manual, with the support of the Defense Advanced Research Projects 
  509. Agency, ARPA Order 6082, arranged by Warren A. Hunt, Jr. of Computational 
  510. Logic, Inc. 
  511.  
  512.  Corrections were supplied by Karl Berry, Bard Bloom, David Boyes, Alan 
  513. Carroll, David A. Duff, Beverly Erlebacher, David Eckelkamp, Eirik Fuller, Eric 
  514. Hanchrow, George Hartzell, Nathan Hess, Dan Jacobson, Jak Kirman, Bob Knighten, 
  515. Frederick M. Korz, Joe Lammens, K. Richard Magill, Brian Marick, Roland 
  516. McGrath, Skip Montanaro, John Gardiner Myers, Arnold D. Robbins, Raul Rockwell, 
  517. Shinichirou Sugou, Kimmo Suominen, Edward Tharp, Bill Trost, Jean White, 
  518. Matthew Wilding, Carl Witty, Dale Worley, Rusty Wright, and David D. Zuhn. 
  519.  
  520.  
  521. ΓòÉΓòÉΓòÉ 5. Lisp Data Types ΓòÉΓòÉΓòÉ
  522.  
  523.  A Lisp object is a piece of data used and manipulated by Lisp programs.  For 
  524. our purposes, a type or data type is a set of possible objects. 
  525.  
  526.  Every object belongs to at least one type.  Objects of the same type have 
  527. similar structures and may usually be used in the same contexts. Types can 
  528. overlap, and objects can belong to two or more types. Consequently, we can ask 
  529. whether an object belongs to a particular type, but not for ``the'' type of an 
  530. object. 
  531.  
  532.  A few fundamental object types are built into Emacs.  These, from which all 
  533. other types are constructed, are called primitive types. They include integer, 
  534. cons, symbol, string, vector, subr and several special types, such as buffer, 
  535. that are related to editing.  (See Editing Types.) 
  536.  
  537.  While an object may be a member of more than one type, every object is a 
  538. member of exactly one primitive type.  The primitive type of an object is 
  539. stored with the object's data.  A Lisp function is provided for each primitive 
  540. type to check whether an object is a member of that type. 
  541.  
  542.  Note that Lisp is unlike many other languages in that Lisp objects are 
  543. ``self-typing'': the primitive type of the object is implicit in the object 
  544. itself.  For example, if an object is a vector, it cannot be treated as a 
  545. number because Lisp knows it is a vector, not a number.  In most languages, the 
  546. programmer must declare the data type of each variable, and the type is known 
  547. by the compiler but not represented in the data.  Such type declarations do not 
  548. exist in Emacs Lisp. 
  549.  
  550.  This chapter describes the purpose, printed representation, and read syntax of 
  551. each of the standard types in GNU Emacs Lisp.  Details on how to use these 
  552. types can be found in later chapters. 
  553.  
  554.  
  555. ΓòÉΓòÉΓòÉ 5.1. Printed Representation and Read Syntax ΓòÉΓòÉΓòÉ
  556.  
  557.  The printed representation of an object is the format of the output generated 
  558. by the Lisp printer (the function print) for that object.  The read syntax of 
  559. an object is the format of the input accepted by the Lisp reader (the function 
  560. read) for that object.  Most objects have more than one possible read syntax. 
  561. Some types of object have no read syntax; except in these cases, the printed 
  562. representation of an object is also a read syntax for it. 
  563.  
  564.  In other languages, an expression is text; it has no other form.  In Lisp, an 
  565. expression is primarily a Lisp object and only secondarily the text that is the 
  566. object's read syntax.  Often there is no need to emphasize this distinction, 
  567. but you must keep it in the back of your mind, or you will occasionally be very 
  568. confused. 
  569.  
  570.  Every type has a printed representation.  Some types have no read syntax, 
  571. since it may not make sense to enter objects of these types directly in a Lisp 
  572. program.  For example, the buffer type does not have a read syntax.  Objects of 
  573. these types are printed in hash notation: the characters `#<' followed by a 
  574. descriptive string (typically the type name followed by the name of the 
  575. object), and closed with a matching `>'.  Hash notation cannot be read at all, 
  576. so the Lisp reader signals the error invalid-read-syntax whenever a `#' is 
  577. encountered. 
  578.  
  579. (current-buffer)
  580.      => #<buffer objects.texi>
  581.  
  582.  When you evaluate an expression interactively, the Lisp interpreter first 
  583. reads the textual representation of it, producing a Lisp object, and then 
  584. evaluates that object (see Evaluation).  However, evaluation and reading are 
  585. separate activities.  Reading returns the Lisp object represented by the text 
  586. that is read; the object may or may not be evaluated later.  See Input 
  587. Functions, for a description of read, the basic function for reading objects. 
  588.  
  589.  
  590. ΓòÉΓòÉΓòÉ 5.2. Comments ΓòÉΓòÉΓòÉ
  591.  
  592.  A comment is text that is written in a program only for the sake of humans 
  593. that read the program, and that has no effect on the meaning of the program. 
  594. In Lisp, a comment starts with a semicolon (`;') and continues to the end of 
  595. line.  Comments are discarded by the Lisp reader, and do not become part of the 
  596. Lisp objects which represent the program within the Lisp system. 
  597.  
  598.  We recommend these conventions for where to put comments and how to indent 
  599. them: 
  600.  
  601. `;' 
  602.           Comments that start with a single semicolon, `;', should all be 
  603.           aligned to the same column on the right of the source code.  Such 
  604.           comments usually explain how the code on the same line does its job. 
  605.           In Lisp mode and related modes, the M-; (indent-for-comment) command 
  606.           automatically inserts such a `;' in the right place, or aligns such a 
  607.           comment if it is already inserted. 
  608.  
  609.           (The following examples are taken from the Emacs sources.) 
  610.  
  611.                     (setq base-version-list                 ; there was a base
  612.                           (assoc (substring fn 0 start-vn)  ; version to which
  613.                                  file-version-assoc-list))  ; this looks like
  614.                                                             ; a subversion
  615.  
  616. `;;' 
  617.           Comments that start with two semicolons, `;;', should be aligned to 
  618.           the same level of indentation as the code.  Such comments are used to 
  619.           describe the purpose of the following lines or the state of the 
  620.           program at that point.  For example: 
  621.  
  622.                       (prog1 (setq auto-fill-hook
  623.                                    ...
  624.                                    ...
  625.                         ;; update mode-line
  626.                         (set-buffer-modified-p (buffer-modified-p))))
  627.  
  628.           These comments are also written before a function definition to 
  629.           explain what the function does and how to call it properly. 
  630.  
  631. `;;;' 
  632.           Comments that start with three semicolons, `;;;', should start at the 
  633.           left margin.  Such comments are not used within function definitions, 
  634.           but are used to make more general comments.  For example: 
  635.  
  636.                     ;;; This Lisp code is run in Emacs when it is to operate as
  637.                     ;;; a server for other processes.
  638.  
  639. `;;;;' 
  640.           Comments that start with four semicolons, `;;;;', should be aligned 
  641.           to the left margin and are used for headings of major sections of a 
  642.           program.  For example: 
  643.  
  644.                     ;;;; The kill ring
  645.  
  646. The indentation commands of the Lisp modes in Emacs, such as M-; 
  647. (indent-for-comment) and TAB (lisp-indent-line) automatically indent comments 
  648. according to these conventions, depending on the the number of semicolons. See 
  649. Manipulating Comments. 
  650.  
  651.  Any character may be included in a comment, but it is advisable to precede a 
  652. character with syntactic significance in Lisp (such as `\' or unpaired `(' or 
  653. `)') with a `\', to prevent it from confusing the Emacs commands for editing 
  654. Lisp. 
  655.  
  656.  
  657. ΓòÉΓòÉΓòÉ 5.3. Programming Types ΓòÉΓòÉΓòÉ
  658.  
  659.  There are two general categories of types in Emacs Lisp: those having to do 
  660. with Lisp programming, and those having to do with editing.  The former are 
  661. provided in many Lisp implementations, in one form or another.  The latter are 
  662. unique to Emacs Lisp. 
  663.  
  664.  
  665. ΓòÉΓòÉΓòÉ 5.3.1. Number Type ΓòÉΓòÉΓòÉ
  666.  
  667.  Integers are the only kind of number in GNU Emacs Lisp, version 18. The range 
  668. of values for integers is -8388608 to 8388607 (24 bits; i.e., -2**23 to 2**23 - 
  669. 1) on most machines, but is 25 or 26 bits on some systems.  It is important to 
  670. note that the Emacs Lisp arithmetic functions do not check for overflow.  Thus 
  671. (1+ 8388607) is -8388608 on 24-bit implementations. 
  672.  
  673. Version 19 supports floating point numbers. 
  674.  
  675.  The read syntax for numbers is a sequence of (base ten) digits with an 
  676. optional sign.  The printed representation produced by the Lisp interpreter 
  677. never has a leading `+'. 
  678.  
  679. -1               ; The integer -1.
  680. 1                ; The integer 1.
  681. +1               ; Also the integer 1.
  682. 16777217         ; Also the integer 1! (on a 24-bit or 25-bit implementation)
  683.  
  684.  See Numbers, for more information. 
  685.  
  686.  
  687. ΓòÉΓòÉΓòÉ 5.3.2. Character Type ΓòÉΓòÉΓòÉ
  688.  
  689.  A character in Emacs Lisp is nothing more than an integer.  In other words, 
  690. characters are represented by their eight-bit ASCII values.  For example, the 
  691. character A is represented as the integer 65.  If an arbitrary integer is used 
  692. as a character, only the lower eight bits are significant. 
  693.  
  694.  Individual characters are not often used in programs.  It is far more common 
  695. to work with strings, which are sequences composed of characters.  See String 
  696. Type. 
  697.  
  698.  Since characters are really integers, the printed representation of a 
  699. character is a decimal number.  This is also a possible read syntax for a 
  700. character, but it is not convenient for that purpose.  Therefore, Emacs Lisp 
  701. provides a variety of read syntax formats, such as `?A' and `?\101', for 
  702. entering characters.  They all start with a question mark. 
  703.  
  704.  The usual read syntax for alphanumeric characters is a question mark followed 
  705. by the character; thus, `?A' for the character A, `?B' for the character B, and 
  706. `?a' for the character a.  For example: 
  707.  
  708. ?Q => 81
  709.  
  710. ?q => 113
  711.  
  712.  The characters backspace, tab, newline, vertical tab, formfeed, return, and 
  713. escape may be represented as `?\b', `?\t', `?\n', `?\v', `?\f', `?\r', `?\e', 
  714. respectively.  Those values are 8, 9, 10, 11, 12, 13, and 27 in decimal. Thus, 
  715.  
  716. ?\b => 8                 ; backspace, BS, C-h
  717. ?\t => 9                 ; tab, TAB, C-i
  718. ?\n => 10                ; newline, LFD, C-j
  719. ?\v => 11                ; vertical tab, C-k
  720. ?\f => 12                ; formfeed character, C-l
  721. ?\r => 13                ; carriage return, RET, C-m
  722. ?\e => 27                ; escape character, ESC, C-[
  723. ?\\ => 92                ; backslash character, \
  724.  
  725.  Control characters may be represented using yet another read syntax. This 
  726. consists of a question mark followed by a backslash, caret, and the 
  727. corresponding non-control character, in either upper or lower case.  For 
  728. example, either `?\^I' or `?\^i' may be used as the read syntax for the 
  729. character C-i, the character whose value is 9. 
  730.  
  731.  Instead of the `^', you can use `C-'; thus, `?\C-i' is equivalent to `?\^I', 
  732. and `?\C-i' is equivalent to `?\^i'.  For example: 
  733.  
  734. ?\^I => 9
  735.  
  736. ?\C-I => 9
  737.  
  738.  The DEL key can be considered and written as Control-?: 
  739.  
  740. ?\^? => 127
  741.  
  742. ?\C-? => 127
  743.  
  744.  When you represent control characters to be found in files or strings, we 
  745. recommend the `^' syntax; but when you refer to keyboard input, we prefer the 
  746. `C-' syntax.  This does not affect the meaning of the program, but may guide 
  747. the understanding of people who read it. 
  748.  
  749.  A meta character is a character that has its eighth bit set. The read syntax 
  750. for these characters is question mark, backslash, `M-', and the corresponding 
  751. seven-bit character.  For example, `?\M-A' stands for M-A, the character with 
  752. code 193 (301 octal).  The seven-bit character can be written directly or 
  753. specified by any of the `\' escapes described above or below.  Thus, M-A can be 
  754. written as `?\M-A', or as `?\M-\101', or as `?\301'.  Likewise, the character 
  755. whose decimal printed representation is 130 (202 octal) can use any one of the 
  756. following for its read syntax: `?\202', `?\M-\C-b', `?\C-\M-b', or `?\M-\002'. 
  757. For example: 
  758.  
  759. ?\C-\M-b => 130          ?\M-\C-b => 130
  760.  
  761. ?\^\M-b => 130           ?\M-\002 => 130
  762.  
  763.  Finally, the most general read syntax consists of a question mark followed by 
  764. a backslash and the ASCII code for the character in octal (up to three octal 
  765. digits); thus, `?\101' for the character A, `?\001' for the character C-a, and 
  766. ?\002 for the character C-b.  Although this syntax can represent any character, 
  767. it is preferred only when the precise octal value is more important than the 
  768. ASCII representation.  (These sequences which start with backslash are also 
  769. known as escape sequences, because backslash plays the role of an escape 
  770. character, but they have nothing to do with the character ESC.) 
  771.  
  772. ?\012 => 10        ?\n => 10         ?\C-j => 10
  773.  
  774. ?\101 => 65        ?A => 65
  775.  
  776. ?\301 => 193       ?\M-A => 193      ?\M-\101 => 193
  777.  
  778.  A backslash is allowed, and harmless, preceding any character without a 
  779. special escape meaning; thus, `?\A' is equivalent to `?A'. There is no reason 
  780. to use a backslash before most such characters. However, any of the characters 
  781. `()\|;'`"#.,' should be preceded by a backslash to avoid confusing the Emacs 
  782. commands for editing Lisp code. Whitespace characters such as space, tab, 
  783. newline and formfeed should also be preceded by a backslash.  However, it is 
  784. cleaner to use one of the easily readable escape sequences, such as `\t', 
  785. instead of an actual control character such as a tab. 
  786.  
  787.  
  788. ΓòÉΓòÉΓòÉ 5.3.3. Sequence Types ΓòÉΓòÉΓòÉ
  789.  
  790.  A sequence is a Lisp object that represents an ordered set of elements.  There 
  791. are two kinds of sequence in Emacs Lisp, lists and arrays.  Thus, an object of 
  792. type list or of type array is also considered a sequence. 
  793.  
  794.  Arrays are further subdivided into strings and vectors.  Vectors can hold 
  795. elements of any type, but string elements must be characters---integers from 0 
  796. to 255. 
  797.  
  798.  Lists, strings and vectors are different, but they have important 
  799. similarities.  For example, all have a length l, and all have elements which 
  800. can be indexed from zero to l minus one.  Also, several functions, called 
  801. sequence functions, accept any kind of sequence.  For example, the function elt 
  802. can be used to extract an element of a sequence, given its index. See Sequences 
  803. Arrays Vectors. 
  804.  
  805.  It is impossible to read the same sequence twice, in the sense of eq (see 
  806. Equality Predicates), since sequences are always created anew upon reading. 
  807. There is one exception: the empty list () is always read as the same object, 
  808. nil. 
  809.  
  810.  
  811. ΓòÉΓòÉΓòÉ 5.3.4. List Type ΓòÉΓòÉΓòÉ
  812.  
  813.  A list is a series of cons cells, linked together.  A cons cell is an object 
  814. comprising two pointers named the car and the cdr.  Each of them can point to 
  815. any Lisp object, but when the cons cell is part of a list, the cdr points 
  816. either to another cons cell or to the empty list.  See Lists, for functions 
  817. that work on lists. 
  818.  
  819.  The names car and cdr have only historical meaning now.  The original Lisp 
  820. implementation ran on an IBM 704 computer which divided words into two parts, 
  821. called the ``address'' part and the ``decrement''; car was an instruction to 
  822. extract the contents of the address part of a register, and cdr an instruction 
  823. to extract the contents of the decrement.  By contrast, ``cons cells'' are 
  824. named for the function cons that creates them, which in turn is named for its 
  825. purpose, the construction of cells. 
  826.  
  827.  Because cons cells are so central to Lisp, we also have a word for ``an object 
  828. which is not a cons cell''.  These objects are called atoms. 
  829.  
  830.  The read syntax and printed representation for lists are identical, and 
  831. consist of a left parenthesis, an arbitrary number of elements, and a right 
  832. parenthesis. 
  833.  
  834.   Upon reading, any object inside the parentheses is made into an element of 
  835. the list.  That is, a cons cell is made for each element. The car of the cons 
  836. cell points to the element, and its cdr points to the next cons cell which 
  837. holds the next element in the list. The cdr of the last cons cell is set to 
  838. point to nil. 
  839.  
  840.  A list can be illustrated by a diagram in which the cons cells are shown as 
  841. pairs of boxes.  (The Lisp reader cannot read such an illustration; unlike the 
  842. textual notation, which can be understood both humans and computers, the box 
  843. illustrations can only be understood by humans.)  The following represents the 
  844. three-element list (rose violet buttercup): 
  845.  
  846.     ___ ___      ___ ___      ___ ___
  847.    |___|___|--> |___|___|--> |___|___|--> nil
  848.      |            |            |
  849.      |            |            |
  850.       --> rose     --> violet   --> buttercup
  851.  
  852.  In the diagram, each box represents a slot that can refer to any Lisp object. 
  853. Each pair of boxes represents a cons cell.  Each arrow is a reference to a Lisp 
  854. object, either an atom or another cons cell. 
  855.  
  856.  In this example, the first box, the car of the first cons cell, refers to or 
  857. ``contains'' rose (a symbol).  The second box, the cdr of the first cons cell, 
  858. refers to the next pair of boxes, the second cons cell.  The car of the second 
  859. cons cell refers to violet and the cdr refers to the third cons cell.  The cdr 
  860. of the third (and last) cons cell refers to nil. 
  861.  
  862. Here is another diagram of the same list, (rose violet buttercup), sketched in 
  863. a different manner: 
  864.  
  865.  ---------------         ----------------         -------------------
  866. |car    |cdr    |       |car     |cdr    |       |car        |cdr    |
  867. | rose  |   o---------->| violet |   o---------->| buttercup |  nil  |
  868. |       |       |       |        |       |       |           |       |
  869.  ---------------         ----------------         -------------------
  870.  
  871.  A list with no elements in it is the empty list; it is identical to the symbol 
  872. nil.  In other words, nil is both a symbol and a list. 
  873.  
  874.  Here are examples of lists written in Lisp syntax: 
  875.  
  876. (A 2 "A")            ; A list of three elements.
  877. ()                   ; A list of no elements (the empty list).
  878. nil                  ; A list of no elements (the empty list).
  879. ("A ()")             ; A list of one element: the string "A ()".
  880. (A ())               ; A list of two elements: A and the empty list.
  881. (A nil)              ; Equivalent to the previous.
  882. ((A B C))            ; A list of one element
  883.                      ; (which is a list of three elements).
  884.  
  885.  Here is the list (A ()), or equivalently (A nil), depicted with boxes and 
  886. arrows: 
  887.  
  888.     ___ ___      ___ ___
  889.    |___|___|--> |___|___|--> nil
  890.      |            |
  891.      |            |
  892.       --> A        --> nil
  893.  
  894.  
  895. ΓòÉΓòÉΓòÉ 5.3.4.1. Dotted Pair Notation ΓòÉΓòÉΓòÉ
  896.  
  897.  Dotted pair notation is an alternative syntax for cons cells that represents 
  898. the car and cdr explicitly.  In this syntax, (a . b) stands for a cons cell 
  899. whose car is the object a, and whose cdr is the object b.  Dotted pair notation 
  900. is therefore more general than list syntax.  In the dotted pair notation, the 
  901. list `(1 2 3)' is written as `(1 .  (2 . (3 . nil)))'.  For nil-terminated 
  902. lists, the two notations produce the same result, but list notation is usually 
  903. clearer and more convenient when it is applicable.  When printing a list, the 
  904. dotted pair notation is only used if the cdr of a cell is not a list. 
  905.  
  906.  Box notation can also be used to illustrate what dotted pairs look like.  For 
  907. example, (rose . violet) is diagrammed as follows: 
  908.  
  909.     ___ ___
  910.    |___|___|--> violet
  911.      |
  912.      |
  913.       --> rose
  914.  
  915.  Dotted pair notation can be combined with list notation to represent a chain 
  916. of cons cells with a non-nil final cdr.  For example, (rose violet . buttercup) 
  917. is equivalent to (rose . (violet . buttercup)).  The object looks like this: 
  918.  
  919.     ___ ___      ___ ___
  920.    |___|___|--> |___|___|--> buttercup
  921.      |            |
  922.      |            |
  923.       --> rose     --> violet
  924.  
  925.  These diagrams make it evident that (rose . violet . buttercup) must have an 
  926. invalid syntax since it would require that a cons cell have three parts rather 
  927. than two. 
  928.  
  929.  The list (rose violet) is equivalent to (rose . (violet)) and looks like this: 
  930.  
  931.     ___ ___      ___ ___
  932.    |___|___|--> |___|___|--> nil
  933.      |            |
  934.      |            |
  935.       --> rose     --> violet
  936.  
  937.  Similarly, the three-element list (rose violet buttercup) is equivalent to 
  938. (rose . (violet . (buttercup))). It looks like this: 
  939.  
  940.     ___ ___      ___ ___      ___ ___
  941.    |___|___|--> |___|___|--> |___|___|--> nil
  942.      |            |            |
  943.      |            |            |
  944.       --> rose     --> violet   --> buttercup
  945.  
  946.  
  947. ΓòÉΓòÉΓòÉ 5.3.4.2. Association List Type ΓòÉΓòÉΓòÉ
  948.  
  949.  An association list or alist is a specially-constructed list whose elements 
  950. are cons cells.  In each element, the car is considered a key, and the cdr is 
  951. considered an associated value.  (In some cases, the associated value is stored 
  952. in the car of the cdr.)  Association lists are often used to implement stacks, 
  953. since new associations may easily be added to or removed from the front of the 
  954. list. 
  955.  
  956.  For example, 
  957.  
  958. (setq alist-of-colors '((rose . red) (lily . white)  (buttercup . yellow)))
  959.  
  960. sets the variable alist-of-colors to an alist of three elements.  In the first 
  961. element, rose is the key and red is the value. 
  962.  
  963.  See Association Lists, for a further explanation of alists and for functions 
  964. that work on alists. 
  965.  
  966.  
  967. ΓòÉΓòÉΓòÉ 5.3.5. Array Type ΓòÉΓòÉΓòÉ
  968.  
  969.  An array is composed of an arbitrary number of other Lisp objects, arranged in 
  970. a contiguous block of memory.  Any element of an array may be accessed in 
  971. constant time.  In contrast, accessing an element of a list requires time 
  972. proportional to the position of the element in the list.  (Elements at the end 
  973. of a list take longer to access than elements at the beginning of a list.) 
  974.  
  975.  Emacs defines two types of array, strings and vectors.  A string is an array 
  976. of characters and a vector is an array of arbitrary objects.  Both are 
  977. one-dimensional.  (Most other programming languages support multidimensional 
  978. arrays, but we don't think they are essential in Emacs Lisp.)  Each type of 
  979. array has its own read syntax; see String Type, and Vector Type. 
  980.  
  981.  An array may have any length up to the largest integer; but once created, it 
  982. has a fixed size.  The first element of an array has index zero, the second 
  983. element has index 1, and so on.  This is called zero-origin indexing.  For 
  984. example, an array of four elements has indices 0, 1, 2, and 3. 
  985.  
  986.  The array type is contained in the sequence type and contains both strings and 
  987. vectors. 
  988.  
  989.  
  990. ΓòÉΓòÉΓòÉ 5.3.6. String Type ΓòÉΓòÉΓòÉ
  991.  
  992.  A string is an array of characters.  Strings are used for many purposes in 
  993. Emacs, as can be expected in a text editor; for example, as the names of Lisp 
  994. symbols, as messages for the user, and to represent text extracted from 
  995. buffers.  Strings in Lisp are constants; evaluation of a string returns the 
  996. same string. 
  997.  
  998.  The read syntax for strings is a double-quote, an arbitrary number of 
  999. characters, and another double-quote, "like this".  The Lisp reader accepts the 
  1000. same formats for reading the characters of a string as it does for reading 
  1001. single characters (without the question mark that begins a character literal). 
  1002. You can enter a nonprinting character such as tab, C-a or M-C-A using the 
  1003. convenient escape sequences, like this: "\t, \C-a, \M-\C-a".  You can include a 
  1004. double-quote in a string by preceding it with a backslash; thus, "\"" is a 
  1005. string containing just a single double-quote character. (See Character Type, 
  1006. for a description of the read syntax for characters.) 
  1007.  
  1008.  In contrast with the C programming language, newlines are allowed in Emacs 
  1009. Lisp string literals.  But an escaped newline---one that is preceded by 
  1010. `\'---does not become part of the string; i.e., the Lisp reader ignores an 
  1011. escaped newline in a string literal. 
  1012.  
  1013. "It is useful to include newlines in
  1014. documentation strings, but the newline is \
  1015. ignored if escaped."
  1016.      => "It is useful to include newlines in
  1017. documentation strings, but the newline is ignored if escaped."
  1018.  
  1019.  The printed representation of a string consists of a double-quote, the 
  1020. characters it contains, and another double-quote.  However, any backslash or 
  1021. double-quote characters in the string are preceded with a backslash like this: 
  1022. "this \" is an embedded quote". 
  1023.  
  1024.  See Strings and Characters, for functions that work on strings. 
  1025.  
  1026.  
  1027. ΓòÉΓòÉΓòÉ 5.3.7. Vector Type ΓòÉΓòÉΓòÉ
  1028.  
  1029.  A vector is a one-dimensional array of elements of any type.  It takes a 
  1030. constant amount of time to access any element of a vector.  (In a list, the 
  1031. access time of an element is proportional to the distance of the element from 
  1032. the beginning of the list.) 
  1033.  
  1034.  The printed representation of a vector consists of a left square bracket, the 
  1035. elements, and a right square bracket.  This is also the read syntax.  Like 
  1036. numbers and strings, vectors are considered constants for evaluation. 
  1037.  
  1038. [1 "two" (three)]      ; A vector of three elements.
  1039.      => [1 "two" (three)]
  1040.  
  1041.  See Vectors, for functions that work with vectors. 
  1042.  
  1043.  
  1044. ΓòÉΓòÉΓòÉ 5.3.8. Symbol Type ΓòÉΓòÉΓòÉ
  1045.  
  1046.  A symbol in GNU Emacs Lisp is an object with a name.  The symbol name is the 
  1047. printed representation of the symbol.  In ordinary use, the name is unique---no 
  1048. two symbols have the same name. 
  1049.  
  1050.  A symbol may be used in programs as a variable, as a function name, or to hold 
  1051. a list of properties.  Or it may serve only to be distinct from all other Lisp 
  1052. objects, so that its presence in a data structure may be recognized reliably. 
  1053. In a given context, usually only one of these uses is intended. 
  1054.  
  1055.  A symbol name can contain any characters whatever.  Most symbol names are 
  1056. written with letters, digits, and the punctuation characters `-+=*/'.  Such 
  1057. names require no special punctuation; the characters of the name suffice as 
  1058. long as the name does not look like a number. (If it does, write a `\' at the 
  1059. beginning of the name to force interpretation as a symbol.)  The characters 
  1060. `_~!@$%^&:<>{}' are less often used but also require no special punctuation. 
  1061. Any other characters may be included in a symbol's name by escaping them with a 
  1062. backslash.  In contrast to its use in strings, however, a backslash in the name 
  1063. of a symbol quotes the single character that follows the backslash, without 
  1064. conversion.  For example, in a string, `\t' represents a tab character; in the 
  1065. name of a symbol, however, `\t' merely quotes the letter t.  To have a symbol 
  1066. with a tab character in its name, you must actually type an tab (preceded with 
  1067. a backslash). But you would hardly ever do such a thing. 
  1068.  
  1069. Common Lisp note: in Common Lisp, lower case letters are always ``folded'' to 
  1070. upper case, unless they are explicitly escaped.  This is in contrast to Emacs 
  1071. Lisp, in which upper case and lower case letters are distinct. 
  1072.  
  1073.  Here are several examples of symbol names.  Note that the `+' in the fifth 
  1074. example is escaped to prevent it from being read as a number. This is not 
  1075. necessary in the last example because the rest of the name makes it invalid as 
  1076. a number. 
  1077.  
  1078. foo                 ; A symbol named `foo'.
  1079. FOO                 ; A symbol named `FOO', different from `foo'.
  1080. char-to-string      ; A symbol named `char-to-string'.
  1081. 1+                  ; A symbol named `1+'
  1082.                     ;     (not `+1', which is an integer).
  1083. \+1                 ; A symbol named `+1' (not a very readable name).
  1084. \(*\ 1\ 2\)         ; A symbol named `(* 1 2)' (a worse name).
  1085. +-*/_~!@$%^&=:<>{}  ; A symbol named `+-*/_~!@$%^&=:<>{}'.
  1086.                     ;     These characters need not be escaped.
  1087.  
  1088.  
  1089. ΓòÉΓòÉΓòÉ 5.3.9. Lisp Function Type ΓòÉΓòÉΓòÉ
  1090.  
  1091.  Just as functions in other programming languages are executable, a Lisp 
  1092. function object is a piece of executable code.  However, Lisp functions are 
  1093. primarily Lisp objects, and only secondarily the text which represents them. 
  1094. These Lisp objects are lambda expressions: lists whose first element is the 
  1095. symbol lambda ( see Lambda Expressions). 
  1096.  
  1097.  In most programming languages, it is impossible to have a function without a 
  1098. name.  In Lisp, a function has no intrinsic name.  A lambda expression is also 
  1099. called an anonymous function ( see Anonymous Functions).  A named function in 
  1100. Lisp is actually a symbol with a valid function in its function cell (see 
  1101. Defining Functions). 
  1102.  
  1103.  Most of the time, functions are called when their names are written in Lisp 
  1104. expressions in Lisp programs.  However, a function object found or constructed 
  1105. at run time can be called and passed arguments with the primitive functions 
  1106. funcall and apply. See Calling Functions. 
  1107.  
  1108.  
  1109. ΓòÉΓòÉΓòÉ 5.3.10. Lisp Macro Type ΓòÉΓòÉΓòÉ
  1110.  
  1111.  A Lisp macro is a user-defined construct that extends the Lisp language.  It 
  1112. is represented as an object much like a function, but with different 
  1113. parameter-passing semantics.  A Lisp macro has the form of a list whose first 
  1114. element is the symbol macro and whose cdr is a Lisp function object, including 
  1115. the lambda symbol. 
  1116.  
  1117.  Lisp macro objects are usually defined with the built-in function defmacro, 
  1118. but any list that begins with macro is a macro as far as Emacs is concerned. 
  1119. See Macros, for an explanation of how to write a macro. 
  1120.  
  1121.  
  1122. ΓòÉΓòÉΓòÉ 5.3.11. Primitive Function Type ΓòÉΓòÉΓòÉ
  1123.  
  1124.  A primitive function is a function callable from Lisp but written in the C 
  1125. programming language.  Primitive functions are also called subrs or built-in 
  1126. functions.  (The word ``subr'' is derived from ``subroutine''.)  Most primitive 
  1127. functions evaluate all their arguments when they are called.  A primitive 
  1128. function that does not evaluate all its arguments is called a special form (see 
  1129. Special Forms). 
  1130.  
  1131.  It does not matter to the caller of a function whether the function is 
  1132. primitive.  However, this does matter if you are trying to substitute a 
  1133. function written in Lisp for a primitive of the same name.  The reason is that 
  1134. the primitive function may be called directly from C code.  When the redefined 
  1135. function is called from Lisp, the new definition will be used; but calls from C 
  1136. code may still use the old definition. 
  1137.  
  1138.  The term function is used to refer to all Emacs functions, whether written in 
  1139. Lisp or C.  See Lisp Function Type, for information about the functions written 
  1140. in Lisp. 
  1141.  
  1142.  Primitive functions have no read syntax and print in hash notation with the 
  1143. name of the subroutine. 
  1144.  
  1145. (symbol-function 'car)          ; Access the function cell of the symbol.
  1146.      => #<subr car>
  1147. (subrp (symbol-function 'car))  ; Is this a primitive function?
  1148.      => t                       ; Yes.
  1149.  
  1150.  
  1151. ΓòÉΓòÉΓòÉ 5.3.12. Autoload Type ΓòÉΓòÉΓòÉ
  1152.  
  1153.  An autoload object is a list whose first element is the symbol autoload.  It 
  1154. is stored as the function definition of a symbol to say that a file of Lisp 
  1155. code should be loaded when necessary to find the true definition of that 
  1156. symbol.  The autoload object contains the name of the file, plus some other 
  1157. information about the real definition. 
  1158.  
  1159.  After the file has been loaded, the symbol should have a new function 
  1160. definition that is not an autoload object.  The new definition is then called 
  1161. as if it had been there to begin with.  From the user's point of view, the 
  1162. function call works as expected, using the function definition in the loaded 
  1163. file. 
  1164.  
  1165.  An autoload object is usually created with the function autoload, which stores 
  1166. the object in the function cell of a symbol.  See Autoload, for more details. 
  1167.  
  1168.  
  1169. ΓòÉΓòÉΓòÉ 5.4. Editing Types ΓòÉΓòÉΓòÉ
  1170.  
  1171.  The types in the previous section are common to many Lisp-like languages.  But 
  1172. Emacs Lisp provides several additional data types for purposes connected with 
  1173. editing. 
  1174.  
  1175.  
  1176. ΓòÉΓòÉΓòÉ 5.4.1. Buffer Type ΓòÉΓòÉΓòÉ
  1177.  
  1178.  A buffer is an object that holds text that can be edited (see Buffers).  Most 
  1179. buffers hold the contents of a disk file (see Files) so they can be edited, but 
  1180. some are used for other purposes.  Most buffers are also meant to be seen by 
  1181. the user, and therefore displayed, at some time, in a window (see Windows). 
  1182. But a buffer need not be displayed in a window. 
  1183.  
  1184.  The contents of a buffer are much like a string, but buffers are not used like 
  1185. strings in Emacs Lisp, and the available operations are different.  For 
  1186. example, text can be inserted into a buffer very quickly, while ``inserting'' 
  1187. text into a string is accomplished by concatenation and the result is an 
  1188. entirely new string object. 
  1189.  
  1190.  Each buffer has a designated position called point (see Positions).  And one 
  1191. buffer is the current buffer.  Most editing commands act on the contents of the 
  1192. current buffer in the neighborhood of point.  Many other functions manipulate 
  1193. or test the characters in the current buffer and much of this manual is devoted 
  1194. to describing these functions (see Text). 
  1195.  
  1196.  Several other data structures are associated with each buffer: 
  1197.  
  1198. o a local syntax table (see Syntax Tables); 
  1199.  
  1200. o a local keymap (see Keymaps); and, 
  1201.  
  1202. o a local variable binding list (see Variables). 
  1203.  
  1204. The local keymap and variable list contain entries which individually override 
  1205. global bindings or values.  These are used to customize the behavior of 
  1206. programs in different buffers, without actually changing the programs. 
  1207.  
  1208.  Buffers have no read syntax.  They print in hash notation with the buffer 
  1209. name. 
  1210.  
  1211. (current-buffer)
  1212.      => #<buffer objects.texi>
  1213.  
  1214.  
  1215. ΓòÉΓòÉΓòÉ 5.4.2. Window Type ΓòÉΓòÉΓòÉ
  1216.  
  1217.  A window describes the portion of the terminal screen that Emacs uses to 
  1218. display a buffer.  Every window has one associated buffer, whose contents 
  1219. appear in the window.  By contrast, a given buffer may appear in one window, no 
  1220. window, or several windows. 
  1221.  
  1222.  Though many windows may exist simultaneously, one window is designated the 
  1223. selected window.  This is the window where the cursor is (usually) displayed 
  1224. when Emacs is ready for a command.  The selected window usually displays the 
  1225. current buffer, but this is not necessarily the case. 
  1226.  
  1227.  Windows have no read syntax.  They print in hash notation, giving the window 
  1228. number and the name of the buffer being displayed.  The window numbers exist to 
  1229. identify windows uniquely, since the buffer displayed in any given window can 
  1230. change frequently. 
  1231.  
  1232. (selected-window)
  1233.      => #<window 1 on objects.texi>
  1234.  
  1235.  See Windows, for a description of the functions that work on windows. 
  1236.  
  1237.  
  1238. ΓòÉΓòÉΓòÉ 5.4.3. Window Configuration Type ΓòÉΓòÉΓòÉ
  1239.  
  1240.  A window configuration stores information about the positions and sizes of 
  1241. windows at the time the window configuration is created, so that the screen 
  1242. layout may be recreated later. 
  1243.  
  1244.  Window configurations have no read syntax.  They print as 
  1245. `#<window-configuration>'.  See Window Configurations, for a description of 
  1246. several functions related to window configurations. 
  1247.  
  1248.  
  1249. ΓòÉΓòÉΓòÉ 5.4.4. Marker Type ΓòÉΓòÉΓòÉ
  1250.  
  1251.  A marker denotes a position in a specific buffer.  Markers therefore have two 
  1252. components: one for the buffer, and one for the position.  The position value 
  1253. is changed automatically as necessary as text is inserted into or deleted from 
  1254. the buffer.  This is to ensure that the marker always points between the same 
  1255. two characters in the buffer. 
  1256.  
  1257.  Markers have no read syntax.  They print in hash notation, giving the current 
  1258. character position and the name of the buffer. 
  1259.  
  1260. (point-marker)
  1261.      => #<marker at 10779 in objects.texi>
  1262.  
  1263. See Markers, for information on how to test, create, copy, and move markers. 
  1264.  
  1265.  
  1266. ΓòÉΓòÉΓòÉ 5.4.5. Process Type ΓòÉΓòÉΓòÉ
  1267.  
  1268.  The word process means a running program.  Emacs itself runs in a process of 
  1269. this sort.  However, in Emacs Lisp, a process is a Lisp object that designates 
  1270. a subprocess created by Emacs process.  External subprocesses, such as shells, 
  1271. GDB, ftp, and compilers, may be used to extend the processing capability of 
  1272. Emacs. 
  1273.  
  1274.  A process takes input from Emacs and returns output to Emacs for further 
  1275. manipulation.  Both text and signals can be communicated between Emacs and a 
  1276. subprocess. 
  1277.  
  1278.  Processes have no read syntax.  They print in hash notation, giving the name 
  1279. of the process: 
  1280.  
  1281. (process-list)
  1282.      => (#<process shell>)
  1283.  
  1284. See Processes, for information about functions that create, delete, return 
  1285. information about, send input or signals to, and receive output from processes. 
  1286.  
  1287.  
  1288. ΓòÉΓòÉΓòÉ 5.4.6. Stream Type ΓòÉΓòÉΓòÉ
  1289.  
  1290.  A stream is an object that can be used as a source or sink for 
  1291. characters---either to supply characters for input or to accept them as output. 
  1292. Many different types can be used this way: markers, buffers, strings, and 
  1293. functions.  Most often, input streams (character sources) obtain characters 
  1294. from the keyboard, a buffer, or a file, and output streams (character sinks) 
  1295. send characters to a buffer, such as a `*Help*' buffer, or to the echo area. 
  1296.  
  1297.  The object nil, in addition to its other meanings, may be used as a stream. 
  1298. It stands for the value of the variable standard-input or standard-output. 
  1299. Also, the object t as a stream specifies input using the minibuffer (see 
  1300. Minibuffers) or output in the echo area ( see The Echo Area). 
  1301.  
  1302.  Streams have no special printed representation or read syntax, and print as 
  1303. whatever primitive type they are. 
  1304.  
  1305.  See Streams, for a description of various functions related to streams, 
  1306. including various parsing and printing functions. 
  1307.  
  1308.  
  1309. ΓòÉΓòÉΓòÉ 5.4.7. Keymap Type ΓòÉΓòÉΓòÉ
  1310.  
  1311.  A keymap maps keys typed by the user to functions.  This mapping controls how 
  1312. the user's command input is executed.  Emacs defines two kinds of keymaps: full 
  1313. keymaps, which are vectors of 128 elements, and sparse keymaps, which are 
  1314. association lists whose first element is the symbol keymap. 
  1315.  
  1316.  See Keymaps, for information about creating keymaps, handling prefix keys, 
  1317. local as well as global keymaps, and changing key bindings. 
  1318.  
  1319.  
  1320. ΓòÉΓòÉΓòÉ 5.4.8. Syntax Table Type ΓòÉΓòÉΓòÉ
  1321.  
  1322.  A syntax table is a vector of 256 integers.  Each element of the vector 
  1323. defines how one character is interpreted when it appears in a buffer.  For 
  1324. example, in C mode (see Major Modes), the `+' character is punctuation, but in 
  1325. Lisp mode it is a valid character in a symbol.  These different interpretations 
  1326. are effected by changing the syntax table entry for `+', i.e., at index 43. 
  1327.  
  1328.  Syntax tables are only used for scanning text in buffers, not for reading Lisp 
  1329. expressions.  The table the Lisp interpreter uses to read expressions is built 
  1330. into the Emacs source code and cannot be changed; thus, to change the list 
  1331. delimiters to be `{' and `}' instead of `(' and `)' would be impossible. 
  1332.  
  1333.  See Syntax Tables, for details about syntax classes and how to make and modify 
  1334. syntax tables. 
  1335.  
  1336.  
  1337. ΓòÉΓòÉΓòÉ 5.5. Type Predicates ΓòÉΓòÉΓòÉ
  1338.  
  1339.  The Emacs Lisp interpreter itself does not perform type checking on the actual 
  1340. arguments passed to functions when they are called.  It could not do otherwise, 
  1341. since variables in Lisp are not declared to be of a certain type, as they are 
  1342. in other programming languages.  It is therefore up to the individual function 
  1343. to test whether each actual argument belongs to a type that can be used by the 
  1344. function. 
  1345.  
  1346.  All built-in functions do check the types of their actual arguments when 
  1347. appropriate and signal a wrong-type-argument error if an argument is of the 
  1348. wrong type.  For example, here is what happens if you pass an argument to + 
  1349. which it cannot handle: 
  1350.  
  1351. (+ 2 'a)
  1352.      error--> Wrong type argument: integer-or-marker-p, a
  1353.  
  1354.  Many functions, called type predicates, are provided to test whether an object 
  1355. is a member of a given type.  (Following a convention of long standing, the 
  1356. names of most Emacs Lisp predicates end in `p'.) 
  1357.  
  1358. Here is a table of predefined type predicates, in alphabetical order, with 
  1359. references to further information. 
  1360.  
  1361. atom 
  1362.           see List-related Predicates 
  1363.  
  1364. arrayp 
  1365.           see Array Functions 
  1366.  
  1367. bufferp 
  1368.           see Buffer Basics 
  1369.  
  1370. char-or-string-p 
  1371.           see Predicates for Strings 
  1372.  
  1373. consp 
  1374.           see List-related Predicates 
  1375.  
  1376. integer-or-marker-p 
  1377.           see Predicates on Markers 
  1378.  
  1379. integerp 
  1380.           see Predicates on Numbers 
  1381.  
  1382. keymapp 
  1383.           see Creating Keymaps 
  1384.  
  1385. listp 
  1386.           see List-related Predicates 
  1387.  
  1388. markerp 
  1389.           see Predicates on Markers 
  1390.  
  1391. natnump 
  1392.           see Predicates on Numbers 
  1393.  
  1394. nlistp 
  1395.           see List-related Predicates 
  1396.  
  1397. processp 
  1398.           see Processes 
  1399.  
  1400. sequencep 
  1401.           see Sequence Functions 
  1402.  
  1403. stringp 
  1404.           see Predicates for Strings 
  1405.  
  1406. subrp 
  1407.           see Function Cells 
  1408.  
  1409. symbolp 
  1410.           see Symbols 
  1411.  
  1412. syntax-table-p 
  1413.           see Syntax Tables 
  1414.  
  1415. user-variable-p 
  1416.           see Defining Variables 
  1417.  
  1418. vectorp 
  1419.           see Vectors 
  1420.  
  1421. windowp 
  1422.           see Basic Windows 
  1423.  
  1424.  
  1425. ΓòÉΓòÉΓòÉ 5.6. Equality Predicates ΓòÉΓòÉΓòÉ
  1426.  
  1427.  Here we describe two functions that test for equality between any two objects. 
  1428. Other functions test equality between objects of specific types, e.g., strings. 
  1429. See the appropriate chapter describing the data type for these predicates. 
  1430.  
  1431. -- Function: eq object1 object2 
  1432.  This function returns t if object1 and object2 are the same object, nil 
  1433. otherwise.  The ``same object'' means that a change in one will be reflected by 
  1434. the same change in the other. 
  1435.  
  1436.  eq will be true if object1 and object2 are numbers with the same value.  Also, 
  1437. since symbol names are normally unique, if the arguments are symbols with the 
  1438. same name, they are eq.  For other types (e.g., lists, vectors, strings), two 
  1439. arguments with the same contents or elements are not necessarily eq to each 
  1440. other: they are eq only if they are the same object. 
  1441.  
  1442.  (The make-symbol function returns an uninterned symbol that is not interned in 
  1443. the standard obarray.  When uninterned symbols are in use, symbol names are no 
  1444. longer unique.  Distinct symbols with the same name are not eq.  See Creating 
  1445. Symbols.) 
  1446.  
  1447. (eq 'foo 'foo)
  1448.      => t
  1449.  
  1450. (eq 456 456)
  1451.      => t
  1452.  
  1453. (eq "asdf" "asdf")
  1454.      => nil
  1455.  
  1456. (eq '(1 (2 (3))) '(1 (2 (3))))
  1457.      => nil
  1458.  
  1459. (eq [(1 2) 3] [(1 2) 3])
  1460.      => nil
  1461.  
  1462. (eq (point-marker) (point-marker))
  1463.      => nil
  1464.  
  1465. -- Function: equal object1 object2 
  1466.  This function returns t if object1 and object2 have equal components, nil 
  1467. otherwise.  Whereas eq tests if its arguments are the same object, equal looks 
  1468. inside nonidentical arguments to see if their elements are the same.  So, if 
  1469. two objects are eq, they are equal, but the converse is not always true. 
  1470.  
  1471. (equal 'foo 'foo)
  1472.      => t
  1473.  
  1474. (equal 456 456)
  1475.      => t
  1476.  
  1477. (equal "asdf" "asdf")
  1478.      => t
  1479. (eq "asdf" "asdf")
  1480.      => nil
  1481.  
  1482. (equal '(1 (2 (3))) '(1 (2 (3))))
  1483.      => t
  1484. (eq '(1 (2 (3))) '(1 (2 (3))))
  1485.      => nil
  1486.  
  1487. (equal [(1 2) 3] [(1 2) 3])
  1488.      => t
  1489. (eq [(1 2) 3] [(1 2) 3])
  1490.      => nil
  1491.  
  1492. (equal (point-marker) (point-marker))
  1493.      => t
  1494. (eq (point-marker) (point-marker))
  1495.      => nil
  1496.  
  1497. Comparison of strings is case-sensitive. 
  1498.  
  1499. (equal "asdf" "ASDF")
  1500.      => nil
  1501.  
  1502.  The test for equality is implemented recursively, and circular lists may 
  1503. therefore cause infinite recursion (leading to an error). 
  1504.  
  1505.  
  1506. ΓòÉΓòÉΓòÉ 6. Numbers ΓòÉΓòÉΓòÉ
  1507.  
  1508.  Integers are the only kind of number in version 18 Emacs Lisp.  These are 
  1509. whole numbers such as -3, 0, 7, 13, and 511. 
  1510.  
  1511.  In version 19, there is a compile time option to support floating point 
  1512. numbers, which are represented internally as the C type double. A floating 
  1513. point number is a number with a fractional part, such as -4.5, 0.0, or 2.71828. 
  1514. A floating point number can be expressed in an exponential notation as well: 
  1515. thus, 1.5e2 equals 150; in this example, `e2' stands for ten to the second 
  1516. power, and is multiplied by 1.5. 
  1517.  
  1518.  
  1519. ΓòÉΓòÉΓòÉ 6.1. Number Basics ΓòÉΓòÉΓòÉ
  1520.  
  1521.  The range of values for an integer depends on the machine.  The range is 
  1522. -8388608 to 8388607 (24 bits; i.e., -2**23 to 2**23 - 1 ) on most machines, but 
  1523. on others it is -16777216 to 16777215 (25 bits), or -33554432 to 33554431 (26 
  1524. bits).  All of the examples shown below assume an integer has 24 bits. 
  1525.  
  1526.  The Lisp reader reads numbers as a sequence of digits with an optional sign. 
  1527.  
  1528. 1                ; The integer 1.
  1529. +1               ; Also the integer 1.
  1530. -1               ; The integer -1.
  1531. 16777217         ; Also the integer 1, due to overflow.
  1532. 0                ; The number 0.
  1533. -0               ; The number 0.
  1534. 1.               ; Invalid syntax.
  1535.  
  1536.  To understand how various functions work on integers, especially the bitwise 
  1537. operators (see Bitwise Operations), it is often helpful to view the numbers in 
  1538. their binary form. 
  1539.  
  1540.  In 24 bit binary, the decimal integer 5 looks like this: 
  1541.  
  1542. 0000 0000  0000 0000  0000 0101
  1543.  
  1544. (We have inserted spaces between groups of 4 bits, and two spaces between 
  1545. groups of 8 bits, to make the binary integer easier to read.) 
  1546.  
  1547.  The integer -1 looks like this: 
  1548.  
  1549. 1111 1111  1111 1111  1111 1111
  1550.  
  1551. -1 is represented as 24 ones.  (This is called two's complement notation.) 
  1552.  
  1553.  The negative integer, -5, is creating by subtracting 4 from -1.  In binary, 
  1554. the decimal integer 4 is 100.  Consequently, -5 looks like this: 
  1555.  
  1556. 1111 1111  1111 1111  1111 1011
  1557.  
  1558.  In this implementation, the largest 24 bit binary integer is the decimal 
  1559. integer 8,388,607.  In binary, this number looks like this: 
  1560.  
  1561. 0111 1111  1111 1111  1111 1111
  1562.  
  1563.  Since the arithmetic functions do not check whether integers go outside their 
  1564. range, when you add 1 to 8,388,607, the value is negative integer -8,388,608: 
  1565.  
  1566. (+ 1 8388607)
  1567.      => -8388608
  1568.      => 1000 0000  0000 0000  0000 0000
  1569.  
  1570.  Many of the following functions accept markers for arguments as well as 
  1571. integers.  (See Markers.)  More precisely, the actual parameters to such 
  1572. functions may be either integers or markers, which is why we often give these 
  1573. parameters the name marker-or-int.  When the actual parameter is a marker, the 
  1574. position value of the marker is used and the buffer of the marker is ignored. 
  1575.  
  1576.  
  1577. ΓòÉΓòÉΓòÉ 6.2. Type Predicates for Numbers ΓòÉΓòÉΓòÉ
  1578.  
  1579.  The functions in this section test whether the argument is a number or whether 
  1580. it is a certain sort of number.  integerp and natnump can take any type of Lisp 
  1581. object as argument (the predicates would not be of much use otherwise); but the 
  1582. zerop predicate requires an integer as its argument. 
  1583.  
  1584. -- Function: integerp object 
  1585. This predicate tests whether its argument is an integer (a whole number) and 
  1586. returns t if so, nil otherwise. 
  1587.  
  1588. -- Function: natnump object 
  1589. The natnump predicate (whose name comes from the phrase ``natural-number-p'') 
  1590. tests to see whether its argument is a nonnegative integer, and returns t if 
  1591. so, nil otherwise.  0 is considered non-negative. 
  1592.  
  1593. Markers are not converted to integers, hence natnump of a marker is always nil. 
  1594.  
  1595. People have pointed out that this function is misnamed, because the term 
  1596. ``natural number'' is usually understood as excluding zero.  We are open to 
  1597. suggestions for a better name to use in version 19. 
  1598.  
  1599. -- Function: zerop integer 
  1600. This predicate tests whether its argument is zero, and returns t if so, nil 
  1601. otherwise.  These two forms are equivalent: (zerop x) == (= x 0). 
  1602.  
  1603.  
  1604. ΓòÉΓòÉΓòÉ 6.3. Comparison of Numbers ΓòÉΓòÉΓòÉ
  1605.  
  1606.  The integer type is implemented by storing the value in the ``pointer part'' 
  1607. of a Lisp object (which, on typical target machines, has 24 bits of pointer, 7 
  1608. bits of type and 1 bit for the garbage collector). Because of this, the 
  1609. function eq will return t for two integers with the same value.  See Equality 
  1610. Predicates. 
  1611.  
  1612. Common Lisp note: because of the way numbers are implemented in Common Lisp, 
  1613. you generally need to use `=' to test for equality between numbers.  However, 
  1614. GNU Emacs Lisp does not need very large integers; as a consequence, it is 
  1615. possible to restrict them to the size of a single word, allowing eq to be used. 
  1616.  
  1617. -- Function: = marker-or-int1 marker-or-int2 
  1618. This function tests whether its arguments are the same number, and returns t if 
  1619. so, nil otherwise. 
  1620.  
  1621. -- Function: /= marker-or-int1 marker-or-int2 
  1622. This function tests whether its arguments are not the same number, and returns 
  1623. t if so, nil otherwise. 
  1624.  
  1625. -- Function: <  marker-or-int1 marker-or-int2 
  1626. This function tests whether its first argument is strictly less than its second 
  1627. argument.  It returns t if so, nil otherwise. 
  1628.  
  1629. -- Function: <=  marker-or-int1 marker-or-int2 
  1630. This function tests whether its first argument is less than or equal to its 
  1631. second argument.  It returns t if so, nil otherwise. 
  1632.  
  1633. -- Function: >  marker-or-int1 marker-or-int2 
  1634. This function tests whether its first argument is strictly greater than its 
  1635. second argument.  It returns t if so, nil otherwise. 
  1636.  
  1637. -- Function: >=  marker-or-int1 marker-or-int2 
  1638. This function tests whether its first argument is greater than or equal to its 
  1639. second argument.  It returns t if so, nil otherwise. 
  1640.  
  1641. -- Function: max marker-or-int &rest markers-or-ints 
  1642. This function returns the largest of its arguments. 
  1643.  
  1644. (max 20)
  1645.      => 20
  1646. (max 1 2)
  1647.      => 2
  1648. (max 1 3 2)
  1649.      => 3
  1650.  
  1651. -- Function: min marker-or-int &rest markers-or-ints 
  1652. This function returns the smallest of its arguments. 
  1653.  
  1654.  
  1655. ΓòÉΓòÉΓòÉ 6.4. Arithmetic Operations ΓòÉΓòÉΓòÉ
  1656.  
  1657.  Emacs Lisp provides the traditional four arithmetic operations: addition, 
  1658. subtraction, multiplication, and division.  A remainder function supplements 
  1659. the (integer) division function.  In addition, as a convenience, incrementing 
  1660. and decrementing functions are provided. 
  1661.  
  1662.  It is important to note that in GNU Emacs Lisp, arithmetic functions do not 
  1663. check for overflow.  Thus (1+ 8388607) may equal -8388608, depending on your 
  1664. hardware. 
  1665.  
  1666. -- Function: 1+ marker-or-int 
  1667. This function adds one to marker-or-int. 
  1668.  
  1669. -- Function: 1- marker-or-int 
  1670. This function subtracts one from marker-or-int. 
  1671.  
  1672. -- Function: + &rest markers-or-ints 
  1673. This function adds its arguments together.  When given no arguments, + returns 
  1674. 0.  It does not check for overflow. 
  1675.  
  1676. (+)
  1677.      => 0
  1678. (+ 1)
  1679.      => 1
  1680. (+ 1 2 3 4)
  1681.      => 10
  1682.  
  1683. -- Function: - &optional marker-or-int &rest other-markers-or-ints 
  1684. The - function serves two purposes: negation and subtraction. When - has a 
  1685. single argument, the value is the negative of the argument.  When there are 
  1686. multiple arguments, each of the other-markers-or-ints is subtracted from 
  1687. marker-or-int, cumulatively.  If there are no arguments, the result is 0.  This 
  1688. function does not check for overflow. 
  1689.  
  1690. (- 10 1 2 3 4)
  1691.      => 0
  1692. (- 10)
  1693.      => -10
  1694. (-)
  1695.      => 0
  1696.  
  1697. -- Function: * &rest markers-or-integers 
  1698. This function multiplies its arguments together, and returns the product.  When 
  1699. given no arguments, * returns 1.  It does not check for overflow. 
  1700.  
  1701. (*)
  1702.      => 1
  1703. (* 1)
  1704.      => 1
  1705. (* 1 2 3 4)
  1706.      => 24
  1707.  
  1708. -- Function: / dividend divisor &rest divisors 
  1709. This function divides dividend by divisors and returns the quotient.  If there 
  1710. are additional arguments divisors, then dividend is divided by each divisor in 
  1711. turn.   Each argument may be an integer or a marker. 
  1712.  
  1713. The result is normally rounded towars zero after each division, but some 
  1714. machines may round differently with negative arguments.  This is because the 
  1715. Lisp function / is implemented using the C division operator, which has the 
  1716. same possibility for machine-dependent rounding. In practice, all known 
  1717. machines round in the standard fashion. 
  1718.  
  1719. If you divide by 0, an arith-error error is signaled. (See Errors.) 
  1720.  
  1721. (/ 6 2)
  1722.      => 3
  1723. (/ 5 2)
  1724.      => 2
  1725. (/ 25 3 2)
  1726.      => 4
  1727. (/ -17 6)
  1728.      => -2          ; (Could be -3 on some machines.)
  1729.  
  1730. -- Function: % dividend divisor 
  1731. This function returns the value of dividend modulo divisor; in other words, the 
  1732. integer remainder after division of dividend by divisor.  The sign of the 
  1733. result is the sign of dividend. The sign of divisor is ignored.  The arguments 
  1734. must be integers. 
  1735.  
  1736. For negative arguments, the value is in principle machine-dependent since the 
  1737. quotient is; but in practice, all known machines behave alike. 
  1738.  
  1739. An arith-error results if divisor is 0. 
  1740.  
  1741. (% 9 4)
  1742.      => 1
  1743. (% -9 4)
  1744.      => -1
  1745. (% 9 -4)
  1746.      => 1
  1747. (% -9 -4)
  1748.      => -1
  1749.  
  1750. For any two numbers dividend and divisor, 
  1751.  
  1752. (+ (% dividend divisor)
  1753.    (* (/ dividend divisor) divisor))
  1754.  
  1755. always equals dividend. 
  1756.  
  1757.  
  1758. ΓòÉΓòÉΓòÉ 6.5. Bitwise Operations on Integers ΓòÉΓòÉΓòÉ
  1759.  
  1760.  In a computer, an integer is represented as a binary number, a sequence of 
  1761. bits (digits which are either zero or one).  A bitwise operation acts on the 
  1762. individual bits of such a sequence.  For example, shifting moves the whole 
  1763. sequence left or right one or more places, reproducing the same pattern ``moved 
  1764. over''. 
  1765.  
  1766.  The bitwise operations in Emacs Lisp apply only to integers. 
  1767.  
  1768. -- Function: lsh integer1 count 
  1769. lsh, which is an abbreviation for logical shift, shifts the bits in integer1 to 
  1770. the left count places, or to the right if count is negative.  If count is 
  1771. negative, lsh shifts zeros into the most-significant bit, producing a positive 
  1772. result even if integer1 is negative.  Contrast this with ash, below. 
  1773.  
  1774. Thus, the decimal number 5 is the binary number 00000101.  Shifted once to the 
  1775. left, with a zero put in the one's place, the number becomes 00001010, decimal 
  1776. 10. 
  1777.  
  1778. Here are two examples of shifting the pattern of bits one place to the left. 
  1779. Since the contents of the rightmost place has been moved one place to the left, 
  1780. a value has to be inserted into the rightmost place. With lsh, a zero is placed 
  1781. into the rightmost place.  (These examples show only the low-order eight bits 
  1782. of the binary pattern; the rest are all zero.) 
  1783.  
  1784. (lsh 5 1)
  1785.      => 10
  1786.  
  1787. 00000101 => 00001010     ; Decimal 5 becomes decimal 10.
  1788.  
  1789. (lsh 7 1)
  1790.      => 14
  1791.  
  1792. 00000111 => 00001110     ; Decimal 7 becomes decimal 14.
  1793.  
  1794. As the examples illustrate, shifting the pattern of bits one place to the left 
  1795. produces a number that is twice the value of the previous number. 
  1796.  
  1797. Note, however that functions do not check for overflow, and a returned value 
  1798. may be negative (and in any case, no more than a 24 bit value) when an integer 
  1799. is sufficiently left shifted.  For example: 
  1800.  
  1801. (lsh 8388607 1)          ; left shift
  1802.      => -2
  1803.  
  1804. In binary, in the 24 bit implementation, 
  1805.  
  1806. 0111 1111  1111 1111  1111 1111         ; Decimal 8,388,607
  1807.  
  1808. becomes 
  1809.  
  1810. 1111 1111  1111 1111  1111 1110         ; Decimal -2
  1811.  
  1812. Shifting the pattern of bits two places to the left produces results like this 
  1813. (with 8-bit binary numbers): 
  1814.  
  1815. (lsh 3 2)
  1816.      => 12
  1817.  
  1818. 00000011 => 00001100       ; Decimal 3 becomes decimal 12.
  1819.  
  1820. On the other hand, shifting the pattern of bits one place to the right looks 
  1821. like this: 
  1822.  
  1823. (lsh 6 -1)
  1824.      => 3
  1825.  
  1826. 00000110 => 00000011       ; Decimal 6 becomes decimal 3.
  1827.  
  1828. (lsh 5 -1)
  1829.      => 2
  1830.  
  1831. 00000101 => 00000010       ; Decimal 5 becomes decimal 2.
  1832.  
  1833. As the example illustrates, shifting the pattern of bits one place to the right 
  1834. divides the value of the binary number by two, rounding downward. 
  1835.  
  1836. -- Function: ash integer1 count 
  1837. ash (arithmetic shift) shifts the bits in integer1 to the left count places, or 
  1838. to the right if count is negative. 
  1839.  
  1840. ash gives the same results as lsh except when integer1 and count are both 
  1841. negative.  In that case, ash puts a one in the leftmost position, while lsh 
  1842. puts a zero in the leftmost position. 
  1843.  
  1844. Thus, with ash, shifting the pattern of bits one place to the right looks like 
  1845. this: 
  1846.  
  1847. (ash -6 -1)
  1848.      => -3            ; Decimal -6 becomes decimal -3.
  1849.  
  1850. 1111 1111  1111 1111  1111 1010
  1851.      =>
  1852. 1111 1111  1111 1111  1111 1101
  1853.  
  1854. In contrast, shifting the pattern of bits one place to the right with lsh looks 
  1855. like this: 
  1856.  
  1857. (lsh -6 -1)
  1858.      => 8388605       ; Decimal -6 becomes decimal 8,388,605.
  1859.  
  1860. 1111 1111  1111 1111  1111 1010
  1861.      =>
  1862. 0111 1111  1111 1111  1111 1101
  1863.  
  1864. In this case, the 1 in the leftmost position is shifted one place to the right, 
  1865. and a zero is shifted into the leftmost position. 
  1866.  
  1867. Here are other examples: 
  1868.  
  1869.                        ;  24-bit binary values
  1870.  
  1871. (lsh 5 2)              ;   5  =  0000 0000  0000 0000  0000 0101
  1872.      => 20             ;  20  =  0000 0000  0000 0000  0001 0100
  1873. (ash 5 2)
  1874.      => 20
  1875. (lsh -5 2)             ;  -5  =  1111 1111  1111 1111  1111 1011
  1876.      => -20            ; -20  =  1111 1111  1111 1111  1110 1100
  1877. (ash -5 2)
  1878.      => -20
  1879.  
  1880. (lsh 5 -2)             ;   5  =  0000 0000  0000 0000  0000 0101
  1881.      => 1              ;   1  =  0000 0000  0000 0000  0000 0001
  1882. (ash 5 -2)
  1883.      => 1
  1884. (lsh -5 -2)            ;  -5  =  1111 1111  1111 1111  1111 1011
  1885.      => 4194302        ;         0011 1111  1111 1111  1111 1110
  1886. (ash -5 -2)            ;  -5  =  1111 1111  1111 1111  1111 1011
  1887.      => -2             ;  -2  =  1111 1111  1111 1111  1111 1110
  1888.  
  1889. -- Function: logand &rest markers-or-ints 
  1890. This function returns the ``logical and'' of the arguments: the nth bit is set 
  1891. in the result if, and only if, the nth bit is set in all the arguments. 
  1892. (``Set'' means that the value of the bit is 1 rather than 0.) 
  1893.  
  1894. For example, using 4-bit binary numbers, the ``logical and'' of 13 and 12 is 
  1895. 12: 1101 combined with 1100 produces 1100. 
  1896.  
  1897. In both the binary numbers, the leftmost two bits are set (i.e., they are 1's), 
  1898. so the leftmost two bits of the returned value are set. However, for the 
  1899. rightmost two bits, each is zero in at least one of the arguments, so the 
  1900. rightmost two bits of the returned value are 0's. 
  1901.  
  1902. Therefore, 
  1903.  
  1904. (logand 13 12)
  1905.      => 12
  1906.  
  1907. If logand is not passed any argument, it returns a value of -1.  This number is 
  1908. an identity element for logand because its binary representation consists 
  1909. entirely of ones.  If logand is passed just one argument, it returns that 
  1910. argument. 
  1911.  
  1912.                        ; 24-bit binary values
  1913.  
  1914. (logand 14 13)         ; 14  =  0000 0000  0000 0000  0000 1110
  1915.                        ; 13  =  0000 0000  0000 0000  0000 1101
  1916.      => 12             ; 12  =  0000 0000  0000 0000  0000 1100
  1917.  
  1918. (logand 14 13 4)       ; 14  =  0000 0000  0000 0000  0000 1110
  1919.                        ; 13  =  0000 0000  0000 0000  0000 1101
  1920.                        ;  4  =  0000 0000  0000 0000  0000 0100
  1921.      => 4              ;  4  =  0000 0000  0000 0000  0000 0100
  1922.  
  1923. (logand)
  1924.      => -1             ; -1  =  1111 1111  1111 1111  1111 1111
  1925.  
  1926. -- Function: logior &rest markers-or-ints 
  1927. This function returns the ``inclusive or'' of its arguments: the nth bit is set 
  1928. in the result if, and only if, the nth bit is set in at least one of the 
  1929. arguments.  If there are no arguments, the result is zero, which is an identity 
  1930. element for this operation.  If logior is passed just one argument, it returns 
  1931. that argument. 
  1932.  
  1933.                        ; 24-bit binary values
  1934.  
  1935. (logior 12 5)          ; 12  =  0000 0000  0000 0000  0000 1100
  1936.                        ;  5  =  0000 0000  0000 0000  0000 0101
  1937.      => 13             ; 13  =  0000 0000  0000 0000  0000 1101
  1938.  
  1939. (logior 12 5 7)        ; 12  =  0000 0000  0000 0000  0000 1100
  1940.                        ;  5  =  0000 0000  0000 0000  0000 0101
  1941.                        ;  7  =  0000 0000  0000 0000  0000 0111
  1942.      => 15             ; 15  =  0000 0000  0000 0000  0000 1111
  1943.  
  1944. -- Function: logxor &rest markers-or-ints 
  1945. This function returns the ``exclusive or'' of its arguments: the nth bit is set 
  1946. in the result if, and only if, the nth bit is set in an odd number of the 
  1947. arguments.  If there are no arguments, the result is 0.  If logxor is passed 
  1948. just one argument, it returns that argument. 
  1949.  
  1950.                        ; 24-bit binary values
  1951.  
  1952. (logxor 12 5)          ; 12  =  0000 0000  0000 0000  0000 1100
  1953.                        ;  5  =  0000 0000  0000 0000  0000 0101
  1954.      => 9              ;  9  =  0000 0000  0000 0000  0000 1001
  1955.  
  1956. (logxor 12 5 7)        ; 12  =  0000 0000  0000 0000  0000 1100
  1957.                        ;  5  =  0000 0000  0000 0000  0000 0101
  1958.                        ;  7  =  0000 0000  0000 0000  0000 0111
  1959.      => 14             ; 14  =  0000 0000  0000 0000  0000 1110
  1960.  
  1961. -- Function: lognot integer 
  1962. This function returns the logical complement of its argument: the nth bit is 
  1963. one in the result if, and only if, the nth bit is zero in integer, and 
  1964. vice-versa. 
  1965.  
  1966. (lognot 5)             ;  5  =  0000 0000  0000 0000  0000 0101
  1967.      => -6             ; -6  =  1111 1111  1111 1111  1111 1010
  1968.  
  1969.  
  1970. ΓòÉΓòÉΓòÉ 6.6. Random Numbers ΓòÉΓòÉΓòÉ
  1971.  
  1972. -- Function: random &optional flag 
  1973. This function returns a pseudo-random number of type integer.  When called more 
  1974. than once, this function returns a series of pseudo-random numbers. 
  1975.  
  1976. In a computer, a series of a pseudo-random numbers is generated in a 
  1977. deterministic fashion.  The numbers are not truly random, but they have certain 
  1978. properties that mimic a random series.  For example, all possible values occur 
  1979. equally often in a pseudo-random series. 
  1980.  
  1981. In Emacs, pseudo-random numbers are generated from a ``seed'' number. If the 
  1982. random function starts with the same seed, it generates the same sequence of 
  1983. numbers.  Emacs always starts with the same seed value, so the sequence of 
  1984. values of random is actually the same in each Emacs run!  For example, in one 
  1985. operating system, the first call to (random) after you start Emacs always 
  1986. returns -1457731, and the second one always returns -7692030.  This is helpful 
  1987. for debugging. 
  1988.  
  1989. If you want different random numbers, execute (random t).  This chooses a new 
  1990. seed based on the current time of day and on Emacs' process id number. 
  1991.  
  1992. On some machines, any integer representable in Lisp may be the result of 
  1993. random.  On other machines, the result can never be larger than a certain 
  1994. maximum or less than a certain (negative) minimum. 
  1995.  
  1996.  
  1997. ΓòÉΓòÉΓòÉ 7. Strings and Characters ΓòÉΓòÉΓòÉ
  1998.  
  1999.  A string in Emacs Lisp is an array that contains an ordered sequence of 
  2000. characters.  Strings are used as names of symbols, buffers, and files, to send 
  2001. messages to users, to hold text being copied between buffers, and for many 
  2002. other purposes.  Because strings are so important, many functions are provided 
  2003. expressly for manipulating them.  Emacs Lisp programs use strings more often 
  2004. than individual characters. 
  2005.  
  2006.  
  2007. ΓòÉΓòÉΓòÉ 7.1. Introduction to Strings and Characters ΓòÉΓòÉΓòÉ
  2008.  
  2009.  Characters are represented in Emacs Lisp as integers; whether an integer was 
  2010. intended as a character or not is determined only by how it is used.  Strings 
  2011. in Emacs Lisp are arrays that contain an ordered sequence of characters. 
  2012.  
  2013.  The length of a string (like any array) is fixed and independent of the string 
  2014. contents, and cannot be altered.  Strings in Lisp are not terminated by a 
  2015. distinguished character code.  (By contrast, strings in C are terminated by a 
  2016. character with ASCII code 0.) This means that any character, including the null 
  2017. character (ASCII code 0), is a valid element of a string. 
  2018.  
  2019.  Since strings are considered arrays, you can operate on them with the general 
  2020. array functions.  (See Sequences Arrays Vectors.)  For example, you can access 
  2021. or change individual characters in a string using the functions aref and aset ( 
  2022. see Array Functions). 
  2023.  
  2024.  Each character in a string is stored in a single byte.  Therefore, numbers not 
  2025. in the range 0 to 255 are truncated when stored into a string.  This means that 
  2026. a string takes up much less memory than a vector of the same length. 
  2027.  
  2028.  See Text, for information about functions that display strings or copy them 
  2029. into buffers.  See Character Type, and String Type, for information about the 
  2030. syntax of characters and strings. 
  2031.  
  2032.  
  2033. ΓòÉΓòÉΓòÉ 7.2. The Predicates for Strings ΓòÉΓòÉΓòÉ
  2034.  
  2035. For more information about general sequence and array predicates, see Sequences 
  2036. Arrays Vectors, and Arrays. 
  2037.  
  2038. -- Function: stringp object 
  2039.  This function returns t if object is a string, nil otherwise. 
  2040.  
  2041. -- Function: char-or-string-p object 
  2042.  This function returns t if object is a string or a character (i.e., an 
  2043. integer), nil otherwise. 
  2044.  
  2045.  
  2046. ΓòÉΓòÉΓòÉ 7.3. Creating Strings ΓòÉΓòÉΓòÉ
  2047.  
  2048.  The following functions create strings, either from scratch, or by putting 
  2049. strings together, or by taking them apart. 
  2050.  
  2051. -- Function: make-string count character 
  2052.  This function returns a string made up of count repetitions of character.  If 
  2053. count is negative, an error is signaled. 
  2054.  
  2055. (make-string 5 ?x)
  2056.      => "xxxxx"
  2057. (make-string 0 ?x)
  2058.      => ""
  2059.  
  2060.  Other functions to compare with this one include char-to-string (see String 
  2061. Conversion), make-vector (see Vectors), and make-list (see Building Lists). 
  2062.  
  2063. -- Function: substring string start &optional end 
  2064.  This function returns a new string which consists of those characters from 
  2065. string in the range from (and including) the character at the index start up to 
  2066. (but excluding) the character at the index end.  The first character is at 
  2067. index zero. 
  2068.  
  2069. (substring "abcdefg" 0 3)
  2070.      => "abc"
  2071.  
  2072. Here the index for `a' is 0, the index for `b' is 1, and the index for `c' is 
  2073. 2.  Thus, three letters, `abc', are copied from the full string.  The index 3 
  2074. marks the character position up to which the substring is copied.  The 
  2075. character whose index is 3 is actually the fourth character in the string. 
  2076.  
  2077. A negative number counts from the end of the string, so that -1 signifies the 
  2078. index of the last character of the string.  For example: 
  2079.  
  2080. (substring "abcdefg" -3 -1)
  2081.      => "ef"
  2082.  
  2083. In this example, the index for `e' is -3, the index for `f' is -2, and the 
  2084. index for `g' is -1. Therefore, `e' and `f' are included, and `g' is excluded. 
  2085.  
  2086. When nil is used as an index, it falls after the last character in the string. 
  2087. Thus: 
  2088.  
  2089. (substring "abcdefg" -3 nil)
  2090.      => "efg"
  2091.  
  2092. Omitting the argument end is equivalent to specifying nil. It follows that 
  2093. (substring string 0) returns a copy of all of string. 
  2094.  
  2095. (substring "abcdefg" 0)
  2096.      => "abcdefg"
  2097.  
  2098. But we recommend copy-sequence for this purpose. 
  2099.  
  2100.  A wrong-type-argument error is signaled if either start or end are 
  2101. non-integers.  An args-out-of-range error is signaled if start indicates a 
  2102. character following end, or if either integer is out of range for string. 
  2103.  
  2104.  Contrast this function with buffer-substring ( see Buffer Contents), which 
  2105. returns a string containing a portion of the text in the current buffer.  The 
  2106. beginning of a string is at index 0, but the beginning of a buffer is at index 
  2107. 1. 
  2108.  
  2109. -- Function: concat &rest sequences 
  2110.  This function returns a new string consisting of the characters in the 
  2111. arguments passed to it.  The arguments may be strings, lists of numbers, or 
  2112. vectors of numbers; they are not themselves changed.  If no arguments are 
  2113. passed to concat, it returns an empty string. 
  2114.  
  2115. (concat "abc" "-def")
  2116.      => "abc-def"
  2117. (concat "abc" (list 120 (+ 256 121)) [122])
  2118.      => "abcxyz"
  2119. (concat "The " "quick brown " "fox.")
  2120.      => "The quick brown fox."
  2121. (concat)
  2122.      => ""
  2123.  
  2124. The second example above shows how characters stored in strings are taken 
  2125. modulo 256.  In other words, each character in the string is stored in one 
  2126. byte. 
  2127.  
  2128.  The concat function always constructs a new string that is not eq to any 
  2129. existing string. 
  2130.  
  2131.  When an argument is an integer (not a sequence of integers), it is converted 
  2132. to a string of digits making up the decimal printed representation of the 
  2133. integer.  This special case exists for compatibility with Mocklisp, and we 
  2134. don't recommend you take advantage of it.  If you want to convert an integer in 
  2135. this way, use format (see Formatting Strings) or int-to-string ( see String 
  2136. Conversion). 
  2137.  
  2138. (concat 137)
  2139.      => "137"
  2140. (concat 54 321)
  2141.      => "54321"
  2142.  
  2143.  For information about other concatenation functions, see mapconcat in Mapping 
  2144. Functions, vconcat in Vectors, and append in Building Lists. 
  2145.  
  2146.  
  2147. ΓòÉΓòÉΓòÉ 7.4. Comparison of Characters and Strings ΓòÉΓòÉΓòÉ
  2148.  
  2149. -- Function: char-equal character1 character2 
  2150.  This function returns t if the arguments represent the same character, nil 
  2151. otherwise.  This is done by comparing two integers modulo 256. 
  2152.  
  2153. (char-equal ?x ?x)
  2154.      => t
  2155. (char-to-string (+ 256 ?x))
  2156.      => "x"
  2157. (char-equal ?x  (+ 256 ?x))
  2158.      => t
  2159.  
  2160. -- Function: string= string1 string2 
  2161.  This function returns t if the characters of the two strings match exactly; 
  2162. case is significant. 
  2163.  
  2164. (string= "abc" "abc")
  2165.      => t
  2166. (string= "abc" "ABC")
  2167.      => nil
  2168. (string= "ab" "ABC")
  2169.      => nil
  2170.  
  2171. -- Function: string-equal string1 string2 
  2172.  string-equal is another name for string=. 
  2173.  
  2174. -- Function: string< string1 string2 
  2175.  This function compares two strings a character at a time.  First it scans both 
  2176. the strings at once to find the first pair of corresponding characters that do 
  2177. not match.  If the lesser character of those two is the character from string1, 
  2178. then string1 is less, and this function returns t.  If the lesser character is 
  2179. the one from string2, then string1 is greater, and this function returns nil. 
  2180. If the two strings match entirely, the value is nil. 
  2181.  
  2182.  Pairs of characters are compared by their ASCII codes.  Keep in mind that 
  2183. lower case letters have higher numeric values in the ASCII character set than 
  2184. their upper case counterparts; numbers and many punctuation characters have a 
  2185. lower numeric value than upper case letters. 
  2186.  
  2187. (string< "abc" "abd")
  2188.      => t
  2189. (string< "abd" "abc")
  2190.      => nil
  2191. (string< "123" "abc")
  2192.      => t
  2193.  
  2194.  When the strings have different lengths, and they match up to the length of 
  2195. string1, then the result is t.  If they match up to the length of string2, the 
  2196. result is nil. A string without any characters in it is the smallest possible 
  2197. string. 
  2198.  
  2199. (string< "" "abc")
  2200.      => t
  2201. (string< "ab" "abc")
  2202.      => t
  2203. (string< "abc" "")
  2204.      => nil
  2205. (string< "abc" "ab")
  2206.      => nil
  2207. (string< "" "")
  2208.      => nil
  2209.  
  2210. -- Function: string-lessp string1 string2 
  2211. string-lessp is another name for string<. 
  2212.  
  2213.  
  2214. ΓòÉΓòÉΓòÉ 7.5. Conversion of Characters and Strings ΓòÉΓòÉΓòÉ
  2215.  
  2216.  Characters and strings may be converted into each other and into integers. 
  2217. format and prin1-to-string (see Output Functions) may also be used to convert 
  2218. Lisp objects into strings.  read-from-string (see Input Functions) may be used 
  2219. to ``convert'' a string representation of a Lisp object into an object. 
  2220.  
  2221.  See Documentation, for a description of the functions single-key-description 
  2222. and text-char-description, which return a string representing the Emacs 
  2223. standard notation of the argument character.  These functions are used 
  2224. primarily for printing help messages. 
  2225.  
  2226. -- Function: char-to-string character 
  2227.  This function returns a new string with a length of one character. The value 
  2228. of character, modulo 256, is used to initialize the element of the string. 
  2229.  
  2230. This function is similar to make-string with an integer argument of 1.  (See 
  2231. Creating Strings.)  This conversion can also be done with format using the `%c' 
  2232. format specification. (See Formatting Strings.) 
  2233.  
  2234. (char-to-string ?x)
  2235.      => "x"
  2236. (char-to-string (+ 256 ?x))
  2237.      => "x"
  2238. (make-string 1 ?x)
  2239.      => "x"
  2240.  
  2241. -- Function: string-to-char string 
  2242.  This function returns the first character in string.  If the string is empty, 
  2243. the function returns 0.  The value is also 0 when the first character of string 
  2244. is the null character, ASCII code 0. 
  2245.  
  2246. (string-to-char "ABC")
  2247.      => 65
  2248. (string-to-char "xyz")
  2249.      => 120
  2250. (string-to-char "")
  2251.      => 0
  2252. (string-to-char "\000")
  2253.      => 0
  2254.  
  2255. This function may be eliminated in version 19 if it does not seem useful enough 
  2256. to retain. 
  2257.  
  2258. -- Function: int-to-string integer 
  2259.  This function returns a string consisting of the digits of integer, base ten. 
  2260. When passed a positive integer as an argument, this function returns an 
  2261. unsigned string.  When passed a negative integer, the function returns a string 
  2262. with a leading minus sign. 
  2263.  
  2264. (int-to-string 256)
  2265.      => "256"
  2266. (int-to-string -23)
  2267.      => "-23"
  2268.  
  2269.  See also the function format in Formatting Strings. 
  2270.  
  2271. -- Function: string-to-int string 
  2272.  This function returns the integer value of the characters in string, read as a 
  2273. number in base ten. 
  2274.  
  2275.  The string is read starting from (and including) the first character, and it 
  2276. is read until a non-digit is encountered.  If the first character is not a 
  2277. digit or a minus sign, this function returns 0. 
  2278.  
  2279. (string-to-int "256")
  2280.      => 256
  2281. (string-to-int "25 is a perfect square.")
  2282.      => 25
  2283. (string-to-int "X256")
  2284.      => 0
  2285. (string-to-int "-4")
  2286.      => -4
  2287.  
  2288.  
  2289. ΓòÉΓòÉΓòÉ 7.6. Formatting Strings ΓòÉΓòÉΓòÉ
  2290.  
  2291.  Formatting means constructing a string by substitution of computed values at 
  2292. various places in a constant string.  This string controls how the other values 
  2293. are printed as well as where they appear; it is called a format string. 
  2294.  
  2295.  Formatting is often useful for computing messages to be displayed.  In fact, 
  2296. the functions message and error provide the same formatting feature described 
  2297. here; they differ from format only in how they use the result of formatting. 
  2298.  
  2299. -- Function: format string &rest objects 
  2300.  This function returns a new string that is made by copying string and then 
  2301. replacing any format specification in the copy with encodings of the 
  2302. corresponding objects.  The arguments objects are the computed values to be 
  2303. formatted. 
  2304.  
  2305.  A format specification is a sequence of characters beginning with a `%'. 
  2306. Thus, if there is a `%d' in string, the format function replaces it with the 
  2307. printed representation of one of the values to be formatted (one of the 
  2308. arguments objects). For example: 
  2309.  
  2310. (format "The value of fill-column is %d." fill-column)
  2311.      => "The value of fill-column is 72."
  2312.  
  2313.  If string contains more than one format specification, the format 
  2314. specifications are matched in order with successive values from objects.  Thus, 
  2315. the first format specification in string is matched with the first such value, 
  2316. the second format specification is matched with the second such value, and so 
  2317. on.  Any extra format specifications (those for which there are no 
  2318. corresponding values) cause unpredictable behavior.  Any extra values to be 
  2319. formatted will be ignored. 
  2320.  
  2321.  Certain format specifications require values of particular types. However, no 
  2322. error is signaled if the value actually supplied fails to have the expected 
  2323. type.  Instead, meaningless text is likely to be output. 
  2324.  
  2325.  Here is a table of the characters that can follow `%' to make up a format 
  2326. specification: 
  2327.  
  2328. `s' 
  2329.           Replace the specification with the printed representation of the 
  2330.           object. If there is no corresponding object, the empty string is 
  2331.           used. 
  2332.  
  2333. `o' 
  2334.           Replace the specification with the base-eight representation of an 
  2335.           integer. 
  2336.  
  2337. `d' 
  2338.           Replace the specification with the base-ten representation of an 
  2339.           integer. 
  2340.  
  2341. `x' 
  2342.           Replace the specification with the base-sixteen representation of an 
  2343.           integer. 
  2344.  
  2345. `c' 
  2346.           Replace the specification with the character which is the value 
  2347.           given. 
  2348.  
  2349. `%' 
  2350.           A single `%' is placed in the string.  This format specification is 
  2351.           unusual in that it does not use a value.  For example, (format "%% 
  2352.           %d" 30) returns "% 30". 
  2353.  
  2354.  Any other format character results in an `Invalid format operation' error. 
  2355.  
  2356.  Here are several examples: 
  2357.  
  2358. (format "The name of this buffer is %s." (buffer-name))
  2359.      => "The name of this buffer is strings.texi."
  2360.  
  2361. (format "The buffer object prints as %s." (current-buffer))
  2362.      => "The buffer object prints as #<buffer strings.texi>."
  2363.  
  2364. (format "The octal value of 18 is %o, and the hex value is %x."
  2365.         18 18)
  2366.      => "The octal value of 18 is 22, and the hex value is 12."
  2367.  
  2368.  All the specification characters allow an optional numeric prefix between the 
  2369. `%' and the character.  The optional numeric prefix defines the minimum width 
  2370. for the object.  If the printed representation of the object contains fewer 
  2371. characters than this, then it is padded. The padding is on the left if the 
  2372. prefix is positive (or starts with zero) and on the right if the prefix is 
  2373. negative.  The padding character is normally a space, but if the numeric prefix 
  2374. starts with a zero, zeros are used for padding. 
  2375.  
  2376. (format "%06d will be padded on the left with zeros" 123)
  2377.      => "000123 will be padded on the left with zeros"
  2378.  
  2379. (format "%-6d will be padded on the right" 123)
  2380.      => "123    will be padded on the right"
  2381.  
  2382.  No matter what the prefix, nothing in the printed representation will be 
  2383. truncated.  This allows the programmer to specify minimum spacing without 
  2384. knowing how many characters there are in the object's printed representation. 
  2385.  
  2386.  In the following three examples, `%7s' specifies a minimum width of 7.  In the 
  2387. first case, the string inserted in place of `%7s' has only 3 letters, so 4 
  2388. blank spaces are inserted for padding.  In the second case, the string 
  2389. "specification" is 13 letters wide but is not truncated.  In the third case, 
  2390. the padding is on the right.  (This does not work in version 18, but does work 
  2391. in version 19.) 
  2392.  
  2393. (format "The word `%7s' actually has %d letters in it." "foo"
  2394.         (length "foo"))
  2395.      => "The word `    foo' actually has 3 letters in it."
  2396.  
  2397. (format "The word `%7s' actually has %d letters in it."
  2398.         "specification"
  2399.         (length "specification"))
  2400.      => "The word `specification' actually has 13 letters in it."
  2401.  
  2402. (format "The word `%-7s' actually has %d letters in it." "foo"
  2403.         (length "foo"))
  2404.      => "The word `foo    ' actually has 3 letters in it."
  2405. ;; `%-7s' fails to work in version 18, but does work in version 19.
  2406. ;; In version 18, padding is not inserted.
  2407.  
  2408.  
  2409. ΓòÉΓòÉΓòÉ 7.7. Character Case ΓòÉΓòÉΓòÉ
  2410.  
  2411.  The character case functions change the case of single characters or of the 
  2412. contents of strings.  The functions convert only alphabetic characters (the 
  2413. letters `A' through `Z' and `a' through `z'); other characters are not altered. 
  2414. The functions do not modify the strings that are passed to them as arguments. 
  2415.  
  2416.  The examples below use the characters `X' and `x' which have ASCII codes 88 
  2417. and 120 respectively. 
  2418.  
  2419. -- Function: downcase string-or-char 
  2420.  This function converts a character or a string to lower case. 
  2421.  
  2422.  When the argument to downcase is a string, the function creates and returns a 
  2423. new string in which each letter in the argument that is upper case is converted 
  2424. to lower case.  When the argument to downcase is a character, downcase returns 
  2425. the corresponding lower case character.  This value is an integer.  If the 
  2426. original character is lower case, or is not a letter, then the value equals the 
  2427. original character. 
  2428.  
  2429. (downcase "The cat in the hat")
  2430.      => "the cat in the hat"
  2431.  
  2432. (downcase ?X)
  2433.      => 120
  2434.  
  2435. -- Function: upcase string-or-char 
  2436.  This function converts a character or a string to upper case. 
  2437.  
  2438.  When the argument to upcase is a string, the function creates and returns a 
  2439. new string in which each letter in the argument that is lower case is converted 
  2440. to upper case. 
  2441.  
  2442.  When the argument to upcase is a character, upcase returns the corresponding 
  2443. upper case character.  This value is an integer. If the original character is 
  2444. upper case, or is not a letter, then the value equals the original character. 
  2445.  
  2446. (upcase "The cat in the hat")
  2447.      => "THE CAT IN THE HAT"
  2448.  
  2449. (upcase ?x)
  2450.      => 88
  2451.  
  2452. -- Function: capitalize string-or-char 
  2453.  This function capitalizes strings or characters.  If string-or-char is a 
  2454. string, the function creates and returns a new string, whose contents are a 
  2455. copy of string-or-char in which each word has been capitalized.  This means 
  2456. that the first character of each word is converted to upper case, and the rest 
  2457. are converted to lower case. 
  2458.  
  2459.  The definition of a word is any sequence of consecutive characters that are 
  2460. assigned to the word constituent category in the current syntax table (See 
  2461. Syntax Class Table). 
  2462.  
  2463.  When the argument to capitalize is a character, capitalize has the same result 
  2464. as upcase. 
  2465.  
  2466. (capitalize "The cat in the hat")
  2467.      => "The Cat In The Hat"
  2468.  
  2469. (capitalize "THE 77TH-HATTED CAT")
  2470.      => "The 77th-Hatted Cat"
  2471.  
  2472. (capitalize ?x)
  2473.      => 88
  2474.  
  2475.  
  2476. ΓòÉΓòÉΓòÉ 8. Lists ΓòÉΓòÉΓòÉ
  2477.  
  2478.  A list represents a sequence of zero or more elements (which may be any Lisp 
  2479. objects).  The important difference between lists and vectors is that two or 
  2480. more lists can share part of their structure; in addition, you can insert or 
  2481. delete elements in a list without copying the whole list. 
  2482.  
  2483.  
  2484. ΓòÉΓòÉΓòÉ 8.1. Lists and Cons Cells ΓòÉΓòÉΓòÉ
  2485.  
  2486.  Lists in Lisp are not a primitive data type; they are built up from cons 
  2487. cells.  A cons cell is a data object which represents an ordered pair.  It 
  2488. records two Lisp objects, one labeled as the car, and the other labeled as the 
  2489. cdr.  (These names are traditional.) 
  2490.  
  2491.  A list is made by chaining cons cells together, one cons cell per element.  By 
  2492. convention, the cars of the cons cells are the elements of the list, and the 
  2493. cdrs are used to chain the list: the cdr of each cons cell is the following 
  2494. cons cell.  The cdr of the last cons cell is nil.  This asymmetry between the 
  2495. car and the cdr is entirely a matter of convention; at the level of cons cells, 
  2496. the car and cdr slots have the same characteristics. 
  2497.  
  2498.  The symbol nil is considered a list as well as a symbol; it is the list with 
  2499. no elements.  Therefore, the cdr of any nonempty list l is a list containing 
  2500. all the elements of l except the first.  For convenience, the symbol nil is 
  2501. considered to have nil as its cdr (and also as its car). 
  2502.  
  2503.  
  2504. ΓòÉΓòÉΓòÉ 8.2. Lists as Linked Pairs of Boxes ΓòÉΓòÉΓòÉ
  2505.  
  2506.  A cons cell can be illustrated as a pair of boxes.  The first box represents 
  2507. the car and the second box represents the cdr. Here is an illustration of the 
  2508. two-element list, (tulip lily), made from two cons cells: 
  2509.  
  2510.  ---------------         ---------------
  2511. |car    |cdr    |       |car    |cdr    |
  2512. | tulip |   o---------->| lily  |  nil  |
  2513. |       |       |       |       |       |
  2514.  ---------------         ---------------
  2515.  
  2516.  Each pair of boxes represents a cons cell.  Each box ``refers to'', ``points 
  2517. to'' or ``contains'' a Lisp object.  (These terms are synonymous.)  The first 
  2518. box, which is the car of the first cons cell, contains the symbol tulip.  The 
  2519. arrow from the cdr of the first cons cell to the second cons cell indicates 
  2520. that the cdr of the first cons cell points to the second cons cell. 
  2521.  
  2522.  The same list can be illustrated in a different sort of box notation like 
  2523. this: 
  2524.  
  2525.     ___ ___      ___ ___
  2526.    |___|___|--> |___|___|--> nil
  2527.      |            |
  2528.      |            |
  2529.       --> tulip    --> lily
  2530.  
  2531.  Here is a more complex illustration, this time of the three-element list, 
  2532. ((pine needles) oak maple), the first element of which is a two-element list: 
  2533.  
  2534.     ___ ___      ___ ___      ___ ___
  2535.    |___|___|--> |___|___|--> |___|___|--> nil
  2536.      |            |            |
  2537.      |            |            |
  2538.      |             --> oak      --> maple
  2539.      |
  2540.      |     ___ ___      ___ ___
  2541.       --> |___|___|--> |___|___|--> nil
  2542.             |            |
  2543.             |            |
  2544.              --> pine     --> needles
  2545.  
  2546.  The same list is represented in the first box notation like this: 
  2547.  
  2548.  ---------------         ---------------         ---------------
  2549. |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  2550. |   o   |   o---------->|  oak  |   o---------->| maple |  nil  |
  2551. |   |   |       |       |       |       |       |       |       |
  2552.  -- | ----------         ---------------         ---------------
  2553.     |
  2554.     |
  2555.     |        ---------------         -----------------
  2556.     |       |car    |cdr    |       |car      |cdr    |
  2557.      ------>| pine  |   o---------->| needles |  nil  |
  2558.             |       |       |       |         |       |
  2559.              ---------------         -----------------
  2560.  
  2561.  See List Type, for the read and print syntax of lists, and for more ``box and 
  2562. arrow'' illustrations of lists. 
  2563.  
  2564.  
  2565. ΓòÉΓòÉΓòÉ 8.3. Predicates on Lists ΓòÉΓòÉΓòÉ
  2566.  
  2567. The following predicates test whether a Lisp object is an atom, is a cons cell 
  2568. or is a list, or whether it is the distinguished object nil. (Many of these 
  2569. tests can be defined in terms of the others, but they are used so often that it 
  2570. is worth having all of them.) 
  2571.  
  2572. -- Function: consp object 
  2573.  This function returns t if object is a cons cell, nil otherwise.  nil is not a 
  2574. cons cell, although it is a list. 
  2575.  
  2576. -- Function: atom object 
  2577.  This function returns t if object is an atom, nil otherwise.  All objects 
  2578. except cons cells are atoms.  The symbol nil is an atom and is also a list; it 
  2579. is the only Lisp object which is both. 
  2580.  
  2581. (atom object) == (not (consp object))
  2582.  
  2583. -- Function: listp object 
  2584.  This function returns t if object is a cons cell or nil.  Otherwise, it 
  2585. returns nil. 
  2586.  
  2587. (listp '(1))
  2588.      => t
  2589. (listp '())
  2590.      => t
  2591.  
  2592. -- Function: nlistp object 
  2593.  This function is the opposite of listp: it returns t if object is not a list. 
  2594. Otherwise, it returns nil. 
  2595.  
  2596. (listp object) == (not (nlistp object))
  2597.  
  2598. -- Function: null object 
  2599.  This function returns t if object is nil, and returns nil otherwise.  This 
  2600. function is identical to not, but as a matter of clarity we use null when 
  2601. object is considered a list and not when it is considered a truth value (see 
  2602. not in Combining Conditions). 
  2603.  
  2604. (null '(1))
  2605.      => nil
  2606. (null '())
  2607.      => t
  2608.  
  2609.  
  2610. ΓòÉΓòÉΓòÉ 8.4. Accessing Elements of Lists ΓòÉΓòÉΓòÉ
  2611.  
  2612. -- Function: car cons-cell 
  2613.  This function returns the value pointed to by the first pointer of the cons 
  2614. cell cons-cell.  Expressed another way, this function returns the car of 
  2615. cons-cell. 
  2616.  
  2617.  As a special case, if cons-cell is nil, then car is defined to return nil; 
  2618. therefore, any list is a valid argument for car.  An error is signaled if the 
  2619. argument is not a cons cell or nil. 
  2620.  
  2621. (car '(a b c))
  2622.      => a
  2623. (car '())
  2624.      => nil
  2625.  
  2626. -- Function: cdr cons-cell 
  2627.  This function returns the value pointed to by the second pointer of the cons 
  2628. cell cons-cell.  Expressed another way, this function returns the cdr of 
  2629. cons-cell. 
  2630.  
  2631.  As a special case, if cons-cell is nil, then cdr is defined to return nil; 
  2632. therefore, any list is a valid argument for cdr.  An error is signaled if the 
  2633. argument is not a cons cell or nil. 
  2634.  
  2635. (cdr '(a b c))
  2636.      => (b c)
  2637. (cdr '())
  2638.      => nil
  2639.  
  2640. -- Function: car-safe object 
  2641.  This function lets you take the car of a cons cell while avoiding errors for 
  2642. other data types.  It returns the car of object if object is a cons cell, nil 
  2643. otherwise.  This is in contrast to car, which signals an error if object is not 
  2644. a list. 
  2645.  
  2646. (car-safe object)
  2647. ==
  2648. (let ((x object))
  2649.   (if (consp x)
  2650.       (car x)
  2651.     nil))
  2652.  
  2653. -- Function: cdr-safe object 
  2654.  This function lets you take the cdr of a cons cell while avoiding errors for 
  2655. other data types.  It returns the cdr of object if object is a cons cell, nil 
  2656. otherwise. This is in contrast to cdr, which signals an error if object is not 
  2657. a list. 
  2658.  
  2659. (cdr-safe object)
  2660. ==
  2661. (let ((x object))
  2662.   (if (consp x)
  2663.       (cdr x)
  2664.     nil))
  2665.  
  2666. -- Function: nth n list 
  2667.  This function returns the nth element of list.  Elements are numbered starting 
  2668. with zero, so the car of list is element number zero.  If the length of list is 
  2669. n or less, the value is nil. 
  2670.  
  2671. If n is less than zero, then the first element is returned. 
  2672.  
  2673. (nth 2 '(1 2 3 4))
  2674.      => 3
  2675. (nth 10 '(1 2 3 4))
  2676.      => nil
  2677. (nth -3 '(1 2 3 4))
  2678.      => 1
  2679.  
  2680. (nth n x) == (car (nthcdr n x))
  2681.  
  2682. -- Function: nthcdr n list 
  2683.  This function returns the nth cdr of list.  In other words, it removes the 
  2684. first n links of list and returns what follows. 
  2685.  
  2686. If n is less than or equal to zero, then all of list is returned.  If the 
  2687. length of list is n or less, the value is nil. 
  2688.  
  2689. (nthcdr 1 '(1 2 3 4))
  2690.      => (2 3 4)
  2691. (nthcdr 10 '(1 2 3 4))
  2692.      => nil
  2693. (nthcdr -3 '(1 2 3 4))
  2694.      => (1 2 3 4)
  2695.  
  2696.  
  2697. ΓòÉΓòÉΓòÉ 8.5. Building Cons Cells and Lists ΓòÉΓòÉΓòÉ
  2698.  
  2699.  Many functions build lists, as lists reside at the very heart of Lisp. cons is 
  2700. the fundamental list-building function; however, it is interesting to note that 
  2701. list is used more times in the source code for Emacs than cons. 
  2702.  
  2703. -- Function: cons object1 object2 
  2704.  This function is the fundamental function used to build new list structure. 
  2705. It creates a new cons cell, making object1 the car, and object2 the cdr.  It 
  2706. then returns the new cons cell.  The arguments object1 and object2 may be any 
  2707. Lisp objects, but most often object2 is a list. 
  2708.  
  2709. (cons 1 '(2))
  2710.      => (1 2)
  2711. (cons 1 '())
  2712.      => (1)
  2713. (cons 1 2)
  2714.      => (1 . 2)
  2715.  
  2716. cons is often used to add a single element to the front of a list.  This is 
  2717. called consing the element onto the list.  For example: 
  2718.  
  2719. (setq list (cons newelt list))
  2720.  
  2721. -- Function: list &rest objects 
  2722.  This function creates a list with objects as its elements.  The resulting list 
  2723. is always nil-terminated.  If no objects are given, the empty list is returned. 
  2724.  
  2725. (list 1 2 3 4 5)
  2726.      => (1 2 3 4 5)
  2727. (list 1 2 '(3 4 5) 'foo)
  2728.      => (1 2 (3 4 5) foo)
  2729. (list)
  2730.      => nil
  2731.  
  2732. -- Function: make-list length object 
  2733.  This function creates a list of length length, in which all the elements have 
  2734. the identical value object.  Compare make-list with make-string (see Creating 
  2735. Strings). 
  2736.  
  2737. (make-list 3 'pigs)
  2738.      => (pigs pigs pigs)
  2739. (make-list 0 'pigs)
  2740.      => nil
  2741.  
  2742. -- Function: append &rest sequences 
  2743.  This function returns a list containing all the elements of sequences.  The 
  2744. sequences may be lists, vectors, strings, or integers.  All arguments except 
  2745. the last one are copied, so none of them are altered. 
  2746.  
  2747.  The final argument to append may be any object but it is typically a list. 
  2748. The final argument is not copied or converted; it becomes part of the structure 
  2749. of the new list. 
  2750.  
  2751.  Here is an example: 
  2752.  
  2753. (setq trees '(pine oak))
  2754.      => (pine oak)
  2755. (setq more-trees (append '(maple birch) trees))
  2756.      => (maple birch pine oak)
  2757.  
  2758. trees
  2759.      => (pine oak)
  2760. more-trees
  2761.      => (maple birch pine oak)
  2762. (eq trees (cdr (cdr more-trees)))
  2763.      => t
  2764.  
  2765.  You can see what happens by looking at a box diagram.  The variable trees is 
  2766. set to the list (pine oak) and then the variable more-trees is set to the list 
  2767. (maple birch pine oak). However, the variable trees continues to refer to the 
  2768. original list: 
  2769.  
  2770. more-trees                trees
  2771. |                           |
  2772. |     ___ ___      ___ ___   -> ___ ___      ___ ___
  2773.  --> |___|___|--> |___|___|--> |___|___|--> |___|___|--> nil
  2774.        |            |            |            |
  2775.        |            |            |            |
  2776.         --> maple    -->birch     --> pine     --> oak
  2777.  
  2778.  An empty sequence contributes nothing to the value returned by append.  As a 
  2779. consequence of this, a final nil argument forces a copy of the previous 
  2780. argument. 
  2781.  
  2782. trees
  2783.      => (pine oak)
  2784. (setq wood (append trees ()))
  2785.      => (pine oak)
  2786. wood
  2787.      => (pine oak)
  2788. (eq wood trees)
  2789.      => nil
  2790.  
  2791. This once was the standard way to copy a list, before the function 
  2792. copy-sequence was invented.  See Sequences Arrays Vectors. 
  2793.  
  2794. With the help of apply, we can append all the lists in a list of lists: 
  2795.  
  2796. (apply 'append '((a b c) nil (x y z) nil))
  2797.      => (a b c x y z)
  2798.  
  2799. If no sequences are given, nil is returned: 
  2800.  
  2801. (append)
  2802.      => nil
  2803.  
  2804. In the special case where one of the sequences is an integer (not a sequence of 
  2805. integers), it is first converted to a string of digits making up the decimal 
  2806. print representation of the integer.  This special case exists for 
  2807. compatibility with Mocklisp, and we don't recommend you take advantage of it. 
  2808. If you want to convert an integer in this way, use format (see Formatting 
  2809. Strings) or int-to-string (see String Conversion). 
  2810.  
  2811. (setq trees '(pine oak))
  2812.      => (pine oak)
  2813. (char-to-string ?\054)
  2814.      => "6"
  2815. (setq longer-list (append trees 6 '(spruce)))
  2816.      => (pine oak 54 spruce)
  2817. (setq x-list (append trees 6 6))
  2818.      => (pine oak 54 . 6)
  2819.  
  2820. See nconc in Rearrangement, for another way to join lists without copying. 
  2821.  
  2822. -- Function: reverse list 
  2823. This function creates a new list whose elements are the elements of list, but 
  2824. in reverse order.  The original argument list is not altered. 
  2825.  
  2826. (setq x '(1 2 3 4))
  2827.      => (1 2 3 4)
  2828. (reverse x)
  2829.      => (4 3 2 1)
  2830. x
  2831.      => (1 2 3 4)
  2832.  
  2833.  
  2834. ΓòÉΓòÉΓòÉ 8.6. Modifying Existing List Structure ΓòÉΓòÉΓòÉ
  2835.  
  2836.  You can modify the car and cdr contents of a cons cell with the primitives 
  2837. setcar and setcdr. 
  2838.  
  2839. Common Lisp note: Common Lisp uses functions rplaca and rplacd to alter list 
  2840. structure; they change structure the same way as setcar and setcdr, but the 
  2841. Common Lisp functions return the cons cell while setcar and setcdr return the 
  2842. new car or cdr. 
  2843.  
  2844.  
  2845. ΓòÉΓòÉΓòÉ 8.6.1. Altering List Elements with setcar ΓòÉΓòÉΓòÉ
  2846.  
  2847.  Changing the car of a cons cell is done with setcar and replaces one element 
  2848. of a list with a different element. 
  2849.  
  2850. -- Function: setcar cons object 
  2851.  This function stores object as the new car of cons, replacing its previous 
  2852. car.  It returns the value object. For example: 
  2853.  
  2854. (setq x '(1 2))
  2855.      => (1 2)
  2856. (setcar x '4)
  2857.      => 4
  2858. x
  2859.      => (4 2)
  2860.  
  2861.  When a cons cell is part of the shared structure of several lists, storing a 
  2862. new car into the cons changes one element of each of these lists.  Here is an 
  2863. example: 
  2864.  
  2865. ;; Create two lists that are partly shared.
  2866. (setq x1 '(a b c))
  2867.      => (a b c)
  2868. (setq x2 (cons 'z (cdr x1)))
  2869.      => (z b c)
  2870.  
  2871. ;; Replace the car of a shared link.
  2872. (setcar (cdr x1) 'foo)
  2873.      => foo
  2874. x1                           ; Both lists are changed.
  2875.      => (a foo c)
  2876. x2
  2877.      => (z foo c)
  2878.  
  2879. ;; Replace the car of a link that is not shared.
  2880. (setcar x1 'baz)
  2881.      => baz
  2882. x1                           ; Only one list is changed.
  2883.      => (baz foo c)
  2884. x2
  2885.      => (z foo c)
  2886.  
  2887.  Here is a graphical depiction of the shared structure of the two lists x1 and 
  2888. x2, showing why replacing b changes them both: 
  2889.  
  2890.         ___ ___        ___ ___      ___ ___
  2891. x1---> |___|___|----> |___|___|--> |___|___|--> nil
  2892.          |        -->   |            |
  2893.          |       |      |            |
  2894.           --> a  |       --> b        --> c
  2895.                  |
  2896.        ___ ___   |
  2897. x2--> |___|___|--
  2898.         |
  2899.         |
  2900.          --> z
  2901.  
  2902.  Here is an alternative form of box diagram, showing the same relationship: 
  2903.  
  2904. x1:
  2905.  ---------------         ---------------         ---------------
  2906. |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  2907. |   a   |   o---------->|   b   |   o---------->|   c   |  nil  |
  2908. |       |       |    -->|       |       |       |       |       |
  2909.  ---------------    |    ---------------         ---------------
  2910.                     |
  2911. x2:                 |
  2912.  ---------------    |
  2913. |car    |cdr    |   |
  2914. |   z   |   o-------
  2915. |       |       |
  2916.  ---------------
  2917.  
  2918.  
  2919. ΓòÉΓòÉΓòÉ 8.6.2. Altering the CDR of a List ΓòÉΓòÉΓòÉ
  2920.  
  2921.  The lowest-level primitive for modifying a cdr is setcdr: 
  2922.  
  2923. -- Function: setcdr cons object 
  2924.  This function stores object into the cdr of cons.  The value returned is 
  2925. object, not cons. 
  2926.  
  2927.  Here is an example of replacing the cdr of a list with a different list.  All 
  2928. but the first element of the list are removed in favor of a different sequence 
  2929. of elements.  The first element is unchanged, because it resides in the car of 
  2930. the list, and is not reached via the cdr. 
  2931.  
  2932. (setq x '(1 2 3))
  2933.      => (1 2 3)
  2934. (setcdr x '(4))
  2935.      => (4)
  2936. x
  2937.      => (1 4)
  2938.  
  2939.  You can delete elements from the middle of a list by altering the cdrs of the 
  2940. cons cells in the list.  For example, here we delete the second element, b, 
  2941. from the list (a b c), by changing the cdr of the first cell: 
  2942.  
  2943. (setq x1 '(a b c))
  2944.      => (a b c)
  2945. (setcdr x1 '(c))
  2946.      => (c)
  2947. x1
  2948.      => (a c)
  2949.  
  2950. Here is the result in box notation: 
  2951.  
  2952.                      -----------------------
  2953.                     |                       |
  2954.  ---------------    |    ---------------    |    ---------------
  2955. |car    |cdr    |   |   |car    |cdr    |    -->|car    |cdr    |
  2956. |   a   |   o-------    |   b   |   o---------->|   c   |  nil  |
  2957. |       |       |       |       |       |       |       |       |
  2958.  ---------------         ---------------         ---------------
  2959.  
  2960. The second cons cell, which previously held the element b, still exists and its 
  2961. car is still b, but it no longer forms part of this list. 
  2962.  
  2963.  It is equally easy to insert a new element by changing cdrs: 
  2964.  
  2965. (setq x1 '(a b c))
  2966.      => (a b c)
  2967. (setcdr x1 (cons 'd (cdr x1)))
  2968.      => (d b c)
  2969. x1
  2970.      => (a d b c)
  2971.  
  2972.  Here is this result in box notation: 
  2973.  
  2974.  ---------------         ---------------         ---------------
  2975. |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  2976. |   a   |   o   |    -->|   b   |   o---------->|   c   |  nil  |
  2977. |       |   |   |   |   |       |       |       |       |       |
  2978.  ---------- | --    |    ---------------         ---------------
  2979.             |       |
  2980.       ------         -------
  2981.      |                      |
  2982.      |    ---------------   |
  2983.      |   |car    |cdr    |  |
  2984.       -->|   d   |   o------
  2985.          |       |       |
  2986.           ---------------
  2987.  
  2988.  
  2989. ΓòÉΓòÉΓòÉ 8.6.3. Functions that Rearrange Lists ΓòÉΓòÉΓòÉ
  2990.  
  2991.  Here are some functions that rearrange lists ``destructively'' by modifying 
  2992. the cdrs of their component cons cells.  We call these functions 
  2993. ``destructive'' because the original lists passed as arguments to them are 
  2994. chewed up to produce a new list that is subsequently returned. 
  2995.  
  2996. -- Function: nconc &rest lists 
  2997. This function returns a list containing all the elements of lists. Unlike 
  2998. append (see Building Lists), the lists are not copied.  Instead, the last cdr 
  2999. of each of the lists is changed to refer to the following list.  The last of 
  3000. the lists is not altered.  For example: 
  3001.  
  3002. (setq x '(1 2 3))
  3003.      => (1 2 3)
  3004. (nconc x '(4 5))
  3005.      => (1 2 3 4 5)
  3006. x
  3007.      => (1 2 3 4 5)
  3008.  
  3009.   Since the last argument of nconc is not itself modified, it is reasonable to 
  3010. use a constant list, such as '(4 5), as is done in the above example.  For the 
  3011. same reason, the last argument need not be a list: 
  3012.  
  3013. (setq x '(1 2 3))
  3014.      => (1 2 3)
  3015. (nconc x 'z)
  3016.      => (1 2 3 . z)
  3017. x
  3018.      => (1 2 3 . z)
  3019.  
  3020. A common pitfall is to use a quoted constant list as a non-last argument to 
  3021. nconc.  If you do this, your program will change each time you run it!  Here is 
  3022. what happens: 
  3023.  
  3024. (defun add-foo (x)                ; This function should add
  3025.   (nconc '(foo) x))               ; foo to the front of its arg.
  3026.  
  3027. (symbol-function 'add-foo)
  3028.      => (lambda (x) (nconc (quote (foo)) x))
  3029.  
  3030. (setq xx (add-foo '(1 2)))        ; It seems to work.
  3031.      => (foo 1 2)
  3032. (setq xy (add-foo '(3 4)))        ; What happened?
  3033.      => (foo 1 2 3 4)
  3034. (eq xx xy)
  3035.      => t
  3036.  
  3037. (symbol-function 'add-foo)
  3038.      => (lambda (x) (nconc (quote (foo 1 2 3 4) x)))
  3039.  
  3040. -- Function: nreverse list 
  3041.  This function reverses the order of the elements of list. Unlike reverse, 
  3042. nreverse alters its argument destructively by reversing the cdrs in the cons 
  3043. cells forming the list.  The cons cell which used to be the last one in list 
  3044. becomes the first cell of the value. 
  3045.  
  3046.  For example: 
  3047.  
  3048. (setq x '(1 2 3 4))
  3049.      => (1 2 3 4)
  3050. x
  3051.      => (1 2 3 4)
  3052. (nreverse x)
  3053.      => (4 3 2 1)
  3054. ;; The cell that was first is now last.
  3055. x
  3056.      => (1)
  3057.  
  3058.  To avoid confusion, we usually store the result of nreverse back in the same 
  3059. variable which held the original list: 
  3060.  
  3061. (setq x (nreverse x))
  3062.  
  3063.  Here is the nreverse of our favorite example, (a b c), presented graphically: 
  3064.  
  3065. Original list head:                                 Reversed list:
  3066.  ---------------         ---------------         ---------------
  3067. |car    |cdr    |       |car    |cdr    |       |car    |cdr    |
  3068. |   a   |  nil  |<--    |   b   |   o   |<--    |   c   |   o   |
  3069. |       |       |   |   |       |   |   |   |   |       |   |   |
  3070.  ---------------    |    ---------- | --    |    ---------- | --
  3071.                     |               |       |               |
  3072.                      ---------------         ---------------
  3073.  
  3074. -- Function: sort list predicate 
  3075.  This function sorts list stably, though destructively, and returns the sorted 
  3076. list.  It compares elements using predicate.  A stable sort is one in which 
  3077. elements with equal sort keys maintain their relative order before and after 
  3078. the sort.  Stability is important when successive sorts are used to order 
  3079. elements according to different criteria. 
  3080.  
  3081.  The argument predicate must be a function that accepts two arguments.  It is 
  3082. called with two elements of list.  To get an increasing order sort, the 
  3083. predicate should return t if the first element is ``less than'' the second, or 
  3084. nil if not. 
  3085.  
  3086.  The destructive aspect of sort is that it rearranges the cons cells forming 
  3087. list by changing cdrs.  A nondestructive sort function would create new cons 
  3088. cells to store the elements in their sorted order.  If you wish to sort a list 
  3089. without destroying the original, copy it first with copy-sequence. 
  3090.  
  3091.  The cars of the cons cells are not changed; the cons cell that originally 
  3092. contained the element a in list still has a in its car after sorting, but it 
  3093. now appears in a different position in the list due to the change of cdrs.  For 
  3094. example: 
  3095.  
  3096. (setq nums '(1 3 2 6 5 4 0))
  3097.      => (1 3 2 6 5 4 0)
  3098. (sort nums '<)
  3099.      => (0 1 2 3 4 5 6)
  3100. nums
  3101.      => (1 2 3 4 5 6)
  3102.  
  3103. Note that the list in nums no longer contains 0; this is the same cons cell 
  3104. that it was before, but it is no longer the first one in the list.  Don't 
  3105. assume a variable that formerly held the argument now holds the entire sorted 
  3106. list!  Instead, save the result of sort and use that.  Most often we store the 
  3107. result back into the variable that held the original list: 
  3108.  
  3109. (setq nums (sort nums '<))
  3110.  
  3111.  See Sorting, for more functions that perform sorting. See documentation in 
  3112. Accessing Documentation, for a useful example of sort. 
  3113.  
  3114.  See delq, in Sets And Lists, for another function that modifies cons cells. 
  3115.  
  3116.  
  3117. ΓòÉΓòÉΓòÉ 8.7. Using Lists as Sets ΓòÉΓòÉΓòÉ
  3118.  
  3119.  A list can represent an unordered mathematical set---simply consider a value 
  3120. an element of a set if it appears in the list, and ignore the order of the 
  3121. list.  To form the union of two sets, use append (as long as you don't mind 
  3122. having duplicate elements).  Two other useful functions for sets are memq and 
  3123. delq. 
  3124.  
  3125. Common Lisp note: Common Lisp has functions union (which avoids duplicate 
  3126. elements) and intersection for set operations, but GNU Emacs Lisp does not have 
  3127. them.  You can write them in Lisp if you wish. 
  3128.  
  3129. -- Function: memq object list 
  3130.  This function tests to see whether object is a member of list.  If it is, memq 
  3131. returns a list starting with the first occurrence of object.  Otherwise, it 
  3132. returns nil. The letter `q' in memq says that it uses eq to compare object 
  3133. against the elements of the list.  For example: 
  3134.  
  3135. (memq 2 '(1 2 3 2 1))
  3136.      => (2 3 2 1)
  3137. (memq '(2) '((1) (2)))   ; (2) and (2) are not eq.
  3138.      => nil
  3139.  
  3140. -- Function: delq object list 
  3141.  This function removes all elements eq to object from list. 
  3142.  
  3143. Elements at the front of the list are removed (when necessary) simply by 
  3144. advancing down the list and returning a sublist that starts after those 
  3145. elements: 
  3146.  
  3147. (delq 'a '(a b c))
  3148. ==
  3149. (cdr '(a b c))
  3150.  
  3151. When an element to be deleted appears in the middle of the list, removing it 
  3152. involves changing the cdrs (see Setcdr). 
  3153.  
  3154. (setq sample-list '(1 2 3 (4)))
  3155.      => (1 2 3 (4))
  3156. (delq 1 sample-list)
  3157.      => (2 3 (4))
  3158. sample-list
  3159.      => (1 2 3 (4))
  3160. (delq 2 sample-list)
  3161.      => (1 3 (4))
  3162. sample-list
  3163.      => (1 3 (4))
  3164.  
  3165. Note that (delq 2 sample-list) removes the second element of sample-list, but 
  3166. (delq 1 sample-list) does not remove the first element---it just returns a 
  3167. shorter list.  Don't assume that a variable which formerly held the argument 
  3168. list now has fewer elements, or that it still holds the original list! 
  3169. Instead, save the result of delq and use that.  Most often we store the result 
  3170. back into the variable that held the original list: 
  3171.  
  3172. (setq flowers (delq 'rose flowers))
  3173.  
  3174. In the following example, the (4) that delq attempts to match and the (4) in 
  3175. the sample-list are not eq: 
  3176.  
  3177. (delq '(4) sample-list)
  3178.      => (1 3 (4))
  3179.  
  3180.  
  3181. ΓòÉΓòÉΓòÉ 8.8. Association Lists ΓòÉΓòÉΓòÉ
  3182.  
  3183.  An association list, or alist for short, records a mapping from keys to 
  3184. values.  It is a list of cons cells called associations: the car of each cell 
  3185. is the key, and the cdr is the associated value.  (This usage of ``key'' is not 
  3186. related to the term ``key sequence''; it means any object which can be looked 
  3187. up in a table.) 
  3188.  
  3189.  Here is an example of an alist.  The key pine is associated with the value 
  3190. cones; the key oak is associated with acorns; and the key maple is associated 
  3191. with seeds. 
  3192.  
  3193. '((pine . cones)
  3194.   (oak . acorns)
  3195.   (maple . seeds))
  3196.  
  3197.  The associated values in an alist may be any Lisp objects; so may the keys. 
  3198. For example, in the following alist, the symbol a is associated with the number 
  3199. 1, and the string "b" is associated with the list (2 3), which is the cdr of 
  3200. the alist element: 
  3201.  
  3202. ((a . 1) ("b" 2 3))
  3203.  
  3204.  Sometimes it is better to design an alist to store the associated value in the 
  3205. car of the cdr of the element.  Here is an example: 
  3206.  
  3207. '((rose red) (lily white) (buttercup yellow)))
  3208.  
  3209. Here we regard red as the value associated with rose.  One advantage of this 
  3210. method is that you can store other related information---even a list of other 
  3211. items---in the cdr of the cdr.  One disadvantage is that you cannot use rassq 
  3212. (see below) to find the element containing a given value.  When neither of 
  3213. these considerations is important, the choice is a matter of taste, as long as 
  3214. you are consistent about it for any given alist. 
  3215.  
  3216.  Note that the same alist shown above could be regarded as having the 
  3217. associated value in the cdr of the element; the the value associated with rose 
  3218. would be the list (red). 
  3219.  
  3220.  Association lists are often used to record information that you might 
  3221. otherwise keep on a stack, since new associations may be added easily to the 
  3222. front of the list.  When searching an association list for an association with 
  3223. a given key, the first one found is returned, if there is more than one. 
  3224.  
  3225.  In Emacs Lisp, it is not an error if an element of an association list is not 
  3226. a cons cell.  The alist search functions simply ignore such elements.  Many 
  3227. other versions of Lisp signal errors in such cases. 
  3228.  
  3229.  Note that property lists are similar to association lists in several respects. 
  3230. A property list behaves like an association list in which each key can occur 
  3231. only once.  See Property Lists, for a comparison of property lists and 
  3232. association lists. 
  3233.  
  3234. -- Function: assoc key alist 
  3235.  This function returns the first association for key in alist.  It compares key 
  3236. against the alist elements using equal (see Equality Predicates).  It returns 
  3237. nil if no association in alist has a car equal to key. For example: 
  3238.  
  3239. (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  3240.      => ((pine . cones) (oak . acorns) (maple . seeds))
  3241. (assoc 'oak trees)
  3242.      => (oak . acorns)
  3243. (cdr (assoc 'oak trees))
  3244.      => acorns
  3245. (assoc 'birch trees)
  3246.      => nil
  3247.  
  3248. Here is another example in which the keys and values are not symbols: 
  3249.  
  3250. (setq needles-per-cluster
  3251.       '((2 . ("Austrian Pine" "Red Pine"))
  3252.         (3 . "Pitch Pine")
  3253.         (5 . "White Pine")))
  3254.  
  3255. (cdr (assoc 3 needles-per-cluster))
  3256.      => "Pitch Pine"
  3257. (cdr (assoc 2 needles-per-cluster))
  3258.      => ("Austrian Pine" "Red Pine")
  3259.  
  3260. -- Function: assq key alist 
  3261.  This function is like assoc in that it returns the first association for key 
  3262. in alist, but it makes the comparison using eq instead of equal.  assq returns 
  3263. nil if no association in alist has a car eq to key. This function is used more 
  3264. often than assoc, since eq is faster than equal and most alists use symbols as 
  3265. keys. See Equality Predicates. 
  3266.  
  3267. (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  3268.  
  3269. (assq 'pine trees)
  3270.      => (pine . cones)
  3271.  
  3272. On the other hand, assq is not usually useful in alists where the keys may not 
  3273. be symbols: 
  3274.  
  3275. (setq leaves
  3276.       '(("simple leaves" . oak)
  3277.         ("compound leaves" . horsechestnut)))
  3278.  
  3279. (assq "simple leaves" leaves)
  3280.      => nil
  3281. (assoc "simple leaves" leaves)
  3282.      => ("simple leaves" . oak)
  3283.  
  3284. -- Function: rassq alist value 
  3285.  This function returns the first association with value value in alist.  It 
  3286. returns nil if no association in alist has a cdr eq to value. 
  3287.  
  3288.  rassq is like assq except that the cdr of the alist associations is tested 
  3289. instead of the car.  You can think of this as ``reverse assq'', finding the key 
  3290. for a given value. 
  3291.  
  3292.  For example: 
  3293.  
  3294. (setq trees '((pine . cones) (oak . acorns) (maple . seeds)))
  3295.  
  3296. (rassq 'acorns trees)
  3297.      => (oak . acorns)
  3298. (rassq 'spores trees)
  3299.      => nil
  3300.  
  3301. Note that rassq cannot be used to search for a value stored in the car of the 
  3302. cdr of an element: 
  3303.  
  3304. (setq colors '((rose red) (lily white) (buttercup yellow)))
  3305.  
  3306. (rassq 'white colors)
  3307.      => nil
  3308.  
  3309. In this case, the cdr of the association (lily white) is not the symbol white, 
  3310. but rather the list (white).  This can be seen more clearly if the association 
  3311. is written in dotted pair notation: 
  3312.  
  3313. (lily white) == (lily . (white))
  3314.  
  3315. -- Function: copy-alist alist 
  3316. This function returns a two-level deep copy of alist: it creates a new copy of 
  3317. each association, so that you can alter the associations of the new alist 
  3318. without changing the old one. 
  3319.  
  3320. (setq needles-per-cluster
  3321.       '((2 . ("Austrian Pine" "Red Pine"))
  3322.         (3 . "Pitch Pine")
  3323.         (5 . "White Pine")))
  3324. =>
  3325. ((2 "Austrian Pine" "Red Pine")
  3326.  (3 . "Pitch Pine")
  3327.  (5 . "White Pine"))
  3328.  
  3329. (setq copy (copy-alist needles-per-cluster))
  3330. =>
  3331. ((2 "Austrian Pine" "Red Pine")
  3332.  (3 . "Pitch Pine")
  3333.  (5 . "White Pine"))
  3334.  
  3335. (eq needles-per-cluster copy)
  3336.      => nil
  3337. (equal needles-per-cluster copy)
  3338.      => t
  3339. (eq (car needles-per-cluster) (car copy))
  3340.      => nil
  3341. (cdr (car (cdr needles-per-cluster)))
  3342.      => "Pitch Pine"
  3343. (eq (cdr (car (cdr needles-per-cluster)))
  3344.     (cdr (car (cdr copy))))
  3345.      => t
  3346.  
  3347.  
  3348. ΓòÉΓòÉΓòÉ 9. Sequences, Arrays, and Vectors ΓòÉΓòÉΓòÉ
  3349.  
  3350.  Recall that the sequence type is the union of three other Lisp types: lists, 
  3351. vectors, and strings.  In other words, any list is a sequence, any vector is a 
  3352. sequence, and any string is a sequence.  The common property that all sequences 
  3353. have is that each is an ordered collection of elements. 
  3354.  
  3355.  An array is a single primitive object directly containing all its elements. 
  3356. Therefore, all the elements are accessible in constant time.  The length of an 
  3357. existing array cannot be changed.  Both strings and vectors are arrays.  A list 
  3358. is a sequence of elements, but it is not a single primitive object; it is made 
  3359. of cons cells, one cell per element.  Therefore, elements farther from the 
  3360. beginning of the list take longer to access, but it is possible to add elements 
  3361. to the list or remove elements.  The elements of vectors and lists may be any 
  3362. Lisp objects.  The elements of strings are all characters. 
  3363.  
  3364.  The following diagram shows the relationship between these types: 
  3365.  
  3366.             ___________________________________
  3367.            |                                   |
  3368.            |          Sequence                 |
  3369.            |  ______   ______________________  |
  3370.            | |      | |                      | |
  3371.            | | List | |         Array        | |
  3372.            | |      | |  ________   _______  | |
  3373.            | |______| | |        | |       | | |
  3374.            |          | | String | | Vector| | |
  3375.            |          | |________| |_______| | |
  3376.            |          |______________________| |
  3377.            |___________________________________|
  3378.  
  3379.          The  Relationship  between  Sequences ,  Arrays ,  and  Vectors
  3380.  
  3381.  
  3382. ΓòÉΓòÉΓòÉ 9.1. Sequences ΓòÉΓòÉΓòÉ
  3383.  
  3384.  In Emacs Lisp, a sequence is either a list, a vector or a string.  The common 
  3385. property that all sequences have is that each is an ordered collection of 
  3386. elements.  This section describes functions that accept any kind of sequence. 
  3387.  
  3388. -- Function: sequencep object 
  3389. Returns t if object is a list, vector, or string, nil otherwise. 
  3390.  
  3391. -- Function: copy-sequence sequence 
  3392. Returns a copy of sequence.  The copy is the same type of object as the 
  3393. original sequence, and it has the same elements in the same order. 
  3394.  
  3395. Storing a new element into the copy does not affect the original sequence, and 
  3396. vice versa.  However, the elements of the new sequence are not copies; they are 
  3397. identical (eq) to the elements of the original.  Therefore, changes made within 
  3398. these elements, as found via the copied sequence, are also visible in the 
  3399. original sequence. 
  3400.  
  3401. See also append in Building Lists, concat in Creating Strings, and vconcat in 
  3402. Vectors, for others ways to copy sequences. 
  3403.  
  3404. (setq bar '(1 2))
  3405.      => (1 2)
  3406. (setq x (vector 'foo bar))
  3407.      => [foo (1 2)]
  3408. (setq y (copy-sequence x))
  3409.      => [foo (1 2)]
  3410.  
  3411. (eq x y)
  3412.      => nil
  3413. (equal x y)
  3414.      => t
  3415. (eq (elt x 1) (elt y 1))
  3416.      => t
  3417.  
  3418. ;; Replacing an element of one sequence.
  3419. (aset x 0 'quux)
  3420. x => [quux (1 2)]
  3421. y => [foo (1 2)]
  3422.  
  3423. ;; Modifying the inside of a shared element.
  3424. (setcar (aref x 1) 69)
  3425. x => [quux (69 2)]
  3426. y => [foo (69 2)]
  3427.  
  3428. -- Function: length sequence 
  3429. Returns the number of elements in sequence.  If sequence is a cons cell that is 
  3430. not a list (because the final cdr is not nil), a wrong-type-argument error is 
  3431. signaled. 
  3432.  
  3433. (length '(1 2 3))
  3434.     => 3
  3435. (length nil)
  3436.     => 0
  3437. (length "foobar")
  3438.     => 6
  3439. (length [1 2 3])
  3440.     => 3
  3441.  
  3442. -- Function: elt sequence index 
  3443. This function returns the element of sequence indexed by index.  Legitimate 
  3444. values of index are integers ranging from 0 up to one less than the length of 
  3445. sequence; other values produce an args-out-of-range error. 
  3446.  
  3447. (elt [1 2 3 4] 2)
  3448.      => 3
  3449. (elt '(1 2 3 4) 2)
  3450.      => 3
  3451. (char-to-string (elt "1234" 2))
  3452.      => "3"
  3453. (elt [1 2 3 4] 4)
  3454.      error-->Args out of range: [1 2 3 4], 4
  3455. (elt [1 2 3 4] -1)
  3456.      error-->Args out of range: [1 2 3 4], -1
  3457.  
  3458. This function duplicates aref (see Array Functions) and nth (see List 
  3459. Elements), except that it works for any kind of sequence. 
  3460.  
  3461.  
  3462. ΓòÉΓòÉΓòÉ 9.2. Arrays ΓòÉΓòÉΓòÉ
  3463.  
  3464.  An array object refers directly to a number of other Lisp objects, called the 
  3465. elements of the array.  Any element of an array may be accessed in constant 
  3466. time.  In contrast, an element of a list requires access time that is 
  3467. proportional to the position of the element in the list. 
  3468.  
  3469.  When you create an array, you must specify how many elements it has. The 
  3470. amount of space allocated depends on the number of elements. Therefore, it is 
  3471. impossible to change the size of an array once it is created.  You cannot add 
  3472. or remove elements.  However, you can replace an element with a different 
  3473. value. 
  3474.  
  3475.  Emacs defines two types of array, both of which are one-dimensional: strings 
  3476. and vectors.  A vector is a general array; its elements can be any Lisp 
  3477. objects.  A string is a specialized array; its elements must be characters 
  3478. (i.e., integers between 0 and 255).  Each type of array has its own read 
  3479. syntax.  See String Type, and Vector Type. 
  3480.  
  3481.  Both kinds of arrays share these characteristics: 
  3482.  
  3483. o The first element of an array has index zero, the second element has index 1, 
  3484.   and so on.  This is called zero-origin indexing.  For example, an array of 
  3485.   four elements has indices 0, 1, 2, and 3. 
  3486.  
  3487. o The elements of an array may be referenced or changed with the functions aref 
  3488.   and aset, respectively (see Array Functions). 
  3489.  
  3490.  In principle, if you wish to have an array of characters, you could use either 
  3491. a string or a vector.  In practice, we always choose strings for such 
  3492. applications, for three reasons: 
  3493.  
  3494. o They occupy one-fourth the space of a vector of the same elements. 
  3495.  
  3496. o Strings are printed in a way that shows the contents more clearly as 
  3497.   characters. 
  3498.  
  3499. o Many of the specialized editing and I/O facilities of Emacs accept only 
  3500.   strings.  For example, you cannot insert a vector of characters into a buffer 
  3501.   the way you can insert a string.  See Strings and Characters. 
  3502.  
  3503.  
  3504. ΓòÉΓòÉΓòÉ 9.3. Functions that Operate on Arrays ΓòÉΓòÉΓòÉ
  3505.  
  3506.  In this section, we describe the functions that accept both strings and 
  3507. vectors. 
  3508.  
  3509. -- Function: arrayp object 
  3510. This function returns t if object is an array (i.e., either a vector or a 
  3511. string). 
  3512.  
  3513. (arrayp [a])
  3514. => t
  3515. (arrayp "asdf")
  3516. => t
  3517.  
  3518. -- Function: aref array index 
  3519. This function returns the indexth element of array.  The first element is at 
  3520. index zero. 
  3521.  
  3522. (setq primes [2 3 5 7 11 13])
  3523.      => [2 3 5 7 11 13]
  3524. (aref primes 4)
  3525.      => 11
  3526. (elt primes 4)
  3527.      => 11
  3528.  
  3529. (aref "abcdefg" 1)
  3530.      => 98           ; `b' is ASCII code 98.
  3531.  
  3532. See also the function elt, in Sequence Functions. 
  3533.  
  3534. -- Function: aset array index object 
  3535. This function sets the indexth element of array to be object.  It returns 
  3536. object. 
  3537.  
  3538. (setq w [foo bar baz])
  3539.      => [foo bar baz]
  3540. (aset w 0 'fu)
  3541.      => fu
  3542. w
  3543.      => [fu bar baz]
  3544.  
  3545. (setq x "asdfasfd")
  3546.      => "asdfasfd"
  3547. (aset x 3 ?Z)
  3548.      => 90
  3549. x
  3550.      => "asdZasfd"
  3551.  
  3552. If array is a string and object is not a character, a wrong-type-argument error 
  3553. results. 
  3554.  
  3555. -- Function: fillarray array object 
  3556. This function fills the array array with pointers to object, replacing any 
  3557. previous values.  It returns array. 
  3558.  
  3559. (setq a [a b c d e f g])
  3560.      => [a b c d e f g]
  3561. (fillarray a 0)
  3562.      => [0 0 0 0 0 0 0]
  3563. a
  3564.      => [0 0 0 0 0 0 0]
  3565. (setq s "When in the course")
  3566.      => "When in the course"
  3567. (fillarray s ?-)
  3568.      => "------------------"
  3569.  
  3570. If array is a string and object is not a character, a wrong-type-argument error 
  3571. results. 
  3572.  
  3573. The general sequence functions copy-sequence and length are often useful for 
  3574. objects known to be arrays.  See Sequence Functions. 
  3575.  
  3576.  
  3577. ΓòÉΓòÉΓòÉ 9.4. Vectors ΓòÉΓòÉΓòÉ
  3578.  
  3579.  Arrays in Lisp, like arrays in most languages, are blocks of memory whose 
  3580. elements can be accessed in constant time.  A vector is a general-purpose 
  3581. array; its elements can be any Lisp objects.  (The other kind of array provided 
  3582. in Emacs Lisp is the string, whose elements must be characters.)  The main uses 
  3583. of vectors in Emacs are as syntax tables (vectors of integers) and keymaps 
  3584. (vectors of commands).  They are also used internally as part of the 
  3585. representation of a byte-compiled function; if you print such a function, you 
  3586. will see a vector in it. 
  3587.  
  3588.  The indices of the elements of a vector are numbered starting with zero in 
  3589. Emacs Lisp. 
  3590.  
  3591.  Vectors are printed with square brackets surrounding the elements in their 
  3592. order.  Thus, a vector containing the symbols a, b and c is printed as [a b c]. 
  3593. You can write vectors in the same way in Lisp input. 
  3594.  
  3595.  A vector, like a string or a number, is considered a constant for evaluation: 
  3596. the result of evaluating it is the same vector.  The elements of the vector are 
  3597. not evaluated.  See Self-Evaluating Forms. 
  3598.  
  3599.  Here are examples of these principles: 
  3600.  
  3601. (setq avector [1 two '(three) "four" [five]])
  3602.      => [1 two (quote (three)) "four" [five]]
  3603. (eval avector)
  3604.      => [1 two (quote (three)) "four" [five]]
  3605. (eq avector (eval avector))
  3606.      => t
  3607.  
  3608.  Here are some functions that relate to vectors: 
  3609.  
  3610. -- Function: vectorp object 
  3611. This function returns t if object is a vector. 
  3612.  
  3613. (vectorp [a])
  3614.      => t
  3615. (vectorp "asdf")
  3616.      => nil
  3617.  
  3618. -- Function: vector &rest objects 
  3619. This function creates and returns a vector whose elements are the arguments, 
  3620. objects. 
  3621.  
  3622. (vector 'foo 23 [bar baz] "rats")
  3623.      => [foo 23 [bar baz] "rats"]
  3624. (vector)
  3625.      => []
  3626.  
  3627. -- Function: make-vector integer object 
  3628. This function returns a new vector consisting of integer elements, each 
  3629. initialized to object. 
  3630.  
  3631. (setq sleepy (make-vector 9 'Z))
  3632.      => [Z Z Z Z Z Z Z Z Z]
  3633.  
  3634. -- Function: vconcat &rest sequences 
  3635. This function returns a new vector containing all the elements of the 
  3636. sequences.  The arguments sequences may be lists, vectors, or strings.  If no 
  3637. sequences are given, an empty vector is returned. 
  3638.  
  3639. The value is a newly constructed vector that is not eq to any existing vector. 
  3640.  
  3641. (setq a (vconcat '(A B C) '(D E F)))
  3642.      => [A B C D E F]
  3643. (eq a (vconcat a))
  3644.      => nil
  3645. (vconcat)
  3646.      => []
  3647. (vconcat [A B C] "aa" '(foo (6 7)))
  3648.      => [A B C 97 97 foo (6 7)]
  3649.  
  3650. When an argument is an integer (not a sequence of integers), it is converted to 
  3651. a string of digits making up the decimal printed representation of the integer. 
  3652. This special case exists for compatibility with Mocklisp, and we don't 
  3653. recommend you take advantage of it.  If you want to convert an integer in this 
  3654. way, use format (see Formatting Strings) or int-to-string ( see String 
  3655. Conversion). 
  3656.  
  3657. For other concatenation functions, see mapconcat in Mapping Functions, concat 
  3658. in Creating Strings, and append in Building Lists. 
  3659.  
  3660.  The append function may be used to convert a vector into a list with the same 
  3661. elements (see Building Lists): 
  3662.  
  3663. (setq avector [1 two (quote (three)) "four" [five]])
  3664.      => [1 two (quote (three)) "four" [five]]
  3665. (append avector nil)
  3666.      => (1 two (quote (three)) "four" [five])
  3667.  
  3668.  
  3669. ΓòÉΓòÉΓòÉ 10. Symbols ΓòÉΓòÉΓòÉ
  3670.  
  3671.  A symbol is an object with a unique name.  This chapter describes symbols, 
  3672. their components, and how they are created and interned.  Property lists are 
  3673. also described.  The uses of symbols as variables and as function names are 
  3674. described in separate chapters; see Variables, and Functions. 
  3675.  
  3676.  You may test whether an arbitrary Lisp object is a symbol with symbolp: 
  3677.  
  3678. -- Function: symbolp object 
  3679.  This function returns t if object is a symbol, nil otherwise. 
  3680.  
  3681.  
  3682. ΓòÉΓòÉΓòÉ 10.1. Symbol Components ΓòÉΓòÉΓòÉ
  3683.  
  3684.  Each symbol has four components (or ``cells''), each of which references 
  3685. another object: 
  3686.  
  3687. Print name 
  3688.           The print name cell holds a string which names the symbol for reading 
  3689.           and printing.  See symbol-name in Creating Symbols. 
  3690.  
  3691. Value 
  3692.           The value cell holds the current value of the symbol as a variable. 
  3693.           When a symbol is used as a form, the value of the form is the 
  3694.           contents of the symbol's value cell.  See symbol-value in Accessing 
  3695.           Variables. 
  3696.  
  3697. Function 
  3698.           The function cell holds the function definition of the symbol. When a 
  3699.           symbol is used as a function, its function definition is used in its 
  3700.           place.  This cell is also used by the editor command loop to record 
  3701.           keymaps and keyboard macros.  Because each symbol has separate value 
  3702.           and function cells, variables and function names do not conflict. 
  3703.           See symbol-function in Function Cells. 
  3704.  
  3705. Property list 
  3706.           The property list cell holds the property list of the symbol.  See 
  3707.           symbol-plist in Property Lists. 
  3708.  
  3709.  The print name cell always holds a string, and cannot be changed.  The other 
  3710. three cells can be set individually to any specified Lisp object. 
  3711.  
  3712.  The print name cell holds the string that is the name of the symbol. Since 
  3713. symbols are represented textually by their names, it is important not to have 
  3714. two symbols with the same name.  The Lisp reader ensures this: every time it 
  3715. reads a symbol, it looks for an existing symbol with the specified name before 
  3716. it creates a new one.  (In GNU Emacs Lisp, this is done with a hashing 
  3717. algorithm that uses an obarray; see Creating Symbols.) 
  3718.  
  3719.  In normal usage, the function cell usually contains a function or macro, as 
  3720. that is what the Lisp interpreter expects to see there (see Evaluation). 
  3721. Keyboard macros (see Keyboard Macros), keymaps (see Keymaps) and autoload 
  3722. objects (see Autoloading) are also sometimes stored in the function cell of 
  3723. symbols.  We often refer to ``the function foo'' when we really mean the 
  3724. function stored in the function cell of the symbol foo.  The distinction will 
  3725. be made only when necessary. 
  3726.  
  3727.  Similarly, the property list cell normally holds a correctly formatted 
  3728. property list (see Property Lists), as a number of functions will expect to see 
  3729. a property list there. 
  3730.  
  3731.  The function cell or the value cell may be void, which means that the cell 
  3732. does not reference any object.  (This is not the same thing as holding the 
  3733. symbol void, nor the same as holding the symbol nil.)  Examining the value of a 
  3734. cell which is void results in an error, such as `Symbol's value as variable is 
  3735. void'. 
  3736.  
  3737.  The four functions symbol-name, symbol-value, symbol-plist, and 
  3738. symbol-function return the contents of the four cells.  Here as an example we 
  3739. show the contents of the four cells of the symbol buffer-file-name: 
  3740.  
  3741. (symbol-name 'buffer-file-name)
  3742.      => "buffer-file-name"
  3743. (symbol-value 'buffer-file-name)
  3744.      => "/gnu/elisp/symbols.texi"
  3745. (symbol-plist 'buffer-file-name)
  3746.      => (variable-documentation 29529)
  3747. (symbol-function 'buffer-file-name)
  3748.      => #<subr buffer-file-name>
  3749.  
  3750. Because this symbol is the variable which holds the name of the file being 
  3751. visited in the current buffer, the value cell contents we see are the name of 
  3752. the source file of this chapter of the Emacs Lisp Manual. The property list 
  3753. cell contains the list (variable-documentation 29529) which tells the 
  3754. documentation functions where to find documentation about buffer-file-name in 
  3755. the `DOC' file. (29529 is the offset from the beginning of the `DOC' file where 
  3756. the documentation for the function begins.)  The function cell contains the 
  3757. function for returning the name of the file.  Since buffer-file-name is a 
  3758. primitive function, its function definition has no read syntax and prints in 
  3759. hash notation ( see Primitive Function Type).  A function definition written in 
  3760. Lisp will have a lambda expression (or byte-code) in this cell. 
  3761.  
  3762.  
  3763. ΓòÉΓòÉΓòÉ 10.2. Defining Symbols ΓòÉΓòÉΓòÉ
  3764.  
  3765.  A definition in Lisp is a special form that announces your intention to use a 
  3766. certain symbol in a particular way.  In Emacs Lisp, you can define a symbol as 
  3767. a variable, or define it as a function (or macro), or both independently. 
  3768.  
  3769.  A definition construct typically specifies a value or meaning for the symbol 
  3770. for one kind of use, plus documentation for its meaning when used in this way. 
  3771. Thus, when you define a symbol as a variable, you can supply an initial value 
  3772. for the variable, plus documentation for the variable. 
  3773.  
  3774.  defvar and defconst are definitions that establish a symbol as a global 
  3775. variable.  They are documented in detail in Defining Variables. 
  3776.  
  3777.  defun defines a symbol as a function, creating a lambda expression and storing 
  3778. it in the function cell of the symbol.  This lambda expression thus becomes the 
  3779. function definition of the symbol. (The term ``function definition'', meaning 
  3780. the contents of the function cell, is derived from the idea that defun gives 
  3781. the symbol its definition as a function.)  See Functions. 
  3782.  
  3783.  defmacro defines a symbol as a macro.  It creates a macro object and stores it 
  3784. in the function cell of the symbol.  Note that a given symbol can be a macro or 
  3785. a function, but not both at once, because both macro and function definitions 
  3786. are kept in the function cell, and that cell can hold only one Lisp object at 
  3787. any given time. See Macros. 
  3788.  
  3789.  In GNU Emacs Lisp, a definition is not required in order to use a symbol as a 
  3790. variable or function.  Thus, you can make a symbol a global variable with setq, 
  3791. whether you define it first or not.  The real purpose of definitions is to 
  3792. guide programmers and programming tools. They inform programmers who read the 
  3793. code that certain symbols are intended to be used as variables, or as 
  3794. functions.  In addition, utilities such as `etags' and `make-docfile' can 
  3795. recognize definitions, and add the appropriate information to tag tables and 
  3796. the `emacs/etc/DOC-version' file. See Accessing Documentation. 
  3797.  
  3798.  
  3799. ΓòÉΓòÉΓòÉ 10.3. Creating and Interning Symbols ΓòÉΓòÉΓòÉ
  3800.  
  3801.  To understand how symbols are created in GNU Emacs Lisp, it is necessary to 
  3802. know how Lisp reads them.  It is essential to ensure that every time Lisp reads 
  3803. the same set of characters, it finds the same symbol. Failure to do so would be 
  3804. disastrous. 
  3805.  
  3806.  When the Lisp reader encounters a symbol, it reads all the characters of the 
  3807. name.  Then it ``hashes'' those characters to find an index in a table called 
  3808. an obarray.  Hashing is an efficient method of looking something up.  For 
  3809. example, instead of searching a telephone book cover to cover when looking up 
  3810. Jan Jones, you start with the J's and go from there.  That is a simple version 
  3811. of hashing.  Each element of the obarray is a bucket which holds all the 
  3812. symbols with a given hash code; to look for a given name, it is sufficient to 
  3813. look through all the symbols in the bucket for that name's hash code. 
  3814.  
  3815.  If a symbol with the desired name is found, then it is used.  If no such 
  3816. symbol is found, then a new symbol is created and added to the obarray bucket. 
  3817. Adding a symbol to an obarray is called interning it, and the symbol is then 
  3818. called an interned symbol.  In Emacs Lisp, a symbol may be interned in only one 
  3819. obarray. 
  3820.  
  3821. Common Lisp note: in Common Lisp, a symbol may be interned in several obarrays 
  3822. at once. 
  3823.  
  3824.  If a symbol is not in the obarray, then there is no way for Lisp to find it 
  3825. when its name is read.  Such a symbol is called an uninterned symbol relative 
  3826. to the obarray.  An uninterned symbol has all the other characteristics of 
  3827. symbols.  It is possible, though uncommon, for two different symbols to have 
  3828. the same name in different obarrays; they are not eq or equal. 
  3829.  
  3830.  In Emacs Lisp, an obarray is represented as a vector.  Each element of the 
  3831. vector is a bucket; its value is either an interned symbol whose name hashes to 
  3832. that bucket, or 0 if the bucket is empty.  Each interned symbol has an internal 
  3833. link (invisible to the user) to the next symbol in the bucket.  Because these 
  3834. links are invisible, there is no way to scan the symbols in an obarray except 
  3835. using mapatoms (below). The order of symbols in a bucket is not significant. 
  3836.  
  3837.  In an empty obarray, every element is 0, and you can create an obarray with 
  3838. (make-vector length 0).  Prime numbers as lengths tend to result in good 
  3839. hashing; lengths one less than a power of two are also good. 
  3840.  
  3841.  Most of the functions below take a name and sometimes an obarray as arguments. 
  3842. A wrong-type-argument error is signaled if the name is not a string, or if the 
  3843. obarray is not a vector. 
  3844.  
  3845. -- Function: symbol-name symbol 
  3846. This function returns the string that is symbol's name.  For example: 
  3847.  
  3848. (symbol-name 'foo)
  3849.      => "foo"
  3850.  
  3851. Changing the string by substituting characters, etc, will change the name of 
  3852. the symbol, but will fail to update the obarray, so don't do it! 
  3853.  
  3854. -- Function: make-symbol name 
  3855. This function returns a newly-allocated uninterned symbol whose name is name 
  3856. (which must be a string).  Its value and function definition are void, and its 
  3857. property list is nil.  In the example below, the value of sym is not eq to foo 
  3858. because it is a distinct uninterned symbol whose name is also `foo'. 
  3859.  
  3860. (setq sym (make-symbol "foo"))
  3861.      => foo
  3862. (eq sym 'foo)
  3863.      => nil
  3864.  
  3865. -- Function: intern name &optional obarray 
  3866. This function returns the interned symbol whose name is name.  If there is no 
  3867. such symbol in the obarray, a new one is created, added to the obarray, and 
  3868. returned.  If obarray is supplied, it specifies the obarray to use; otherwise, 
  3869. the value of the global variable obarray is used. 
  3870.  
  3871. (setq sym (intern "foo"))
  3872.      => foo
  3873. (eq sym 'foo)
  3874.      => t
  3875.  
  3876. -- Function: intern-soft name &optional obarray 
  3877.  This function returns the symbol whose name is name, or nil if a symbol with 
  3878. that name is not found in the obarray.  Therefore, you can use intern-soft to 
  3879. test whether a symbol with a given name is interned.  If obarray is supplied, 
  3880. it specifies the obarray to use; otherwise the value of the global variable 
  3881. obarray is used. 
  3882.  
  3883. (intern-soft "frazzle")                ; No such symbol exists.
  3884.      => nil
  3885. (make-symbol "frazzle")                ; Create an uninterned one.
  3886.      => frazzle
  3887. (intern-soft "frazzle")                ; That one cannot be found.
  3888.      => nil
  3889. (setq sym (intern "frazzle"))          ; Create an interned one.
  3890.      => frazzle
  3891. (intern-soft "frazzle")                ; That one can be found!
  3892.      => frazzle
  3893. (eq sym 'frazzle)                      ; And it is the same one.
  3894.      => t
  3895.  
  3896. -- Variable: obarray 
  3897.  This variable is the standard obarray for use by intern and read. 
  3898.  
  3899. -- Function: mapatoms function &optional obarray 
  3900. This function applies function to every symbol in obarray. It returns nil.  If 
  3901. obarray is not supplied, it defaults to the value of obarray, the standard 
  3902. obarray for ordinary symbols. 
  3903.  
  3904. (setq count 0)
  3905.      => 0
  3906. (defun count-syms (s)
  3907.   (setq count (1+ count)))
  3908.      => count-syms
  3909. (mapatoms 'count-syms)
  3910.      => nil
  3911. count
  3912.      => 1871
  3913.  
  3914. See documentation in Accessing Documentation, for another example using 
  3915. mapatoms. 
  3916.  
  3917.  
  3918. ΓòÉΓòÉΓòÉ 10.4. Property Lists ΓòÉΓòÉΓòÉ
  3919.  
  3920.  A property list (plist for short) is a list of paired elements stored in the 
  3921. property list cell of a symbol.  Each of the pairs associates a property name 
  3922. (usually a symbol) with a property or value.  Property lists are generally used 
  3923. to record information about a symbol, such as how to compile it, the name of 
  3924. the file where it was defined, or perhaps even the grammatical class of the 
  3925. symbol (representing a word) in a language understanding system. 
  3926.  
  3927.  The property names and property values may be any Lisp objects, but the names 
  3928. are usually symbols.  They are compared using eq.  Here is an example of a 
  3929. property list, found on the symbol progn when the compiler is loaded: 
  3930.  
  3931. (lisp-indent-hook 0 byte-compile byte-compile-progn)
  3932.  
  3933. Here lisp-indent-hook and byte-compile are property names, and the other two 
  3934. elements are the corresponding values. 
  3935.  
  3936.  Association lists (see Association Lists) are very similar to property lists. 
  3937. In contrast to association lists, the order of the pairs in the property list 
  3938. is not significant since the property names must be distinct. 
  3939.  
  3940.  Property lists are better than association lists when it is necessary to 
  3941. attach information to various Lisp function names or variables.  If all the 
  3942. pairs are recorded in one association list, it will be necessary to search that 
  3943. entire list each time a function or variable is to be operated on.  By 
  3944. contrast, if the information is recorded in the property lists of the function 
  3945. names or variables themselves, each search will scan only the length of one 
  3946. property list, which is usually short.  For this reason, the documentation for 
  3947. a variable is recorded in a property named variable-documentation.  The byte 
  3948. compiler likewise uses properties to record those functions needing special 
  3949. treatment. 
  3950.  
  3951.  However, association lists have their own advantages.  Depending on your 
  3952. application, it may be faster to add an association to the front of an 
  3953. association list than to update a property.  All properties for a symbol are 
  3954. stored in the same property list, so there is a possibility of a conflict 
  3955. between different uses of a property name.  (For this reason, it is a good idea 
  3956. to use property names that are probably unique, such as by including the name 
  3957. of the library in the property name.)  An association list may be used like a 
  3958. stack where associations are pushed on the front of the list and later 
  3959. discarded; this is not possible with a property list. 
  3960.  
  3961. -- Function: symbol-plist symbol 
  3962. This function returns the property list of symbol. 
  3963.  
  3964. -- Function: setplist symbol plist 
  3965.  This function sets symbol's property list to plist. Normally, plist should be 
  3966. a well-formed property list, but this is not enforced. 
  3967.  
  3968. (setplist 'foo '(a 1 b (2 3) c nil))
  3969.      => (a 1 b (2 3) c nil)
  3970. (symbol-plist 'foo)
  3971.      => (a 1 b (2 3) c nil)
  3972.  
  3973. For symbols in special obarrays, which are not used for ordinary purposes, it 
  3974. may make sense to use the property list cell in a nonstandard fashion; in fact, 
  3975. the abbrev mechanism does so (see Abbrevs). 
  3976.  
  3977. -- Function: get symbol property 
  3978. This function finds the value of the property named property in symbol's 
  3979. property list.  If there is no such property, nil is returned.  Thus, there is 
  3980. no distinction between a value of nil and the absence of the property. 
  3981.  
  3982. The name property is compared with the existing property names using eq, so any 
  3983. object is a legitimate property. 
  3984.  
  3985. See put for an example. 
  3986.  
  3987. -- Function: put symbol property value 
  3988. This function puts value onto symbol's property list under the property name 
  3989. property, replacing any previous value. 
  3990.  
  3991. (put 'fly 'verb 'transitive)
  3992.      =>'transitive
  3993. (put 'fly 'noun '(a buzzing little bug))
  3994.      => (a buzzing little bug)
  3995. (get 'fly 'verb)
  3996.      => transitive
  3997. (symbol-plist 'fly)
  3998.      => (verb transitive noun (a buzzing little bug))
  3999.  
  4000.  
  4001. ΓòÉΓòÉΓòÉ 11. Evaluation ΓòÉΓòÉΓòÉ
  4002.  
  4003.  The evaluation of expressions in Emacs Lisp is performed by the Lisp 
  4004. interpreter---a program that receives a Lisp object as input and computes its 
  4005. value as an expression.  The value is computed in a fashion that depends on the 
  4006. data type of the object, following rules described in this chapter.  The 
  4007. interpreter runs automatically to evaluate portions of your program, but can 
  4008. also be called explicitly via the Lisp primitive function eval. 
  4009.  
  4010.  
  4011. ΓòÉΓòÉΓòÉ 11.1. Introduction to Evaluation ΓòÉΓòÉΓòÉ
  4012.  
  4013.  The Lisp interpreter, or evaluator, is the program which computes the value of 
  4014. an expression which is given to it.  When a function written in Lisp is called, 
  4015. the evaluator computes the value of the function by evaluating the expressions 
  4016. in the function body.  Thus, running any Lisp program really means running the 
  4017. Lisp interpreter. 
  4018.  
  4019.  How the evaluator handles an object depends primarily on the data type of the 
  4020. object. 
  4021.  
  4022.  A Lisp object which is intended for evaluation is called an expression or a 
  4023. form.  The fact that expressions are data objects and not merely text is one of 
  4024. the fundamental differences between Lisp-like languages and typical programming 
  4025. languages.  Any object can be evaluated, but in practice only numbers, symbols, 
  4026. lists and strings are evaluated very often. 
  4027.  
  4028.  It is very common to read a Lisp expression and then evaluate the expression, 
  4029. but reading and evaluation are separate activities, and either can be performed 
  4030. alone.  Reading per se does not evaluate anything; it converts the printed 
  4031. representation of a Lisp object to the object itself.  It is up to the caller 
  4032. of read whether this object is a form to be evaluated, or serves some entirely 
  4033. different purpose.  See Input Functions. 
  4034.  
  4035.  Do not confuse evaluation with command key interpretation.  The editor command 
  4036. loop translates keyboard input into a command (an interactively callable 
  4037. function) using the current keymaps, and then uses call-interactively to invoke 
  4038. the command.  The execution of the command itself involves evaluation if the 
  4039. command is written in Lisp, but that is not a part of command key 
  4040. interpretation itself. See Command Loop. 
  4041.  
  4042.  Evaluation is a recursive process.  That is, evaluation of a form may cause 
  4043. eval to be called again in order to evaluate parts of the form.  For example, 
  4044. evaluation of a function call first evaluates each argument of the function 
  4045. call, and then evaluates each form in the function body.  Consider evaluation 
  4046. of the form (car x): the subform x must first be evaluated recursively, so that 
  4047. its value can be passed as an argument to the function car. 
  4048.  
  4049.  The evaluation of forms takes place in a context called the environment, which 
  4050. consists of the current values and bindings of all Lisp variables.  Whenever 
  4051. the form refers to a variable without creating a new binding for it, the value 
  4052. of the current binding is used. See Variables. 
  4053.  
  4054.  Evaluation of a form may create new environments for recursive evaluation by 
  4055. binding variables (see Local Variables).  These environments are temporary and 
  4056. will be gone by the time evaluation of the form is complete.  The form may also 
  4057. make changes that persist; these changes are called side-effects.  An example 
  4058. of a form that produces side-effects is (setq foo 1). 
  4059.  
  4060.  Finally, evaluation of one particular function call, byte-code, invokes the 
  4061. byte-code interpreter on its arguments.  Although the byte-code interpreter is 
  4062. not the same as the Lisp interpreter, it uses the same environment as the Lisp 
  4063. interpreter, and may on occasion invoke the Lisp interpreter.  (See Byte 
  4064. Compilation.) 
  4065.  
  4066.  The details of what evaluation means for each kind of form are described below 
  4067. (see Forms). 
  4068.  
  4069.  
  4070. ΓòÉΓòÉΓòÉ 11.2. Eval ΓòÉΓòÉΓòÉ
  4071.  
  4072.  Most often, forms are evaluated automatically, by virtue of their occurrence 
  4073. in a program being run.  On rare occasions, you may need to write code that 
  4074. evaluates a form that is computed at run time, such as when the form is read 
  4075. from text being edited or found on a property list.  On these occasions, use 
  4076. the eval function. 
  4077.  
  4078.   The functions and variables described in this section evaluate forms, specify 
  4079. limits to the evaluation process, or record recently returned values. 
  4080. Evaluation is also performed by load (see Loading). 
  4081.  
  4082. -- Function: eval form 
  4083.  This is the basic function for performing evaluation.  It evaluates form in 
  4084. the current environment and returns the result.  How the evaluation proceeds 
  4085. depends on the type of the object (see Forms). 
  4086.  
  4087.  Since eval is a function, the argument expression that appears in a call to 
  4088. eval is evaluated twice: once as preparation before eval is called, and again 
  4089. by the eval function itself. Here is an example: 
  4090.  
  4091. (setq foo 'bar)
  4092.      => bar
  4093. (setq bar 'baz)
  4094.      => baz
  4095. ;; eval is called on the form bar, which is the value of foo
  4096. (eval foo)
  4097.      => baz
  4098.  
  4099.  The number of currently active calls to eval is limited to 
  4100. max-lisp-eval-depth. 
  4101.  
  4102. -- Command: eval-current-buffer &optional stream 
  4103.  This function evaluates the forms in the current buffer.  It reads forms from 
  4104. the buffer and calls eval on them until the end of the buffer is reached, or 
  4105. until an error is signaled and not handled. 
  4106.  
  4107.  If stream is supplied, the variable standard-output is bound to stream during 
  4108. the evaluation ( see Output Functions). 
  4109.  
  4110. eval-current-buffer always returns nil. 
  4111.  
  4112. -- Command: eval-region start end &optional stream 
  4113.  This function evaluates the forms in the current buffer in the region defined 
  4114. by the positions start and end.  It reads forms from the region and calls eval 
  4115. on them until the end of the region is reached, or until an error is signaled 
  4116. and not handled. 
  4117.  
  4118.  If stream is supplied, standard-output is bound to it for the duration of the 
  4119. command. 
  4120.  
  4121. eval-region always returns nil. 
  4122.  
  4123. -- Variable: max-lisp-eval-depth 
  4124.  This variable defines the maximum depth allowed in calls to eval, apply, and 
  4125. funcall before an error is signaled (with error message "Lisp nesting exceeds 
  4126. max-lisp-eval-depth").  eval is called recursively to evaluate the arguments of 
  4127. Lisp function calls and to evaluate bodies of functions. 
  4128.  
  4129.  This limit, with the associated error when it is exceeded, is one way that 
  4130. Lisp avoids infinite recursion on an ill-defined function. 
  4131.  
  4132.  The default value of this variable is 200.  If you set it to a value less than 
  4133. 100, Lisp will reset it to 100 if the given value is reached. 
  4134.  
  4135. -- Variable: values 
  4136.  The value of this variable is a list of values returned by all expressions 
  4137. which were read from buffers (including the minibuffer), evaluated, and 
  4138. printed.  The elements are in order, most recent first. 
  4139.  
  4140. (setq x 1)
  4141.      => 1
  4142. (list 'A (1+ 2) auto-save-default)
  4143.      => (A 3 t)
  4144. values
  4145.      => ((A 3 t) 1 ...)
  4146.  
  4147. This variable is useful for referring back to values of forms recently 
  4148. evaluated.  It is generally a bad idea to print the value of values itself, 
  4149. since this may be very long.  Instead, examine particular elements, like this: 
  4150.  
  4151. ;; Refer to the most recent evaluation result.
  4152. (nth 0 values)
  4153.      => (A 3 t)
  4154. ;; That put a new element on, so all elements move back one.
  4155. (nth 1 values)
  4156.      => (A 3 t)
  4157. ;; This gets the element that was next-to-last before this example.
  4158. (nth 3 values)
  4159.      => 1
  4160.  
  4161.  
  4162. ΓòÉΓòÉΓòÉ 11.3. Kinds of Forms ΓòÉΓòÉΓòÉ
  4163.  
  4164.  A Lisp object that is intended to be evaluated is called a form. How Emacs 
  4165. evaluates a form depends on its data type.  Emacs has three different kinds of 
  4166. form that are evaluated differently: symbols, lists, and ``all other types''. 
  4167. All three kinds are described in this section, starting with ``all other 
  4168. types'' which are self-evaluating forms. 
  4169.  
  4170.  
  4171. ΓòÉΓòÉΓòÉ 11.3.1. Self-Evaluating Forms ΓòÉΓòÉΓòÉ
  4172.  
  4173.  A self-evaluating form is any form that is not a list or symbol. 
  4174. Self-evaluating forms evaluate to themselves: the result of evaluation is the 
  4175. same object that was evaluated.  Thus, the number 25 evaluates to 25, and the 
  4176. string "foo" evaluates to the string "foo". Likewise, evaluation of a vector 
  4177. does not cause evaluation of the elements of the vector---it returns the same 
  4178. vector with its contents unchanged. 
  4179.  
  4180. '123               ; An object, shown without evaluation.
  4181.      => 123
  4182. 123                ; Evaluated as usual---result is the same.
  4183.      => 123
  4184. (eval '123)        ; Evaluated ``by hand''---result is the same.
  4185.      => 123
  4186. (eval (eval '123)) ; Evaluating twice changes nothing.
  4187.      => 123
  4188.  
  4189.  It is common to write numbers, characters, strings, and even vectors in Lisp 
  4190. code, taking advantage of the fact that they self-evaluate. However, it is 
  4191. quite unusual to do this for types that lack a read syntax, because it is 
  4192. inconvenient and not very useful; however, it is possible to put them inside 
  4193. Lisp programs when they are constructed from subexpressions rather than read. 
  4194. Here is an example: 
  4195.  
  4196. ;; Build such an expression.
  4197. (setq buffer (list 'print (current-buffer)))
  4198.      => (print #<buffer eval.texi>)
  4199. ;; Evaluate it.
  4200. (eval buffer)
  4201.      -| #<buffer eval.texi>
  4202.      => #<buffer eval.texi>
  4203.  
  4204.  
  4205. ΓòÉΓòÉΓòÉ 11.3.2. Symbol Forms ΓòÉΓòÉΓòÉ
  4206.  
  4207.  When a symbol is evaluated, it is treated as a variable.  The result is the 
  4208. variable's value, if it has one.  If it has none (if its value cell is void), 
  4209. an error is signaled.  For more information on the use of variables, see 
  4210. Variables. 
  4211.  
  4212.  In the following example, the value of a symbol is set with setq.  When the 
  4213. symbol is later evaluated, that value is returned. 
  4214.  
  4215. (setq a 123)
  4216.      => 123
  4217. (eval 'a)
  4218.      => 123
  4219. a
  4220.      => 123
  4221.  
  4222.  The symbols nil and t are treated specially, so that the value of nil is 
  4223. always nil, and the value of t is always t.  Thus, these two symbols act like 
  4224. self-evaluating forms, even though eval treats them like any other symbol. 
  4225.  
  4226.  
  4227. ΓòÉΓòÉΓòÉ 11.3.3. Classification of List Forms ΓòÉΓòÉΓòÉ
  4228.  
  4229.  A form that is a nonempty list is either a function call, a macro call, or a 
  4230. special form, according to its first element.  These three kinds of forms are 
  4231. evaluated in different ways, described below.  The rest of the list consists of 
  4232. arguments for the function, macro or special form. 
  4233.  
  4234.  The first step in evaluating a nonempty list is to examine its first element. 
  4235. This element alone determines what kind of form the list is and how the rest of 
  4236. the list is to be processed.  The first element is not evaluated, as it would 
  4237. be in some Lisp dialects including Scheme. 
  4238.  
  4239.  If the first element of the list is a symbol, as it most commonly is, then the 
  4240. symbol's function cell is examined, and its contents are used instead of the 
  4241. original symbol.  If the contents are another symbol, this process, called 
  4242. symbol function indirection, is repeated until a non-symbol is obtained. 
  4243.  
  4244.  One possible consequence of this process is an infinite loop, in the event 
  4245. that a symbol's function cell refers to the same symbol.  Or a symbol may have 
  4246. a void function cell, causing a void-function error.  But if neither of these 
  4247. things happens, we eventually obtain a non-symbol, which ought to be a function 
  4248. or other suitable object. 
  4249.  
  4250.  More precisely, we should now have a Lisp function (a lambda expression), a 
  4251. primitive function, a Lisp macro, a special form, or an autoload object.  Each 
  4252. of these types is a case described in one of the following sections.  If the 
  4253. object is not one of these types, the error invalid-function is signaled. 
  4254.  
  4255.  The following example illustrates the symbol indirection process.  We use fset 
  4256. to set the function cell of a symbol and symbol-function to get the function 
  4257. cell contents (see Function Cells).  Specifically, we store the symbol car into 
  4258. the function cell of first, and the symbol first into the function cell of 
  4259. erste. 
  4260.  
  4261. ;; Build this function cell linkage:
  4262. ;;    -------------       -----        -------        -------
  4263. ;;   | #<subr car> | <-- | car |  <-- | first |  <-- | erste |
  4264. ;;    -------------       -----        -------        -------
  4265.  
  4266. (symbol-function 'car)
  4267.      => #<subr car>
  4268. (fset 'first 'car)
  4269.      => car
  4270. (fset 'erste 'first)
  4271.      => first
  4272. (erste '(1 2 3))           ; Call the function referenced by erste.
  4273.      => 1
  4274.  
  4275.  By contrast, the following example calls a function without any symbol 
  4276. function indirection, because the first element is an anonymous Lisp function, 
  4277. not a symbol. 
  4278.  
  4279. ((lambda (arg) (erste arg))
  4280.  '(1 2 3))
  4281.      => 1
  4282.  
  4283. After that function is called, its body is evaluated; this does involve symbol 
  4284. function indirection when calling erste. 
  4285.  
  4286.  
  4287. ΓòÉΓòÉΓòÉ 11.3.4. Evaluation of Function Forms ΓòÉΓòÉΓòÉ
  4288.  
  4289.  If the first element of a list being evaluated is a Lisp function object or 
  4290. primitive function object, then that list is a function call.  For example, 
  4291. here is a call to the function +: 
  4292.  
  4293. (+ 1 x)
  4294.  
  4295.  When a function call is evaluated, the first step is to evaluate the remaining 
  4296. elements of the list in the order they appear.  The results are the actual 
  4297. argument values, one argument from each element.  Then the function is called 
  4298. with this list of arguments, effectively using the function apply (see Calling 
  4299. Functions).  If the function is written in Lisp, the arguments are used to bind 
  4300. the argument variables of the function (see Lambda Expressions); then the forms 
  4301. in the function body are evaluated in order, and the result of the last one is 
  4302. used as the value of the function call. 
  4303.  
  4304.  
  4305. ΓòÉΓòÉΓòÉ 11.3.5. Lisp Macro Evaluation ΓòÉΓòÉΓòÉ
  4306.  
  4307.  If the first element of a list being evaluated is a macro object, then the 
  4308. list is a macro call.  When a macro call is evaluated, the elements of the rest 
  4309. of the list are not initially evaluated. Instead, these elements themselves are 
  4310. used as the arguments of the macro.  The macro definition computes a 
  4311. replacement form, called the expansion of the macro, which is evaluated in 
  4312. place of the original form.  The expansion may be any sort of form: a 
  4313. self-evaluating constant, a symbol or a list.  If the expansion is itself a 
  4314. macro call, this process of expansion repeats until some other sort of form 
  4315. results. 
  4316.  
  4317.  Normally, the argument expressions are not evaluated as part of computing the 
  4318. macro expansion, but instead appear as part of the expansion, so they are 
  4319. evaluated when the expansion is evaluated. 
  4320.  
  4321.  For example, given a macro defined as follows: 
  4322.  
  4323. (defmacro cadr (x)
  4324.   (list 'car (list 'cdr x)))
  4325.  
  4326. an expression such as (cadr (assq 'handler list)) is a macro call, and its 
  4327. expansion is: 
  4328.  
  4329. (car (cdr (assq 'handler list)))
  4330.  
  4331. Note that the argument (assq 'handler list) appears in the expansion. 
  4332.  
  4333. See Macros, for a complete description of Emacs Lisp macros. 
  4334.  
  4335.  
  4336. ΓòÉΓòÉΓòÉ 11.3.6. Special Forms ΓòÉΓòÉΓòÉ
  4337.  
  4338.  A special form is a primitive function specially marked so that its arguments 
  4339. are not all evaluated.  Special forms define control structures or perform 
  4340. variable bindings---things which functions cannot do. 
  4341.  
  4342.  Each special form has its own rules for which arguments are evaluated and 
  4343. which are used without evaluation.  Whether a particular argument is evaluated 
  4344. may depend on the results of evaluating other arguments. 
  4345.  
  4346.  Here is a list, in alphabetical order, of all of the special forms in Emacs 
  4347. Lisp with a reference to where each is described. 
  4348.  
  4349. and 
  4350.           see Combining Conditions 
  4351.  
  4352. catch 
  4353.           see Catch and Throw 
  4354.  
  4355. cond 
  4356.           see Conditionals 
  4357.  
  4358. condition-case 
  4359.           see Errors 
  4360.  
  4361. defconst 
  4362.           see Defining Variables 
  4363.  
  4364. defmacro 
  4365.           see Defining Macros 
  4366.  
  4367. defun 
  4368.           see Defining Functions 
  4369.  
  4370. defvar 
  4371.           see Defining Variables 
  4372.  
  4373. function 
  4374.           see Anonymous Functions 
  4375.  
  4376. if 
  4377.           see Conditionals 
  4378.  
  4379. interactive 
  4380.           see Interactive Call 
  4381.  
  4382. let 
  4383.           see Local Variables 
  4384.  
  4385. let* 
  4386.           see Local Variables 
  4387.  
  4388. or 
  4389.           see Combining Conditions 
  4390.  
  4391. prog1 
  4392.           see Sequencing 
  4393.  
  4394. prog2 
  4395.           see Sequencing 
  4396.  
  4397. progn 
  4398.           see Sequencing 
  4399.  
  4400. quote 
  4401.           see Quoting 
  4402.  
  4403. save-excursion 
  4404.           see Excursions 
  4405.  
  4406. save-restriction 
  4407.           see Narrowing 
  4408.  
  4409. save-window-excursion 
  4410.           see Window Configurations 
  4411.  
  4412. setq 
  4413.           see Setting Variables 
  4414.  
  4415. setq-default 
  4416.           see Creating Buffer-Local 
  4417.  
  4418. unwind-protect 
  4419.           see Nonlocal Exits 
  4420.  
  4421. while 
  4422.           see Iteration 
  4423.  
  4424. with-output-to-temp-buffer 
  4425.           see Temporary Displays 
  4426.  
  4427. Common Lisp note: here are some comparisons of special forms in GNU Emacs Lisp 
  4428. and Common Lisp.  setq, if, and catch are special forms in both Emacs Lisp and 
  4429. Common Lisp. defun is a special form in Emacs Lisp, but a macro in Common Lisp. 
  4430. save-excursion is a special form in Emacs Lisp, but doesn't exist in Common 
  4431. Lisp.  throw is a special form in Common Lisp (because it must be able to throw 
  4432. multiple values), but it is a function in Emacs Lisp (which doesn't have 
  4433. multiple values). 
  4434.  
  4435.  
  4436. ΓòÉΓòÉΓòÉ 11.3.7. Autoloading ΓòÉΓòÉΓòÉ
  4437.  
  4438.  The autoload feature allows you to call a function or macro whose function 
  4439. definition has not yet been loaded into Emacs.  When an autoload object appears 
  4440. as a symbol's function definition and that symbol is used as a function, Emacs 
  4441. will automatically install the real definition (plus other associated code) and 
  4442. then call that definition. (See Autoload.) 
  4443.  
  4444.  
  4445. ΓòÉΓòÉΓòÉ 11.4. Quoting ΓòÉΓòÉΓòÉ
  4446.  
  4447.  The special form quote returns its single argument ``unchanged''. 
  4448.  
  4449. -- Special Form: quote object 
  4450. This special form returns object, without evaluating it.  This allows symbols 
  4451. and lists, which would normally be evaluated, to be included literally in a 
  4452. program.  (It is not necessary to quote numbers, strings, and vectors since 
  4453. they are self-evaluating.)  Use function instead of quote when quoting lambda 
  4454. expressions (see Anonymous Functions). 
  4455.  
  4456. Because quote is used so often in programs, a convenient read syntax is defined 
  4457. for it.  An apostrophe character (`'') followed by a Lisp object (in read 
  4458. syntax) expands to a list whose first element is quote, and whose second 
  4459. element is the object.  Thus, the read syntax 'x is an abbreviation for (quote 
  4460. x). 
  4461.  
  4462. Here are some examples of expressions that use quote: 
  4463.  
  4464. (quote (+ 1 2))
  4465.      => (+ 1 2)
  4466. (quote foo)
  4467.      => foo
  4468. 'foo
  4469.      => foo
  4470. ''foo
  4471.      => (quote foo)
  4472. '(quote foo)
  4473.      => (quote foo)
  4474. ['foo]
  4475.      => [(quote foo)]
  4476.  
  4477.  
  4478. ΓòÉΓòÉΓòÉ 12. Control Structures ΓòÉΓòÉΓòÉ
  4479.  
  4480.  A Lisp program consists of expressions or forms (see Forms). We control the 
  4481. order of execution of the forms by enclosing them in control structures. 
  4482. Control structures are special forms which control when, whether, or how many 
  4483. times to execute the forms they contain. 
  4484.  
  4485.  The simplest control structure is sequential execution: first form a, then 
  4486. form b, and so on.  This is what happens when you write several forms in 
  4487. succession in the body of a function, or at top level in a file of Lisp 
  4488. code---the forms are executed in the order they are written.  We call this 
  4489. textual order.  For example, if a function body consists of two forms a and b, 
  4490. evaluation of the function evaluates first a and then b, and the function's 
  4491. value is the value of b. 
  4492.  
  4493.  Naturally, Emacs Lisp has many kinds of control structures, including other 
  4494. varieties of sequencing, function calls, conditionals, iteration, and 
  4495. (controlled) jumps.  The built-in control structures are special forms since 
  4496. their subforms are not necessarily evaluated.  You can use macros to define 
  4497. your own control structure constructs (see Macros). 
  4498.  
  4499.  
  4500. ΓòÉΓòÉΓòÉ 12.1. Sequencing ΓòÉΓòÉΓòÉ
  4501.  
  4502.  Evaluating forms in the order they are written is the most common control 
  4503. structure.  Sometimes this happens automatically, such as in a function body. 
  4504. Elsewhere you must use a control structure construct to do this: progn, the 
  4505. simplest control construct of Lisp. 
  4506.  
  4507.  A progn special form looks like this: 
  4508.  
  4509. (progn a b c ...)
  4510.  
  4511. and it says to execute the forms a, b, c and so on, in that order.  These forms 
  4512. are called the body of the progn form. The value of the last form in the body 
  4513. becomes the value of the entire progn. 
  4514.  
  4515.  When Lisp was young, progn was the only way to execute two or more forms in 
  4516. succession and use the value of the last of them.  But programmers found they 
  4517. often needed to use a progn in the body of a function, where (at that time) 
  4518. only one form was allowed.  So the body of a function was made into an 
  4519. ``implicit progn'': several forms are allowed just as in the body of an actual 
  4520. progn.  Many other control structures likewise contain an implicit progn.  As a 
  4521. result, progn is not used as often as it used to be.  It is needed now most 
  4522. often inside of an unwind-protect, and, or or. 
  4523.  
  4524. -- Special Form: progn forms... 
  4525. This special form evaluates all of the forms, in textual order, returning the 
  4526. result of the final form. 
  4527.  
  4528. (progn (print "The first form")
  4529.        (print "The second form")
  4530.        (print "The third form"))
  4531.      -| "The first form"
  4532.      -| "The second form"
  4533.      -| "The third form"
  4534. => "The third form"
  4535.  
  4536.  Two other control constructs likewise evaluate a series of forms but return a 
  4537. different value: 
  4538.  
  4539. -- Special Form: prog1 form1 forms... 
  4540. This special form evaluates form1 and all of the forms, in textual order, 
  4541. returning the result of form1. 
  4542.  
  4543. (prog1 (print "The first form")
  4544.        (print "The second form")
  4545.        (print "The third form"))
  4546.      -| "The first form"
  4547.      -| "The second form"
  4548.      -| "The third form"
  4549. => "The first form"
  4550.  
  4551. Here is a way to remove the first element from a list in the variable x, then 
  4552. return the value of that former element: 
  4553.  
  4554. (prog1 (car x) (setq x (cdr x)))
  4555.  
  4556. -- Special Form: prog2 form1 form2 forms... 
  4557. This special form evaluates form1, form2, and all of the following forms, in 
  4558. textual order, returning the result of form2. 
  4559.  
  4560. (prog2 (print "The first form")
  4561.        (print "The second form")
  4562.        (print "The third form"))
  4563.      -| "The first form"
  4564.      -| "The second form"
  4565.      -| "The third form"
  4566. => "The second form"
  4567.  
  4568.  
  4569. ΓòÉΓòÉΓòÉ 12.2. Conditionals ΓòÉΓòÉΓòÉ
  4570.  
  4571.  Conditional control structures choose among alternatives.  Emacs Lisp has two 
  4572. conditional forms: if, which is much the same as in other languages, and cond, 
  4573. which is a generalized case statement. 
  4574.  
  4575. -- Special Form: if condition then-form else-forms... 
  4576. if chooses between the then-form and the else-forms based on the value of 
  4577. condition.  If the evaluated condition is non-nil, then-form is evaluated and 
  4578. the result returned. Otherwise, the else-forms are evaluated in textual order, 
  4579. and the value of the last one is returned.  (The else part of if is an example 
  4580. of an implicit progn.  See Sequencing.) 
  4581.  
  4582. If condition has the value nil, and no else-forms are given, if returns nil. 
  4583.  
  4584. if is a special form because the branch which is not selected is never 
  4585. evaluated---it is ignored.  Thus, in the example below, true is not printed 
  4586. because print is never called. 
  4587.  
  4588. (if nil
  4589.     (print 'true)
  4590.   'very-false)
  4591. => very-false
  4592.  
  4593. -- Special Form: cond clause... 
  4594. cond chooses among an arbitrary number of alternatives.  Each clause in the 
  4595. cond must be a list.  The car of this list is the condition; the remaining 
  4596. elements, if any, the body-forms.  Thus, a clause looks like this: 
  4597.  
  4598. (condition body-forms...)
  4599.  
  4600. cond tries the clauses in textual order, by evaluating the condition of each 
  4601. clause.  If the value of condition is non-nil, the body-forms are evaluated, 
  4602. and the value of the last of body-forms becomes the value of the cond.  The 
  4603. remaining clauses are ignored. 
  4604.  
  4605. If the value of condition is nil, the clause ``fails'', so the cond moves on to 
  4606. the following clause, trying its condition. 
  4607.  
  4608. If every condition evaluates to nil, so that every clause fails, cond returns 
  4609. nil. 
  4610.  
  4611. A clause may also look like this: 
  4612.  
  4613. (condition)
  4614.  
  4615. Then, if condition is non-nil when tested, the value of condition becomes the 
  4616. value of the cond form. 
  4617.  
  4618. The following example has four clauses, which test for the cases where the 
  4619. value of x is a number, string, buffer and symbol, respectively: 
  4620.  
  4621. (cond ((numberp x) x)
  4622.        ((stringp x) x)
  4623.        ((bufferp x)
  4624.         (setq temporary-hack x) ; multiple body-forms
  4625.         (buffer-name x))        ; in one clause
  4626.        ((symbolp x) (symbol-value x)))
  4627.  
  4628. Often we want the last clause to be executed whenever none of the previous 
  4629. clauses was successful.  To do this, we use t as the condition of the last 
  4630. clause, like this: (t body-forms).  The form t evaluates to t, which is never 
  4631. nil, so this clause never fails, provided the cond gets to it at all. 
  4632.  
  4633. For example, 
  4634.  
  4635. (cond ((eq a 1) 'foo)
  4636.       (t "default"))
  4637. => "default"
  4638.  
  4639. This expression is a cond which returns foo if the value of a is 1, and returns 
  4640. the string "default" otherwise. 
  4641.  
  4642. Both cond and if can usually be written in terms of the other.  Therefore, the 
  4643. choice between them is a matter of taste and style.  For example: 
  4644.  
  4645. (if a b c)
  4646. ==
  4647. (cond (a b) (t c))
  4648.  
  4649.  
  4650. ΓòÉΓòÉΓòÉ 12.3. Constructs for Combining Conditions ΓòÉΓòÉΓòÉ
  4651.  
  4652.  This section describes three constructs that are often used together with if 
  4653. and cond to express complicated conditions.  The constructs and and or can also 
  4654. be used individually as kinds of multiple conditional constructs. 
  4655.  
  4656. -- Function: not condition 
  4657. This function tests for the falsehood of condition.  It returns t if condition 
  4658. is nil, and nil otherwise. The function not is identical to null, and we 
  4659. recommend using null if you are testing for an empty list. 
  4660.  
  4661. -- Special Form: and conditions... 
  4662. The and special form tests whether all the conditions are true.  It works by 
  4663. evaluating the conditions one by one in the order written. 
  4664.  
  4665. If any of the conditions evaluates to nil, then the result of the and must be 
  4666. nil regardless of the remaining conditions; so the remaining conditions are 
  4667. ignored and the and returns right away. 
  4668.  
  4669. If all the conditions turn out non-nil, then the value of the last of them 
  4670. becomes the value of the and form. 
  4671.  
  4672. Here is an example.  The first condition returns the integer 1, which is not 
  4673. nil.  Similarly, the second condition returns the integer 2, which is not nil. 
  4674. The third condition is nil, so the remaining condition is never evaluated. 
  4675.  
  4676. (and (print 1) (print 2) nil (print 3))
  4677.      -| 1
  4678.      -| 2
  4679. => nil
  4680.  
  4681. Here is a more realistic example of using and: 
  4682.  
  4683. (if (and (consp foo) (eq (car foo) 'x))
  4684.     (message "foo is a list starting with x"))
  4685.  
  4686. Note that (car foo) is not executed if (consp foo) returns nil, thus avoiding 
  4687. an error. 
  4688.  
  4689. and can be expressed in terms of either if or cond. For example: 
  4690.  
  4691. (and arg1 arg2 arg3)
  4692. ==
  4693. (if arg1 (if arg2 arg3))
  4694. ==
  4695. (cond (arg1 (cond (arg2 arg3))))
  4696.  
  4697. -- Special Form: or conditions... 
  4698. The or special form tests whether at least one of the conditions is true.  It 
  4699. works by evaluating all the conditions one by one in the order written. 
  4700.  
  4701. If any of the conditions evaluates to a non-nil value, then the result of the 
  4702. or must be non-nil; so the remaining conditions are ignored and the or returns 
  4703. right away.  The value it returns is the non-nil value of the condition just 
  4704. evaluated. 
  4705.  
  4706. If all the conditions turn out nil, then the or expression returns nil. 
  4707.  
  4708. For example, this expression tests whether x is either 0 or nil: 
  4709.  
  4710. (or (eq x nil) (= x 0))
  4711.  
  4712. Like the and construct, or can be written in terms of cond.  For example: 
  4713.  
  4714. (or arg1 arg2 arg3)
  4715. ==
  4716. (cond (arg1)
  4717.       (arg2)
  4718.       (arg3))
  4719.  
  4720. You could almost write or in terms of if, but not quite: 
  4721.  
  4722. (if arg1 arg1
  4723.   (if arg2 arg2
  4724.     arg3))
  4725.  
  4726. This is not completely equivalent because it can evaluate arg1 or arg2 twice. 
  4727. By contrast, (or arg1 arg2 arg3) never evaluates any argument more than once. 
  4728.  
  4729.  
  4730. ΓòÉΓòÉΓòÉ 12.4. Iteration ΓòÉΓòÉΓòÉ
  4731.  
  4732.  Iteration means executing part of a program repetitively.  For example, you 
  4733. might want to repeat some expressions once for each element of a list, or once 
  4734. for each integer from 0 to n.  You can do this in Emacs Lisp with the special 
  4735. form while: 
  4736.  
  4737. -- Special Form: while condition forms... 
  4738. while first evaluates condition.  If the result is non-nil, it evaluates forms 
  4739. in textual order.  Then it reevaluates condition, and if the result is non-nil, 
  4740. it evaluates forms again.  This process repeats until condition evaluates to 
  4741. nil. 
  4742.  
  4743. There is no limit on the number of iterations that may occur.  The loop will 
  4744. continue until either condition evaluates to nil or until an error or throw 
  4745. jumps out of it (see Nonlocal Exits). 
  4746.  
  4747. The value of a while form is always nil. 
  4748.  
  4749. (setq num 0)
  4750.      => 0
  4751. (while (< num 4)
  4752.   (princ (format "Iteration %d." num))
  4753.   (setq num (1+ num)))
  4754.      -| Iteration 0.
  4755.      -| Iteration 1.
  4756.      -| Iteration 2.
  4757.      -| Iteration 3.
  4758.      => nil
  4759.  
  4760. If you would like to execute something on each iteration before the end-test, 
  4761. put it together with the end-test in a progn as the first argument of while, as 
  4762. shown here: 
  4763.  
  4764. (while (progn
  4765.          (forward-line 1)
  4766.          (not (looking-at "^$"))))
  4767.  
  4768. This moves forward one line and continues moving by lines until an empty line 
  4769. is reached. 
  4770.  
  4771.  
  4772. ΓòÉΓòÉΓòÉ 12.5. Nonlocal Exits ΓòÉΓòÉΓòÉ
  4773.  
  4774.  A nonlocal exit is a transfer of control from one point in a program to 
  4775. another remote point.  Nonlocal exits can occur in Emacs Lisp as a result of 
  4776. errors; you can also use them under explicit control. 
  4777.  
  4778.  
  4779. ΓòÉΓòÉΓòÉ 12.5.1. Explicit Nonlocal Exits: catch and throw ΓòÉΓòÉΓòÉ
  4780.  
  4781.  Most control constructs affect only the flow of control within the construct 
  4782. itself.  The function throw is the sole exception: it performs a nonlocal exit 
  4783. on request.  throw is used inside a catch, and jumps back to that catch.  For 
  4784. example: 
  4785.  
  4786. (catch 'foo
  4787.   (progn
  4788.     ...
  4789.       (throw 'foo t)
  4790.     ...))
  4791.  
  4792. The throw transfers control straight back to the corresponding catch, which 
  4793. returns immediately.  The code following the throw is not executed.  The second 
  4794. argument of throw is used as the return value of the catch. 
  4795.  
  4796.  The throw and the catch are matched through the first argument: throw searches 
  4797. for a catch whose first argument is eq to the one specified.  Thus, in the 
  4798. above example, the throw specifies foo, and the catch specifies the same 
  4799. symbol, so that catch is applicable.  If there is more than one applicable 
  4800. catch, the innermost one takes precedence. 
  4801.  
  4802.  All Lisp constructs between the catch and the throw, including function calls, 
  4803. are exited automatically along with the catch.  When binding constructs such as 
  4804. let or function calls are exited in this way, the bindings are unbound, just as 
  4805. they are when the binding construct is exited normally (see Local Variables). 
  4806. Likewise, the buffer and position saved by save-excursion (see Excursions) are 
  4807. restored, and so is the narrowing status saved by save-restriction and the 
  4808. window selection saved by save-window-excursion (see Window Configurations). 
  4809. Any cleanups established with the unwind-protect special form are executed if 
  4810. the unwind-protect is exited with a throw. 
  4811.  
  4812.  The throw need not appear lexically within the catch that it jumps to.  It can 
  4813. equally well be called from another function called within the catch.  As long 
  4814. as the throw takes place chronologically after entry to the catch, and 
  4815. chronologically before exit from it, it has access to that catch.  This is why 
  4816. throw can be used in commands such as exit-recursive-edit which throw back to 
  4817. the editor command loop (see Recursive Editing). 
  4818.  
  4819. Common Lisp note: most other versions of Lisp, including Common Lisp, have 
  4820. several ways of transferring control nonsequentially: return, return-from, and 
  4821. go, for example.  Emacs Lisp has only throw. 
  4822.  
  4823. -- Special Form: catch tag body... 
  4824. catch establishes a return point for the throw function.  The return point is 
  4825. distinguished from other such return points by tag, which may be any Lisp 
  4826. object.  The argument tag is evaluated normally before the return point is 
  4827. established. 
  4828.  
  4829. With the return point in effect, the forms of the body are evaluated in textual 
  4830. order.  If the forms execute normally, without error or nonlocal exit, the 
  4831. value of the last body form is returned from the catch. 
  4832.  
  4833. If a throw is done within body specifying the same value tag, the catch exits 
  4834. immediately; the value it returns is whatever was specified as the second 
  4835. argument of throw. 
  4836.  
  4837. -- Function: throw tag value 
  4838. The purpose of throw is to return from a return point previously established 
  4839. with catch.  The argument tag is used to choose among the various existing 
  4840. return points; it must be eq to the value specified in the catch.  If multiple 
  4841. return points match tag, the innermost one is used. 
  4842.  
  4843. The argument value is used as the value to return from that catch. 
  4844.  
  4845. If no return point is in effect with tag tag, then a no-catch error is signaled 
  4846. with data (tag value). 
  4847.  
  4848.  
  4849. ΓòÉΓòÉΓòÉ 12.5.2. Examples of catch and throw ΓòÉΓòÉΓòÉ
  4850.  
  4851.  One way to use catch and throw is to exit from a doubly nested loop.  (In most 
  4852. languages, this would be done with a ``go to''.) Here we compute (foo i j) for 
  4853. i and j varying from 0 to 9: 
  4854.  
  4855. (defun search-foo ()
  4856.   (catch 'loop
  4857.     (let ((i 0))
  4858.       (while (< i 10)
  4859.         (let ((j 0))
  4860.           (while (< j 10)
  4861.             (if (foo i j)
  4862.                 (throw 'loop (list i j)))
  4863.             (setq j (1+ j))))
  4864.         (setq i (1+ i))))))
  4865.  
  4866. If foo ever returns non-nil, we stop immediately and return a list of i and j. 
  4867. If foo always returns nil, the catch returns normally, and the value is nil, 
  4868. since that is the result of the while. 
  4869.  
  4870.  Here are two tricky examples, slightly different, showing two return points at 
  4871. once.  First, two return points with the same tag, hack: 
  4872.  
  4873. (defun catch2 (tag)
  4874.   (catch tag
  4875.     (throw 'hack 'yes)))
  4876. => catch2
  4877.  
  4878. (catch 'hack
  4879.   (print (catch2 'hack))
  4880.   'no)
  4881. -| yes
  4882. => no
  4883.  
  4884. Since both return points have tags that match the throw, it goes to the inner 
  4885. one, the one established in catch2.  Therefore, catch2 returns normally with 
  4886. value yes, and this value is printed.  Finally the second body form in the 
  4887. outer catch, which is 'no, is evaluated and returned from the outer catch. 
  4888.  
  4889.  Now let's change the argument given to catch2: 
  4890.  
  4891. (defun catch2 (tag)
  4892.   (catch tag
  4893.     (throw 'hack 'yes)))
  4894. => catch2
  4895.  
  4896. (catch 'hack
  4897.   (print (catch2 'quux))
  4898.   'no)
  4899. => yes
  4900.  
  4901. We still have two return points, but this time only the outer one has the tag 
  4902. hack; the inner one has the tag quux instead.  Therefore, the throw returns the 
  4903. value yes from the outer return point. The function print is never called, and 
  4904. the body-form 'no is never evaluated. 
  4905.  
  4906.  
  4907. ΓòÉΓòÉΓòÉ 12.5.3. Errors ΓòÉΓòÉΓòÉ
  4908.  
  4909.  When Emacs Lisp attempts to evaluate a form that, for some reason, cannot be 
  4910. evaluated, it signals an error. 
  4911.  
  4912.  When an error is signaled, Emacs's default reaction is to print an error 
  4913. message and terminate execution of the current command.  This is the right 
  4914. thing to do in most cases, such as if you type C-f at the end of the buffer. 
  4915.  
  4916.  In complicated programs, simple termination may not be what you want. For 
  4917. example, the program may have made temporary changes in data structures, or 
  4918. created temporary buffers which should be deleted before the program is 
  4919. finished.  In such cases, you would use unwind-protect to establish cleanup 
  4920. expressions to be evaluated in case of error.  Occasionally, you may wish the 
  4921. program to continue execution despite an error in a subroutine.  In these 
  4922. cases, you would use condition-case to establish error handlers to recover 
  4923. control in case of error. 
  4924.  
  4925.  Resist the temptation to use error handling to transfer control from one part 
  4926. of the program to another; use catch and throw. See Catch and Throw. 
  4927.  
  4928.  
  4929. ΓòÉΓòÉΓòÉ 12.5.3.1. How to Signal an Error ΓòÉΓòÉΓòÉ
  4930.  
  4931.  Most errors are signaled ``automatically'' within Lisp primitives which you 
  4932. call for other purposes, such as if you try to take the car of an integer or 
  4933. move forward a character at the end of the buffer; you can also signal errors 
  4934. explicitly with the functions error and signal. 
  4935.  
  4936. -- Function: error format-string &rest args 
  4937. This function signals an error with an error message constructed by applying 
  4938. format (see String Conversion) to format-string and args. 
  4939.  
  4940. Typical uses of error is shown in the following examples: 
  4941.  
  4942. (error "You have committed an error.  Try something else.")
  4943.      error--> You have committed an error.  Try something else.
  4944.  
  4945. (error "You have committed %d errors.  You don't learn fast." 10)
  4946.      error--> You have committed 10 errors.  You don't learn fast.
  4947.  
  4948. error works by calling signal with two arguments: the error symbol error, and a 
  4949. list containing the string returned by format. 
  4950.  
  4951. If you want to use a user-supplied string as an error message verbatim, don't 
  4952. just write (error string).  If string contains `%', it will be interpreted as a 
  4953. format specifier, with undesirable results.  Instead, use (error "%s" string). 
  4954.  
  4955. -- Function: signal error-symbol data 
  4956. This function signals an error named by error-symbol.  The argument data is a 
  4957. list of additional Lisp objects relevant to the circumstances of the error. 
  4958.  
  4959. The argument error-symbol must be an error symbol---a symbol that has an 
  4960. error-conditions property whose value is a list of condition names.  This is 
  4961. how different sorts of errors are classified. 
  4962.  
  4963. The number and significance of the objects in data depends on error-symbol. 
  4964. For example, with a wrong-type-arg error, there are two objects in the list: a 
  4965. predicate which describes the type that was expected, and the object which 
  4966. failed to fit that type. See Error Names, for a description of error symbols. 
  4967.  
  4968. Both error-symbol and data are available to any error handlers which handle the 
  4969. error: a list (error-symbol . data) is constructed to become the value of the 
  4970. local variable bound in the condition-case form (see Handling Errors).  If the 
  4971. error is not handled, both of them are used in printing the error message. 
  4972.  
  4973. (signal 'wrong-number-of-arguments '(x y))
  4974.      error--> Wrong number of arguments: x, y
  4975.  
  4976. (signal 'no-such-error '("My unknown error condition."))
  4977.      error--> peculiar error: "My unknown error condition."
  4978.  
  4979. Common Lisp note: Emacs Lisp has nothing like the Common Lisp concept of 
  4980. continuable errors. 
  4981.  
  4982.  
  4983. ΓòÉΓòÉΓòÉ 12.5.3.2. How Emacs Processes Errors ΓòÉΓòÉΓòÉ
  4984.  
  4985. When an error is signaled, Emacs searches for an active handler for the error. 
  4986. A handler is a specially marked place in the Lisp code of the current function 
  4987. or any of the functions by which it was called. If an applicable handler 
  4988. exists, its code is executed, and control resumes following the handler.  The 
  4989. handler executes in the environment of the condition-case which established it; 
  4990. all functions called within that condition-case have already been exited, and 
  4991. the handler cannot return to them. 
  4992.  
  4993. If no applicable handler is in effect in your program, the current command is 
  4994. terminated and control returns to the editor command loop, because the command 
  4995. loop has an implicit handler for all kinds of errors.  The command loop's 
  4996. handler uses the error symbol and associated data to print an error message. 
  4997.  
  4998. When an error is not handled explicitly, it may cause the Lisp debugger to be 
  4999. called.  The debugger is enabled if the variable debug-on-error (see Error 
  5000. Debugging) is non-nil. Unlike error handlers, the debugger runs in the 
  5001. environment of the error, so that you can examine values of variables precisely 
  5002. as they were at the time of the error. 
  5003.  
  5004.  
  5005. ΓòÉΓòÉΓòÉ 12.5.3.3. Writing Code to Handle Errors ΓòÉΓòÉΓòÉ
  5006.  
  5007.  The usual effect of signaling an error is to terminate the command that is 
  5008. running and return immediately to the Emacs editor command loop. You can 
  5009. arrange to trap errors occurring in a part of your program by establishing an 
  5010. error handler with the special form condition-case.  A simple example looks 
  5011. like this: 
  5012.  
  5013. (condition-case nil
  5014.     (delete-file filename)
  5015.   (error nil))
  5016.  
  5017. This deletes the file named filename, catching any error and returning nil if 
  5018. an error occurs. 
  5019.  
  5020.  The second argument of condition-case is called the protected form.  (In the 
  5021. example above, the protected form is a call to delete-file.)  The error 
  5022. handlers go into effect when this form begins execution and are deactivated 
  5023. when this form returns. They remain in effect for all the intervening time.  In 
  5024. particular, they are in effect during the execution of subroutines called by 
  5025. this form, and their subroutines, and so on.  This is a good thing, since, 
  5026. strictly speaking, errors can be signaled only by Lisp primitives (including 
  5027. signal and error) called by the protected form, not by the protected form 
  5028. itself. 
  5029.  
  5030.  The arguments after the protected form are handlers.  Each handler lists one 
  5031. or more condition names (which are symbols) to specify which errors it will 
  5032. handle.  The error symbol specified when an error is signaled also defines a 
  5033. list of condition names.  A handler applies to an error if they have any 
  5034. condition names in common.  In the example above, there is one handler, and it 
  5035. specifies one condition name, error, which covers all errors. 
  5036.  
  5037.  The search for an applicable handler checks all the established handlers 
  5038. starting with the most recently established one.  Thus, if two nested 
  5039. condition-case forms try to handle the same error, the inner of the two will 
  5040. actually handle it. 
  5041.  
  5042.  When an error is handled, control returns to the handler, unbinding all 
  5043. variable bindings made by binding constructs that are exited and executing the 
  5044. cleanups of all unwind-protect forms that are exited by doing so.  Then the 
  5045. body of the handler is executed.  After this, execution continues by returning 
  5046. from the condition-case form.  Because the protected form is exited completely 
  5047. before execution of the handler, the handler cannot resume execution at the 
  5048. point of the error, nor can it examine variable bindings that were made within 
  5049. the protected form.  All it can do is clean up and proceed. 
  5050.  
  5051.  Error signaling and handling have some resemblance to throw and catch, but 
  5052. they are entirely separate facilities.  An error cannot be caught by a catch, 
  5053. and a throw cannot be handled by an error handler (though if there is no catch, 
  5054. throw will signal an error which can be handled). 
  5055.  
  5056. -- Special Form: condition-case var protected-form handlers... 
  5057. This special form establishes the error handlers handlers around the execution 
  5058. of protected-form.  If protected-form executes without error, the value it 
  5059. returns becomes the value of the condition-case form; in this case, the 
  5060. condition-case has no effect.  The condition-case form makes a difference when 
  5061. an error occurs during protected-form. 
  5062.  
  5063. Each of the handlers is a list of the form (conditions body...).  conditions is 
  5064. a condition name to be handled, or a list of condition names; body is one or 
  5065. more Lisp expressions to be executed when this handler handles an error. 
  5066.  
  5067. Each error that occurs has an error symbol which describes what kind of error 
  5068. it is.  The error-conditions property of this symbol is a list of condition 
  5069. names (see Error Names).  Emacs searches all the active condition-case forms 
  5070. for a handler which specifies one or more of these names; the innermost 
  5071. matching condition-case handles the error.  The handlers in this condition-case 
  5072. are tested in the order in which they appear. 
  5073.  
  5074. The body of the handler is then executed, and the condition-case returns 
  5075. normally, using the value of the last form in the body as the overall value. 
  5076.  
  5077. The argument var is a variable.  condition-case does not bind this variable 
  5078. when executing the protected-form, only when it handles an error.  At that 
  5079. time, var is bound locally to a list of the form (error-symbol . data), giving 
  5080. the particulars of the error.  The handler can refer to this list to decide 
  5081. what to do.  For example, if the error is for failure opening a file, the file 
  5082. name is the second element of data---the third element of var. 
  5083.  
  5084. If var is nil, that means no variable is bound.  Then the error symbol and 
  5085. associated data are not made available to the handler. 
  5086.  
  5087.  Here is an example of using condition-case to handle the error that results 
  5088. from dividing by zero.  The handler prints out a warning message and returns a 
  5089. very large number. 
  5090.  
  5091. (defun safe-divide (dividend divisor)
  5092.   (condition-case err
  5093.       ;; Protected form.
  5094.       (/ dividend divisor)
  5095.     ;; The handler.
  5096.     (arith-error                        ; Condition.
  5097.      (princ (format "Arithmetic error: %s" err))
  5098.      1000000)))
  5099. => safe-divide
  5100.  
  5101. (safe-divide 5 0)
  5102.      -| Arithmetic error: (arith-error)
  5103. => 1000000
  5104.  
  5105. The handler specifies condition name arith-error so that it will handle only 
  5106. division-by-zero errors.  Other kinds of errors will not be handled, at least 
  5107. not by this condition-case.  Thus, 
  5108.  
  5109. (safe-divide nil 3)
  5110.      error--> Wrong type argument: integer-or-marker-p, nil
  5111.  
  5112.  Here is a condition-case that catches all kinds of errors, including those 
  5113. signaled with error: 
  5114.  
  5115. (setq baz 34)
  5116.      => 34
  5117.  
  5118. (condition-case err
  5119.     (if (eq baz 35)
  5120.         t
  5121.       ;; This is a call to the function error.
  5122.       (error "Rats!  The variable %s was %s, not 35." 'baz baz))
  5123.   ;; This is the handler; it is not a form.
  5124.   (error (princ (format "The error was: %s" err))
  5125.          2))
  5126.  
  5127.      -| The error was: (error "Rats!  The variable baz was 34, not 35.")
  5128.      => 2
  5129.  
  5130.  condition-case is often used to trap errors that are predictable, such as 
  5131. failure to open a file in a call to insert-file-contents.  It is also used to 
  5132. trap errors that are totally unpredictable, such as when the program evaluates 
  5133. an expression read from the user. 
  5134.  
  5135.  
  5136. ΓòÉΓòÉΓòÉ 12.5.3.4. Error Symbols and Condition Names ΓòÉΓòÉΓòÉ
  5137.  
  5138.  When you signal an error, you specify an error symbol to specify the kind of 
  5139. error you have in mind.  Each error has one and only one error symbol to 
  5140. categorize it.  This is the finest classification of errors defined by the Lisp 
  5141. language. 
  5142.  
  5143.  These narrow classifications are grouped into a hierarchy of wider classes 
  5144. called error conditions, identified by condition names.  The narrowest such 
  5145. classes belong to the error symbols themselves: each error symbol is also a 
  5146. condition name.  There are also condition names for more extensive classes, up 
  5147. to the condition name error which takes in all kinds of errors.  Thus, each 
  5148. error has one or more condition names: error, the error symbol if that is 
  5149. distinct from error, and perhaps some intermediate classifications. 
  5150.  
  5151.  In order for a symbol to be usable as an error symbol, it must have an 
  5152. error-conditions property which gives a list of condition names. This list 
  5153. defines the conditions which this kind of error belongs to. (The error symbol 
  5154. itself, and the symbol error, should always be members of this list.)  Thus, 
  5155. the hierarchy of condition names is defined by the error-conditions properties 
  5156. of the error symbols. 
  5157.  
  5158.  In addition to the error-conditions list, the error symbol should have an 
  5159. error-message property whose value is a string to be printed when that error is 
  5160. signaled but not handled.  If the error-message property exists, but is not a 
  5161. string, the error message `peculiar error' is used. 
  5162.  
  5163.  Here is how we define a new error symbol, new-error: 
  5164.  
  5165. (put 'new-error 'error-conditions '(error my-own-errors new-error))
  5166.      => (error my-own-errors new-error)
  5167. (put 'new-error 'error-message "A new error")
  5168.      => "A new error"
  5169.  
  5170. This error has three condition names: new-error, the narrowest classification; 
  5171. my-own-errors, which we imagine is a wider classification; and error, which is 
  5172. the widest of all. 
  5173.  
  5174.  Naturally, Emacs will never signal a new-error on its own; only an explicit 
  5175. call to signal (see Errors) in your code can do this: 
  5176.  
  5177. (signal 'new-error '(x y))
  5178.      error--> A new error: x, y
  5179.  
  5180.  This error can be handled through any of the three condition names. This 
  5181. example handles new-error and any other errors in the class my-own-errors: 
  5182.  
  5183. (condition-case foo
  5184.     (bar nil t)
  5185.   (my-own-errors nil))
  5186.  
  5187.  The significant way that errors are classified is by their condition 
  5188. names---the names used to match errors with handlers.  An error symbol serves 
  5189. only as a convenient way to specify the intended error message and list of 
  5190. condition names.  If signal were given a list of condition names rather than 
  5191. one error symbol, that would be cumbersome. 
  5192.  
  5193.  By contrast, using only error symbols without condition names would seriously 
  5194. decrease the power of condition-case.  Condition names make it possible to 
  5195. categorize errors at various levels of generality when you write an error 
  5196. handler.  Using error symbols alone would eliminate all but the narrowest level 
  5197. of classification. 
  5198.  
  5199.  See Standard Errors, for a list of all the standard error symbols and their 
  5200. conditions. 
  5201.  
  5202.  
  5203. ΓòÉΓòÉΓòÉ 12.5.4. Cleaning up from Nonlocal Exits ΓòÉΓòÉΓòÉ
  5204.  
  5205.  The unwind-protect construct is essential whenever you temporarily put a data 
  5206. structure in an inconsistent state; it permits you to ensure the data are 
  5207. consistent in the event of an error. 
  5208.  
  5209. -- Special Form: unwind-protect body cleanup-forms... 
  5210. unwind-protect executes the body with a guarantee that the cleanup-forms will 
  5211. be evaluated if control leaves body, no matter how that happens.  The body may 
  5212. complete normally, or execute a throw out of the unwind-protect, or cause an 
  5213. error; in all cases, the cleanup-forms will be evaluated. 
  5214.  
  5215. Only the body is actually protected by the unwind-protect. If any of the 
  5216. cleanup-forms themselves exit nonlocally (e.g., via a throw or an error), it is 
  5217. not guaranteed that the rest of them will be executed.  If the failure of one 
  5218. of the cleanup-forms has the potential to cause trouble, then it should be 
  5219. protected by another unwind-protect around that form. 
  5220.  
  5221. The number of currently active unwind-protect forms counts, together with the 
  5222. number of local variable bindings, against the limit max-specpdl-size (see 
  5223. Local Variables). 
  5224.  
  5225.  For example, here we make an invisible buffer for temporary use, and make sure 
  5226. to kill it before finishing: 
  5227.  
  5228. (save-excursion
  5229.   (let ((buffer (get-buffer-create " *temp*")))
  5230.     (set-buffer buffer)
  5231.     (unwind-protect
  5232.         body
  5233.       (kill-buffer buffer))))
  5234.  
  5235. You might think that we could just as well write (kill-buffer (current-buffer)) 
  5236. and dispense with the variable buffer. However, the way shown above is safer, 
  5237. if body happens to get an error after switching to a different buffer! 
  5238. (Alternatively, you could write another save-excursion around the body, to 
  5239. ensure that the temporary buffer becomes current in time to kill it.) 
  5240.  
  5241.  Here is an actual example taken from the file `ftp.el'.  It creates a process 
  5242. (see Processes) to try to establish a connection to a remote machine.  As the 
  5243. function ftp-login is highly susceptible to numerous problems which the writer 
  5244. of the function cannot anticipate, it is protected with a form that guarantees 
  5245. deletion of the process in the event of failure.  Otherwise, Emacs might fill 
  5246. up with useless subprocesses. 
  5247.  
  5248. (let ((win nil))
  5249.   (unwind-protect
  5250.       (progn
  5251.         (setq process (ftp-setup-buffer host file))
  5252.         (if (setq win (ftp-login process host user password))
  5253.             (message "Logged in")
  5254.           (error "Ftp login failed")))
  5255.     (or win (and process (delete-process process)))))
  5256.  
  5257.  This example actually has a small bug: if the user types C-g to quit, and the 
  5258. quit happens immediately after the function ftp-setup-buffer returns but before 
  5259. the variable process is set, the process will not be killed.  There is no easy 
  5260. way to fix this bug, but at least it is very unlikely. 
  5261.  
  5262.  
  5263. ΓòÉΓòÉΓòÉ 13. Variables ΓòÉΓòÉΓòÉ
  5264.  
  5265.  A variable is a name used in a program to stand for a value. Nearly all 
  5266. programming languages have variables of some sort.  In the text for a Lisp 
  5267. program, variables are written using the syntax for symbols. 
  5268.  
  5269.  In Lisp, unlike most programming languages, programs are represented primarily 
  5270. as Lisp objects and only secondarily as text.  The Lisp objects used for 
  5271. variables are symbols: the symbol name is the variable name, and the variable's 
  5272. value is stored in the value cell of the symbol.  The use of a symbol as a 
  5273. variable is independent of whether the same symbol has a function definition. 
  5274. See Symbol Components. 
  5275.  
  5276.  The textual form of a program is determined by its Lisp object representation; 
  5277. it is the read syntax for the Lisp object which constitutes the program.  This 
  5278. is why a variable in a textual Lisp program is written as the read syntax for 
  5279. the symbol that represents the variable. 
  5280.  
  5281.  
  5282. ΓòÉΓòÉΓòÉ 13.1. Global Variables ΓòÉΓòÉΓòÉ
  5283.  
  5284.  The simplest way to use a variable is globally.  This means that the variable 
  5285. has just one value at a time, and this value is in effect (at least for the 
  5286. moment) throughout the Lisp system.  The value remains in effect until you 
  5287. specify a new one.  When a new value replaces the old one, no trace of the old 
  5288. value remains in the variable. 
  5289.  
  5290.  You specify a value for a symbol with setq.  For example, 
  5291.  
  5292. (setq x '(a b))
  5293.  
  5294. gives the variable x the value (a b).  Note that the first argument of setq, 
  5295. the name of the variable, is not evaluated, but the second argument, the 
  5296. desired value, is evaluated normally. 
  5297.  
  5298.  Once the variable has a value, you can refer to it by using the symbol by 
  5299. itself as an expression.  Thus, 
  5300.  
  5301. x
  5302.      => (a b)
  5303.  
  5304. assuming the setq form shown above has already been executed. 
  5305.  
  5306.  If you do another setq, the new value replaces the old one: 
  5307.  
  5308. x
  5309.      => (a b)
  5310. (setq x 4)
  5311.      => 4
  5312. x
  5313.      => 4
  5314.  
  5315.  
  5316. ΓòÉΓòÉΓòÉ 13.2. Variables that Never Change ΓòÉΓòÉΓòÉ
  5317.  
  5318.  Emacs Lisp has two special symbols, nil and t, that always evaluate to 
  5319. themselves.  These symbols cannot be rebound, nor can their value cells be 
  5320. changed.  An attempt to change the value of nil or t signals a setting-constant 
  5321. error. 
  5322.  
  5323. nil == 'nil
  5324.      => nil
  5325. (setq nil 500)
  5326. error--> Attempt to set constant symbol: nil
  5327.  
  5328.  
  5329. ΓòÉΓòÉΓòÉ 13.3. Local Variables ΓòÉΓòÉΓòÉ
  5330.  
  5331.  Global variables are given values that last until explicitly superseded with 
  5332. new values.  Sometimes it is useful to create variable values that exist 
  5333. temporarily---only while within a certain part of the program.  These values 
  5334. are called local, and the variables so used are called local variables. 
  5335.  
  5336.  For example, when a function is called, its argument variables receive new 
  5337. local values which last until the function exits.  Similarly, the let special 
  5338. form explicitly establishes new local values for specified variables; these 
  5339. last until exit from the let form. 
  5340.  
  5341.  When a local value is established, the previous value (or lack of one) of the 
  5342. variable is saved away.  When the life span of the local value is over, the 
  5343. previous value is restored.  In the mean time, we say that the previous value 
  5344. is shadowed and not visible.  Both global and local values may be shadowed. 
  5345.  
  5346.  If you set a variable (such as with setq) while it is local, this replaces the 
  5347. local value; it does not alter the global value, or previous local values that 
  5348. are shadowed.  To model this behavior, we speak of a local binding of the 
  5349. variable as well as a local value. 
  5350.  
  5351.  The local binding is a conceptual place that holds a local value. Entry to a 
  5352. function, or a special form such as let, creates the local binding; exit from 
  5353. the function or from the let removes the local binding.  As long as the local 
  5354. binding lasts, the variable's value is stored within it.  Use of setq or set 
  5355. while there is a local binding stores a different value into the local binding; 
  5356. it does not create a new binding. 
  5357.  
  5358.  We also speak of the global binding, which is where (conceptually) the global 
  5359. value is kept. 
  5360.  
  5361.  A variable can have more than one local binding at a time (for example, if 
  5362. there are nested let forms that bind it).  In such a case, the most recently 
  5363. created local binding that still exists is the current binding of the variable. 
  5364. (This is called dynamic scoping; see Variable Scoping.)  If there are no local 
  5365. bindings, the variable's global binding is its current binding.  We also call 
  5366. the current binding the most-local existing binding, for emphasis. Ordinary 
  5367. evaluation of a symbol always returns the value of its current binding. 
  5368.  
  5369.  The special forms let and let* exist to create local bindings. 
  5370.  
  5371. -- Special Form: let (bindings...) forms... 
  5372. This function binds variables according to bindings and then evaluates all of 
  5373. the forms in textual order.  The let-form returns the value of the last form in 
  5374. forms. 
  5375.  
  5376. Each of the bindings is either (i) a symbol, in which case that symbol is bound 
  5377. to nil; or (ii) a list of the form (symbol value-form), in which case symbol is 
  5378. bound to the result of evaluating value-form.  If value-form is omitted, nil is 
  5379. used. 
  5380.  
  5381. All of the value-forms in bindings are evaluated in the order they appear and 
  5382. before any of the symbols are bound.  Here is an example of this: Z is bound to 
  5383. the old value of Y, which is 2, not the new value, 1. 
  5384.  
  5385. (setq Y 2)
  5386.      => 2
  5387. (let ((Y 1)
  5388.       (Z Y))
  5389.   (list Y Z))
  5390.      => (1 2)
  5391.  
  5392. -- Special Form: let* (bindings...) forms... 
  5393. This special form is like let, except that each symbol in bindings is bound as 
  5394. soon as its new value is computed, before the computation of the values of the 
  5395. following local bindings.  Therefore, an expression in bindings may reasonably 
  5396. refer to the preceding symbols bound in this let* form.  Compare the following 
  5397. example with the example above for let. 
  5398.  
  5399. (setq Y 2)
  5400.      => 2
  5401. (let* ((Y 1)
  5402.        (Z Y))    ; Use the just-established value of Y.
  5403.   (list Y Z))
  5404.      => (1 1)
  5405.  
  5406.  Here is a complete list of the other facilities which create local bindings: 
  5407.  
  5408. o Function calls (see Functions). 
  5409.  
  5410. o Macro calls (see Macros). 
  5411.  
  5412. o condition-case (see Errors). 
  5413.  
  5414. -- Variable: max-specpdl-size 
  5415.  This variable defines the limit on the number of local variable bindings and 
  5416. unwind-protect cleanups (see Nonlocal Exits) that are allowed before signaling 
  5417. an error (with data "Variable binding depth exceeds max-specpdl-size"). 
  5418.  
  5419.  This limit, with the associated error when it is exceeded, is one way that 
  5420. Lisp avoids infinite recursion on an ill-defined function. 
  5421.  
  5422.  The default value is 600. 
  5423.  
  5424.  
  5425. ΓòÉΓòÉΓòÉ 13.4. When a Variable is ``Void'' ΓòÉΓòÉΓòÉ
  5426.  
  5427.  If you have never given a symbol any value as a global variable, we say that 
  5428. that symbol's global value is void.  In other words, the symbol's value cell 
  5429. does not have any Lisp object in it.  If you try to evaluate the symbol, you 
  5430. get a void-variable error rather than a value. 
  5431.  
  5432.  Note that a value of nil is not the same as void.  The symbol nil is a Lisp 
  5433. object and can be the value of a variable just as any other object can be; but 
  5434. it is a value.  A void variable does not have any value. 
  5435.  
  5436.  After you have given a variable a value, you can make it void once more using 
  5437. makunbound. 
  5438.  
  5439. -- Function: makunbound symbol 
  5440. This function makes the current binding of symbol void.  This causes any future 
  5441. attempt to use this symbol as a variable to signal the error void-variable, 
  5442. unless or until you set it again. 
  5443.  
  5444. makunbound returns symbol. 
  5445.  
  5446. (makunbound 'x)          ; Make the global value of x void.
  5447.      => x
  5448. x
  5449. error--> Symbol's value as variable is void: x
  5450.  
  5451. If symbol is locally bound, makunbound affects the most local existing binding. 
  5452. This is the only way a symbol can have a void local binding, since all the 
  5453. constructs that create local bindings create them with values.  In this case, 
  5454. the voidness lasts at most as long as the binding does; when the binding is 
  5455. removed due to exit from the construct that made it, the previous or global 
  5456. binding is reexposed as usual, and the variable is no longer void unless the 
  5457. newly reexposed binding was void all along. 
  5458.  
  5459. (setq x 1)               ; Put a value in the global binding.
  5460.      => 1
  5461. (let ((x 2))             ; Locally bind it.
  5462.   (makunbound 'x)        ; Void the local binding.
  5463.   x)
  5464. error--> Symbol's value as variable is void: x
  5465. x                        ; The global binding is unchanged.
  5466.      => 1
  5467.  
  5468. (let ((x 2))             ; Locally bind it.
  5469.   (let ((x 3))           ; And again.
  5470.     (makunbound 'x)      ; Void the innermost-local binding.
  5471.     x))                  ; And refer: it's void.
  5472. error--> Symbol's value as variable is void: x
  5473.  
  5474. (let ((x 2))
  5475.   (let ((x 3))
  5476.     (makunbound 'x))     ; Void inner binding, then remove it.
  5477.   x)                     ; Now outer let binding is visible.
  5478.      => 2
  5479.  
  5480.  A variable that has been made void with makunbound is indistinguishable from 
  5481. one that has never received a value and has always been void. 
  5482.  
  5483.  You can use the function boundp to test whether a variable is currently void. 
  5484.  
  5485. -- Function: boundp variable 
  5486. boundp returns t if variable (a symbol) is not void; more precisely, if its 
  5487. current binding is not void.  It returns nil otherwise. 
  5488.  
  5489. (boundp 'abracadabra)                ; Starts out void.
  5490.      => nil
  5491. (let ((abracadabra 5))               ; Locally bind it.
  5492.   (boundp 'abracadabra))
  5493.      => t
  5494. (boundp 'abracadabra)                ; Still globally void.
  5495.      => nil
  5496. (setq abracadabra 5)                 ; Make it globally nonvoid.
  5497.      => 5
  5498. (boundp 'abracadabra)
  5499.      => t
  5500.  
  5501.  
  5502. ΓòÉΓòÉΓòÉ 13.5. Defining Global Variables ΓòÉΓòÉΓòÉ
  5503.  
  5504.  You may announce your intention to use a symbol as a global variable with a 
  5505. definition, using defconst or defvar. 
  5506.  
  5507.  In Emacs Lisp, definitions serve three purposes.  First, they inform the user 
  5508. who reads the code that certain symbols are intended to be used as variables. 
  5509. Second, they inform the Lisp system of these things, supplying a value and 
  5510. documentation.  Third, they provide information to utilities such as etags and 
  5511. make-docfile, which create data bases of the functions and variables in a 
  5512. program. 
  5513.  
  5514.  The difference between defconst and defvar is primarily a matter of intent, 
  5515. serving to inform human readers of whether programs will change the variable. 
  5516. Emacs Lisp does not restrict the ways in which a variable can be used based on 
  5517. defconst or defvar declarations.  However, it also makes a difference for 
  5518. initialization: defconst unconditionally initializes the variable, while defvar 
  5519. initializes it only if it is void. 
  5520.  
  5521.  One would expect user option variables to be defined with defconst, since 
  5522. programs do not change them.  Unfortunately, this has bad results if the 
  5523. definition is in a library that is not preloaded: defconst would override any 
  5524. prior value when the library is loaded.  Users would like to be able to set the 
  5525. option in their init files, and override the default value given in the 
  5526. definition.  For this reason, user options must be defined with defvar. 
  5527.  
  5528. -- Special Form: defvar symbol [value [doc-string]] 
  5529. This special form informs a person reading your code that symbol will be used 
  5530. as a variable that the programs are likely to set or change.  It is also used 
  5531. for all user option variables except in the preloaded parts of Emacs.  Note 
  5532. that symbol is not evaluated; the symbol to be defined must appear explicitly 
  5533. in the defvar. 
  5534.  
  5535. If symbol already has a value (i.e., it is not void), value is not even 
  5536. evaluated, and symbol's value remains unchanged.  If symbol is void and value 
  5537. is specified, it is evaluated and symbol is set to the result.  (If value is 
  5538. not specified, the value of symbol is not changed in any case.) 
  5539.  
  5540. If the doc-string argument appears, it specifies the documentation for the 
  5541. variable.  (This opportunity to specify documentation is one of the main 
  5542. benefits of defining the variable.)  The documentation is stored in the 
  5543. symbol's variable-documentation property.  The Emacs help functions (see 
  5544. Documentation) look for this property. 
  5545.  
  5546. If the first character of doc-string is `*', it means that this variable is 
  5547. considered to be a user option.  This affects commands such as set-variable and 
  5548. edit-options. 
  5549.  
  5550. For example, this form defines foo but does not set its value: 
  5551.  
  5552. (defvar foo)
  5553.      => foo
  5554.  
  5555. The following example sets the value of bar to 23, and gives it a documentation 
  5556. string: 
  5557.  
  5558. (defvar bar 23 "The normal weight of a bar.")
  5559.      => bar
  5560.  
  5561. The following form changes the documentation string for bar, making it a user 
  5562. option, but does not change the value, since bar already has a value.  (The 
  5563. addition (1+ 23) is not even performed.) 
  5564.  
  5565. (defvar bar (1+ 23) "*The normal weight of a bar.")
  5566.      => bar
  5567. bar
  5568.      => 23
  5569.  
  5570. Here is an equivalent expression for the defvar special form: 
  5571.  
  5572. (defvar symbol value doc-string)
  5573. ==
  5574. (progn
  5575.   (if (not (boundp 'symbol))
  5576.       (setq symbol value))
  5577.   (put 'symbol 'variable-documentation 'doc-string)
  5578.   'symbol)
  5579.  
  5580. The defvar form returns symbol, but it is normally used at top level in a file 
  5581. where its value does not matter. 
  5582.  
  5583. -- Special Form: defconst symbol [value [doc-string]] 
  5584. This special form informs a person reading your code that symbol has a global 
  5585. value, established here, that will not normally be changed or locally bound by 
  5586. the execution of the program.  The user, however, may be welcome to change it. 
  5587. Note that symbol is not evaluated; the symbol to be defined must appear 
  5588. explicitly in the defconst. 
  5589.  
  5590. defconst always evaluates value and sets the global value of symbol to the 
  5591. result, provided value is given. 
  5592.  
  5593. *Note:* don't use defconst for user option variables in libraries that are not 
  5594. normally loaded.  The user should be able to specify a value for such a 
  5595. variable in the `.emacs' file, so that it will be in effect if and when the 
  5596. library is loaded later. 
  5597.  
  5598. Here, pi is a constant that presumably ought not to be changed by anyone 
  5599. (attempts by the Indiana State Legislature notwithstanding). As the second form 
  5600. illustrates, however, this is only advisory. 
  5601.  
  5602. (defconst pi 3 "Pi to one place.")
  5603.      => pi
  5604. (setq pi 4)
  5605.      => pi
  5606. pi
  5607.      => 4
  5608.  
  5609. -- Function: user-variable-p variable 
  5610. This function returns t if variable is a user option, intended to be set by the 
  5611. user for customization, nil otherwise. (Variables other than user options exist 
  5612. for the internal purposes of Lisp programs, and users need not know about 
  5613. them.) 
  5614.  
  5615. User option variables are distinguished from other variables by the first 
  5616. character of the variable-documentation property.  If the property exists and 
  5617. is a string, and its first character is `*', then the variable is a user 
  5618. option. 
  5619.  
  5620.  Note that if the defconst and defvar special forms are used while the variable 
  5621. has a local binding, the local binding's value is set, and the global binding 
  5622. is not changed.  This would be confusing. But the normal way to use these 
  5623. special forms is at top level in a file, where no local binding should be in 
  5624. effect. 
  5625.  
  5626.  
  5627. ΓòÉΓòÉΓòÉ 13.6. Accessing Variable Values ΓòÉΓòÉΓòÉ
  5628.  
  5629.  The usual way to reference a variable is to write the symbol which names it 
  5630. (see Symbol Forms).  This requires you to specify the variable name when you 
  5631. write the program.  Usually that is exactly what you want to do.  Occasionally 
  5632. you need to choose at run time which variable to reference; then you can use 
  5633. symbol-value. 
  5634.  
  5635. -- Function: symbol-value symbol 
  5636. This function returns the value of symbol.  This is the value in the innermost 
  5637. local binding of the symbol, or its global value if it has no local bindings. 
  5638.  
  5639. (setq abracadabra 5)
  5640.      => 5
  5641. (setq foo 9)
  5642.      => 9
  5643.  
  5644. ;; Here the symbol abracadabra
  5645. ;; is the symbol whose value is examined.
  5646. (let ((abracadabra 'foo))
  5647.   (symbol-value 'abracadabra))
  5648.      => foo
  5649.  
  5650. ;; Here the value of abracadabra,
  5651. ;; which is foo,
  5652. ;; is the symbol whose value is examined.
  5653. (let ((abracadabra 'foo))
  5654.   (symbol-value abracadabra))
  5655.      => 9
  5656.  
  5657. (symbol-value 'abracadabra)
  5658.      => 5
  5659.  
  5660. A void-variable error is signaled if symbol has neither a local binding nor a 
  5661. global value. 
  5662.  
  5663.  
  5664. ΓòÉΓòÉΓòÉ 13.7. How to Alter a Variable Value ΓòÉΓòÉΓòÉ
  5665.  
  5666.  The usual way to change the value of a variable is with the special form setq. 
  5667. When you need to compute the choice of variable at run time, use the function 
  5668. set. 
  5669.  
  5670. -- Special Form: setq [symbol form]... 
  5671. This special form is the most common method of changing a variable's value. 
  5672. Each symbol is given a new value, which is the result of evaluating the 
  5673. corresponding form.  The most-local existing binding of the symbol is changed. 
  5674.  
  5675. The value of the setq form is the value of the last form. 
  5676.  
  5677. (setq x (1+ 2))
  5678.      => 3
  5679. x                     ; x now has a global value.
  5680.      => 3
  5681. (let ((x 5))
  5682.   (setq x 6)          ; The local binding of x is set.
  5683.   x)
  5684.      => 6
  5685. x                     ; The global value is unchanged.
  5686.      => 3
  5687.  
  5688. Note that the first form is evaluated, then the first symbol is set, then the 
  5689. second form is evaluated, then the second symbol is set, and so on: 
  5690.  
  5691. (setq x 10            ; Notice that x is set
  5692.       y (1+ x))       ; before the value of y is computed.
  5693.      => 11
  5694.  
  5695. -- Function: set symbol value 
  5696. This function sets symbol's value to value, then returns value.  Since set is a 
  5697. function, the expression written for symbol is evaluated to obtain the symbol 
  5698. to be set. 
  5699.  
  5700. The most-local existing binding of the variable is the binding that is set; 
  5701. shadowed bindings are not affected.  If symbol is not actually a symbol, a 
  5702. wrong-type-argument error is signaled. 
  5703.  
  5704. (set one 1)
  5705. error--> Symbol's value as variable is void: one
  5706. (set 'one 1)
  5707.      => 1
  5708. (set 'two 'one)
  5709.      => one
  5710. (set two 2)            ; two evaluates to symbol one.
  5711.      => 2
  5712. one                    ; So it is one that was set.
  5713.      => 2
  5714. (let ((one 1))         ; This binding of one is set,
  5715.   (set 'one 3)         ; not the global value.
  5716.   one)
  5717.      => 3
  5718. one
  5719.      => 2
  5720.  
  5721. Logically speaking, set is a more fundamental primitive that setq.  Any use of 
  5722. setq can be trivially rewritten to use set; setq could even be defined as a 
  5723. macro, given the availability of set.  However, set itself is rarely used; 
  5724. beginners hardly need to know about it.  It is needed only when the choice of 
  5725. variable to be set is made at run time.  For example, the command set-variable, 
  5726. which reads a variable name from the user and then sets the variable, needs to 
  5727. use set. 
  5728.  
  5729. Common Lisp note: in Common Lisp, set always changes the symbol's special 
  5730. value, ignoring any lexical bindings.  In Emacs Lisp, all variables and all 
  5731. bindings are special, so set always affects the most local existing binding. 
  5732.  
  5733.  
  5734. ΓòÉΓòÉΓòÉ 13.8. Scoping Rules for Variable Bindings ΓòÉΓòÉΓòÉ
  5735.  
  5736.  A given symbol foo may have several local variable bindings, established at 
  5737. different places in the Lisp program, as well as a global binding.  The most 
  5738. recently established binding takes precedence over the others. 
  5739.  
  5740.  Local bindings in Emacs Lisp have indefinite scope and dynamic extent.  Scope 
  5741. refers to where textually in the source code the binding can be accessed. 
  5742. Indefinite scope means that any part of the program can potentially access the 
  5743. variable binding.  Extent refers to when, as the program is executing, the 
  5744. binding exists.  Dynamic extent means that the binding lasts as long as the 
  5745. activation of the construct that established it. 
  5746.  
  5747.  The combination of dynamic extent and indefinite scope is called dynamic 
  5748. scoping.  By contrast, most programming languages use lexical scoping, in which 
  5749. references to a local variable must be textually within the function or block 
  5750. that binds the variable. 
  5751.  
  5752. Common Lisp note: variables declared ``special'' in Common Lisp are dynamically 
  5753. scoped like variables in Emacs Lisp. 
  5754.  
  5755.  
  5756. ΓòÉΓòÉΓòÉ 13.8.1. Scope ΓòÉΓòÉΓòÉ
  5757.  
  5758.  Emacs Lisp uses indefinite scope for local variable bindings. This means that 
  5759. any function anywhere in the program text might access a given binding of a 
  5760. variable.  Consider the following function definitions: 
  5761.  
  5762. (defun binder (x)  ; x is bound in binder.
  5763.    (foo 5))        ; foo is some other function.
  5764.  
  5765. (defun user ()     ; x is used in user.
  5766.   (list x))
  5767.  
  5768.  In a lexically scoped language, the binding of x from binder would never be 
  5769. accessible in user, because user is not textually contained within the function 
  5770. binder.  However, in dynamically scoped Emacs Lisp, user may or may not refer 
  5771. to the binding of x established in binder, depending on circumstances: 
  5772.  
  5773. o If we call user directly without calling binder at all, then whatever binding 
  5774.   of x is found, it cannot come from binder. 
  5775.  
  5776. o If we define foo as follows and call binder, then the binding made in binder 
  5777.   will be seen in user: 
  5778.  
  5779.     (defun foo (lose)
  5780.       (user))
  5781.  
  5782. o If we define foo as follows and call binder, then the binding made in binder 
  5783.   will not be seen in user: 
  5784.  
  5785.     (defun foo (x)
  5786.       (user))
  5787.  
  5788.   Here, when foo is called by binder, it binds x. (The binding in foo is said 
  5789.   to shadow the one made in binder.)  Therefore, user will access the x bound 
  5790.   by foo instead of the one bound by binder. 
  5791.  
  5792.  
  5793. ΓòÉΓòÉΓòÉ 13.8.2. Extent ΓòÉΓòÉΓòÉ
  5794.  
  5795.  Extent refers to the time during program execution that a variable name is 
  5796. valid.  In Emacs Lisp, a variable is valid only while the form that bound it is 
  5797. executing.  This is called dynamic extent.  ``Local'' or ``automatic'' 
  5798. variables in most languages, including C and Pascal, have dynamic extent. 
  5799.  
  5800.  One alternative to dynamic extent is indefinite extent.  This means that a 
  5801. variable binding can live on past the exit from the form that made the binding. 
  5802. Common Lisp and Scheme, for example, support this, but Emacs Lisp does not. 
  5803.  
  5804.  To illustrate this, the function below, make-add, returns a function that 
  5805. purports to add n to its own argument m. This would work in Common Lisp, but it 
  5806. does not work as intended in Emacs Lisp, because after the call to make-add 
  5807. exits, the variable n is no longer bound to the actual argument 2. 
  5808.  
  5809. (defun make-add (n)
  5810.     (function (lambda (m) (+ n m))))  ; Return a function.
  5811.      => make-add
  5812. (fset 'add2 (make-add 2))  ; Define function add2 with (make-add 2).
  5813.      => (lambda (m) (+ n m))
  5814. (add2 4)                   ; Try to add 2 to 4.
  5815. error--> Symbol's value as variable is void: n
  5816.  
  5817.  
  5818. ΓòÉΓòÉΓòÉ 13.8.3. Implementation of Dynamic Scoping ΓòÉΓòÉΓòÉ
  5819.  
  5820.  A simple sample implementation (which is not how Emacs Lisp actually works) 
  5821. may help you understand dynamic binding.  This technique is called deep binding 
  5822. and was used in early Lisp systems. 
  5823.  
  5824.  Suppose there is a stack of bindings: variable-value pairs.  At entry to a 
  5825. function or to a let form, we can push bindings on the stack for the arguments 
  5826. or local variables created there.  We can pop those bindings from the stack at 
  5827. exit from the binding construct. 
  5828.  
  5829.  We can find the value of a variable by searching the stack from top to bottom 
  5830. for a binding for that variable; the value from that binding is the value of 
  5831. the variable.  To set the variable, we search for the current binding, then 
  5832. store the new value into that binding. 
  5833.  
  5834.  As you can see, a function's bindings remain in effect as long as it continues 
  5835. execution, even during its calls to other functions.  That is why we say the 
  5836. extent of the binding is dynamic.  And any other function can refer to the 
  5837. bindings, if it uses the same variables while the bindings are in effect.  That 
  5838. is why we say the scope is indefinite. 
  5839.  
  5840.  The actual implementation of variable scoping in GNU Emacs Lisp uses a 
  5841. technique called shallow binding.  Each variable has a standard place in which 
  5842. its current value is always found---the value cell of the symbol. 
  5843.  
  5844.  In shallow binding, setting the variable works by storing a value in the value 
  5845. cell.  When a new local binding is created, the local value is stored in the 
  5846. value cell, and the old value (belonging to a previous binding) is pushed on a 
  5847. stack.  When a binding is eliminated, the old value is popped off the stack and 
  5848. stored in the value cell. 
  5849.  
  5850.  We use shallow binding because it has the same results as deep binding, but 
  5851. runs faster, since there is never a need to search for a binding. 
  5852.  
  5853.  
  5854. ΓòÉΓòÉΓòÉ 13.8.4. Proper Use of Dynamic Scoping ΓòÉΓòÉΓòÉ
  5855.  
  5856.  Binding a variable in one function and using it in another is a powerful 
  5857. technique, but if used without restraint, it can make programs hard to 
  5858. understand.  There are two clean ways to use this technique: 
  5859.  
  5860. o Use or bind the variable only in a few related functions, written close 
  5861.   together in one file.  Such a variable is used for communication within one 
  5862.   program. 
  5863.  
  5864.   You should write comments to inform other programmers that they can see all 
  5865.   uses of the variable before them, and to advise them not to add uses 
  5866.   elsewhere. 
  5867.  
  5868. o Give the variable a well-defined, documented meaning, and make all 
  5869.   appropriate functions refer to it (but not bind it or set it) wherever that 
  5870.   meaning is relevant.  For example, the variable case-fold-search is defined 
  5871.   as ``non-nil means ignore case when searching''; various search and replace 
  5872.   functions refer to it directly or through their subroutines, but do not bind 
  5873.   or set it. 
  5874.  
  5875.   Then you can bind the variable in other programs, knowing reliably what the 
  5876.   effect will be. 
  5877.  
  5878.  
  5879. ΓòÉΓòÉΓòÉ 13.9. Buffer-Local Variables ΓòÉΓòÉΓòÉ
  5880.  
  5881.  Global and local variable bindings are found in most programming languages in 
  5882. one form or another.  Emacs also supports another, unusual kind of variable 
  5883. binding: buffer-local bindings, which apply only to one buffer.  Emacs Lisp is 
  5884. meant for programming editing commands, and having different values for a 
  5885. variable in different buffers is an important customization method. 
  5886.  
  5887.  
  5888. ΓòÉΓòÉΓòÉ 13.9.1. Introduction to Buffer-Local Variables ΓòÉΓòÉΓòÉ
  5889.  
  5890.  A buffer-local variable has a buffer-local binding associated with a 
  5891. particular buffer.  The binding is in effect when that buffer is current; 
  5892. otherwise, it is not in effect.  If you set the variable while a buffer-local 
  5893. binding is in effect, the new value goes in that binding, so the global binding 
  5894. is unchanged; this means that the change is visible in that buffer alone. 
  5895.  
  5896.  A variable may have buffer-local bindings in some buffers but not in others. 
  5897. The global binding is shared by all the buffers that don't have their own 
  5898. bindings.  Thus, if you set the variable in a buffer that does not have a 
  5899. buffer-local binding for it, the new value is visible in all buffers except 
  5900. those with buffer-local bindings.  (Here we are assuming that there are no 
  5901. let-style local bindings to complicate the issue.) 
  5902.  
  5903.  The most common use of buffer-local bindings is for major modes to change 
  5904. variables that control the behavior of commands.  For example, C mode and Lisp 
  5905. mode both set the variable paragraph-start to specify that only blank lines 
  5906. separate paragraphs.  They do this by making the variable buffer-local in the 
  5907. buffer that is being put into C mode or Lisp mode, and then setting it to the 
  5908. new value for that mode. 
  5909.  
  5910.  The usual way to make a buffer-local binding is with make-local-variable, 
  5911. which is what major mode commands use.  This affects just the current buffer; 
  5912. all other buffers (including those yet to be created) continue to share the 
  5913. global value. 
  5914.  
  5915.  A more powerful operation is to mark the variable as automatically 
  5916. buffer-local by calling make-variable-buffer-local.  You can think of this as 
  5917. making the variable local in all buffers, even those yet to be created.  More 
  5918. precisely, the effect is that setting the variable automatically makes the 
  5919. variable local to the current buffer if it is not already so.  All buffers 
  5920. start out by sharing the global value of the variable as usual, but any setq 
  5921. creates a buffer-local binding for the current buffer.  The new value is stored 
  5922. in the buffer-local binding, leaving the (default) global binding untouched. 
  5923. The global value can no longer be changed with setq; you need to use 
  5924. setq-default to do that. 
  5925.  
  5926.  When a variable has local values in one or more buffers, you can get Emacs 
  5927. very confused by binding the variable with let, changing to a different current 
  5928. buffer in which a different binding is in effect, and then exiting the let. 
  5929. The best way to preserve your sanity is to avoid such situations.  If you use 
  5930. save-excursion around each piece of code that changes to a different current 
  5931. buffer, you will not have this problem.  Here is an example of incorrect code: 
  5932.  
  5933. (setq foo 'b)
  5934. (set-buffer "a")
  5935. (make-local-variable 'foo)
  5936. (setq foo 'a)
  5937. (let ((foo 'temp))
  5938.   (set-buffer "b")
  5939.   ...)
  5940. foo => 'a      ; The old buffer-local value from buffer `a'
  5941.                       ; is now the default value.
  5942. (set-buffer "a")
  5943. foo => 'temp   ; The local value that should be gone
  5944.                       ; is now the buffer-local value in buffer `a'.
  5945.  
  5946. But save-excursion as shown here avoids the problem: 
  5947.  
  5948. (let ((foo 'temp))
  5949.   (save-excursion
  5950.     (set-buffer "b")
  5951.     ...))
  5952.  
  5953.  Local variables in a file you edit are also represented by buffer-local 
  5954. bindings for the buffer that holds the file within Emacs. See Auto Major Mode. 
  5955.  
  5956.  
  5957. ΓòÉΓòÉΓòÉ 13.9.2. Creating and Destroying Buffer-local Bindings ΓòÉΓòÉΓòÉ
  5958.  
  5959. -- Command: make-local-variable symbol 
  5960. This function creates a buffer-local binding for symbol in the current buffer. 
  5961. Other buffers are not affected.  The value returned is symbol. 
  5962.  
  5963. The buffer-local value of symbol starts out as the same value symbol previously 
  5964. had. 
  5965.  
  5966. ;; In buffer `b1':
  5967. (setq foo 5)                ; Affects all buffers.
  5968.      => 5
  5969. (make-local-variable 'foo)  ; Now it is local in `b1'.
  5970.      => foo
  5971. foo                         ; That did not change the value.
  5972.      => 5
  5973. (setq foo 6)                ; Change the value in `b1'.
  5974.      => 6
  5975. foo
  5976.      => 6
  5977.  
  5978. ;; In buffer `b2', the value hasn't changed.
  5979. (save-excursion
  5980.   (set-buffer "b2")
  5981.   foo)
  5982.      => 5
  5983.  
  5984. -- Command: make-variable-buffer-local symbol 
  5985. This function marks symbol automatically buffer-local, so that any attempt to 
  5986. set it will make it local to the current buffer at the time. 
  5987.  
  5988. The value returned is symbol. 
  5989.  
  5990. -- Function: buffer-local-variables &optional buffer 
  5991. This function tells you what the buffer-local variables are in buffer buffer. 
  5992. It returns an association list ( see Association Lists) in which each 
  5993. association contains one buffer-local variable and its value.  If buffer is 
  5994. omitted, the current buffer is used. 
  5995.  
  5996. (setq lcl (buffer-local-variables))
  5997. => ((fill-column . 75)
  5998.     (case-fold-search . t)
  5999.     ...
  6000.     (mark-ring #<marker at 5454 in buffers.texi>)
  6001.     (require-final-newline . t))
  6002.  
  6003. Note that storing new values into the cdrs of the elements in this list will 
  6004. not change the local values of the variables. 
  6005.  
  6006. -- Command: kill-local-variable symbol 
  6007. This function deletes the buffer-local binding (if any) for symbol in the 
  6008. current buffer.  As a result, the global (default) binding of symbol becomes 
  6009. visible in this buffer.  Usually this results in a change in the value of 
  6010. symbol, since the global value is usually different from the buffer-local value 
  6011. just eliminated. 
  6012.  
  6013. It is possible to kill the local binding of a variable that automatically 
  6014. becomes local when set.  This causes the variable to show its global value in 
  6015. the current buffer.  However, if you set the variable again, this will once 
  6016. again create a local value. 
  6017.  
  6018. kill-local-variable returns symbol. 
  6019.  
  6020. -- Function: kill-all-local-variables 
  6021. This function eliminates all the buffer-local variable bindings of the current 
  6022. buffer.  As a result, the buffer will see the default values of all variables. 
  6023. This function also resets certain other information pertaining to the buffer: 
  6024. its local keymap is set to nil, its syntax table is set to the value of 
  6025. standard-syntax-table, and its abbrev table is set to the value of 
  6026. fundamental-mode-abbrev-table. 
  6027.  
  6028. Every major mode command begins by calling this function, which has the effect 
  6029. of switching to Fundamental mode and erasing most of the effects of the 
  6030. previous major mode. 
  6031.  
  6032. kill-all-local-variables returns nil. 
  6033.  
  6034.  
  6035. ΓòÉΓòÉΓòÉ 13.9.3. The Default Value of a Buffer-Local Variable ΓòÉΓòÉΓòÉ
  6036.  
  6037.  The global value of a variable with buffer-local bindings is also called the 
  6038. default value, because it is the value that is in effect except when 
  6039. specifically overridden. 
  6040.  
  6041.  The functions default-value and setq-default allow you to access and change 
  6042. the default value regardless of whether the current buffer has a buffer-local 
  6043. binding.  For example, you could use setq-default to change the default setting 
  6044. of paragraph-start for most buffers; and this would work even when you are in a 
  6045. C or Lisp mode buffer which has a buffer-local value for this variable. 
  6046.  
  6047. -- Function: default-value symbol 
  6048. This function returns symbol's default value.  This is the value that is seen 
  6049. in buffers that do not have their own values for this variable.  If symbol is 
  6050. not buffer-local, this is equivalent to symbol-value (see Accessing Variables). 
  6051.  
  6052. -- Special Form: setq-default symbol value 
  6053. This sets the default value of symbol to value. symbol is not evaluated, but 
  6054. value is.  The value of the setq-default form is value. 
  6055.  
  6056. If a symbol is not buffer-local for the current buffer, and is not marked 
  6057. automatically buffer-local, this has the same effect as setq.  If symbol is 
  6058. buffer-local for the current buffer, then this changes the value that other 
  6059. buffers will see (as long as they don't have a buffer-local value), but not the 
  6060. value that the current buffer sees. 
  6061.  
  6062. ;; In buffer `foo':
  6063. (make-local-variable 'local)
  6064.      => local
  6065. (setq local 'value-in-foo)
  6066.      => value-in-foo
  6067. (setq-default local 'new-default)
  6068.      => new-default
  6069. local
  6070.      => value-in-foo
  6071. (default-value 'local)
  6072.      => new-default
  6073.  
  6074. ;; In (the new) buffer `bar':
  6075. local
  6076.      => new-default
  6077. (default-value 'local)
  6078.      => new-default
  6079. (setq local 'another-default)
  6080.      => another-default
  6081. (default-value 'local)
  6082.      => another-default
  6083.  
  6084. ;; Back in buffer `foo':
  6085. local
  6086.      => value-in-foo
  6087. (default-value 'local)
  6088.      => another-default
  6089.  
  6090. -- Function: set-default symbol value 
  6091. This function is like setq-default, except that symbol is evaluated. 
  6092.  
  6093. (set-default (car '(a b c)) 23)
  6094.      => 23
  6095. (default-value 'a)
  6096.      => 23
  6097.  
  6098.  
  6099. ΓòÉΓòÉΓòÉ 14. Functions ΓòÉΓòÉΓòÉ
  6100.  
  6101.  A Lisp program is composed mainly of Lisp functions.  This chapter explains 
  6102. what functions are, how they accept arguments, and how to define them. 
  6103.  
  6104.  
  6105. ΓòÉΓòÉΓòÉ 14.1. What Is a Function? ΓòÉΓòÉΓòÉ
  6106.  
  6107.  In a general sense, a function is a rule for carrying on a computation given 
  6108. several values called arguments.  The result of the computation is called the 
  6109. value of the function.  The computation can also have side effects: lasting 
  6110. changes in the values of variables or the contents of data structures. 
  6111.  
  6112.  Here are important terms for functions in Emacs Lisp and for other 
  6113. function-like objects. 
  6114.  
  6115. function 
  6116.           In Emacs Lisp, a function is anything that can be applied to 
  6117.           arguments in a Lisp program.  In some cases, we will use it more 
  6118.           specifically to mean a function written in Lisp.  Special forms and 
  6119.           macros are not functions. 
  6120.  
  6121. primitive 
  6122.           A primitive is a function callable from Lisp that is written in C, 
  6123.           such as car or append.  These functions are also called built-in 
  6124.           functions or subrs.  (Special forms are also considered primitives.) 
  6125.  
  6126.           Primitives provide the lowest-level interfaces to editing functions 
  6127.           or operating system services, or in a few cases they perform 
  6128.           important operations more quickly than a Lisp program could. 
  6129.           Primitives can be modified or added only by changing the C sources 
  6130.           and recompiling the editor.  See Writing Emacs Primitives. 
  6131.  
  6132. lambda expression 
  6133.           A lambda expression is a function written in Lisp. These are 
  6134.           described in the following section. See Lambda Expressions. 
  6135.  
  6136. special form 
  6137.           A special form is a primitive that is like a function but does not 
  6138.           evaluate all of its arguments in the usual way.  It may evaluate only 
  6139.           some of the arguments, or may evaluate them in an unusual order, or 
  6140.           several times.  Many special forms are described in Control 
  6141.           Structures. 
  6142.  
  6143. macro 
  6144.           A macro is a construct defined in Lisp by the programmer.  It differs 
  6145.           from a function in that it translates a Lisp expression that you 
  6146.           write into an equivalent expression to be evaluated instead of the 
  6147.           original expression.  See Macros, for how to define and use macros. 
  6148.  
  6149. command 
  6150.           A command is an object that command-execute can invoke; it is a 
  6151.           possible definition for a key sequence.  Some functions are commands; 
  6152.           a function written in Lisp is a command if it contains an interactive 
  6153.           declaration (see Defining Commands).  Such a function can be called 
  6154.           from Lisp expressions like other functions; in this case, the fact 
  6155.           that the function is a command makes no difference. 
  6156.  
  6157.           Strings are commands also, even though they are not functions.  A 
  6158.           symbol is a command if its function definition is a command; such 
  6159.           symbols can be invoked with M-x.  The symbol is a function as well if 
  6160.           the definition is a function.  See Command Overview. 
  6161.  
  6162. keystroke command 
  6163.           A keystroke command is a command that is bound to a key sequence 
  6164.           (typically one to three keystrokes).  The distinction is made here 
  6165.           merely to avoid confusion with the meaning of ``command'' in 
  6166.           non-Emacs editors; for programmers, the distinction is normally 
  6167.           unimportant. 
  6168.  
  6169. -- Function: subrp object 
  6170. This function returns t if object is a built-in function (i.e. a Lisp 
  6171. primitive). 
  6172.  
  6173. (subrp 'message)                ; message is a symbol,
  6174.      => nil                     ; not a subr object.
  6175. (subrp (symbol-function 'message))
  6176.      => t
  6177.  
  6178.  
  6179. ΓòÉΓòÉΓòÉ 14.2. Lambda Expressions ΓòÉΓòÉΓòÉ
  6180.  
  6181.  A function written in Lisp is a list that looks like this: 
  6182.  
  6183. (lambda (arg-variables...)
  6184.   [documentation-string]
  6185.   [interactive-declaration]
  6186.   body-forms...)
  6187.  
  6188. (Such a list is called a lambda expression, even though it is not an expression 
  6189. at all, for historical reasons.) 
  6190.  
  6191.  
  6192. ΓòÉΓòÉΓòÉ 14.2.1. Components of a Lambda Expression ΓòÉΓòÉΓòÉ
  6193.  
  6194.  A function written in Lisp (a ``lambda expression'') is a list that looks like 
  6195. this: 
  6196.  
  6197. (lambda (arg-variables...)
  6198.   [documentation-string]
  6199.   [interactive-declaration]
  6200.   body-forms...)
  6201.  
  6202.  The first element of a lambda expression is always the symbol lambda.  This 
  6203. indicates that the list represents a function.  The reason functions are 
  6204. defined to start with lambda is so that other lists, intended for other uses, 
  6205. will not accidentally be valid as functions. 
  6206.  
  6207.  The second element is a list of argument variable names (symbols). This is 
  6208. called the lambda list.  When a Lisp function is called, the argument values 
  6209. are matched up against the variables in the lambda list, which are given local 
  6210. bindings with the values provided. See Local Variables. 
  6211.  
  6212.  The documentation string is an actual string that serves to describe the 
  6213. function for the Emacs help facilities.  See Function Documentation. 
  6214.  
  6215.  The interactive declaration is a list of the form (interactive code-string). 
  6216. This declares how to provide arguments if the function is used interactively. 
  6217. Functions with this declaration are called commands; they can be called using 
  6218. M-x or bound to a key. Functions not intended to be called in this way should 
  6219. not have interactive declarations.  See Defining Commands, for how to write an 
  6220. interactive declaration. 
  6221.  
  6222.  The rest of the elements are the body of the function: the Lisp code to do the 
  6223. work of the function (or, as a Lisp programmer would say, ``a list of Lisp 
  6224. forms to evaluate'').  The value returned by the function is the value returned 
  6225. by the last element of the body. 
  6226.  
  6227.  
  6228. ΓòÉΓòÉΓòÉ 14.2.2. A Simple Lambda-Expression Example ΓòÉΓòÉΓòÉ
  6229.  
  6230.  Consider for example the following function: 
  6231.  
  6232. (lambda (a b c) (+ a b c))
  6233.  
  6234. We can call this function by writing it as the car of an expression, like this: 
  6235.  
  6236. ((lambda (a b c) (+ a b c))
  6237.  1 2 3)
  6238.  
  6239. The body of this lambda expression is evaluated with the variable a bound to 1, 
  6240. b bound to 2, and c bound to 3. Evaluation of the body adds these three 
  6241. numbers, producing the result 6; therefore, this call to the function returns 
  6242. the value 6. 
  6243.  
  6244.  Note that the arguments can be the results of other function calls, as in this 
  6245. example: 
  6246.  
  6247. ((lambda (a b c) (+ a b c))
  6248.  1 (* 2 3) (- 5 4))
  6249.  
  6250. Here all the arguments 1, (* 2 3), and (- 5 4) are evaluated, left to right. 
  6251. Then the lambda expression is applied to the argument values 1, 6 and 1 to 
  6252. produce the value 8. 
  6253.  
  6254.  It is not often useful to write a lambda expression as the car of a form in 
  6255. this way.  You can get the same result, of making local variables and giving 
  6256. them values, using the special form let (see Local Variables).  And let is 
  6257. clearer and easier to use. In practice, lambda expressions are either stored as 
  6258. the function definitions of symbols, to produce named functions, or passed as 
  6259. arguments to other functions (see Anonymous Functions). 
  6260.  
  6261.  However, calls to explicit lambda expressions were very useful in the old days 
  6262. of Lisp, before the special form let was invented.  At that time, they were the 
  6263. only way to bind and initialize local variables. 
  6264.  
  6265.  
  6266. ΓòÉΓòÉΓòÉ 14.2.3. Advanced Features of Argument Lists ΓòÉΓòÉΓòÉ
  6267.  
  6268.  Our simple sample function, (lambda (a b c) (+ a b c)), specifies three 
  6269. argument variables, so it must be called with three arguments: if you try to 
  6270. call it with only two arguments or four arguments, you will get a 
  6271. wrong-number-of-arguments error. 
  6272.  
  6273.  It is often convenient to write a function that allows certain arguments to be 
  6274. omitted.  For example, the function substring accepts three arguments---a 
  6275. string, the start index and the end index---but the third argument defaults to 
  6276. the end of the string if you omit it.  It is also convenient for certain 
  6277. functions to accept an indefinite number of arguments, as the functions and and 
  6278. + do. 
  6279.  
  6280.  To specify optional arguments that may be omitted when a function is called, 
  6281. simply include the keyword &optional before the optional arguments.  To specify 
  6282. a list of zero or more extra arguments, include the keyword &rest before one 
  6283. final argument. 
  6284.  
  6285.  Thus, the complete syntax for an argument list is as follows: 
  6286.  
  6287. (required-vars...
  6288.  [&optional optional-vars...]
  6289.  [&rest rest-var])
  6290.  
  6291. The square brackets indicate that the &optional and &rest clauses, and the 
  6292. variables that follow them, are optional. 
  6293.  
  6294.  A call to the function requires one actual argument for each of the 
  6295. required-vars.  There may be actual arguments for zero or more of the 
  6296. optional-vars, and there cannot be any more actual arguments than these unless 
  6297. &rest exists.  In that case, there may be any number of extra actual arguments. 
  6298.  
  6299.  If actual arguments for the optional and rest variables are omitted, then they 
  6300. always default to nil.  However, the body of the function is free to consider 
  6301. nil an abbreviation for some other meaningful value.  This is what substring 
  6302. does; nil as the third argument means to use the length of the string supplied. 
  6303. There is no way for the function to distinguish between an explicit argument of 
  6304. nil and an omitted argument. 
  6305.  
  6306. Common Lisp note: Common Lisp allows the function to specify what default 
  6307. values will be used when an optional argument is omitted; GNU Emacs Lisp always 
  6308. uses nil. 
  6309.  
  6310.  For example, an argument list that looks like this: 
  6311.  
  6312. (a b &optional c d &rest e)
  6313.  
  6314. binds a and b to the first two actual arguments, which are required.  If one or 
  6315. two more arguments are provided, c and d are bound to them respectively; any 
  6316. arguments after the first four are collected into a list and e is bound to that 
  6317. list.  If there are only two arguments, c is nil; if two or three arguments, d 
  6318. is nil; if four arguments or fewer, e is nil. 
  6319.  
  6320.  There is no way to have required arguments following optional ones---it would 
  6321. not make sense.  To see why this must be so, suppose that c in the example were 
  6322. optional and d were required. If three actual arguments are given; then which 
  6323. variable would the third argument be for?  Similarly, it makes no sense to have 
  6324. any more arguments (either required or optional) after a &rest argument. 
  6325.  
  6326.  Here are some examples of argument lists and proper calls: 
  6327.  
  6328. ((lambda (n) (1+ n))                ; One required:
  6329.  1)                                 ; requires exactly one argument.
  6330.      => 2
  6331. ((lambda (n &optional n1)           ; One required and one optional:
  6332.          (if n1 (+ n n1) (1+ n)))   ; 1 or 2 arguments.
  6333.  1 2)
  6334.      => 3
  6335. ((lambda (n &rest ns)               ; One required and one rest:
  6336.          (+ n (apply '+ ns)))       ; 1 or more arguments.
  6337.  1 2 3 4 5)
  6338.      => 15
  6339.  
  6340.  
  6341. ΓòÉΓòÉΓòÉ 14.2.4. Documentation Strings of Functions ΓòÉΓòÉΓòÉ
  6342.  
  6343.  A lambda expression may optionally have a documentation string just after the 
  6344. lambda list.  This string does not affect execution of the function; it is a 
  6345. kind of comment, but a systematized comment which actually appears inside the 
  6346. Lisp world and can be used by the Emacs help facilities.  See Documentation, 
  6347. for how the documentation-string is accessed. 
  6348.  
  6349.  It is a good idea to provide documentation strings for all commands, and for 
  6350. all other functions in your program that users of your program should know 
  6351. about; internal functions might as well have only comments, since comments 
  6352. don't take up any room when your program is loaded. 
  6353.  
  6354.  The first line of the documentation string should stand on its own, because 
  6355. apropos displays just this first line.  It should consist of one or two 
  6356. complete sentences that summarize the function's purpose. 
  6357.  
  6358.  The start of the documentation string is usually indented, but since these 
  6359. spaces come before the starting double-quote, they are not part of the string. 
  6360. Some people make a practice of indenting any additional lines of the string so 
  6361. that the text lines up.  This is a mistake.  The indentation of the following 
  6362. lines is inside the string; what looks nice in the source code will look ugly 
  6363. when displayed by the help commands. 
  6364.  
  6365.  You may wonder how the documentation string could be optional, since there are 
  6366. required components of the function that follow it (the body). Since evaluation 
  6367. of a string returns that string, without any side effects, it has no effect if 
  6368. it is not the last form in the body.  Thus, in practice, there is no confusion 
  6369. between the first form of the body and the documentation string; if the only 
  6370. body form is a string then it serves both as the return value and as the 
  6371. documentation. 
  6372.  
  6373.  
  6374. ΓòÉΓòÉΓòÉ 14.3. Naming a Function ΓòÉΓòÉΓòÉ
  6375.  
  6376.  In most computer languages, every function has a name; the idea of a function 
  6377. without a name is nonsensical.  In Lisp, a function in the strictest sense has 
  6378. no name.  It is simply a list whose first element is lambda, or a primitive 
  6379. subr-object. 
  6380.  
  6381.  However, a symbol can serve as the name of a function.  This happens when you 
  6382. put the function in the symbol's function cell (see Symbol Components).  Then 
  6383. the symbol itself becomes a valid, callable function, equivalent to the list or 
  6384. subr-object that its function cell refers to.  The contents of the function 
  6385. cell are also called the symbol's function definition. 
  6386.  
  6387.  In practice, nearly all functions are given names in this way and referred to 
  6388. through their names.  For example, the symbol car works as a function and does 
  6389. what it does because the primitive subr-object #<subr car> is stored in its 
  6390. function cell. 
  6391.  
  6392.  We give functions names because it is more convenient to refer to them by 
  6393. their names in other functions.  For primitive subr-objects such as #<subr 
  6394. car>, names are the only way you can refer to them: there is no read syntax for 
  6395. such objects.  For functions written in Lisp, the name is more convenient to 
  6396. use in a call than an explicit lambda expression.  Also, a function with a name 
  6397. can refer to itself---it can be recursive.  Writing the function's name in its 
  6398. own definition is much more convenient than making the function definition 
  6399. point to itself (something that is not impossible but that has various 
  6400. disadvantages in practice). 
  6401.  
  6402.  Functions are often identified with the symbols used to name them.  For 
  6403. example, we often speak of ``the function car'', not distinguishing between the 
  6404. symbol car and the primitive subr-object that is its function definition.  For 
  6405. most purposes, there is no need to distinguish. 
  6406.  
  6407.  Even so, keep in mind that a function need not have a unique name.  While a 
  6408. given function object usually appears in the function cell of only one symbol, 
  6409. this is just a matter of convenience.  It is very easy to store it in several 
  6410. symbols using fset; then each of the symbols is equally well a name for the 
  6411. same function. 
  6412.  
  6413.  A symbol used as a function name may also be used as a variable; these two 
  6414. uses of a symbol are independent and do not conflict. 
  6415.  
  6416.  
  6417. ΓòÉΓòÉΓòÉ 14.4. Defining Named Functions ΓòÉΓòÉΓòÉ
  6418.  
  6419.  We usually give a name to a function when it is first created.  This is called 
  6420. defining a function, and it is done with the defun special form. 
  6421.  
  6422. -- Special Form: defun name argument-list body-forms 
  6423. defun is the usual way to define new Lisp functions.  It defines the symbol 
  6424. name as a function that looks like this: 
  6425.  
  6426. (lambda argument-list . body-forms)
  6427.  
  6428. This lambda expression is stored in the function cell of name. The value 
  6429. returned by evaluating the defun form is name, but usually we ignore this 
  6430. value. 
  6431.  
  6432. As described previously (see Lambda Expressions), argument-list is a list of 
  6433. argument names and may include the keywords &optional and &rest.  Also, the 
  6434. first two forms in body-forms may be a documentation string and an interactive 
  6435. declaration. 
  6436.  
  6437. Note that the same symbol name may also be used as a global variable, since the 
  6438. value cell is independent of the function cell. 
  6439.  
  6440. Here are some examples: 
  6441.  
  6442. (defun foo () 5)
  6443.      => foo
  6444. (foo)
  6445.      => 5
  6446.  
  6447. (defun bar (a &optional b &rest c)
  6448.     (list a b c))
  6449.      => bar
  6450. (bar 1 2 3 4 5)
  6451.      => (1 2 (3 4 5))
  6452. (bar 1)
  6453.      => (1 nil nil)
  6454. (bar)
  6455. error--> Wrong number of arguments.
  6456.  
  6457. (defun capitalize-backwards ()
  6458.   "This function makes the last letter of a word upper case."
  6459.   (interactive)
  6460.   (backward-word 1)
  6461.   (forward-word 1)
  6462.   (backward-char 1)
  6463.   (capitalize-word 1))
  6464.      => capitalize-backwards
  6465.  
  6466. Be careful not to redefine existing functions unintentionally. defun will 
  6467. redefine even primitive functions such as car without any hesitation or 
  6468. notification.  Redefining a function already defined is often done 
  6469. deliberately, and there is no way to distinguish deliberate redefinition from 
  6470. unintentional redefinition. 
  6471.  
  6472.  
  6473. ΓòÉΓòÉΓòÉ 14.5. Calling Functions ΓòÉΓòÉΓòÉ
  6474.  
  6475.  Defining functions is only half the battle.  Functions don't do anything until 
  6476. you call them, i.e., tell them to run.  This process is also known as 
  6477. invocation. 
  6478.  
  6479.  The most common way of invoking a function is by evaluating a list.  For 
  6480. example, evaluating the list (concat "a" "b") calls the function concat.  See 
  6481. Evaluation, for a description of evaluation. 
  6482.  
  6483.  When you write a list as an expression in your program, the function name is 
  6484. part of the program.  This means that the choice of which function to call is 
  6485. made when you write the program.  Usually that's just what you want. 
  6486. Occasionally you need to decide at run time which function to call.  Then you 
  6487. can use the functions funcall and apply. 
  6488.  
  6489. -- Function: funcall function &rest arguments 
  6490. funcall calls function with arguments, and returns whatever function returns. 
  6491.  
  6492. Since funcall is a function, all of its arguments, including function, are 
  6493. evaluated before funcall is called.  This means that you can use any expression 
  6494. to obtain the function to be called.  It also means that funcall does not see 
  6495. the expressions you write for the arguments, only their values.  These values 
  6496. are not evaluated a second time in the act of calling function; funcall enters 
  6497. the normal procedure for calling a function at the place where the arguments 
  6498. have already been evaluated. 
  6499.  
  6500. The argument function must be either a Lisp function or a primitive function. 
  6501. Special forms and macros are not allowed, because they make sense only when 
  6502. given the ``unevaluated'' argument expressions.  funcall cannot provide these 
  6503. because, as we saw above, it never knows them in the first place. 
  6504.  
  6505. (setq f 'list)
  6506.      => list
  6507. (funcall f 'x 'y 'z)
  6508.      => (x y z)
  6509. (funcall f 'x 'y '(z))
  6510.      => (x y (z))
  6511. (funcall 'and t nil)
  6512. error--> Invalid function: #<subr and>
  6513.  
  6514. Compare this example with that of apply. 
  6515.  
  6516. -- Function: apply function &rest arguments 
  6517. apply calls function with arguments, just like funcall but with one difference: 
  6518. the last of arguments is a list of arguments to give to function, rather than a 
  6519. single argument.  We also say that this list is appended to the other 
  6520. arguments. 
  6521.  
  6522. apply returns the result of calling function.  As with funcall, function must 
  6523. either be a Lisp function or a primitive function; special forms and macros do 
  6524. not make sense in apply. 
  6525.  
  6526. (setq f 'list)
  6527.      => list
  6528. (apply f 'x 'y 'z)
  6529. error--> Wrong type argument: listp, z
  6530. (apply '+ 1 2 '(3 4))
  6531.      => 10
  6532. (apply '+ '(1 2 3 4))
  6533.      => 10
  6534.  
  6535. (apply 'append '((a b c) nil (x y z) nil))
  6536.      => (a b c x y z)
  6537.  
  6538. An interesting example of using apply is found in the description of mapcar; 
  6539. see the following section. 
  6540.  
  6541.  It is common for Lisp functions to accept functions as arguments or find them 
  6542. in data structures (especially in hook variables and property lists) and call 
  6543. them using funcall or apply.  Functions that accept function arguments are 
  6544. often called functionals. 
  6545.  
  6546.  Sometimes, when you call such a function, it is useful to supply a no-op 
  6547. function as the argument.  Here are two different kinds of no-op function: 
  6548.  
  6549. -- Function: identity arg 
  6550. This function returns arg and has no side effects. 
  6551.  
  6552. -- Function: ignore &rest args 
  6553. This function ignores any arguments and returns nil. 
  6554.  
  6555.  
  6556. ΓòÉΓòÉΓòÉ 14.6. Mapping Functions ΓòÉΓòÉΓòÉ
  6557.  
  6558.  A mapping function applies a given function to each element of a list or other 
  6559. collection.  Emacs Lisp has three such functions; mapcar and mapconcat, which 
  6560. scan a list, are described here.  For the third mapping function, mapatoms, see 
  6561. Creating Symbols. 
  6562.  
  6563. -- Function: mapcar function sequence 
  6564. mapcar applies function to each element of sequence in turn.  The results are 
  6565. made into a nil-terminated list. 
  6566.  
  6567. The argument sequence may be a list, a vector or a string.  The result is 
  6568. always a list.  The length of the result is the same as the length of sequence. 
  6569.  
  6570. For example: 
  6571.  
  6572. (mapcar 'car '((a b) (c d) (e f)))
  6573.      => (a c e)
  6574. (mapcar '1+ [1 2 3])
  6575.      => (2 3 4)
  6576. (mapcar 'char-to-string "abc")
  6577.      => ("a" "b" "c")
  6578.  
  6579. ;; Call each function in my-hooks.
  6580. (mapcar 'funcall my-hooks)
  6581.  
  6582. (defun mapcar* (f &rest args)
  6583.   "Apply FUNCTION to successive cars of all ARGS, until one ends.
  6584. Return the list of results."
  6585.   (if (not (memq 'nil args))              ; If no list is exhausted,
  6586.       (cons (apply f (mapcar 'car args))  ; Apply function to CARs.
  6587.             (apply 'mapcar* f             ; Recurse for rest of elements.
  6588.                    (mapcar 'cdr args)))))
  6589.  
  6590. (mapcar* 'cons '(a b c) '(1 2 3 4))
  6591.      => ((a . 1) (b . 2) (c . 3))
  6592.  
  6593. -- Function: mapconcat function sequence separator 
  6594. mapconcat applies function to each element of sequence: the results, which must 
  6595. be strings, are concatenated. Between each pair of result strings, mapconcat 
  6596. inserts the string separator.  Usually separator contains a space or comma or 
  6597. other suitable punctuation. 
  6598.  
  6599. The argument function must be a function that can take one argument and returns 
  6600. a string. 
  6601.  
  6602. (mapconcat 'symbol-name
  6603.            '(The cat in the hat)
  6604.            " ")
  6605.      => "The cat in the hat"
  6606.  
  6607. (mapconcat (function (lambda (x) (format "%c" (1+ x))))
  6608.            "HAL-8000"
  6609.            "")
  6610.      => "IBM.9111"
  6611.  
  6612.  
  6613. ΓòÉΓòÉΓòÉ 14.7. Anonymous Functions ΓòÉΓòÉΓòÉ
  6614.  
  6615.  In Lisp, a function is a list that starts with lambda (or alternatively a 
  6616. primitive subr-object); names are ``extra''.  Although usually functions are 
  6617. defined with defun and given names at the same time, it is occasionally more 
  6618. concise to use an explicit lambda expression---an anonymous function.  Such a 
  6619. list is valid wherever a function name is. 
  6620.  
  6621.  Any method of creating such a list makes a valid function.  Even this: 
  6622.  
  6623. (setq silly (append '(lambda (x)) (list (list '+ (* 3 4) 'x))))
  6624.      => (lambda (x) (+ 12 x))
  6625.  
  6626. This computes a list that looks like (lambda (x) (+ 12 x)) and makes it the 
  6627. value (not the function definition!) of silly. 
  6628.  
  6629.  Here is how we might call this function: 
  6630.  
  6631. (funcall silly 1)
  6632.      => 13
  6633.  
  6634. (It does not work to write (silly 1), because this function is not the function 
  6635. definition of silly.  We have not given silly any function definition, just a 
  6636. value as a variable.) 
  6637.  
  6638.  Most of the time, anonymous functions are constants that appear in your 
  6639. program.  For example, you might want to pass one as an argument to the 
  6640. function mapcar, which applies any given function to each element of a list. 
  6641. Here we pass an anonymous function that multiplies a number by two: 
  6642.  
  6643. (defun double-each (list)
  6644.   (mapcar '(lambda (x) (* 2 x)) list))
  6645.      => double-each
  6646. (double-each '(2 11))
  6647.      => (4 22)
  6648.  
  6649. In such cases, we usually use the special form function instead of simple 
  6650. quotation to quote the anonymous function. 
  6651.  
  6652. -- Special Form: function function-object 
  6653. This special form returns function-object without evaluating it. In this, it is 
  6654. equivalent to quote.  However, it serves as a note to the Emacs Lisp compiler 
  6655. that function-object is intended to be used only as a function, and therefore 
  6656. can safely be compiled. See Quoting, for comparison. 
  6657.  
  6658.  Using function instead of quote makes a difference inside a function or macro 
  6659. that you are going to compile.  For example: 
  6660.  
  6661. (defun double-each (list)
  6662.   (mapcar (function (lambda (x) (* 2 x))) list))
  6663.      => double-each
  6664. (double-each '(2 11))
  6665.      => (4 22)
  6666.  
  6667. If this definition of double-each is compiled, the anonymous function is 
  6668. compiled as well.  By contrast, in the previous definition where ordinary quote 
  6669. is used, the argument passed to mapcar is the precise list shown: 
  6670.  
  6671. (lambda (arg) (+ arg 5))
  6672.  
  6673. The Lisp compiler cannot assume this list is a function, even though it looks 
  6674. like one, since it does not know what mapcar does with the list.  Perhaps 
  6675. mapcar will check that the car of the third element is the symbol +!  The 
  6676. advantage of function is that it tells the compiler to go ahead and compile the 
  6677. constant function. 
  6678.  
  6679.  We sometimes write function instead of quote when quoting the name of a 
  6680. function, but this usage is just a sort of comment. 
  6681.  
  6682. (function symbol) == (quote symbol) == 'symbol
  6683.  
  6684.  See documentation in Accessing Documentation, for a realistic example using 
  6685. function and an anonymous function. 
  6686.  
  6687.  
  6688. ΓòÉΓòÉΓòÉ 14.8. Accessing Function Cell Contents ΓòÉΓòÉΓòÉ
  6689.  
  6690.  The function definition of a symbol is the object stored in the function cell 
  6691. of the symbol.  The functions described here access, test, and set the function 
  6692. cell of symbols. 
  6693.  
  6694. -- Function: symbol-function symbol 
  6695. This returns the object in the function cell of symbol.  If the symbol's 
  6696. function cell is void, a void-function error is signaled. 
  6697.  
  6698. This function does not check that the returned object is a legitimate function. 
  6699.  
  6700. (defun bar (n) (+ n 2))
  6701.      => bar
  6702. (symbol-function 'bar)
  6703.      => (lambda (n) (+ n 2))
  6704. (fset 'baz 'bar)
  6705.      => bar
  6706. (symbol-function 'baz)
  6707.      => bar
  6708.  
  6709.  If you have never given a symbol any function definition, we say that that 
  6710. symbol's function cell is void.  In other words, the function cell does not 
  6711. have any Lisp object in it.  If you try to call such a symbol as a function, it 
  6712. signals a void-function error. 
  6713.  
  6714.  Note that void is not the same as nil or the symbol void.  The symbols nil and 
  6715. void are Lisp objects, and can be stored into a function cell just as any other 
  6716. object can be (and they can be valid functions if you define them in turn with 
  6717. defun); but nil or void is an object.  A void function cell contains no object 
  6718. whatsoever. 
  6719.  
  6720.  You can test the voidness of a symbol's function definition with fboundp. 
  6721. After you have given a symbol a function definition, you can make it void once 
  6722. more using fmakunbound. 
  6723.  
  6724. -- Function: fboundp symbol 
  6725. Returns t if the symbol has an object in its function cell, nil otherwise.  It 
  6726. does not check that the object is a legitimate function. 
  6727.  
  6728. -- Function: fmakunbound symbol 
  6729. This function makes symbol's function cell void, so that a subsequent attempt 
  6730. to access this cell will cause a void-function error.  (See also makunbound, in 
  6731. Local Variables.) 
  6732.  
  6733. (defun foo (x) x)
  6734.      => x
  6735. (fmakunbound 'foo)
  6736.      => x
  6737. (foo 1)
  6738. error--> Symbol's function definition is void: foo
  6739.  
  6740. -- Function: fset symbol object 
  6741. This function stores object in the function cell of symbol. The result is 
  6742. object.  Normally object should be a function or the name of a function, but 
  6743. this is not checked. 
  6744.  
  6745. There are three normal uses of this function: 
  6746.  
  6747. o Copying one symbol's function definition to another.  (In other words, making 
  6748.   an alternate name for a function.) 
  6749.  
  6750. o Giving a symbol a function definition that is not a list and therefore cannot 
  6751.   be made with defun.  See Classifying Lists, for an example of this usage. 
  6752.  
  6753. o In constructs for defining or altering functions.  If defun were not a 
  6754.   primitive, it could be written in Lisp (as a macro) using fset. 
  6755.  
  6756. Here are examples of the first two uses: 
  6757.  
  6758. ;; Give first the same definition car has.
  6759. (fset 'first (symbol-function 'car))
  6760.      => #<subr car>
  6761. (first '(1 2 3))
  6762.      => 1
  6763.  
  6764. ;; Make the symbol car the function definition of xfirst.
  6765. (fset 'xfirst 'car)
  6766.      => car
  6767. (xfirst '(1 2 3))
  6768.      => 1
  6769. (symbol-function 'xfirst)
  6770.      => car
  6771. (symbol-function (symbol-function 'xfirst))
  6772.      => #<subr car>
  6773.  
  6774. ;; Define a named keyboard macro.
  6775. (fset 'kill-two-lines "\^u2\^k")
  6776.      => "\^u2\^k"
  6777.  
  6778.  When writing a function that extends a previously defined function, the 
  6779. following idiom is often used: 
  6780.  
  6781. (fset 'old-foo (symbol-function 'foo))
  6782.  
  6783. (defun foo ()
  6784.   "Just like old-foo, except more so."
  6785.   (old-foo)
  6786.   (more-so))
  6787.  
  6788. This does not work properly if foo has been defined to autoload. In such a 
  6789. case, when foo calls old-foo, Lisp will attempt to define old-foo by loading a 
  6790. file.  Since this presumably defines foo rather than old-foo, it will not 
  6791. produce the proper results.  The only way to avoid this problem is to make sure 
  6792. the file is loaded before moving aside the old definition of foo. 
  6793.  
  6794.  
  6795. ΓòÉΓòÉΓòÉ 14.9. Other Topics Related to Functions ΓòÉΓòÉΓòÉ
  6796.  
  6797.  Here is a table of several functions that do things related to function 
  6798. calling and function definitions. 
  6799.  
  6800. apply 
  6801.           See Calling Functions. 
  6802.  
  6803. autoload 
  6804.           See Autoload. 
  6805.  
  6806. call-interactively 
  6807.           See Interactive Call. 
  6808.  
  6809. commandp 
  6810.           See Interactive Call. 
  6811.  
  6812. documentation 
  6813.           See Accessing Documentation. 
  6814.  
  6815. eval 
  6816.           See Eval. 
  6817.  
  6818. funcall 
  6819.           See Calling Functions. 
  6820.  
  6821. ignore 
  6822.           See Calling Functions. 
  6823.  
  6824. interactive 
  6825.           See Using Interactive. 
  6826.  
  6827. interactive-p 
  6828.           See Interactive Call. 
  6829.  
  6830. mapatoms 
  6831.           See Creating Symbols. 
  6832.  
  6833. mapcar 
  6834.           See Mapping Functions. 
  6835.  
  6836. mapconcat 
  6837.           See Mapping Functions. 
  6838.  
  6839. undefined 
  6840.           See Key Lookup. 
  6841.  
  6842.  
  6843. ΓòÉΓòÉΓòÉ 15. Macros ΓòÉΓòÉΓòÉ
  6844.  
  6845.  Macros enable you to define new control constructs and other language 
  6846. features.  A macro is defined much like a function, but instead of telling how 
  6847. to compute a value, it tells how to compute another Lisp expression which will 
  6848. in turn compute the value.  We call this expression the expansion of the macro. 
  6849.  
  6850.  Macros can do this because they operate on the unevaluated expressions for the 
  6851. arguments, not on the argument values as functions do.  They can therefore 
  6852. construct an expansion containing these argument expressions or parts of them. 
  6853.  
  6854.  
  6855. ΓòÉΓòÉΓòÉ 15.1. A Simple Example of a Macro ΓòÉΓòÉΓòÉ
  6856.  
  6857.  Suppose we would like to define a Lisp construct to increment a variable 
  6858. value, much like the ++ operator in C.  We would like to write (inc x) and have 
  6859. the effect of (setq x (1+ x)). Here's a macro definition that will do the job: 
  6860.  
  6861. (defmacro inc (var)
  6862.    (list 'setq var (list '1+ var)))
  6863.  
  6864.  When this is called with (inc x), the argument var has the value x---not the 
  6865. value of x.  The body of the macro uses this to construct the expansion, which 
  6866. is (setq x (1+ x)).  Once the macro definition returns this expansion, Lisp 
  6867. proceeds to evaluate it, thus incrementing x. 
  6868.  
  6869.  
  6870. ΓòÉΓòÉΓòÉ 15.2. Expansion of a Macro Call ΓòÉΓòÉΓòÉ
  6871.  
  6872.  A macro call looks just like a function call in that it is a list which starts 
  6873. with the name of the macro.  The rest of the elements of the list are the 
  6874. arguments of the macro. 
  6875.  
  6876.  Evaluation of the macro call begins like evaluation of a function call except 
  6877. for one crucial difference: the macro arguments are the actual expressions 
  6878. appearing in the macro call.  They are not evaluated before they are given to 
  6879. the macro definition.  By contrast, the arguments of a function are results of 
  6880. evaluating the elements of the function call list. 
  6881.  
  6882.  Having obtained the arguments, Lisp invokes the macro definition just as a 
  6883. function is invoked.  The argument variables of the macro are bound to the 
  6884. argument values from the macro call, or to a list of them in the case of a 
  6885. &rest argument.  And the macro body executes and returns its value just as a 
  6886. function body does. 
  6887.  
  6888.  The second crucial difference between macros and functions is that the value 
  6889. returned by the macro body is not the value of the macro call. Instead, it is 
  6890. an alternate expression for computing that value, also known as the expansion 
  6891. of the macro.  The Lisp interpreter proceeds to evaluate the expansion as soon 
  6892. as it comes back from the macro. 
  6893.  
  6894.  Since the expansion is evaluated in the normal manner, it may contain calls to 
  6895. other macros.  It may even be a call to the same macro, though this is unusual. 
  6896.  
  6897.  You can see the expansion of a given macro call by calling macroexpand: 
  6898.  
  6899. -- Function: macroexpand form &optional environment 
  6900. This function expands form, if it is a macro call.  If the result is another 
  6901. macro call, it is expanded in turn, until something which is not a macro call 
  6902. results.  That is the value returned by macroexpand.  If form is not a macro 
  6903. call to begin with, it is returned as given. 
  6904.  
  6905. Note that macroexpand does not look at the subexpressions of form (although 
  6906. some macro definitions may do so).  If they are macro calls themselves, 
  6907. macroexpand will not expand them. 
  6908.  
  6909. If environment is provided, it specifies an alist of macro definitions that 
  6910. shadow the currently defined macros.  This is used by byte compilation. 
  6911.  
  6912. (defmacro inc (var)
  6913.     (list 'setq var (list '1+ var)))
  6914.      => inc
  6915.  
  6916. (macroexpand '(inc r))
  6917.      => (setq r (1+ r))
  6918.  
  6919. (defmacro inc2 (var1 var2)
  6920.     (list 'progn (list 'inc var1) (list 'inc var2)))
  6921.      => inc2
  6922.  
  6923. (macroexpand '(inc2 r s))
  6924.      => (progn (inc r) (inc s))        ; inc not expanded here.
  6925.  
  6926.  
  6927. ΓòÉΓòÉΓòÉ 15.3. Macros and Byte Compilation ΓòÉΓòÉΓòÉ
  6928.  
  6929.  You might ask why we take the trouble to compute an expansion for a macro and 
  6930. then evaluate the expansion.  Why not have the macro body produce the desired 
  6931. results directly?  The reason has to do with compilation. 
  6932.  
  6933.  When a macro call appears in a Lisp program being compiled, the Lisp compiler 
  6934. calls the macro definition just as the interpreter would, and receives an 
  6935. expansion.  But instead of evaluating this expansion, it compiles expansion as 
  6936. if it had appeared directly in the program.  As a result, the compiled code 
  6937. produces the value and side effects intended for the macro, but executes at 
  6938. full compiled speed.  This would not work if the macro body computed the value 
  6939. and side effects itself---they would be computed at compile time, which is not 
  6940. useful. 
  6941.  
  6942.  In order for compilation of macro calls to work, the macros must be defined in 
  6943. Lisp when the calls to them are compiled.  The compiler has a special feature 
  6944. to help you do this: if a file being compiled contains a defmacro form, the 
  6945. macro is defined temporarily for the rest of the compilation of that file.  To 
  6946. use this feature, you must define the macro in the same file where it is used 
  6947. and before its first use. 
  6948.  
  6949.  While byte-compiling a file, any require calls at top-level are executed.  One 
  6950. way to ensure that necessary macro definitions are available during compilation 
  6951. is to require the file that defines them. See Features. 
  6952.  
  6953.  
  6954. ΓòÉΓòÉΓòÉ 15.4. Defining Macros ΓòÉΓòÉΓòÉ
  6955.  
  6956.  A Lisp macro is a list whose car is macro.  Its cdr should be a function; 
  6957. expansion of the macro works by applying the function (with apply) to the list 
  6958. of unevaluated argument-expressions from the macro call. 
  6959.  
  6960.  It is possible to use an anonymous Lisp macro just like an anonymous function, 
  6961. but this is never done, because it does not make sense to pass an anonymous 
  6962. macro to mapping functions such as mapcar.  In practice, all Lisp macros have 
  6963. names, and they are usually defined with the special form defmacro. 
  6964.  
  6965. -- Special Form: defmacro name argument-list body-forms... 
  6966. defmacro defines the symbol name as a macro that looks like this: 
  6967.  
  6968. (macro lambda argument-list . body-forms)
  6969.  
  6970. This macro object is stored in the function cell of name.  The value returned 
  6971. by evaluating the defmacro form is name, but usually we ignore this value. 
  6972.  
  6973. The shape and meaning of argument-list is the same as in a function, and the 
  6974. keywords &rest and &optional may be used (see Argument List).  Macros may have 
  6975. a documentation string, but any interactive declaration is ignored since macros 
  6976. cannot be called interactively. 
  6977.  
  6978.  
  6979. ΓòÉΓòÉΓòÉ 15.5. Backquote ΓòÉΓòÉΓòÉ
  6980.  
  6981.  It could prove rather awkward to write macros of significant size, simply due 
  6982. to the number of times the function list needs to be called.  To make writing 
  6983. these forms easier, a macro ``' (often called backquote) exists. 
  6984.  
  6985.  Backquote allows you to quote a list, but selectively evaluate elements of 
  6986. that list.  In the simplest case, it is identical to the special form quote 
  6987. (see Quoting).  For example, these two forms yield identical results: 
  6988.  
  6989. (` (a list of (+ 2 3) elements))
  6990.      => (a list of (+ 2 3) elements)
  6991. (quote (a list of (+ 2 3) elements))
  6992.      => (a list of (+ 2 3) elements)
  6993.  
  6994. By inserting a special marker, `,', inside of the argument to backquote, it is 
  6995. possible to evaluate desired portions of the argument: 
  6996.  
  6997. (list 'a 'list 'of (+ 2 3) 'elements)
  6998.      => (a list of 5 elements)
  6999. (` (a list of (, (+ 2 3)) elements))
  7000.      => (a list of 5 elements)
  7001.  
  7002. It is also possible to have an evaluated list spliced into the resulting list 
  7003. by using the special marker `,@'.  The elements of the spliced list become 
  7004. elements at the same level as the other elements of the resulting list.  The 
  7005. equivalent code without using ` is often unreadable.  Here are some examples: 
  7006.  
  7007. (setq some-list '(2 3))
  7008.      => (2 3)
  7009. (cons 1 (append some-list '(4) some-list))
  7010.      => (1 2 3 4 2 3)
  7011. (` (1 (,@ some-list) 4 (,@ some-list)))
  7012.      => (1 2 3 4 2 3)
  7013.  
  7014. (setq list '(hack foo bar))
  7015.      => (hack foo bar)
  7016. (cons 'use
  7017.   (cons 'the
  7018.     (cons 'words (append (cdr list) '(as elements)))))
  7019.      => (use the words foo bar as elements)
  7020. (` (use the words (,@ (cdr list)) as elements (,@ nil)))
  7021.      => (use the words foo bar as elements)
  7022.  
  7023. The reason for (,@ nil) is to avoid a bug in Emacs version 18. The bug occurs 
  7024. when a call to ,@ is followed only by constant elements.  Thus, 
  7025.  
  7026. (` (use the words (,@ (cdr list)) as elements))
  7027.  
  7028. would not work, though it really ought to.  (,@ nil) avoids the problem by 
  7029. being a nonconstant element that does not affect the result. 
  7030.  
  7031. -- Macro: ` list 
  7032. This macro returns list as quote would, except that the list is copied each 
  7033. time this expression is evaluated, and any sublist of the form (, subexp) is 
  7034. replaced by the value of subexp.  Any sublist of the form (,@ listexp) is 
  7035. replaced by evaluating listexp and splicing its elements into the containing 
  7036. list in place of this sublist.  (A single sublist can in this way be replaced 
  7037. by any number of new elements in the containing list.) 
  7038.  
  7039. There are certain contexts in which `,' would not be recognized and should not 
  7040. be used: 
  7041.  
  7042. ;; Use of a `,' expression as the cdr of a list.
  7043. (` (a . (, 1)))                                 ; Not (a . 1)
  7044.      => (a \, 1)
  7045.  
  7046. ;; Use of `,' in a vector.
  7047. (` [a (, 1) c])                                 ; Not [a 1 c]
  7048.      error--> Wrong type argument
  7049.  
  7050. ;; Use of a `,' as the entire argument of ``'.
  7051. (` (, 2))                                       ; Not 2
  7052.      => (\, 2)
  7053.  
  7054. Common Lisp note: in Common Lisp, `,' and `,@' are implemented as reader 
  7055. macros, so they do not require parentheses.  Emacs Lisp implements them as 
  7056. functions because reader macros are not supported (to save space). 
  7057.  
  7058.  
  7059. ΓòÉΓòÉΓòÉ 15.6. Common Problems Using Macros ΓòÉΓòÉΓòÉ
  7060.  
  7061.  The basic facts of macro expansion have all been described above, but there 
  7062. consequences are often counterintuitive.  This section describes some important 
  7063. consequences that can lead to trouble, and rules to follow to avoid trouble. 
  7064.  
  7065.  
  7066. ΓòÉΓòÉΓòÉ 15.6.1. Evaluating Macro Arguments Too Many Times ΓòÉΓòÉΓòÉ
  7067.  
  7068.  When defining a macro you must pay attention to the number of times the 
  7069. arguments will be evaluated when the expansion is executed.  The following 
  7070. macro (used to facilitate iteration) illustrates the problem. This macro allows 
  7071. us to write a simple ``for'' loop such as one might find in Pascal. 
  7072.  
  7073. (defmacro for (var from init to final do &rest body)
  7074.   "Execute a simple \"for\" loop, e.g.,
  7075.     (for i from 1 to 10 do (print i))."
  7076.   (list 'let (list (list var init))
  7077.         (cons 'while (cons (list '<= var final)
  7078.                            (append body (list (list 'inc var)))))))
  7079. => for
  7080.  
  7081. (for i from 1 to 3 do
  7082.    (setq square (* i i))
  7083.    (princ (format "\n%d %d" i square)))
  7084. ->
  7085. (let ((i 1))
  7086.   (while (<= i 3)
  7087.     (setq square (* i i))
  7088.     (princ (format "%d      %d" i square))
  7089.     (inc i)))
  7090.  
  7091.      -|1       1
  7092.      -|2       4
  7093.      -|3       9
  7094. => nil
  7095.  
  7096. (The arguments from, to, and do in this macro are ``syntactic sugar''; they are 
  7097. entirely ignored.  The idea is that you will write noise words (such as from, 
  7098. to, and do) in those positions in the macro call.) 
  7099.  
  7100. This macro suffers from the defect that final is evaluated on every iteration. 
  7101. If final is a constant, this is not a problem. If it is a more complex form, 
  7102. say (long-complex-calculation x), this can slow down the execution 
  7103. significantly.  If final has side effects, executing it more than once is 
  7104. probably incorrect. 
  7105.  
  7106. A well-designed macro definition takes steps to avoid this problem by producing 
  7107. an expansion that evaluates the argument expressions exactly once unless 
  7108. repeated evaluation is part of the intended purpose of the macro.  Here is a 
  7109. correct expansion for the for macro: 
  7110.  
  7111. (let ((i 1)
  7112.       (max 3))
  7113.   (while (<= i max)
  7114.     (setq square (* i i))
  7115.     (princ (format "%d      %d" i square))
  7116.     (inc i)))
  7117.  
  7118. Here is a macro definition that creates this expansion: 
  7119.  
  7120. (defmacro for (var from init to final do &rest body)
  7121.   "Execute a simple for loop: (for i from 1 to 10 do (print i))."
  7122.   (` (let (((, var) (, init))
  7123.            (max (, final)))
  7124.        (while (<= (, var) max)
  7125.          (,@ body)
  7126.          (inc (, var))))))
  7127.  
  7128.  Unfortunately, this introduces another problem. Proceed to the following node. 
  7129.  
  7130.  
  7131. ΓòÉΓòÉΓòÉ 15.6.2. Local Variables in Macro Expansions ΓòÉΓòÉΓòÉ
  7132.  
  7133.  In the previous section, the definition of for was fixed as follows to make 
  7134. the expansion evaluate the macro arguments the proper number of times: 
  7135.  
  7136. (defmacro for (var from init to final do &rest body)
  7137.   "Execute a simple for loop: (for i from 1 to 10 do (print i))."
  7138.   (` (let (((, var) (, init))
  7139.            (max (, final)))
  7140.        (while (<= (, var) max)
  7141.          (,@ body)
  7142.          (inc (, var))))))
  7143.  
  7144.  The new definition of for has a new problem: it introduces a local variable 
  7145. named max which the user does not expect.  This will cause trouble in examples 
  7146. such as the following: 
  7147.  
  7148. (let ((max 0))
  7149.   (for x from 0 to 10 do
  7150.     (let ((this (frob x)))
  7151.       (if (< max this)
  7152.           (setq max this)))))
  7153.  
  7154. The references to max inside the body of the for, which are supposed to refer 
  7155. to the user's binding of max, will instead access the binding made by for. 
  7156.  
  7157. The way to correct this is to use an uninterned symbol instead of max (see 
  7158. Creating Symbols).  The uninterned symbol can be bound and referred to just 
  7159. like any other symbol, but since it is created by for, we know that it cannot 
  7160. appear in the user's program. Since it is not interned, there is no way the 
  7161. user can put it into the program later.  It will not appear anywhere except 
  7162. where put by for.  Here is a definition of for which works this way: 
  7163.  
  7164. (defmacro for (var from init to final do &rest body)
  7165.   "Execute a simple for loop: (for i from 1 to 10 do (print i))."
  7166.   (let ((tempvar (make-symbol "max")))
  7167.     (` (let (((, var) (, init))
  7168.              ((, tempvar) (, final)))
  7169.          (while (<= (, var) (, tempvar))
  7170.                 (,@ body)
  7171.                 (inc (, var)))))))
  7172.  
  7173. This creates an uninterned symbol named max and puts it in the expansion 
  7174. instead of the usual interned symbol max that appears in expressions 
  7175. ordinarily. 
  7176.  
  7177.  
  7178. ΓòÉΓòÉΓòÉ 15.6.3. Evaluating Macro Arguments in Expansion ΓòÉΓòÉΓòÉ
  7179.  
  7180.  Another problem can happen if you evaluate any of the macro argument 
  7181. expressions during the computation of the expansion, such as by calling eval 
  7182. (see Eval).  If the argument is supposed to refer to the user's variables, you 
  7183. may have trouble if the user happens to use a variable with the same name as 
  7184. one of the macro arguments.  Inside the macro body, the macro argument binding 
  7185. is the most local binding of this variable, so any references inside the form 
  7186. being evaluated will refer to it.  Here is an example: 
  7187.  
  7188. (defmacro foo (a)
  7189.   (list 'setq (eval a) t))
  7190.      => foo
  7191. (setq x 'b)
  7192. (foo x) -> (setq b t)
  7193.      => t                  ; and b has been set.
  7194. ;; but
  7195. (setq a 'b)
  7196. (foo a) -> (setq 'b t)     ; invalid!
  7197. error--> Symbol's value is void: b
  7198.  
  7199.  It makes a difference whether the user types a or x, because a conflicts with 
  7200. the macro argument variable a. 
  7201.  
  7202.  In general it is best to avoid calling eval in a macro definition at all. 
  7203.  
  7204.  
  7205. ΓòÉΓòÉΓòÉ 15.6.4. How Many Times is the Macro Expanded? ΓòÉΓòÉΓòÉ
  7206.  
  7207.  Occasionally problems result from the fact that a macro call is expanded each 
  7208. time it is evaluated in an interpreted function, but is expanded only once 
  7209. (during compilation) for a compiled function.  If the macro definition has side 
  7210. effects, they will work differently depending on how many times the macro is 
  7211. expanded. 
  7212.  
  7213.  In particular, constructing objects is a kind of side effect.  If the macro is 
  7214. called once, then the objects are constructed only once.  In other words, the 
  7215. same structure of objects is used each time the macro call is executed.  In 
  7216. interpreted operation, the macro is reexpanded each time, producing a fresh 
  7217. collection of objects each time.  Usually this does not matter---the objects 
  7218. have the same contents whether they are shared or not.  But if the surrounding 
  7219. program does side effects on the objects, it makes a difference whether they 
  7220. are shared.  Here is an example: 
  7221.  
  7222. (defmacro new-object ()
  7223.   (list 'quote (cons nil nil)))
  7224.  
  7225. (defun initialize (condition)
  7226.   (let ((object (new-object)))
  7227.     (if condition
  7228.         (setcar object condition))
  7229.     object))
  7230.  
  7231. If initialize is interpreted, a new list (nil) is constructed each time 
  7232. initialize is called.  Thus, no side-effect survives between calls.  If 
  7233. initialize is compiled, then the macro new-object is expanded during 
  7234. compilation, producing a single ``constant'' (nil) that is reused and altered 
  7235. each time initialize is called. 
  7236.  
  7237.  
  7238. ΓòÉΓòÉΓòÉ 16. Loading ΓòÉΓòÉΓòÉ
  7239.  
  7240.  Loading a file of Lisp code means bringing its contents into the Lisp 
  7241. environment in the form of Lisp objects.  Emacs finds and opens the file, reads 
  7242. the text, evaluates each form, and then closes the file. 
  7243.  
  7244.  The load functions evaluate all the expressions in a file just as the 
  7245. eval-current-buffer function evaluates all the expressions in a buffer.  The 
  7246. difference is that the load functions read and evaluate the text in the file as 
  7247. found on disk, not the text in an Emacs buffer. 
  7248.  
  7249.  The loaded file must contain Lisp expressions, either as source code or, 
  7250. optionally, as byte-compiled code.  Each form in the file is called a top-level 
  7251. form.  There is no special format for the forms in a loadable file; any form in 
  7252. a file may equally well be typed directly into a buffer and evaluated there. 
  7253. (Indeed, most code is tested this way.)  Most often, the forms are function 
  7254. definitions and variable definitions. 
  7255.  
  7256.  A file containing Lisp code is often called a library.  Thus, the ``Rmail 
  7257. library'' is a file containing code for Rmail mode. Similarly, a ``Lisp library 
  7258. directory'' is a directory of files containing Lisp code. 
  7259.  
  7260.  
  7261. ΓòÉΓòÉΓòÉ 16.1. How Programs Do Loading ΓòÉΓòÉΓòÉ
  7262.  
  7263.  There are several interface functions for loading.  For example, the autoload 
  7264. function creates a Lisp object that loads a file when it is evaluated (see 
  7265. Autoload).  require also causes files to be loaded (see Features).  Ultimately, 
  7266. all these facilities call the load function to do the work. 
  7267.  
  7268. -- Function: load filename &optional missing-ok nomessage nosuffix 
  7269. This function finds and opens a file of Lisp code, evaluates all the forms in 
  7270. it, and closes the file. 
  7271.  
  7272. To find the file, load first looks for a file named `filename.elc', that is, 
  7273. for a file whose name has `.elc' appended.  If such a file exists, it is 
  7274. loaded.  But if there is no file by that name, then load looks for a file whose 
  7275. name has `.el' appended.  If that file exists, it is loaded. Finally, if there 
  7276. is no file by either name, load looks for a file named filename with nothing 
  7277. appended, and loads it if it exists.  (The load function is not clever about 
  7278. looking at filename.  In the perverse case of a file named `foo.el.el', 
  7279. evaluation of (load "foo.el") will indeed find it.) 
  7280.  
  7281. If the optional argument nosuffix is non-nil, then the suffixes `.elc' and 
  7282. `.el' are not tried.  In this case, the file name must be specified precisely. 
  7283.  
  7284. If filename is a relative file name, such as `foo.bar' or `baz/foo.bar', Emacs 
  7285. searches for the file using the variable load-path.  Emacs does this by 
  7286. appending filename to each of the directories listed in load-path, and loading 
  7287. the first file it finds whose name matches.  The current default directory is 
  7288. tried only if it is specified in load-path, where it is represented as nil. 
  7289. All three possible suffixes are tried in the first directory in load-path, then 
  7290. all three in the second directory in load-path, etc. 
  7291.  
  7292. Messages like `Loading foo...' and `Loading foo...done' are printed in the echo 
  7293. area while loading unless nomessage is non-nil. 
  7294.  
  7295. Any errors that are encountered while loading a file cause load to abort.  If 
  7296. the load was done for the sake of autoload, certain kinds of top-level forms, 
  7297. those which define functions, are undone. 
  7298.  
  7299. The error file-error is signaled (with `Cannot open load file filename') if no 
  7300. file is found.  No error is signaled if missing-ok is non-nil---then load just 
  7301. returns nil. 
  7302.  
  7303. load returns t if the file loads successfully. 
  7304.  
  7305. -- User Option: load-path 
  7306. The value of this variable is a list of directories to search when loading 
  7307. files with load.  Each element is a string (which must be a directory name) or 
  7308. nil (which stands for the current working directory).  The value of load-path 
  7309. is initialized from the environment variable EMACSLOADPATH, if it exists; 
  7310. otherwise it is set to the default specified in `emacs/src/paths.h' when Emacs 
  7311. is built. 
  7312.  
  7313. The syntax of EMACSLOADPATH is the same as that of PATH; fields are separated 
  7314. by `:', and `.' is used for the current default directory.  Here is an example 
  7315. of how to set your EMACSLOADPATH variable from a csh `.login' file: 
  7316.  
  7317. setenv EMACSLOADPATH .:/user/liberte/emacs:/usr/local/lib/emacs/lisp
  7318.  
  7319. Here is how to set it using sh: 
  7320.  
  7321. export EMACSLOADPATH
  7322. EMACSLOADPATH=.:/user/liberte/emacs:/usr/local/lib/emacs/lisp
  7323.  
  7324. Here is an example of code you can place in a `.emacs' file to add several 
  7325. directories to the front of your default load-path: 
  7326.  
  7327. (setq load-path
  7328.       (append
  7329.        (list nil
  7330.              "/user/liberte/emacs"
  7331.              "/usr/local/lisplib")
  7332.        load-path))
  7333.  
  7334. In this example, the path searches the current working directory first, 
  7335. followed by `/user/liberte/emacs' and `/usr/local/lisplib', which are then 
  7336. followed by the standard directories for Lisp code. 
  7337.  
  7338. When Emacs 18 is processing command options `-l' or `-load' which specify Lisp 
  7339. libraries to be loaded, it temporarily adds the current directory to the front 
  7340. of load-path so that files in the current directory can be specified easily. 
  7341. Emacs version 19 will also find such files in the current directory but without 
  7342. altering load-path. 
  7343.  
  7344. -- Variable: load-in-progress 
  7345. This variable is non-nil if Emacs is in the process of loading a file, and it 
  7346. is nil otherwise.  This is how defun and provide determine whether a load is in 
  7347. progress, so that their effect can be undone if the load fails. 
  7348.  
  7349.  To learn how load is used to build Emacs, see Building Emacs. 
  7350.  
  7351.  
  7352. ΓòÉΓòÉΓòÉ 16.2. Autoload ΓòÉΓòÉΓòÉ
  7353.  
  7354.  The autoload facility allows you to make a function or macro available but put 
  7355. off loading its actual definition.  An attempt to call a symbol whose 
  7356. definition is an autoload object automatically reads the file to install the 
  7357. real definition and its other associated code, and then calls the real 
  7358. definition. 
  7359.  
  7360.  To prepare a function or macro for autoloading, you must call autoload, 
  7361. specifying the function name and the name of the file to be loaded.  This is 
  7362. usually done when Emacs is first built, by files such as 
  7363. `emacs/lisp/loaddefs.el'. 
  7364.  
  7365.  The following example shows how doctor is prepared for autoloading in 
  7366. `loaddefs.el': 
  7367.  
  7368. (autoload 'doctor "doctor"
  7369.   "\
  7370. Switch to *doctor* buffer and start giving psychotherapy."
  7371.   t)
  7372.  
  7373. The backslash and newline immediately following the double-quote are a 
  7374. convention used only in the preloaded Lisp files such as `loaddefs.el'; they 
  7375. cause the documentation string to be put in the `etc/DOC' file.  (See Building 
  7376. Emacs.)  In any other source file, you would write just this: 
  7377.  
  7378. (autoload 'doctor "doctor"
  7379.   "Switch to *doctor* buffer and start giving psychotherapy."
  7380.   t)
  7381.  
  7382.  Calling autoload creates an autoload object containing the name of the file 
  7383. and some other information, and makes this the definition of the specified 
  7384. symbol.  When you later try to call that symbol as a function or macro, the 
  7385. file is loaded; the loading should redefine that symbol with its proper 
  7386. definition.  After the file completes loading, the function or macro is called 
  7387. as if it had been there originally. 
  7388.  
  7389.  If, at the end of loading the file, the desired Lisp function or macro has not 
  7390. been defined, then the error error is signaled (with data "Autoloading failed 
  7391. to define function function-name"). 
  7392.  
  7393.  The autoloaded file may, of course, contain other definitions and may require 
  7394. or provide one or more features.  If the file is not completely loaded (due to 
  7395. an error in the evaluation of the contents) any function definitions or provide 
  7396. calls that occurred during the load are undone.  This is to ensure that the 
  7397. next attempt to call any function autoloading from this file will try again to 
  7398. load the file.  If not for this, then some of the functions in the file might 
  7399. appear defined, but they may fail to work properly for the lack of certain 
  7400. subroutines defined later in the file and not loaded successfully. 
  7401.  
  7402. -- Function: autoload symbol filename &optional docstring interactive macro 
  7403.  This function defines the function (or macro) named symbol so as to load 
  7404. automatically from filename.  The string filename is a file name which will be 
  7405. passed to load when the function is called. 
  7406.  
  7407.  The argument docstring is the documentation string for the function. 
  7408. Normally, this is the same string that is in the function definition itself. 
  7409. This makes it possible to look at the documentation without loading the real 
  7410. definition. 
  7411.  
  7412.  If interactive is non-nil, then the function can be called interactively. 
  7413. This lets completion in M-x work without loading the function's real 
  7414. definition.  The complete interactive specification need not be given here.  If 
  7415. macro is non-nil, then the function is really a macro. 
  7416.  
  7417.  If symbol already has a non-nil function definition that is not an autoload 
  7418. object, autoload does nothing and returns nil.  If the function cell of symbol 
  7419. is void, or is already an autoload object, then it is set to an autoload object 
  7420. that looks like this: 
  7421.  
  7422. (autoload filename docstring interactive macro)
  7423.  
  7424.  For example, 
  7425.  
  7426. (symbol-function 'run-prolog)
  7427.      => (autoload "prolog" 169681 t nil)
  7428.  
  7429. In this case, "prolog" is the name of the file to load, 169681 is the reference 
  7430. to the documentation string in the `emacs/etc/DOC' file (see Documentation 
  7431. Basics), t means the function is interactive, and nil that it is not a macro. 
  7432.  
  7433.  
  7434. ΓòÉΓòÉΓòÉ 16.3. Repeated Loading ΓòÉΓòÉΓòÉ
  7435.  
  7436.  You may load a file more than once in an Emacs session.  For example, after 
  7437. you have rewritten and reinstalled a function definition by editing it in a 
  7438. buffer, you may wish to return to the original version; you can do this by 
  7439. reloading the file in which it is located. 
  7440.  
  7441.  When you load or reload files, bear in mind that the load and load-library 
  7442. functions automatically load a byte-compiled file rather than a non-compiled 
  7443. file of similar name.  If you rewrite a file that you intend to save and 
  7444. reinstall, remember to byte-compile it if necessary; otherwise you may find 
  7445. yourself inadvertently reloading the older, byte-compiled file instead of your 
  7446. newer, non-compiled file! 
  7447.  
  7448.  When writing the forms in a library, keep in mind that the library might be 
  7449. loaded more than once.  For example, the choice of defvar vs. defconst for 
  7450. defining a variable depends on whether it is desirable to reinitialize the 
  7451. variable if the library is reloaded: defconst does so, and defvar does not. 
  7452. (See Defining Variables.) 
  7453.  
  7454.  The simplest way to add an element to an alist is like this: 
  7455.  
  7456. (setq minor-mode-alist (cons '(leif-mode " Leif") minor-mode-alist))
  7457.  
  7458. But this would add multiple elements if the library is reloaded. To avoid the 
  7459. problem, write this: 
  7460.  
  7461. (or (assq 'leif-mode minor-mode-alist)
  7462.     (setq minor-mode-alist
  7463.           (cons '(leif-mode " Leif") minor-mode-alist)))
  7464.  
  7465.  Occasionally you will want to test explicitly whether a library has already 
  7466. been loaded; you can do so as follows: 
  7467.  
  7468. (if (not (boundp 'foo-was-loaded))
  7469.     execute-first-time-only)
  7470.  
  7471. (setq foo-was-loaded t)
  7472.  
  7473.  
  7474. ΓòÉΓòÉΓòÉ 16.4. Features ΓòÉΓòÉΓòÉ
  7475.  
  7476.  provide and require are an alternative to autoload for loading files 
  7477. automatically.  They work in terms of named features.  Autoloading is triggered 
  7478. by calling a specific function, but a feature is loaded the first time another 
  7479. program asks for it by name. 
  7480.  
  7481.  The use of named features simplifies the task of determining whether required 
  7482. definitions have been defined.  A feature name is a symbol that stands for a 
  7483. collection of functions, variables, etc.  A program that needs the collection 
  7484. may ensure that they are defined by requiring the feature.  If the file that 
  7485. contains the feature has not yet been loaded, then it will be loaded (or an 
  7486. error will be signaled if it cannot be loaded).  The file thus loaded must 
  7487. provide the required feature or an error will be signaled. 
  7488.  
  7489.  To require the presence of a feature, call require with the feature name as 
  7490. argument.  require looks in the global variable features to see whether the 
  7491. desired feature has been provided already.  If not, it loads the feature from 
  7492. the appropriate file.  This file should call provide at the top-level to add 
  7493. the feature to features. 
  7494.  
  7495.  Features are normally named after the files they are provided in so that 
  7496. require need not be given the file name. 
  7497.  
  7498.  For example, in `emacs/lisp/prolog.el', the definition for run-prolog includes 
  7499. the following code: 
  7500.  
  7501. (interactive)
  7502. (require 'shell)
  7503. (switch-to-buffer (make-shell "prolog" "prolog"))
  7504. (inferior-prolog-mode))
  7505.  
  7506. The expression (require 'shell) loads the file `shell.el' if it has not yet 
  7507. been loaded.  This ensures that make-shell is defined. 
  7508.  
  7509. The `shell.el' file contains the following top-level expression: 
  7510.  
  7511. (provide 'shell)
  7512.  
  7513. This adds shell to the global features list when the `shell' file is loaded, so 
  7514. that (require 'shell) will henceforth know that nothing needs to be done. 
  7515.  
  7516.  When require is used at top-level in a file, it takes effect if you 
  7517. byte-compile that file (see Byte Compilation).  This is in case the required 
  7518. package contains macros that the byte compiler must know about. 
  7519.  
  7520.  Although top-level calls to require are evaluated during byte compilation, 
  7521. provide calls are not.  Therefore, you can ensure that a file of definitions is 
  7522. loaded before it is byte-compiled by including a provide followed by a require 
  7523. for the same feature, as in the following example. 
  7524.  
  7525. (provide 'my-feature)  ; Ignored by byte compiler, evaluated by load.
  7526. (require 'my-feature)  ; Evaluated by byte compiler.
  7527.  
  7528. -- Function: provide feature 
  7529. This function announces that feature is now loaded, or being loaded, into the 
  7530. current Emacs session.  This means that the facilities associated with feature 
  7531. are or will be available for other Lisp programs. 
  7532.  
  7533. The direct effect of calling provide is to add feature to the front of the list 
  7534. features if it is not already in the list. The argument feature must be a 
  7535. symbol.  provide returns feature. 
  7536.  
  7537. features
  7538.      => (bar bish)
  7539.  
  7540. (provide 'foo)
  7541.      => foo
  7542. features
  7543.      => (foo bar bish)
  7544.  
  7545. During autoloading, if the file is not completely loaded (due to an error in 
  7546. the evaluation of the contents) any function definitions or provide calls that 
  7547. occurred during the load are undone. See Autoload. 
  7548.  
  7549. -- Function: require feature &optional filename 
  7550.  This function checks whether feature is present in the current Emacs session 
  7551. (using (featurep feature); see below).  If it is not, then require loads 
  7552. filename with load.  If filename is not supplied, then the name of the symbol 
  7553. feature is used as the file name to load. 
  7554.  
  7555.  If feature is not provided after the file has been loaded, Emacs will signal 
  7556. the error error (with data `Required feature feature was not provided'). 
  7557.  
  7558. -- Function: featurep feature 
  7559.  This function returns t if feature has been provided in the current Emacs 
  7560. session (i.e., feature is a member of features.) 
  7561.  
  7562. -- Variable: features 
  7563.  The value of this variable is a list of symbols that are the features loaded 
  7564. in the current Emacs session.  Each symbol was put in this list with a call to 
  7565. provide.  The order of the elements in the features list is not significant. 
  7566.  
  7567.  
  7568. ΓòÉΓòÉΓòÉ 17. Byte Compilation ΓòÉΓòÉΓòÉ
  7569.  
  7570.  GNU Emacs Lisp has a compiler that translates functions written in Lisp into a 
  7571. special representation called byte-code that can be executed more efficiently. 
  7572. The compiler replaces Lisp function definitions with byte-code.  When a 
  7573. byte-code function is called, its definition is evaluated by the byte-code 
  7574. interpreter. 
  7575.  
  7576.  Because the byte-compiled code is evaluated by the byte-code interpreter, 
  7577. instead of being executed directly by the machine's hardware (as true compiled 
  7578. code is), byte-code is completely transportable from machine to machine without 
  7579. recompilation.  It is not, however, as fast as true compiled code. 
  7580.  
  7581.  See Compilation Errors, for how to investigate errors occurring in byte 
  7582. compilation. 
  7583.  
  7584.  
  7585. ΓòÉΓòÉΓòÉ 17.1. The Compilation Functions ΓòÉΓòÉΓòÉ
  7586.  
  7587.  An individual function or macro definition may be byte-compiled with the 
  7588. byte-compile function.  A whole file may be byte-compiled with 
  7589. byte-compile-file and several files may be byte-compiled with 
  7590. byte-recompile-directory or batch-byte-compile. Only defun and defmacro forms 
  7591. in a file are byte-compiled; other top-level forms are not altered by byte 
  7592. compilation. 
  7593.  
  7594.  Be careful when byte-compiling code that uses macros.  Macro calls are 
  7595. expanded when they are compiled, so the macros must already be defined for 
  7596. proper compilation.  For more details, see Compiling Macros. 
  7597.  
  7598.  While byte-compiling a file, any require calls at top-level are executed.  One 
  7599. way to ensure that necessary macro definitions are available during compilation 
  7600. is to require the file that defines them. See Features. 
  7601.  
  7602.  A byte-compiled function is not as efficient as a primitive function written 
  7603. in C, but will run much faster than the version written in Lisp. For a rough 
  7604. comparison, consider the example below: 
  7605.  
  7606. (defun silly-loop (n)
  7607.   "Return time before and after N iterations of a loop."
  7608.   (let ((t1 (current-time-string)))
  7609.     (while (> (setq n (1- n))
  7610.               0))
  7611.     (list t1 (current-time-string))))
  7612. => silly-loop
  7613.  
  7614. (silly-loop 100000)
  7615. => ("Thu Jan 12 20:18:38 1989"
  7616.     "Thu Jan 12 20:19:29 1989")  ; 51 seconds
  7617.  
  7618. (byte-compile 'silly-loop)
  7619. => [Compiled code not shown]
  7620.  
  7621. (silly-loop 100000)
  7622. => ("Thu Jan 12 20:21:04 1989"
  7623.     "Thu Jan 12 20:21:17 1989")  ; 13 seconds
  7624.  
  7625.  In this example, the interpreted code required 51 seconds to run, whereas the 
  7626. byte-compiled code required 13 seconds.  These results are representative, but 
  7627. actual results will vary greatly. 
  7628.  
  7629. -- Function: byte-compile symbol 
  7630.  This function byte-compiles the function definition of symbol, replacing the 
  7631. previous definition with the compiled one.  The function definition of symbol 
  7632. must be the actual code for the function; i.e., the compiler will not follow 
  7633. indirection to another symbol. byte-compile does not compile macros. 
  7634. byte-compile returns the new, compiled definition of symbol. 
  7635.  
  7636. (defun factorial (integer)
  7637.   "Compute factorial of INTEGER."
  7638.   (if (= 1 integer) 1
  7639.     (* integer (factorial (1- integer)))))
  7640.      => factorial
  7641.  
  7642. (byte-compile 'factorial)
  7643.      => (lambda (integer)
  7644.                  "Compute factorial of INTEGER."
  7645.                  (byte-code "\301^HU\203
  7646. ^@\301\202^Q^@\302^H\303^HS!\"\207"
  7647.                             [integer 1 * factorial] 4))
  7648.  
  7649. The string that is the first argument of byte-code is the actual byte-code. 
  7650. Each character in it is an instruction.  The vector contains all the constants, 
  7651. variable names and function names used by the function, except for certain 
  7652. primitives that are coded as special instructions. 
  7653.  
  7654.  The byte-compile function is not autoloaded as are byte-compile-file and 
  7655. byte-recompile-directory. 
  7656.  
  7657. -- Command: byte-compile-file filename 
  7658.  This function compiles a file of Lisp code named filename into a file of 
  7659. byte-code.  The output file's name is made by appending `c' to the end of 
  7660. filename. 
  7661.  
  7662.  Compilation works by reading the input file one form at a time.  If it is a 
  7663. definition of a function or macro, the compiled function or macro definition is 
  7664. written out.  Other forms are copied out unchanged.  All comments are discarded 
  7665. when the input file is read. 
  7666.  
  7667.  This command returns t.  When called interactively, it prompts for the file 
  7668. name. 
  7669.  
  7670. % ls -l push*
  7671. -rw-r--r--  1 lewis             791 Oct  5 20:31 push.el
  7672.  
  7673. (byte-compile-file "~/emacs/push.el")
  7674.      => t
  7675.  
  7676. % ls -l push*
  7677. -rw-r--r--  1 lewis             791 Oct  5 20:31 push.el
  7678. -rw-rw-rw-  1 lewis             638 Oct  8 20:25 push.elc
  7679.  
  7680. -- Command: byte-recompile-directory directory flag 
  7681.  This function recompiles every `.el' file in directory that needs 
  7682. recompilation.  A file needs recompilation if a `.elc' file exists but is older 
  7683. than the `.el' file. 
  7684.  
  7685.  If a `.el' file exists, but there is no corresponding `.elc' file, then flag 
  7686. is examined.  If it is nil, the file is ignored.  If it is non-nil, the user is 
  7687. asked whether the file should be compiled. 
  7688.  
  7689.  The returned value of this command is unpredictable. 
  7690.  
  7691. -- Function: batch-byte-compile 
  7692.  This function runs byte-compile-file on the files remaining on the command 
  7693. line.  This function must be used only in a batch execution of Emacs, as it 
  7694. kills Emacs on completion.  Each file will be processed, even if an error 
  7695. occurs while compiling a previous file.  (The file with the error will not, of 
  7696. course, produce any compiled code.) 
  7697.  
  7698. % emacs -batch -f batch-byte-compile *.el
  7699.  
  7700. -- Function: byte-code code-string data-vector max-stack 
  7701.  This is the function that actually interprets byte-code.  A byte-compiled 
  7702. function is actually defined with a body that calls byte-code.  Don't call this 
  7703. function yourself.  Only the byte compiler knows how to generate valid calls to 
  7704. this function. 
  7705.  
  7706.  
  7707. ΓòÉΓòÉΓòÉ 17.2. Disassembled Byte-Code ΓòÉΓòÉΓòÉ
  7708.  
  7709.  People do not write byte-code; that job is left to the byte compiler. But we 
  7710. provide a disassembler to satisfy a cat-like curiosity.  The disassembler 
  7711. converts the byte-compiled code into humanly readable form. 
  7712.  
  7713.  The byte-code interpreter is implemented as a simple stack machine. Values get 
  7714. stored by being pushed onto the stack, and are popped off and manipulated, the 
  7715. results being pushed back onto the stack.  When a function returns, the top of 
  7716. the stack is popped and returned as the value of the function. 
  7717.  
  7718.  In addition to the stack, values used during byte-code execution can be stored 
  7719. in ordinary Lisp variables.  Variable values can be pushed onto the stack, and 
  7720. variables can be set by popping the stack. 
  7721.  
  7722. -- Command: disassemble object &optional stream 
  7723. This function prints the disassembled code for object.  If stream is supplied, 
  7724. then output goes there.  Otherwise, the disassembled code is printed to the 
  7725. stream standard-output.  The argument object can be a function name or a lambda 
  7726. expression. 
  7727.  
  7728. As a special exception, if this function is used interactively, it outputs to a 
  7729. buffer named `*Disassemble*'. 
  7730.  
  7731.  Here are two examples of using the disassemble function.  We have added 
  7732. explanatory comments to help you relate the byte-code to the Lisp source; these 
  7733. do not appear in the output of disassemble. 
  7734.  
  7735. (defun factorial (integer)
  7736.   "Compute factorial of an integer."
  7737.   (if (= 1 integer) 1
  7738.     (* integer (factorial (1- integer)))))
  7739.      => factorial
  7740.  
  7741. (factorial 4)
  7742.      => 24
  7743.  
  7744. (disassemble 'factorial)
  7745.      -| byte-code for factorial:
  7746.  doc: Compute factorial of an integer.
  7747.  args: (integer)
  7748.  
  7749. 0   constant 1              ; Push 1 onto stack.
  7750.  
  7751. 1   varref   integer        ; Get value of integer from the environment
  7752.                             ;     and push the value onto the stack.
  7753.  
  7754. 2   eqlsign                 ; Pop top two values off stack,
  7755.                             ;     compare them,
  7756.                             ;     and push result onto stack.
  7757.  
  7758. 3   goto-if-nil 10          ; Pop and test top of stack;
  7759.                             ;     if nil, go to 10,
  7760.                             ;     else continue.
  7761.  
  7762. 6   constant 1              ; Push 1 onto top of stack.
  7763.  
  7764. 7   goto     17             ; Go to 17 (in this case, 1 will be
  7765.                             ;     returned by the function).
  7766.  
  7767. 10  constant *              ; Push symbol * onto stack.
  7768.  
  7769. 11  varref   integer        ; Push value of integer onto stack.
  7770.  
  7771. 12  constant factorial      ; Push factorial onto stack.
  7772.  
  7773. 13  varref   integer        ; Push value of integer onto stack.
  7774.  
  7775. 14  sub1                    ; Pop integer, decrement value,
  7776.                             ;     push new value onto stack.
  7777.  
  7778.                         ; Stack now contains:
  7779.                         ;     decremented value of integer
  7780.                         ;     factorial
  7781.                         ;     value of integer
  7782.                         ;     *
  7783.  
  7784. 15  call     1              ; Call function factorial using
  7785.                             ;     the first (i.e., the top) element
  7786.                             ;     of the stack as the argument;
  7787.                             ;     push returned value onto stack.
  7788.  
  7789.                         ; Stack now contains:
  7790.                         ;        result of result of recursive
  7791.                         ;             call to factorial
  7792.                         ;        value of integer
  7793.                         ;        *
  7794.  
  7795. 16  call     2              ; Using the first two (i.e., the top two)
  7796.                             ;     elements of the stack as arguments,
  7797.                             ;     call the function *,
  7798.                             ;     pushing the result onto the stack.
  7799.  
  7800. 17  return                  ; Return the top element of the stack.
  7801.  
  7802.      => nil
  7803.  
  7804. The silly-loop function is somewhat more complex: 
  7805.  
  7806. (defun silly-loop (n)
  7807.   "Return time before and after N iterations of a loop."
  7808.   (let ((t1 (current-time-string)))
  7809.     (while (> (setq n (1- n))
  7810.               0))
  7811.     (list t1 (current-time-string))))
  7812.      => silly-loop
  7813.  
  7814. (disassemble 'silly-loop)
  7815.      -| byte-code for silly-loop:
  7816.  doc: Return time before and after N iterations of a loop.
  7817.  args: (n)
  7818.  
  7819. 0   constant current-time-string      ; Push current-time-string
  7820.                                       ;     onto top of stack.
  7821.  
  7822. 1   call     0              ; Call current-time-string with no
  7823.                             ;     argument, pushing result onto stack.
  7824.  
  7825. 2   varbind  t1             ; Pop stack and bind t1 to popped value.
  7826.  
  7827. 3   varref   n              ; Get value of n from the environment
  7828.                             ;     and push the value onto the stack.
  7829.  
  7830. 4   sub1                    ; Subtract 1 from top of stack.
  7831.  
  7832. 5   dup                     ; Duplicate the top of the stack;
  7833.                             ;     i.e. copy the top of the stack
  7834.                             ;     and push the copy onto the stack.
  7835.  
  7836. 6   varset   n              ; Pop the top of the stack,
  7837.                             ;     and bind n to the value.
  7838.  
  7839.                     ; In effect, the sequence dup varset copies
  7840.                     ; the top of the stack into the value of n
  7841.                     ; without popping it.
  7842.  
  7843. 7   constant 0              ; Push 0 onto stack.
  7844.  
  7845. 8   gtr                     ; Pop top two values off stack,
  7846.                             ;     test if n is greater than 0
  7847.                             ;     and push result onto stack.
  7848.  
  7849. 9   goto-if-nil-else-pop 17     ; Goto 17 if n > 0 else pop top of stack and continue
  7850.                                 ;     (this exits the while loop).
  7851.  
  7852. 12  constant nil            ; Push nil onto stack
  7853.                             ;     (this is the body of the loop).
  7854.  
  7855. 13  discard                 ; Discard result of the body of the loop
  7856.                             ;     (a while loop is always evaluated
  7857.                             ;     for its side effects).
  7858.  
  7859. 14  goto     3              ; Jump back to beginning of while loop.
  7860.  
  7861. 17  discard                 ; Discard result of while loop
  7862.                             ;     by popping top of stack.
  7863.  
  7864. 18  varref   t1             ; Push value of t1 onto stack.
  7865.  
  7866. 19  constant current-time-string      ; Push current-time-string
  7867.                                       ;     onto top of stack.
  7868.  
  7869. 20  call     0              ; Call current-time-string again.
  7870.  
  7871. 21  list2                   ; Pop top two elements off stack,
  7872.                             ;     create a list of them,
  7873.                             ;     and push list onto stack.
  7874.  
  7875. 22  unbind   1              ; Unbind t1 in local environment.
  7876.  
  7877. 23  return                  ; Return value of the top of stack.
  7878.  
  7879.      => nil
  7880.  
  7881.  
  7882. ΓòÉΓòÉΓòÉ 18. Debugging Lisp Programs ΓòÉΓòÉΓòÉ
  7883.  
  7884.  There are three ways to investigate a problem in an Emacs Lisp program, 
  7885. depending on what you are doing with the program when the problem appears. 
  7886.  
  7887. o If the problem occurs when you run the program, you can use the Lisp debugger 
  7888.   to investigate what is happening during execution. 
  7889.  
  7890. o If the problem is syntactic, so that Lisp cannot even read the program, you 
  7891.   can use the Emacs facilities for editing Lisp to localize it. 
  7892.  
  7893. o If the problem occurs when trying to compile the program with the byte 
  7894.   compiler, you need to know how to examine the compiler's input buffer. 
  7895.  
  7896.  Another useful debugging tool is a dribble file.  When a dribble file is open, 
  7897. Emacs copies all keyboard input characters to that file. Afterward, you can 
  7898. examine the file to find out what input was used. See Terminal Input. 
  7899.  
  7900.  For debugging problems in terminal descriptions, the open-termscript function 
  7901. can be useful.  See Terminal Output. 
  7902.  
  7903.  
  7904. ΓòÉΓòÉΓòÉ 18.1. The Lisp Debugger ΓòÉΓòÉΓòÉ
  7905.  
  7906.  The Lisp debugger provides you with the ability to suspend evaluation of a 
  7907. form.  While evaluation is suspended (a state that is commonly known as a 
  7908. break), you may examine the run time stack, examine the values of local or 
  7909. global variables, or change those values. Since a break is a recursive edit, 
  7910. all the usual editing facilities of Emacs are available; you can even run 
  7911. programs that will enter the debugger recursively.  See Recursive Editing. 
  7912.  
  7913.  
  7914. ΓòÉΓòÉΓòÉ 18.1.1. Entering the Debugger When an Error Occurs ΓòÉΓòÉΓòÉ
  7915.  
  7916.  The most important time to enter the debugger is when a Lisp error happens. 
  7917. This allows you to investigate the immediate causes of the error. 
  7918.  
  7919.  However, entry to the debugger is not a normal consequence of an error.  Many 
  7920. commands frequently get Lisp errors when invoked in inappropriate contexts 
  7921. (such as C-f at the end of the buffer) and during ordinary editing it would be 
  7922. very unpleasant to enter the debugger each time this happens.  If you want 
  7923. errors to enter the debugger, set the variable debug-on-error to non-nil. 
  7924.  
  7925. -- User Option: debug-on-error 
  7926. This variable determines whether the debugger is called when a error is 
  7927. signaled and not handled.  If debug-on-error is non-nil, then the debugger is 
  7928. called when an error happens.  Otherwise the debugger is not called for errors. 
  7929.  
  7930.  
  7931. ΓòÉΓòÉΓòÉ 18.2. Debugging Infinite Loops ΓòÉΓòÉΓòÉ
  7932.  
  7933.  When a program loops infinitely and fails to return, your first problem is to 
  7934. stop the loop.  On most operating systems, you can do this with C-g, which 
  7935. causes quit.  This works if you are not using X windows, and on Berkeley 
  7936. systems even if you are using X windows. 
  7937.  
  7938.  On other inferior operating systems, C-g does not work when using X windows. 
  7939. This is because these systems do not allow Emacs to request a signal when input 
  7940. arrives from the X server.  There is nothing Emacs can do about this. 
  7941.  
  7942.  However, you can still stop a loop by sending Emacs the SIGINT signal.  To do 
  7943. this, go to a shell in another window, use ps to find out the pid of the Emacs 
  7944. process, and then type `kill -INT pid'. 
  7945.  
  7946.  Ordinary quitting gives no information about why the program was looping.  To 
  7947. get more information, you can set the variable debug-on-quit to non-nil. 
  7948. Quitting with C-g is not considered an error, and debug-on-error has no effect 
  7949. on the handling of C-g.  debug-on-quit has no effect on errors. 
  7950.  
  7951.  Once you have the debugger running in the middle of the infinite loop, you can 
  7952. proceed from the debugger using the stepping commands.  If you step through the 
  7953. entire loop, you will probably get enough information to solve the problem. 
  7954.  
  7955. -- User Option: debug-on-quit 
  7956. This variable determines whether the debugger is called when quit is signaled 
  7957. and not handled.  If debug-on-quit is non-nil, then the debugger is called 
  7958. whenever you quit (that is, type C-g). If debug-on-quit is nil, then the 
  7959. debugger is not called when you quit.  See Quitting. 
  7960.  
  7961.  
  7962. ΓòÉΓòÉΓòÉ 18.2.1. Entering the Debugger when Some Function is Called ΓòÉΓòÉΓòÉ
  7963.  
  7964.  To investigate a problem that happens in the middle of a program, one useful 
  7965. technique is to cause the debugger to be entered when a certain function is 
  7966. called.  You can do this to the function in which the problem occurs, and then 
  7967. step through the function, or you can do this to a function called shortly 
  7968. before the problem, step quickly over the call to that function, and then step 
  7969. through its caller. 
  7970.  
  7971. -- Command: debug-on-entry function-name 
  7972.  This function requests function-name to invoke the debugger each time it is 
  7973. called.  It works by inserting the form (debug 'debug) into the function 
  7974. definition as the first form. 
  7975.  
  7976.  Any function defined as Lisp code may be set to break on entry, regardless of 
  7977. whether it is interpreted code or compiled code.  Even functions that are 
  7978. commands may be debugged---they will enter the debugger when called inside a 
  7979. function, or when called interactively. Primitive functions (i.e., those 
  7980. written in C) may not be debugged. 
  7981.  
  7982.  When debug-on-entry is called interactively, it prompts for function-name in 
  7983. the minibuffer. 
  7984.  
  7985.  If debug-on-entry is called more than once on the same function, the second 
  7986. call does nothing.  debug-on-entry returns function-name. 
  7987.  
  7988. (defun fact (n)
  7989.   (if (zerop n) 1
  7990.       (* n (fact (1- n)))))
  7991.      => fact
  7992. (debug-on-entry 'fact)
  7993.      => fact
  7994. (fact 3)
  7995.      => 6
  7996.  
  7997. ---------- Buffer: *Backtrace* ----------
  7998. Entering:
  7999. * fact(3)
  8000.   eval-region(4870 4878 t)
  8001.   byte-code("...")
  8002.   eval-last-sexp(nil)
  8003.   (let ...)
  8004.   eval-insert-last-sexp(nil)
  8005. * call-interactively(eval-insert-last-sexp)
  8006. ---------- Buffer: *Backtrace* ----------
  8007.  
  8008. (symbol-function 'fact)
  8009.      => (lambda (n)
  8010.           (debug (quote debug))
  8011.           (if (zerop n) 1 (* n (fact (1- n)))))
  8012.  
  8013. -- Command: cancel-debug-on-entry function-name 
  8014. This function undoes the effect of debug-on-entry on function-name.  When 
  8015. called interactively, it prompts for function-name in the minibuffer. 
  8016.  
  8017. If cancel-debug-on-entry is called more than once on the same function, the 
  8018. second call does nothing.  cancel-debug-on-entry returns function-name. 
  8019.  
  8020.  
  8021. ΓòÉΓòÉΓòÉ 18.2.2. Explicit Entry to the Debugger ΓòÉΓòÉΓòÉ
  8022.  
  8023.  You can cause the debugger to be called at a certain point in your program by 
  8024. writing the expression (debug) at that point.  To do this, visit the source 
  8025. file, insert the text `(debug)' at the proper place, and type C-M-x.  Be sure 
  8026. to undo this insertion before you save the file! 
  8027.  
  8028.  The place where you insert `(debug)' must be a place where an additional form 
  8029. can be evaluated and its value ignored.  (If the value isn't ignored, it will 
  8030. alter the execution of the program!)  Usually this means inside a progn or an 
  8031. implicit progn (see Sequencing). 
  8032.  
  8033.  
  8034. ΓòÉΓòÉΓòÉ 18.2.3. Using the Debugger ΓòÉΓòÉΓòÉ
  8035.  
  8036.  When the debugger is entered, it displays the previously selected buffer in 
  8037. one window and a buffer named `*Backtrace*' in another window.  The backtrace 
  8038. buffer contains one line for each level of Lisp function execution currently 
  8039. going on.  At the beginning of this buffer is a message describing the reason 
  8040. that the debugger was invoked (such as the error message and associated data, 
  8041. if it was invoked due to an error). 
  8042.  
  8043.  The backtrace buffer is read-only and uses a special major mode, Debugger 
  8044. mode, in which letters are defined as debugger commands.  The usual Emacs 
  8045. editing commands are available; thus, you can switch windows to examine the 
  8046. buffer that was being edited at the time of the error, switch buffers, visit 
  8047. files, or do any other sort of editing.  However, the debugger is a recursive 
  8048. editing level (see Recursive Editing) and it is wise to go back to the 
  8049. backtrace buffer and exit the debugger (with the q command) when you you are 
  8050. finished with it.  Exiting the debugger gets out of the recursive edit and 
  8051. kills the backtrace buffer. 
  8052.  
  8053.  The contents of the backtrace buffer show you the functions that are executing 
  8054. and the arguments that were given to them.  It also allows you to specify a 
  8055. stack frame by moving point to the line describing that frame.  (A stack frame 
  8056. is the place where the Lisp interpreter records information about a particular 
  8057. invocation of a function.  The frame whose line point is on is considered the 
  8058. current frame.) Some of the debugger commands operate on the current frame. 
  8059.  
  8060.  The debugger itself should always be run byte-compiled, since it makes 
  8061. assumptions about how many stack frames are used for the debugger itself. 
  8062. These assumptions are false if the debugger is running interpreted. 
  8063.  
  8064.  
  8065. ΓòÉΓòÉΓòÉ 18.2.4. Debugger Commands ΓòÉΓòÉΓòÉ
  8066.  
  8067.  Inside the debugger (in Debugger mode), these special commands are available 
  8068. in addition to the usual cursor motion commands.  (Keep in mind that all the 
  8069. usual facilities of Emacs, such as switching windows or buffers, are still 
  8070. available.) 
  8071.  
  8072.  The most important use of debugger commands is for stepping through code, so 
  8073. that you can see how control flows.  The debugger can step through the control 
  8074. structures of an interpreted function, but cannot do so in a byte-compiled 
  8075. function.  If you would like to step through a byte-compiled function, replace 
  8076. it with an interpreted definition of the same function.  (To do this, visit the 
  8077. source file for the function and type C-M-x on its definition.) 
  8078.  
  8079.           Exit the debugger and continue execution.  When continuing is 
  8080.           possible, it resumes execution of the program as if the debugger had 
  8081.           never been entered (aside from the effect of any variables or data 
  8082.           structures you may have changed while inside the debugger). 
  8083.  
  8084.           Continuing is possible after entry to the debugger due to function 
  8085.           entry or exit, explicit invocation, quitting or certain errors.  Most 
  8086.           errors cannot be continued; trying to continue an unsuitable error 
  8087.           causes the same error to occur again. 
  8088.  
  8089.           Continue execution, but enter the debugger the next time any Lisp 
  8090.           function is called.  This allows you to step through the 
  8091.           subexpressions of an expression, seeing what values the 
  8092.           subexpressions compute, and what else they do. 
  8093.  
  8094.           The stack frame made for the function call which enters the debugger 
  8095.           in this way will be flagged automatically so that the debugger will 
  8096.           be called again when the frame is exited.  You can use the u command 
  8097.           to cancel this flag. 
  8098.  
  8099.           Flag the current frame so that the debugger will be entered when the 
  8100.           frame is exited.  Frames flagged in this way are marked with stars in 
  8101.           the backtrace buffer. 
  8102.  
  8103.           Don't enter the debugger when the current frame is exited.  This 
  8104.           cancels a b command on that frame. 
  8105.  
  8106.           Read a Lisp expression in the minibuffer, evaluate it, and print the 
  8107.           value in the echo area.  This is the same as the command M-ESC, 
  8108.           except that e is not normally disabled like M-ESC. 
  8109.  
  8110.           Terminate the program being debugged; return to top-level Emacs 
  8111.           command execution. 
  8112.  
  8113.           If the debugger was entered due to a C-g but you really want to quit, 
  8114.           and not debug, use the q command. 
  8115.  
  8116.           Return a value from the debugger.  The value is computed by reading 
  8117.           an expression with the minibuffer and evaluating it. 
  8118.  
  8119.           The r command makes a difference when the debugger was invoked due to 
  8120.           exit from a Lisp call frame (as requested with b); then the value 
  8121.           specified in the r command is used as the value of that frame. 
  8122.  
  8123.           The r also matters in certain cases of errors.  For example, 
  8124.           wrong-type-argument errors will use the debugger's return value 
  8125.           instead of the invalid argument; no-catch errors will use the 
  8126.           debugger value as a throw tag instead of the tag that was not found. 
  8127.           If an error was signaled by calling the Lisp function signal, the 
  8128.           debugger's return value is returned as the value of signal. 
  8129.  
  8130.  
  8131. ΓòÉΓòÉΓòÉ 18.2.5. Invoking the Debugger ΓòÉΓòÉΓòÉ
  8132.  
  8133.  Here we describe fully the function used to invoke the debugger. 
  8134.  
  8135. -- Function: debug &rest debugger-args 
  8136.  This function enters the debugger.  It switches buffers to a buffer named 
  8137. `*Backtrace*' (or `*Backtrace*<2>' if it is the second recursive entry to the 
  8138. debugger, etc.), and fills it with information about the stack of Lisp function 
  8139. calls.  It then enters a recursive edit, leaving that buffer in Debugger mode 
  8140. and displayed in the selected window. 
  8141.  
  8142.  Debugger mode provides a c command which operates by exiting the recursive 
  8143. edit, switching back to the previous buffer, and returning to whatever called 
  8144. debug.  The r command also returns from debug.  These are the only ways the 
  8145. function debug can return to its caller. 
  8146.  
  8147.  If the first of the debugger-args passed to debug is nil (or if it is not one 
  8148. of the following special values), then the rest of the arguments to debug are 
  8149. printed at the top of the `*Backtrace*' buffer.  This mechanism is used to 
  8150. display a message to the user. 
  8151.  
  8152.  However, if the first argument passed to debug is one of the following special 
  8153. values, then it has special significance.  Normally, these values are passed to 
  8154. debug only by the internals of Emacs and the debugger, and not by programmers 
  8155. calling debug. 
  8156.  
  8157.  The special values are: 
  8158.  
  8159. lambda 
  8160.            When the first argument is lambda, the debugger displays `Entering:' 
  8161.           as a line of text at the top of the buffer.  This means that a 
  8162.           function is being entered when debug-on-next-call is non-nil. 
  8163.  
  8164. debug 
  8165.            When the first argument is debug, the debugger displays `Entering:' 
  8166.           just as in the lambda case.  However, debug as the argument indicates 
  8167.           that the reason for entering the debugger is that a function set to 
  8168.           debug on entry is being entered. 
  8169.  
  8170.            In addition, debug as the first argument directs the debugger to 
  8171.           mark the function that called debug so that it will invoke the 
  8172.           debugger when exited.  (When lambda is the first argument, the 
  8173.           debugger does not do this, because it has already been done by the 
  8174.           interpreter.) 
  8175.  
  8176.            When the first argument is t, the debugger displays `Beginning 
  8177.           evaluation of function call form:' as the top line in the buffer, to 
  8178.           indicate that it was entered due to the evaluation of a list form at 
  8179.           a time when debug-on-next-call is non-nil. 
  8180.  
  8181. exit 
  8182.            When the first argument is exit, it indicates the exit of a stack 
  8183.           frame previously marked to invoke the debugger on exit.  The debugger 
  8184.           displays `Return value:' on the top line of the buffer, followed by 
  8185.           the value being returned from the frame. 
  8186.  
  8187. error 
  8188.            When the first argument is error, the debugger indicates that it is 
  8189.           being entered because an error or quit was signaled and not handled, 
  8190.           by displaying `Signaling:' followed by the error signaled and any 
  8191.           arguments to signal.  For example, 
  8192.  
  8193.                     (let ((debug-on-error t))
  8194.                          (/ 1 0))
  8195.  
  8196.                     ---------- Buffer: *Backtrace* ----------
  8197.                     Signaling: (arith-error)
  8198.                       /(1 0)
  8199.                     ...
  8200.  
  8201.            If an error was signaled, presumably the variable debug-on-error is 
  8202.           non-nil.  If quit was signaled, then presumably the variable 
  8203.           debug-on-quit is non-nil. 
  8204.  
  8205. nil 
  8206.            Use nil as the first of the debugger-args when you want to enter the 
  8207.           debugger explicitly.  The rest of the debugger-args are printed on 
  8208.           the top line of the buffer.  You can use this feature to display 
  8209.           messages---for example, to remind yourself of the conditions under 
  8210.           which debug is called. 
  8211.  
  8212.  
  8213. ΓòÉΓòÉΓòÉ 18.2.6. Internals of the Debugger ΓòÉΓòÉΓòÉ
  8214.  
  8215.  This section describes functions and variables used internally by the 
  8216. debugger. 
  8217.  
  8218. -- Variable: debugger 
  8219.  The value of this variable is the function to call to invoke the debugger. 
  8220. Its value must be a function of any number of arguments (or, more typically, 
  8221. the name of a function).  Presumably this function will enter some kind of 
  8222. debugger.  The default value of the variable is debug. 
  8223.  
  8224.  The first argument that Lisp hands to the function indicates why it was 
  8225. called.  The convention for arguments is detailed in the description of debug. 
  8226.  
  8227. -- Command: backtrace 
  8228.  This function prints a trace of Lisp function calls currently active. This is 
  8229. the function used by debug to fill up the `*Backtrace*' buffer.  It is written 
  8230. in C, since it must have access to the stack to determine which function calls 
  8231. are active.  The return value is always nil. 
  8232.  
  8233.  In the following example, backtrace is called explicitly in a Lisp expression. 
  8234. When the expression is evaluated, the backtrace is printed to the stream 
  8235. standard-output: in this case, to the buffer `backtrace-output'.  Each line of 
  8236. the backtrace represents one function call.  If the arguments of the function 
  8237. call are all known, they are displayed; if they are being computed, that fact 
  8238. is stated. The arguments of special forms are elided. 
  8239.  
  8240. (with-output-to-temp-buffer "backtrace-output"
  8241.   (let ((var 1))
  8242.     (save-excursion
  8243.       (setq var (eval '(progn
  8244.                          (1+ var)
  8245.                          (list 'testing (backtrace))))))))
  8246.  
  8247.      => nil
  8248. ----------- Buffer: backtrace-output ------------
  8249.   backtrace()
  8250.   (list ...computing arguments...)
  8251.   (progn ...)
  8252.   eval((progn (1+ var) (list (quote testing) (backtrace))))
  8253.   (setq ...)
  8254.   (save-excursion ...)
  8255.   (let ...)
  8256.   (with-output-to-temp-buffer ...)
  8257.   eval-region(1973 2142 #<buffer *scratch*>)
  8258.   byte-code("...  for eval-print-last-sexp ...")
  8259.   eval-print-last-sexp(nil)
  8260. * call-interactively(eval-print-last-sexp)
  8261. ----------- Buffer: backtrace-output ------------
  8262.  
  8263. -- User Option: stack-trace-on-error 
  8264.  This variable controls whether Lisp automatically displays a backtrace buffer 
  8265. after every error that is not handled.  A quit signal counts as an error for 
  8266. this variable.  If it is non-nil then a backtrace is shown in a pop-up buffer 
  8267. named `*Backtrace*' on every error.  If it is nil, then a backtrace is not 
  8268. shown. 
  8269.  
  8270.  When a backtrace is shown, that buffer is not selected.  If either 
  8271. debug-on-quit or debug-on-error is also non-nil, then a backtrace is shown in 
  8272. one buffer, and the debugger is popped up in another buffer with its own 
  8273. backtrace. 
  8274.  
  8275.  We consider this feature to be obsolete and superseded by the debugger itself. 
  8276.  
  8277. -- Variable: debug-on-next-call 
  8278. This variable determines whether the debugger is called before the next eval, 
  8279. apply or funcall.  It is automatically reset to nil when the debugger is 
  8280. entered. 
  8281.  
  8282. The d command in the debugger works by setting this variable. 
  8283.  
  8284. -- Function: backtrace-debug level flag 
  8285.  This function sets the debug-on-exit flag of the eval frame level levels down 
  8286. to flag.  If flag is non-nil, this will cause the debugger to be entered when 
  8287. that frame exits. 
  8288.  
  8289.  The debug-on-exit flag is an entry in the stack frame of a function call. 
  8290. This flag is examined on every exit from a function. 
  8291.  
  8292.  Normally, this function is only called by the debugger. 
  8293.  
  8294.  
  8295. ΓòÉΓòÉΓòÉ 18.3. Debugging Invalid Lisp Syntax ΓòÉΓòÉΓòÉ
  8296.  
  8297.  It is easy to make a syntax error in an Emacs Lisp program by omitting a 
  8298. parenthesis.  The Lisp reader will detect an error, but cannot say where the 
  8299. real problem is.  For example, if a close parenthesis is omitted, the reader 
  8300. will detect an imbalance at the end of the file, but it cannot tell anything 
  8301. about where the close parenthesis should have been.  However, you can use the 
  8302. following techniques to figure out where. 
  8303.  
  8304.  If the problem is not simply an imbalance of parentheses, a useful technique 
  8305. is to try C-M-e at the beginning of each defun, and see if it goes to the place 
  8306. where that defun appears to end.  If it does not, there is a problem in that 
  8307. defun. 
  8308.  
  8309.  However, unmatched parentheses are the most common syntax errors in Lisp, and 
  8310. we can give further advice for those cases. 
  8311.  
  8312.  
  8313. ΓòÉΓòÉΓòÉ 18.3.1. Excess Open Parentheses ΓòÉΓòÉΓòÉ
  8314.  
  8315.  The first step is to find the defun that is unbalanced.  If there is an excess 
  8316. open parenthesis, the way to do this is to insert a close parenthesis at the 
  8317. end of the file and type C-M-b (backward-sexp).  This will move you to the 
  8318. beginning of the defun that is unbalanced.  (Then type C-SPC C-_ C-u C-SPC to 
  8319. set the mark there, undo the insertion of the close parenthesis, and finally 
  8320. return to the mark.) 
  8321.  
  8322.  The next step is to determine precisely what is wrong.  There is no way to be 
  8323. sure of this except to study the program, but often the existing indentation is 
  8324. a clue to where the parentheses should have been.  The easiest way to use this 
  8325. clue is to reindent with C-M-q and see what moves. 
  8326.  
  8327.  Before you do this, make sure the defun has enough close parentheses. 
  8328. Otherwise, C-M-q will get an error, or will reindent all the rest of the file 
  8329. until the end.  So move to the end of the defun and insert a close parenthesis 
  8330. there.  Don't use C-M-e to move there, since that too will fail to work until 
  8331. the defun is balanced. 
  8332.  
  8333.  Then go to the beginning of the defun and type C-M-q.  Usually all the lines 
  8334. from a certain point to the end of the function will shift to the right.  There 
  8335. is probably a missing close parenthesis, or a superfluous open parenthesis, 
  8336. near that point.  (However, don't assume this is true; study the code to make 
  8337. sure.)  Once you have found the discrepancy, undo the C-M-q, since the old 
  8338. indentation is probably appropriate to the intended parentheses. 
  8339.  
  8340.  After you think you have fixed the problem, use C-M-q again.  It should not 
  8341. change anything, if the problem is really fixed. 
  8342.  
  8343.  
  8344. ΓòÉΓòÉΓòÉ 18.3.2. Excess Close Parentheses ΓòÉΓòÉΓòÉ
  8345.  
  8346.  To deal with an excess close parenthesis, first insert an open parenthesis at 
  8347. the beginning of the file and type C-M-f to find the end of the unbalanced 
  8348. defun.  (Then type C-SPC C-_ C-u C-SPC to set the mark there, undo the 
  8349. insertion of the open parenthesis, and finally return to the mark.) 
  8350.  
  8351.  Then find the actual matching close parenthesis by typing C-M-f at the 
  8352. beginning of the defun.  This will leave you somewhere short of the place where 
  8353. the defun ought to end.  It is possible that you will find a spurious close 
  8354. parenthesis in that vicinity. 
  8355.  
  8356.  If you don't see a problem at that point, the next thing to do is to type 
  8357. C-M-q at the beginning of the defun.  A range of lines will probably shift 
  8358. left; if so, the missing open parenthesis or spurious close parenthesis is 
  8359. probably near the first of those lines.  (However, don't assume this is true; 
  8360. study the code to make sure.)  Once you have found the discrepancy, undo the 
  8361. C-M-q, since the old indentation is probably appropriate to the intended 
  8362. parentheses. 
  8363.  
  8364.  
  8365. ΓòÉΓòÉΓòÉ 18.4. Debugging Problems in Compilation ΓòÉΓòÉΓòÉ
  8366.  
  8367.  When an error happens during byte compilation, it is normally due to an error 
  8368. in the program you are compiling.  The compiler itself can't tell you where in 
  8369. the file the error occurred, so here is how to find out. 
  8370.  
  8371.  What you should do is switch to the buffer `*Compiler Input*'. (Note that the 
  8372. buffer name starts with a space, so it will not show up in M-x list-buffers.) 
  8373. This buffer contains the program being compiled, and point shows how far the 
  8374. byte compiler was able to read. 
  8375.  
  8376.  If the error was due to invalid Lisp syntax, point shows exactly where the 
  8377. invalid syntax was detected.  The cause of the error is not necessarily near 
  8378. by!  Use the techniques in the previous section to find the error. 
  8379.  
  8380.  If the error was detected while compiling a form that had been read 
  8381. successfully, then point is located at the end of the form.  In this case, it 
  8382. can't localize the error precisely, but can still show you which function to 
  8383. check. 
  8384.  
  8385.  
  8386. ΓòÉΓòÉΓòÉ 19. Reading and Printing Lisp Objects ΓòÉΓòÉΓòÉ
  8387.  
  8388.  Printing and reading are the operations of converting Lisp objects to textual 
  8389. form and vice versa.  They use the printed representations and read syntax 
  8390. described in Types of Lisp Object. 
  8391.  
  8392.  This chapter describes the Lisp functions for reading and printing. It also 
  8393. describes streams, which specify where to get the text (if reading) or where to 
  8394. put it (if printing). 
  8395.  
  8396.  
  8397. ΓòÉΓòÉΓòÉ 19.1. Introduction to Reading and Printing ΓòÉΓòÉΓòÉ
  8398.  
  8399.  Reading a Lisp object means parsing a Lisp expression in textual form and 
  8400. producing a corresponding Lisp object.  This is how Lisp programs get into Lisp 
  8401. from files of Lisp code.  We call the text the read syntax of the object.  For 
  8402. example, reading the text `(a . 5)' returns a cons cell whose car is a and 
  8403. whose cdr is the number 5. 
  8404.  
  8405.  Printing a Lisp object means producing text that represents that 
  8406. object---converting the object to its printed representation.  Printing the 
  8407. cons cell described above produces the text `(a . 5)'. 
  8408.  
  8409.  Reading and printing are usually inverse operations: printing the object that 
  8410. results from reading a given piece of text often produces the same text, and 
  8411. reading the text that results from printing an object usually produces a 
  8412. similar-looking object.  For example, printing the symbol foo produces the text 
  8413. `foo', and reading that text returns the symbol foo.  Printing a list whose 
  8414. elements are a and b produces the text `(a b)', and reading that text produces 
  8415. a list (but not the same list) with elements are a and b. 
  8416.  
  8417.  However, these two operations are not precisely inverses.  There are two kinds 
  8418. of exceptions: 
  8419.  
  8420. o Printing can produce text that cannot be read.  For example, buffers, 
  8421.   windows, subprocesses and markers print into text that starts with `#'; if 
  8422.   you try to read this text, you get an error.  There is no way to read those 
  8423.   data types. 
  8424.  
  8425. o One object can have multiple textual representations.  For example, `1' and 
  8426.   `01' represent the same integer, and `(a b)' and `(a . (b))' represent the 
  8427.   same list.  Reading will accept any of the alternatives, but printing must 
  8428.   choose one of them. 
  8429.  
  8430.  
  8431. ΓòÉΓòÉΓòÉ 19.2. Input Streams ΓòÉΓòÉΓòÉ
  8432.  
  8433.  Most of the Lisp functions for reading text take an input stream as an 
  8434. argument.  The input stream specifies where or how to get the characters of the 
  8435. text to be read.  Here are the possible types of input stream: 
  8436.  
  8437. buffer 
  8438.           The input characters are read from buffer, starting with the 
  8439.           character directly after point.  Point advances as characters are 
  8440.           read. 
  8441.  
  8442. marker 
  8443.           The input characters are read from the buffer that marker is in, 
  8444.           starting with the character directly after the marker.  The marker 
  8445.           position advances as characters are read.  The value of point in the 
  8446.           buffer has no effect when the stream is a marker. 
  8447.  
  8448. string 
  8449.           The input characters are taken from string, starting at the first 
  8450.           character in the string and using as many characters as required. 
  8451.  
  8452. function 
  8453.           The input characters are generated by function, one character per 
  8454.           call.  In version 18, function is always called with no arguments and 
  8455.           should return a character. 
  8456.  
  8457.           t used as a stream means that the input is read from the minibuffer. 
  8458.           In fact, the minibuffer is invoked once and the text given by the 
  8459.           user is made into a string that is then used as the input stream. 
  8460.  
  8461. nil 
  8462.           nil used as a stream means that the value of standard-input should be 
  8463.           used instead; that value is the default input stream, and must be a 
  8464.           non-nil input stream. 
  8465.  
  8466.  Here is an example of reading from a stream which is a buffer, showing where 
  8467. point is located before and after: 
  8468.  
  8469. ---------- Buffer: foo ----------
  8470. This-!- is the contents of foo.
  8471. ---------- Buffer: foo ----------
  8472.  
  8473. (read (get-buffer "foo"))
  8474.      => is
  8475. (read (get-buffer "foo"))
  8476.      => the
  8477.  
  8478. ---------- Buffer: foo ----------
  8479. This is the -!-contents of foo.
  8480. ---------- Buffer: foo ----------
  8481.  
  8482. Note that the first read skips a space at the beginning of the buffer. Reading 
  8483. skips any amount of whitespace preceding the significant text. Note also that 
  8484. the second read skips the space which terminates the symbol the.  It has to 
  8485. read this space in order to know that no more letters follow. 
  8486.  
  8487.  Here is an example of reading from a stream that is a marker, initialized to 
  8488. point at the beginning of the buffer shown.  The value of the read is the 
  8489. symbol This. 
  8490.  
  8491. ---------- Buffer: foo ----------
  8492. This is the contents of foo.
  8493. ---------- Buffer: foo ----------
  8494.  
  8495. (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
  8496.      => #<marker at 1 in foo>
  8497. (read m)
  8498.      => This
  8499. m
  8500.      => #<marker at 6 in foo>   ;; After the first space.
  8501.  
  8502.  Here we read from the contents of a string: 
  8503.  
  8504. (read "(When in) the course")
  8505.      => (When in)
  8506.  
  8507.  The following example reads from the minibuffer, prompting with `Lisp 
  8508. expression: '.  (That is always the prompt used when you read from the stream 
  8509. t.)  The user's input is shown following the prompt. 
  8510.  
  8511. (read t)
  8512.      => 23
  8513. ---------- Buffer: Minibuffer ----------
  8514. Lisp expression: 23 RET
  8515.  
  8516.  Finally, here is an example of a stream that is a function, named 
  8517. useless-stream.  Before we use the stream, we initialize the variable 
  8518. useless-list to a list of characters.  Then each call to the function 
  8519. useless-stream obtains the next letter in the list: 
  8520.  
  8521. (setq useless-list (append "XY()" nil))
  8522.      => (88 89 40 41)
  8523.  
  8524. (defun useless-stream ()
  8525.   (prog1 (car useless-list)
  8526.          (setq useless-list (cdr useless-list))))
  8527.      => useless-stream
  8528.  
  8529. Now we read using the stream thus constructed: 
  8530.  
  8531. (read 'useless-stream)
  8532.      => XY
  8533.  
  8534. useless-list
  8535.      => (41)
  8536.  
  8537. Note that the close parenthesis remains in the list.  This is because the open 
  8538. parenthesis was read before the Lisp reader knew it had found the end of the 
  8539. symbol.  A second attempt to read from the stream at this point would get an 
  8540. error due to the unmatched close parenthesis. 
  8541.  
  8542. -- Function: get-file-char 
  8543. This function is used internally as an input stream to read from the input file 
  8544. opened by the function load.  Don't use this function yourself. 
  8545.  
  8546.  
  8547. ΓòÉΓòÉΓòÉ 19.3. Input Functions ΓòÉΓòÉΓòÉ
  8548.  
  8549.  This section describes the Lisp functions and variables that pertain to 
  8550. reading. 
  8551.  
  8552.  In the functions below, stream stands for an input stream (see the previous 
  8553. section).  If stream is nil or omitted, it defaults to the value of 
  8554. standard-input. 
  8555.  
  8556.  An end-of-file error will result if an unterminated list or vector is found. 
  8557.  
  8558. -- Function: read &optional stream 
  8559. This function reads one textual Lisp expression from stream, returning it as a 
  8560. Lisp object.  This is the basic Lisp input function. 
  8561.  
  8562. -- Function: read-from-string string &optional start end 
  8563. This function reads the first textual Lisp expression from the text in string. 
  8564. It returns a cons cell whose car is that expression, and whose cdr is an 
  8565. integer giving the position of the next remaining character in the string 
  8566. (i.e., the first one not read). 
  8567.  
  8568. If start is supplied, then reading begins at index start in the string (where 
  8569. the first character is at index 0).  If end is also supplied, then reading 
  8570. stops at that index as if the rest of the string were not there. 
  8571.  
  8572. For example: 
  8573.  
  8574. (read-from-string "(setq x 55) (setq y 5)")
  8575.      => ((setq x 55) . 11)
  8576. (read-from-string "\"A short string\"")
  8577.      => ("A short string" . 16)
  8578.  
  8579. ;; Read starting at the first character.
  8580. (read-from-string "(list 112)" 0)
  8581.      => ((list 112) . 10)
  8582. ;; Read starting at the second character.
  8583. (read-from-string "(list 112)" 1)
  8584.      => (list . 6)
  8585. ;; Read starting at the seventh character, and stopping at the ninth.
  8586. (read-from-string "(list 112)" 6 8)
  8587.      => (11 . 8)
  8588.  
  8589. -- Variable: standard-input 
  8590. This variable holds the default input stream: the stream that read uses when 
  8591. the stream argument is nil. 
  8592.  
  8593.  
  8594. ΓòÉΓòÉΓòÉ 19.4. Output Streams ΓòÉΓòÉΓòÉ
  8595.  
  8596.  An output stream specifies what to do with the characters produced by 
  8597. printing.  Most print functions accept an output stream as an optional 
  8598. argument.  Here are the possible types of output stream: 
  8599.  
  8600. buffer 
  8601.           The output characters are inserted into buffer at point. Point 
  8602.           advances as characters are inserted. 
  8603.  
  8604. marker 
  8605.           The output characters are inserted into the buffer that marker is in 
  8606.           at the marker position.  The position advances as characters are 
  8607.           inserted.  The value of point in the buffer has no effect when the 
  8608.           stream is a marker. 
  8609.  
  8610. function 
  8611.           The output characters are passed to function, which is responsible 
  8612.           for storing them away.  It is called with a single character as 
  8613.           argument, as many times as there are characters to be output, and is 
  8614.           free to do anything at all with the characters it receives. 
  8615.  
  8616.           The output characters are displayed in the echo area. 
  8617.  
  8618. nil 
  8619.           nil specified as an output stream means that the value of 
  8620.           standard-output should be used as the output stream; that value is 
  8621.           the default output stream, and must be a non-nil output stream. 
  8622.  
  8623.  Here is an example of a buffer used as an output stream.  Point is initially 
  8624. located as shown immediately before the `h' in `the'.  At the end, point is 
  8625. located directly before that same `h'. 
  8626.  
  8627. ---------- Buffer: foo ----------
  8628. This is t-!-he contents of foo.
  8629. ---------- Buffer: foo ----------
  8630.  
  8631. (print "This is the output" (get-buffer "foo"))
  8632.      => "This is the output"
  8633.  
  8634. ---------- Buffer: foo ----------
  8635. This is t
  8636. "This is the output"
  8637. -!-he contents of foo.
  8638. ---------- Buffer: foo ----------
  8639.  
  8640.  Now we show a use of a marker as an output stream.  Initially, the marker 
  8641. points in buffer foo, between the `t' and the `h' in the word `the'.  At the 
  8642. end, the marker has been advanced over the inserted text so that it still 
  8643. points before the same `h'.  Note that the location of point, shown in the 
  8644. usual fashion, has no effect. 
  8645.  
  8646. ---------- Buffer: foo ----------
  8647. "This is the -!-output"
  8648. ---------- Buffer: foo ----------
  8649.  
  8650. m
  8651.      => #<marker at 11 in foo>
  8652.  
  8653. (print "More output for foo." marker)
  8654.      => "More output for foo."
  8655.  
  8656. ---------- Buffer: foo ----------
  8657. "This is t
  8658. "More output for foo."
  8659. he -!-output"
  8660. ---------- Buffer: foo ----------
  8661.  
  8662. m
  8663.      => #<marker at 35 in foo>
  8664.  
  8665.  The following example shows output to the echo area: 
  8666.  
  8667. (print "Echo Area output" t)
  8668.      => "Echo Area output"
  8669. ---------- Echo Area ----------
  8670. "Echo Area output"
  8671. ---------- Echo Area ----------
  8672.  
  8673.  Finally, we show an output stream which is a function.  The function 
  8674. eat-output takes each character that it is given and conses it onto the front 
  8675. of the list last-output (see Building Lists). At the end, the list contains all 
  8676. the characters output, but in reverse order. 
  8677.  
  8678. (setq last-output nil)
  8679.      => nil
  8680.  
  8681. (defun eat-output (c)
  8682.   (setq last-output (cons c last-output)))
  8683.      => eat-output
  8684.  
  8685. (print "This is the output" 'eat-output)
  8686.      => "This is the output"
  8687.  
  8688. last-output
  8689.      => (10 34 116 117 112 116 117 111 32 101 104 116 32 115 105
  8690.     32 115 105 104 84 34 10)
  8691.  
  8692. Now we can put the output in the proper order by reversing the list: 
  8693.  
  8694. (concat (nreverse last-output))
  8695.      => "
  8696. \"This is the output\"
  8697. "
  8698.  
  8699.  
  8700. ΓòÉΓòÉΓòÉ 19.4.1. Output Functions ΓòÉΓòÉΓòÉ
  8701.  
  8702.  This section describes the Lisp functions and variables that pertain to 
  8703. printing. 
  8704.  
  8705.  Some of the Emacs printing functions add quoting characters to the output when 
  8706. necessary so that it can be read properly.  The quoting characters used are `\' 
  8707. and `"'; they are used to distinguish strings from symbols, and to prevent 
  8708. punctuation characters in strings and symbols from being taken as delimiters. 
  8709. See Printed Representation, for full details.  You specify quoting or no 
  8710. quoting by the choice of printing function. 
  8711.  
  8712.  If the text is to be read back into Lisp, then it is best to print with 
  8713. quoting characters to avoid ambiguity.  Likewise, if the purpose is to describe 
  8714. a Lisp object clearly for a Lisp programmer.  However, if the purpose of the 
  8715. output is to look nice for humans, then it is better to print without quoting. 
  8716.  
  8717.  In the functions below, stream stands for an output stream. (See the previous 
  8718. section for a description of output streams.)  If stream is nil or omitted, it 
  8719. defaults to the value of standard-output. 
  8720.  
  8721. -- Function: print object &optional stream 
  8722. The print is a convenient way of printing.  It outputs the printed 
  8723. representation of object to stream, printing in addition one newline before 
  8724. object and another after it.  Quoting characters are used.  print returns 
  8725. object.  For example: 
  8726.  
  8727. (progn (print 'The\ cat\ in)
  8728.        (print "the hat")
  8729.        (print " came back"))
  8730.      -|
  8731.      -| The\ cat\ in
  8732.      -|
  8733.      -| "the hat"
  8734.      -|
  8735.      -| " came back"
  8736.      -|
  8737.      => " came back"
  8738.  
  8739. -- Function: prin1 object &optional stream 
  8740. This function outputs the printed representation of object to stream.  It does 
  8741. not print any spaces or newlines to separate output as print does, but it does 
  8742. use quoting characters just like print.  It returns object. 
  8743.  
  8744. (progn (prin1 'The\ cat\ in)
  8745.        (prin1 "the hat")
  8746.        (prin1 " came back"))
  8747.      -| The\ cat\ in"the hat"" came back"
  8748.      => " came back"
  8749.  
  8750. -- Function: prin1-to-string object 
  8751. This function returns a string containing the text that prin1 would have 
  8752. printed for the same argument. 
  8753.  
  8754. (prin1-to-string 'foo)
  8755.      => "foo"
  8756. (prin1-to-string (mark-marker))
  8757.      => "#<marker at 2773 in strings.texi>"
  8758.  
  8759. See format, in String Conversion, for other ways to obtain the printed 
  8760. representation of a Lisp object as a string. 
  8761.  
  8762. -- Function: princ object &optional stream 
  8763. This function outputs the printed representation of object to stream.  It 
  8764. returns object. 
  8765.  
  8766. This function is intended to produce output that is readable by people, not by 
  8767. read, so quoting characters are not used and double-quotes are not printed 
  8768. around the contents of strings.  It does not add any spacing between calls. 
  8769.  
  8770. (progn
  8771.   (princ 'The\ cat)
  8772.   (princ " in the \"hat\""))
  8773.      -| The cat in the "hat"
  8774.      => " in the \"hat\""
  8775.  
  8776. -- Function: terpri &optional stream 
  8777. This function outputs a newline to stream.  The name stands for ``terminate 
  8778. print''. 
  8779.  
  8780. -- Variable: standard-output 
  8781. The value of this variable is the default output stream, used when the stream 
  8782. argument is omitted or nil. 
  8783.  
  8784. -- Variable: print-escape-newlines 
  8785. If this variable is non-nil, then newline characters in strings are printed as 
  8786. `\n'.  Normally they are printed as actual newlines. 
  8787.  
  8788. This variable affects the print functions prin1 and print; it does not affect 
  8789. princ in Emacs 18, but this may be changed. Here is an example using prin1: 
  8790.  
  8791. (prin1 "a\nb")
  8792.      -| "a
  8793.      -| b"
  8794.      => "a
  8795.      => b"
  8796.  
  8797. (let ((print-escape-newlines t))
  8798.   (prin1 "a\nb"))
  8799.      -| "a\nb"
  8800.      => "a
  8801.      => b"
  8802.  
  8803. In the second expression, the local binding of print-escape-newlines is in 
  8804. effect during the call to prin1, but not during the printing of the result. 
  8805.  
  8806. -- Variable: print-length 
  8807. The value of this variable is the maximum number of elements of a list that 
  8808. will be printed.  If the list being printed has more than this many elements, 
  8809. then it is abbreviated with an ellipsis. 
  8810.  
  8811. If the value is nil (the default), then there is no limit. 
  8812.  
  8813. (setq print-length 2)
  8814.      => 2
  8815. (print '(1 2 3 4 5))
  8816.      -| (1 2 ...)
  8817.      => (1 2 ...)
  8818.  
  8819. -- Function: write-char character &optional stream 
  8820. This function outputs character to stream.  It returns character. 
  8821.  
  8822.  
  8823. ΓòÉΓòÉΓòÉ 20. Minibuffers ΓòÉΓòÉΓòÉ
  8824.  
  8825.  A minibuffer is a special buffer used by Emacs commands to read arguments more 
  8826. complicated than the single numeric prefix argument. These arguments include 
  8827. file names, buffer names, and command names (as in M-x).  The minibuffer is 
  8828. displayed on the bottom line of the screen, in the same place as the echo area, 
  8829. but only while it is in use for reading an argument. 
  8830.  
  8831.  
  8832. ΓòÉΓòÉΓòÉ 20.1. Introduction to Minibuffers ΓòÉΓòÉΓòÉ
  8833.  
  8834.  In most ways, a minibuffer is a normal Emacs buffer.  Most operations within a 
  8835. buffer, such as editing commands, work normally in a minibuffer.  However, many 
  8836. operations for managing buffers do not apply to minibuffers.  The name of a 
  8837. minibuffer always has the form ` *Minibuf-number', and it cannot be changed. 
  8838. There is a special window used only for minibuffers, and minibuffers cannot be 
  8839. displayed in any other window.  This window is normally the single line at the 
  8840. bottom of the screen; it can be resized temporarily with the window sizing 
  8841. commands, but reverts to its normal size when the minibuffer is exited. 
  8842.  
  8843.  A recursive minibuffer may be created when there is an active minibuffer and a 
  8844. command is invoked that requires input from a minibuffer.  The first minibuffer 
  8845. is named `*Minibuf-0*'. Recursive minibuffers are named by incrementing the 
  8846. number at the end of the name.  (The names begin with a space so that they 
  8847. won't show up in normal buffer lists.)  Of several recursive minibuffers, the 
  8848. innermost (or most recently entered) is the active minibuffer, and is the only 
  8849. one that is displayed in a window.  We usually call this ``the'' minibuffer. 
  8850. Recursive minibuffers may be allowed or disallowed by setting the variable 
  8851. enable-recursive-minibuffers. 
  8852.  
  8853.  Like other buffers, a minibuffer may use any of several local keymaps (see 
  8854. Keymaps); these contain various exit commands and in some cases completion 
  8855. commands.  See Completion. 
  8856.  
  8857. o minibuffer-local-map is for ordinary input (no completion). 
  8858.  
  8859. o minibuffer-local-ns-map is similar, except that SPC exits just like RET. 
  8860.   This is used mainly for Mocklisp compatibility. 
  8861.  
  8862. o minibuffer-local-completion-map is for permissive completion. 
  8863.  
  8864. o minibuffer-local-must-match-map is for strict completion and for cautious 
  8865.   completion. 
  8866.  
  8867. o repeat-complex-command-map is for use in C-x ESC. 
  8868.  
  8869.  
  8870. ΓòÉΓòÉΓòÉ 20.2. Reading Text Strings with the Minibuffer ΓòÉΓòÉΓòÉ
  8871.  
  8872.  The minibuffer is usually used to read text which is returned as a string, but 
  8873. can also be used to read a Lisp object in textual form.  The most basic 
  8874. primitive for minibuffer input is read-from-minibuffer. 
  8875.  
  8876. -- Function: read-from-minibuffer prompt-string &optional initial keymap read 
  8877. This function is the most general way to get input through the minibuffer.  By 
  8878. default, it accepts arbitrary text and returns it as a string; however, if read 
  8879. is non-nil, then it uses read to convert the text into a Lisp object ( see 
  8880. Input Functions). 
  8881.  
  8882. The first thing this function does is to activate a minibuffer and display it 
  8883. with  prompt-string as the prompt.  This value must be a string. 
  8884.  
  8885. Then, if initial is non-nil, it must be a string; its contents are inserted 
  8886. into the minibuffer as initial contents.  The text thus inserted is treated as 
  8887. if the user had inserted it; the user can alter it with Emacs editing commands. 
  8888.  
  8889. If keymap is non-nil, that keymap is the local keymap to use while reading.  If 
  8890. keymap is omitted or nil, the value of minibuffer-local-map is used as the 
  8891. keymap.  Specifying a keymap is the most important way to customize minibuffer 
  8892. input for various applications including completion. 
  8893.  
  8894. When the user types a command to exit the minibuffer, the current minibuffer 
  8895. contents are usually made into a string which is the value of 
  8896. read-from-minibuffer.  However, if read is non-nil, Emacs converts the result 
  8897. to a Lisp object and read-from-minibuffer returns that object, unevaluated. 
  8898.  
  8899. Suppose, for example, you are writing a search command and want to record the 
  8900. last search string and provide it as a default for the next search.  Suppose 
  8901. that the previous search string is stored in the variable last-search-string. 
  8902. Here is how you can read a search string while providing the previous string as 
  8903. initial input to be edited: 
  8904.  
  8905. (read-from-minibuffer "Find string: " last-search-string)
  8906.  
  8907. Assuming the value of last-search-string is `No', and the user wants to search 
  8908. for `Nope', the interaction looks like this: 
  8909.  
  8910. (setq last-search-string "No")
  8911.  
  8912. (read-from-minibuffer "Find string: " last-search-string)
  8913. ---------- Buffer: Minibuffer ----------
  8914. Find string: No-!-
  8915. ---------- Buffer: Minibuffer ----------
  8916. ;; The user now types pe RET:
  8917.      => "Nope"
  8918.  
  8919. -- Function: read-string prompt &optional initial 
  8920. This function reads a string from the minibuffer and returns it.  The arguments 
  8921. prompt and initial are used as in read-from-minibuffer. 
  8922.  
  8923. This function is a simplified interface to read-from-minibuffer: 
  8924.  
  8925. (read-string prompt initial)
  8926. ==
  8927. (read-from-minibuffer prompt initial nil nil)
  8928.  
  8929. -- Variable: minibuffer-local-map 
  8930. This is the default local keymap for reading from the minibuffer.  It is the 
  8931. keymap used by the minibuffer for local bindings in the function read-string. 
  8932. By default, it makes the following bindings: 
  8933.  
  8934. LFD 
  8935.           exit-minibuffer 
  8936.  
  8937. RET 
  8938.           exit-minibuffer 
  8939.  
  8940. C-g 
  8941.           abort-recursive-edit 
  8942.  
  8943. -- Function: read-no-blanks-input prompt initial 
  8944. This function reads a string from the minibuffer, but does not allow whitespace 
  8945. characters as part of the input: instead, those characters terminate the input. 
  8946. The arguments prompt and initial are used as in read-from-minibuffer. 
  8947.  
  8948. This function is a simplified interface to read-from-minibuffer, and passes the 
  8949. value of minibuffer-local-ns-map as the keymap argument for that function. 
  8950. Since the keymap minibuffer-local-ns-map does not rebind C-q, it is possible to 
  8951. put a space into the string, by quoting it. 
  8952.  
  8953. (read-no-blanks-input prompt initial)
  8954. ==
  8955. (read-from-minibuffer prompt initial minibuffer-local-ns-map)
  8956.  
  8957. -- Variable: minibuffer-local-ns-map 
  8958. This built-in variable is the keymap used as the minibuffer local keymap in the 
  8959. function read-no-blanks-input.  By default, it makes the following bindings: 
  8960.  
  8961. LFD 
  8962.           exit-minibuffer 
  8963.  
  8964. SPC 
  8965.           exit-minibuffer 
  8966.  
  8967. TAB 
  8968.           exit-minibuffer 
  8969.  
  8970. RET 
  8971.           exit-minibuffer 
  8972.  
  8973. C-g 
  8974.           abort-recursive-edit 
  8975.  
  8976.           self-insert-and-exit 
  8977.  
  8978.  
  8979. ΓòÉΓòÉΓòÉ 20.3. Reading Lisp Objects with the Minibuffer ΓòÉΓòÉΓòÉ
  8980.  
  8981.  This section describes functions for reading Lisp objects with the minibuffer. 
  8982.  
  8983. -- Function: read-minibuffer prompt &optional initial 
  8984.  This function reads a Lisp object in the minibuffer and returns it, 
  8985. unevaluated.  The arguments prompt and initial are used as in 
  8986. read-from-minibuffer; in particular, initial must be a string or nil. 
  8987.  
  8988.  This function is a simplified interface to read-from-minibuffer: 
  8989.  
  8990. (read-minibuffer prompt initial)
  8991. ==
  8992. (read-from-minibuffer prompt initial nil t)
  8993.  
  8994. Here is an example in which we supply the string "(testing)" as initial input: 
  8995.  
  8996. (read-minibuffer "Enter an expression: " (format "%s" '(testing)))
  8997.  
  8998. ;;  Here is how the minibuffer is displayed:
  8999.  
  9000. ---------- Buffer: Minibuffer ----------
  9001. Enter an expression: (testing)-!-
  9002. ---------- Buffer: Minibuffer ----------
  9003.  
  9004. The user can type RET immediately to use the initial input as a default, or can 
  9005. edit the input. 
  9006.  
  9007. -- Function: eval-minibuffer prompt &optional initial 
  9008.  This function reads a Lisp expression in the minibuffer, evaluates it, then 
  9009. returns the result.  The arguments prompt and initial are used as in 
  9010. read-from-minibuffer. 
  9011.  
  9012.  This function simply evaluates the result of a call to read-minibuffer: 
  9013.  
  9014. (eval-minibuffer prompt initial)
  9015. ==
  9016. (eval (read-minibuffer prompt initial))
  9017.  
  9018. -- Function: edit-and-eval-command prompt form 
  9019.  This function reads a Lisp expression in the minibuffer, and then evaluates 
  9020. it.  The difference between this command and eval-minibuffer is that here the 
  9021. initial form is not optional and it is treated as a Lisp object to be converted 
  9022. to printed representation rather than as a string of text.  It is printed with 
  9023. prin1, so if it is a string, double-quote characters (`"') will appear in the 
  9024. initial text.  See Output Functions. 
  9025.  
  9026.  The first thing edit-and-eval-command does is to activate the minibuffer with 
  9027. prompt as the prompt.  The printed representation of form is then inserted in 
  9028. the minibuffer, and the user is allowed to edit.  When the user exits the 
  9029. minibuffer, the edited text is read with read and then evaluated.  The 
  9030. resulting value becomes the value of edit-and-eval-command. 
  9031.  
  9032.  In the following example, we offer the user an expression with initial text 
  9033. which is a valid form already: 
  9034.  
  9035. (edit-and-eval-command "Please edit: " '(forward-word 1))
  9036.  
  9037. ;; After evaluating the preceding expression,
  9038. ;; the following appears in the minibuffer:
  9039.  
  9040. ---------- Buffer: Minibuffer ----------
  9041. Please edit: (forward-word 1)-!-
  9042. ---------- Buffer: Minibuffer ----------
  9043.  
  9044. Typing RET right away would exit the minibuffer and evaluate the expression, 
  9045. thus moving point forward one word. edit-and-eval-command returns nil in this 
  9046. example. 
  9047.  
  9048.  
  9049. ΓòÉΓòÉΓòÉ 20.4. Completion ΓòÉΓòÉΓòÉ
  9050.  
  9051.  Completion is a feature that fills in the rest of a name starting from an 
  9052. abbreviation for it.  Completion works by comparing the user's input against a 
  9053. list of valid names and determining how much of the name is determined uniquely 
  9054. by what the user has typed. 
  9055.  
  9056.  For example, when you type C-x b (switch-to-buffer) and then type the first 
  9057. few letters of the name of the buffer to which you wish to switch, and then 
  9058. type TAB (minibuffer-complete), Emacs extends the name as far as it can. 
  9059. Standard Emacs commands offer completion for names of symbols, files, buffers, 
  9060. and processes; with the functions in this section, you can implement completion 
  9061. for other kinds of names. 
  9062.  
  9063.  The try-completion function is the basic primitive for completion: it returns 
  9064. the longest determined completion of a given initial string, with a given set 
  9065. of strings to match against. 
  9066.  
  9067.  The function completing-read provides a higher-level interface for completion. 
  9068. A call to completing-read specifies how to determine the list of valid names. 
  9069. The function then activates the minibuffer with a local keymap that binds a few 
  9070. keys to commands useful for completion.  Other functions provide convenient 
  9071. simple interfaces for reading certain kinds of names with completion. 
  9072.  
  9073.  
  9074. ΓòÉΓòÉΓòÉ 20.4.1. Basic Completion Functions ΓòÉΓòÉΓòÉ
  9075.  
  9076. -- Function: try-completion string alist-or-obarray &optional predicate 
  9077.  This function returns the longest common substring of all possible completions 
  9078. of string in alist-or-obarray. 
  9079.  
  9080.  If alist-or-obarray is an association list ( see Association Lists), the car 
  9081. of each cons cell in it is compared against string; if the beginning of the car 
  9082. equals string, the cons cell matches.  If no cons cells match, try-completion 
  9083. returns nil.  If only one cons cell matches, and the match is exact, then 
  9084. try-completion returns t.  Otherwise, all matching strings are compared, and 
  9085. the longest initial sequence common to them is returned as a string. 
  9086.  
  9087.  If alist-or-obarray is an obarray (see Creating Symbols), the names of all 
  9088. symbols in the obarray form the space of possible names.  They are tested and 
  9089. used just like the cars of the elements of an association list.  (The global 
  9090. variable obarray holds an obarray containing the names of all interned Lisp 
  9091. symbols.) 
  9092.  
  9093.  If the argument predicate is non-nil, then it must be a function of one 
  9094. argument.  It is used to test each possible match, and the match is accepted 
  9095. only if predicate returns non-nil. The argument given to predicate is either a 
  9096. cons cell from the alist (the car of which is a string) or else it is a symbol 
  9097. (not a symbol name) from the obarray. 
  9098.  
  9099.  It is also possible to use a function as alist-or-obarray.  Then the function 
  9100. is solely responsible for performing completion; try-completion returns 
  9101. whatever this function returns.  The function is called with three arguments: 
  9102. string, predicate and nil.  (The reason for the third argument is so that the 
  9103. same function can be used in all-completions and do the appropriate thing in 
  9104. either case.)  See Programmed Completion. 
  9105.  
  9106.  In the first of the following examples, the string `foo' is matched by three 
  9107. of the alist cars.  All of the matches begin with the characters `fooba', so 
  9108. that is the result.  In the second example, there is only one possible match, 
  9109. and it is exact, so the value is t. 
  9110.  
  9111. (try-completion "foo"
  9112.      '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
  9113.      => "fooba"
  9114.  
  9115. (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
  9116.      => t
  9117.  
  9118.  In the following example, numerous symbols begin with the characters `forw', 
  9119. and all of them begin with the word `forward'.  In most of the symbols, this is 
  9120. followed with a `-', but not in all, so no more than `forward' can be 
  9121. completed. 
  9122.  
  9123. (try-completion "forw" obarray)
  9124.      => "forward"
  9125.  
  9126.  Finally, in the following example, only two of the three possible matches pass 
  9127. the predicate test (the string `foobaz' is too short).  Both of those begin 
  9128. with the string `foobar'. 
  9129.  
  9130. (defun test (s)
  9131.   (> (length (car s)) 6))
  9132.      => test
  9133. (try-completion "foo"
  9134.      '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  9135.      'test)
  9136.      => "foobar"
  9137.  
  9138. -- Function: all-completions string alist-or-obarray &optional predicate 
  9139.  This function returns a list of all possible completions, instead of the 
  9140. longest substring they share.  The parameters to this function are the same as 
  9141. to try-completion. 
  9142.  
  9143.  If alist-or-obarray is a function, it is called with three arguments: string, 
  9144. predicate and t, and all-completions returns whatever the function returns. See 
  9145. Programmed Completion. 
  9146.  
  9147.  Here is an example, using the same function test used in the example for 
  9148. try-completion: 
  9149.  
  9150. (defun test (s)
  9151.   (> (length (car s)) 6))
  9152.      => test
  9153.  
  9154. (all-completions  "foo"
  9155.      '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  9156.      (function test))
  9157.      => ("foobar1" "foobar2")
  9158.  
  9159. -- Variable: completion-ignore-case 
  9160.  If the value of this variable is non-nil, Emacs does not consider case 
  9161. significant in completion. 
  9162.  
  9163.  The two functions try-completion and all-completions have nothing in 
  9164. themselves to do with minibuffers.  However, completion is most often used 
  9165. there, which is why it is described in this chapter. 
  9166.  
  9167.  
  9168. ΓòÉΓòÉΓòÉ 20.4.2. Programmed Completion ΓòÉΓòÉΓòÉ
  9169.  
  9170.  Sometimes it is not possible to create an alist or an obarray containing all 
  9171. the intended possible completions.  In such a case, you can supply your own 
  9172. function to compute the completion of a given string. This is called programmed 
  9173. completion. 
  9174.  
  9175.  To use this feature, pass the function as the alist-or-obarray argument to 
  9176. completing-read.  This command will arrange to pass the function along to 
  9177. try-completion and all-completions, which will then let your function do all 
  9178. the work. 
  9179.  
  9180.  The completion function should accept three arguments: 
  9181.  
  9182. o The string to be completed. 
  9183.  
  9184. o The predicate function to filter possible matches, or nil if none. Your 
  9185.   function should call the predicale for each possible match and ignore the 
  9186.   possible match if the predicate returns nil. 
  9187.  
  9188. o A flag specifying the type of operation. 
  9189.  
  9190.  There are three flag values for three operations: 
  9191.  
  9192. o nil specifies try-completion.  The completion function should return the 
  9193.   completion of the specified string, or t if the string is an exact match 
  9194.   already, or nil if the string matches no possibility. 
  9195.  
  9196. o t specifies all-completions.  The completion function should return a list of 
  9197.   all possible completions of the specified string. 
  9198.  
  9199. o lambda specifies a test for an exact match.  The completion function should 
  9200.   return t if the specified string is an exact match for some possibility; nil 
  9201.   otherwise. 
  9202.  
  9203.  Emacs uses programmed completion when completing file names. See File Name 
  9204. Completion. 
  9205.  
  9206.  
  9207. ΓòÉΓòÉΓòÉ 20.4.3. Completion and the Minibuffer ΓòÉΓòÉΓòÉ
  9208.  
  9209.  This section describes the basic interface for reading from the minibuffer 
  9210. with completion. 
  9211.  
  9212. -- Function: completing-read prompt alist-or-obarray &optional predicate 
  9213. require-match initial 
  9214.  This function reads a string in the minibuffer, assisting the user by 
  9215. providing completion.  It activates the minibuffer with prompt prompt, which 
  9216. must be a string.  If initial is non-nil, completing-read inserts it into the 
  9217. minibuffer as part of the input.  Then it allows the user to edit the input, 
  9218. providing several commands to attempt completion. 
  9219.  
  9220.  The actual completion is done by passing alist-or-obarray and predicate to the 
  9221. function try-completion.  This happens in certain commands bound in the local 
  9222. keymaps used for completion. 
  9223.  
  9224.  If require-match is t, the user will not be allowed to exit unless the input 
  9225. completes to an element of alist-or-obarray. If require-match is neither nil 
  9226. nor t, then completing-read does not exit unless the input typed is itself an 
  9227. element of alist-or-obarray.  To accomplish this, completing-read calls 
  9228. read-minibuffer with the keymap minibuffer-local-completion-map if 
  9229. require-match is nil, or else with the keymap minibuffer-local-must-match-map, 
  9230. if require-match is non-nil. 
  9231.  
  9232.  Case is ignored when comparing the input against the possible matches if the 
  9233. built-in variable completion-ignore-case is non-nil.  See Basic Completion. 
  9234.  
  9235. For example: 
  9236.  
  9237. (completing-read "Complete a foo: "
  9238.      '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  9239.      nil t "fo")
  9240.  
  9241. ;; After evaluating the preceding expression,
  9242. ;; the following appears in the minibuffer:
  9243.  
  9244. ---------- Buffer: Minibuffer ----------
  9245. Complete a foo: fo-!-
  9246. ---------- Buffer: Minibuffer ----------
  9247.  
  9248. If the user then types DEL DEL b RET, completing-read returns barfoo. 
  9249.  
  9250.  The completing-read function binds three variables to pass information to the 
  9251. commands which actually do completion.  Here they are: 
  9252.  
  9253. minibuffer-completion-table 
  9254.           This variable is bound to alist-or-obarray argument.  It is passed to 
  9255.           the try-completion function. 
  9256.  
  9257. minibuffer-completion-predicate 
  9258.           This variable is bound to the predicate argument.  It is passed to 
  9259.           the try-completion function. 
  9260.  
  9261. minibuffer-completion-confirm 
  9262.           This variable is bound to the require-match argument.  It is used in 
  9263.           the minibuffer-complete-and-exit function. 
  9264.  
  9265.  
  9266. ΓòÉΓòÉΓòÉ 20.4.4. Minibuffer Commands That Do Completion ΓòÉΓòÉΓòÉ
  9267.  
  9268.  This section describes the keymaps, commands and user options used in the 
  9269. minibuffer to do completion. 
  9270.  
  9271. -- Variable: minibuffer-local-completion-map 
  9272.  completing-read uses this value as the local keymap when an exact match of one 
  9273. of the completions is not required.  By default, this keymap makes the 
  9274. following bindings: 
  9275.  
  9276.           minibuffer-completion-help 
  9277.  
  9278. SPC 
  9279.           minibuffer-complete-word 
  9280.  
  9281. TAB 
  9282.           minibuffer-complete 
  9283.  
  9284. LFD 
  9285.           exit-minibuffer 
  9286.  
  9287. RET 
  9288.           exit-minibuffer 
  9289.  
  9290. C-g 
  9291.           abort-recursive-edit 
  9292.  
  9293. -- Variable: minibuffer-local-must-match-map 
  9294.  completing-read uses this value as the local keymap when an exact match of one 
  9295. of the completions is required.  Therefore, no keys are bound to 
  9296. exit-minibuffer, the command which exits the minibuffer unconditionally.  By 
  9297. default, this keymap makes the following bindings: 
  9298.  
  9299.           minibuffer-completion-help 
  9300.  
  9301. SPC 
  9302.           minibuffer-complete-word 
  9303.  
  9304. TAB 
  9305.           minibuffer-complete 
  9306.  
  9307. LFD 
  9308.           minibuffer-complete-and-exit 
  9309.  
  9310. RET 
  9311.           minibuffer-complete-and-exit 
  9312.  
  9313. C-g 
  9314.           abort-recursive-edit 
  9315.  
  9316. -- Variable: minibuffer-completion-table 
  9317.  The value of this variable is the alist or obarray used for completion in the 
  9318. minibuffer.  This is the global variable that contains what completing-read 
  9319. passes to try-completion.  It is used by all the minibuffer completion 
  9320. functions, such as minibuffer-complete-word. 
  9321.  
  9322. -- Variable: minibuffer-completion-predicate 
  9323.   The value of this variable is the predicate that completing-read passes to 
  9324. try-completion.  The variable is also used by the other minibuffer completion 
  9325. functions. 
  9326.  
  9327. -- Command: minibuffer-complete-word 
  9328.  This function completes the minibuffer contents by at most a single word. 
  9329. Even if the minibuffer contents has only one completion, 
  9330. minibuffer-complete-word will not add any characters beyond the first character 
  9331. that is not a word constituent.  See Syntax Tables. 
  9332.  
  9333. -- Command: minibuffer-complete 
  9334.  This function completes the minibuffer contents as far as possible. 
  9335.  
  9336. -- Command: minibuffer-complete-and-exit 
  9337.  This function completes the minibuffer contents, and exits if confirmation is 
  9338. not required, i.e., if minibuffer-completion-confirm is non-nil.  If 
  9339. confirmation is required, it is given by repeating this command immediately. 
  9340.  
  9341. -- Variable: minibuffer-completion-confirm 
  9342.  When the value of this variable is non-nil, Emacs asks for confirmation of a 
  9343. completion before exiting the minibuffer.  The function 
  9344. minibuffer-complete-and-exit checks the value of this variable before it exits. 
  9345.  
  9346. -- Command: minibuffer-completion-help 
  9347.  This function creates a list of the possible completions of the current 
  9348. minibuffer contents.  It works by calling all-completions; the values of 
  9349. minibuffer-completion-table and minibuffer-completion-predicate are used as 
  9350. arguments.  The list of completions is displayed as text in a buffer named 
  9351. `*Completions*'. 
  9352.  
  9353. -- Function: display-completion-list completions 
  9354.  This function displays completions to the stream standard-output (usually a 
  9355. buffer).  (See Streams, for more information about streams.)  The argument 
  9356. completions is normally a list of completions just returned by all-completions, 
  9357. but it does not have to be.  Each element may be a symbol or a string, either 
  9358. of which is simply printed, or a list of two strings, which is printed as if 
  9359. the strings were concatenated. 
  9360.  
  9361.  This function is called by minibuffer-completion-help. 
  9362.  
  9363. -- User Option: completion-auto-help 
  9364.  If this variable is non-nil, the completion commands automatically display a 
  9365. list of possible completions whenever nothing can be completed because the next 
  9366. character is not uniquely determined. 
  9367.  
  9368.  
  9369. ΓòÉΓòÉΓòÉ 20.4.5. High-Level Completion  Functions ΓòÉΓòÉΓòÉ
  9370.  
  9371.  This section describes the higher-level convenient functions for reading 
  9372. certain sorts of names with completion. 
  9373.  
  9374. -- Function: read-buffer prompt &optional default existing 
  9375.  This function reads the name of a buffer and returns it as a string. The 
  9376. argument default is the default name to use, the value to return if the user 
  9377. exits with an empty minibuffer.  If non-nil, it should be a string.  It is 
  9378. mentioned in the prompt, but is not inserted in the minibuffer as initial 
  9379. input. 
  9380.  
  9381.  If existing is non-nil, then the name specified must be that of an  existing 
  9382. buffer.  The usual commands to exit the minibuffer will not exit if the text is 
  9383. not valid, and RET will do completion to attempt to find a valid name. 
  9384. (However, default is not checked for this; it is returned, whatever it is, if 
  9385. the user exits with the minibuffer empty.) 
  9386.  
  9387.  In the following example, the user enters `minibuffer.t', and then types RET. 
  9388. The argument existing is t, and the only buffer name starting with the given 
  9389. input is `minibuffer.texi', so that name is the value. 
  9390.  
  9391. (read-buffer "Buffer name? " "foo" t)
  9392.  
  9393. ;; After evaluating the preceding expression,
  9394. ;; the following prompt appears, with an empty minibuffer:
  9395.  
  9396. ---------- Buffer: Minibuffer ----------
  9397. Buffer name? (default foo) -!-
  9398. ---------- Buffer: Minibuffer ----------
  9399.  
  9400. ;; The user types minibuffer.t RET.
  9401.  
  9402.      => "minibuffer.texi"
  9403.  
  9404. -- Function: read-command prompt 
  9405.  This function reads the name of a command and returns it as a Lisp symbol. 
  9406. The argument prompt is used as in read-from-minibuffer.  Recall that a command 
  9407. is anything for which commandp returns t, and a command name is a symbol for 
  9408. which commandp returns t.  See Interactive Call. 
  9409.  
  9410. (read-command "Command name? ")
  9411.  
  9412. ;; After evaluating the preceding expression,
  9413. ;; the following appears in the minibuffer:
  9414.  
  9415. ---------- Buffer: Minibuffer ----------
  9416. Command name?
  9417. ---------- Buffer: Minibuffer ----------
  9418.  
  9419. If the user types forward-c RET, then this function returns forward-char. 
  9420.  
  9421.  The read-command function is a simplified interface to completing-read.  It 
  9422. uses the commandp predicate to allow only commands to be entered, and it uses 
  9423. the variable obarray so as to be able to complete all extant Lisp symbols: 
  9424.  
  9425. (read-command prompt)
  9426. ==
  9427. (intern (completing-read prompt obarray 'commandp t nil))
  9428.  
  9429. -- Function: read-variable prompt 
  9430.  This function reads the name of a user variable and returns it as a symbol. 
  9431.  
  9432. (read-variable "Variable name? ")
  9433.  
  9434. ;; After evaluating the preceding expression,
  9435. ;; the following prompt appears with an empty minibuffer:
  9436.  
  9437. ---------- Buffer: Minibuffer ----------
  9438. Variable name? -!-
  9439. ---------- Buffer: Minibuffer ----------
  9440.  
  9441. If the user then types fill-p RET, read-variable will return fill-prefix. 
  9442.  
  9443. This function is similar to read-command, but uses the predicate 
  9444. user-variable-p instead of commandp: 
  9445.  
  9446. (read-variable prompt)
  9447. ==
  9448. (intern (completing-read prompt obarray 'user-variable-p t nil))
  9449.  
  9450.  
  9451. ΓòÉΓòÉΓòÉ 20.4.6. Reading File Names ΓòÉΓòÉΓòÉ
  9452.  
  9453.  Here is another high-level completion function, designed for reading a file 
  9454. name.  It provides special features including automatic insertion of the 
  9455. default directory. 
  9456.  
  9457. -- Function: read-file-name prompt &optional directory default existing 
  9458.  This function reads a file name in the minibuffer, prompting with prompt and 
  9459. providing completion.  If default is non-nil, then the value of default will be 
  9460. returned by the function if the user just types RET. 
  9461.  
  9462.  If existing is non-nil, then the name must refer to an existing file; then RET 
  9463. performs completion to make the name valid if possible, and then refuses to 
  9464. exit if it is not valid.  If the value of existing is neither nil nor t, then 
  9465. RET also requires confirmation after completion. 
  9466.  
  9467. The argument directory specifies the directory to use for completion of 
  9468. relative file names.  Usually it is inserted in the minibuffer as initial input 
  9469. as well.  It defaults to the current buffer's default directory. 
  9470.  
  9471. Here is an example: 
  9472.  
  9473. (read-file-name "The file is ")
  9474.  
  9475. ;; After evaluating the preceding expression,
  9476. ;; the following appears in the minibuffer:
  9477.  
  9478. ---------- Buffer: Minibuffer ----------
  9479. The file is /gp/gnu/elisp/-!-
  9480. ---------- Buffer: Minibuffer ----------
  9481.  
  9482. Typing manual TAB results in the following: 
  9483.  
  9484. ---------- Buffer: Minibuffer ----------
  9485. The file is /gp/gnu/elisp/manual.texi-!-
  9486. ---------- Buffer: Minibuffer ----------
  9487.  
  9488. If the user types RET, read-file-name returns "/gp/gnu/elisp/manual.texi". 
  9489.  
  9490. -- User Option: insert-default-directory 
  9491.  This variable is used by read-file-name.  The value of this variable controls 
  9492. whether read-file-name starts by placing the name of the default directory in 
  9493. the minibuffer.  If the value of this variable is nil, then read-file-name does 
  9494. not place any initial input in the minibuffer.  In that case, the default 
  9495. directory is still used for completion of relative file names, but is not 
  9496. displayed. 
  9497.  
  9498. For example: 
  9499.  
  9500. ;; Here the minibuffer starts out containing the default directory.
  9501.  
  9502. (let ((insert-default-directory t))
  9503.   (read-file-name "The file is "))
  9504.  
  9505. ---------- Buffer: Minibuffer ----------
  9506. The file is ~lewis/manual/-!-
  9507. ---------- Buffer: Minibuffer ----------
  9508.  
  9509. ;; Here the minibuffer is empty and only the prompt appears on its line.
  9510.  
  9511. (let ((insert-default-directory nil))
  9512.   (read-file-name "The file is "))
  9513.  
  9514. ---------- Buffer: Minibuffer ----------
  9515. The file is -!-
  9516. ---------- Buffer: Minibuffer ----------
  9517.  
  9518.  
  9519. ΓòÉΓòÉΓòÉ 20.4.7. Lisp Symbol Completion ΓòÉΓòÉΓòÉ
  9520.  
  9521.  If you type a part of a symbol, and then type M-TAB (lisp-complete-symbol), it 
  9522. will attempt to fill in as much more of the symbol name as it can.  Not only 
  9523. does this save typing, but it can help you with the name of a symbol that you 
  9524. have partially forgotten. 
  9525.  
  9526. -- Command: lisp-complete-symbol 
  9527.  This function performs completion on the symbol name preceding point. The name 
  9528. is completed against the symbols in the global variable obarray, and characters 
  9529. from the completion are inserted into the buffer, making the name longer.  If 
  9530. there is more than one completion, a list of all possible completions is placed 
  9531. in the `*Help*' buffer. The bell rings if there is no possible completion in 
  9532. obarray. 
  9533.  
  9534.  If an open parenthesis immediately precedes the name, only symbols with 
  9535. function definitions are considered.  (By reducing the number of alternatives, 
  9536. this may succeed in completing more characters.) Otherwise, symbols with either 
  9537. a function definition, a value, or at least one property are considered. 
  9538.  
  9539.  lisp-complete-symbol returns t if the symbol had an exact, and unique, match; 
  9540. otherwise, it returns nil. 
  9541.  
  9542.  In the following example, the user has already inserted `(forwa' into the 
  9543. buffer `foo.el'.  The command lisp-complete-symbol then completes the name to 
  9544. `(forward-'. 
  9545.  
  9546. ---------- Buffer: foo.el ----------
  9547. (forwa-!-
  9548. ---------- Buffer: foo.el ----------
  9549.  
  9550. (lisp-complete-symbol)
  9551.      => nil
  9552.  
  9553. ---------- Buffer: foo.el ----------
  9554. (forward--!-
  9555. ---------- Buffer: foo.el ----------
  9556.  
  9557.  
  9558. ΓòÉΓòÉΓòÉ 20.5. Yes-or-No Queries ΓòÉΓòÉΓòÉ
  9559.  
  9560.  This section describes functions used to ask the user a yes-or-no question. 
  9561. The function y-or-n-p can be answered with a single character; it is useful for 
  9562. questions where an inadvertent wrong answer will not have serious consequences. 
  9563. yes-or-no-p is suitable for more momentous questions, since it requires three 
  9564. or four characters to answer. 
  9565.  
  9566.  Strictly speaking, yes-or-no-p uses the minibuffer and y-or-n-p does not; but 
  9567. it seems best to describe them together. 
  9568.  
  9569. -- Function: y-or-n-p prompt 
  9570.  This function asks the user a question, expecting input in the echo area.  It 
  9571. returns t if the user types y, nil if the user types n.  This function also 
  9572. accepts SPC to mean yes and DEL to mean no.  The answer is a single character, 
  9573. with no RET needed to terminate it.  Upper and lower case are equivalent. 
  9574.  
  9575.  ``Asking the question'' means printing prompt in the echo area, followed by 
  9576. the string `(y or n) '.  If the input is not one of the expected answers (y, n, 
  9577. SPC, or DEL), the function responds `Please answer y or n.', and repeats the 
  9578. request. 
  9579.  
  9580.  This function does not actually use the minibuffer, since it does not allow 
  9581. editing of the answer.  It actually uses the echo area ( see The Echo Area), 
  9582. which uses the same screen space as the minibuffer.  The cursor moves to the 
  9583. echo area while the question is being asked. 
  9584.  
  9585.  In the following example, the user first types q, which is invalid.  At the 
  9586. next prompt the user types n. 
  9587.  
  9588. (y-or-n-p "Do you need a lift? ")
  9589.  
  9590. ;; After evaluating the preceding expression,
  9591. ;; the following prompt appears in the echo area:
  9592.  
  9593. ---------- Echo area ----------
  9594. Do you need a lift? (y or n)
  9595. ---------- Echo area ----------
  9596.  
  9597. ;; If the user then types q, the following appears:
  9598.  
  9599. ---------- Echo area ----------
  9600. Please answer y or n.  Do you need a lift? (y or n)
  9601. ---------- Echo area ----------
  9602.  
  9603. ;; When the user types a valid answer, it is displayed after the question:
  9604.  
  9605. ---------- Echo area ----------
  9606. Do you need a lift? (y or n) y
  9607. ---------- Echo area ----------
  9608.  
  9609. Note that we show successive lines of echo area messages here.  Only one will 
  9610. appear on the screen at a time. 
  9611.  
  9612. -- Function: yes-or-no-p prompt 
  9613.  This function asks the user a question, expecting input in minibuffer. It 
  9614. returns t if the user enters `yes', nil if the user types `no'.  The user must 
  9615. type RET to finalize the response.  Upper and lower case are equivalent. 
  9616.  
  9617.  yes-or-no-p starts by displaying prompt in the echo area, followed by `(yes or 
  9618. no) '.  The user must type one of the expected responses; otherwise, the 
  9619. function responds `Please answer yes or no.', waits about two seconds and 
  9620. repeats the request. 
  9621.  
  9622.  yes-or-no-p requires more work from the user than y-or-n-p and is appropriate 
  9623. for more crucial decisions. 
  9624.  
  9625. Here is an example: 
  9626.  
  9627. (yes-or-no-p "Do you really want to remove your entire directory? ")
  9628.  
  9629. ;; After evaluating the preceding expression,
  9630. ;; the following prompt appears with an empty minibuffer:
  9631.  
  9632. ---------- Buffer: minibuffer ----------
  9633. Do you really want to remove your entire directory? (yes or no)
  9634. ---------- Buffer: minibuffer ----------
  9635.  
  9636. If the user first types y RET, which is invalid because this function demands 
  9637. the entire word `yes', it responds by displaying these prompts, with a brief 
  9638. pause between them: 
  9639.  
  9640. ---------- Buffer: minibuffer ----------
  9641. Please answer yes or no.
  9642. Do you really want to remove your entire directory? (yes or no)
  9643. ---------- Buffer: minibuffer ----------
  9644.  
  9645.  
  9646. ΓòÉΓòÉΓòÉ 20.6. Minibuffer Miscellany ΓòÉΓòÉΓòÉ
  9647.  
  9648.  Some basic minibuffer functions and variables are described in this section. 
  9649.  
  9650. -- Command: exit-minibuffer 
  9651.  This function exits the active minibuffer.  It is normally bound to keys in 
  9652. minibuffer local keymaps. 
  9653.  
  9654. -- Command: self-insert-and-exit 
  9655.  This function exits the active minibuffer after inserting the last character 
  9656. typed on the keyboard (found in last-command-char; see Command Loop Info). 
  9657.  
  9658. -- Variable: minibuffer-help-form 
  9659.  The current value of this variable is used to rebind help-form locally inside 
  9660. the minibuffer (see Help Functions). 
  9661.  
  9662. -- Function: minibuffer-window 
  9663.  This function returns the window that is used for the minibuffer. There is one 
  9664. and only one minibuffer window in Emacs 18; this window always exists and 
  9665. cannot be deleted. 
  9666.  
  9667. -- Variable: minibuffer-scroll-window 
  9668.  If the value of this variable is non-nil, it should be a window object.  When 
  9669. the function scroll-other-window is called in the minibuffer, it will scroll 
  9670. the minibuffer-scroll-window window. 
  9671.  
  9672. Finally, some functions and variables deal with recursive minibuffers (see 
  9673. Recursive Editing): 
  9674.  
  9675. -- Function: minibuffer-depth 
  9676.  This function returns the current depth of activations of the minibuffer, a 
  9677. nonnegative integer.  If no minibuffers are active, it returns zero. 
  9678.  
  9679. -- User Option: enable-recursive-minibuffers 
  9680.  If this variable is non-nil, you can invoke commands (such as find-file) which 
  9681. use minibuffers even while in the minibuffer window.  Such invocation produces 
  9682. a recursive editing level for a new minibuffer.  The outer-level minibuffer is 
  9683. invisible while you are editing the inner one. 
  9684.  
  9685. This variable only affects invoking the minibuffer while the minibuffer window 
  9686. is selected.  If you switch windows while in the minibuffer, you can always 
  9687. invoke minibuffer commands while some other window is selected. 
  9688.  
  9689.  
  9690. ΓòÉΓòÉΓòÉ 21. Command Loop ΓòÉΓòÉΓòÉ
  9691.  
  9692.  When you run Emacs, it enters the editor command loop almost immediately. 
  9693. This loop reads key sequences, executes their definitions, and displays the 
  9694. results.  In this chapter, we describe how these things are done, and the 
  9695. subroutines that allow Lisp programs to do them. 
  9696.  
  9697.  
  9698. ΓòÉΓòÉΓòÉ 21.1. Command Loop Overview ΓòÉΓòÉΓòÉ
  9699.  
  9700.  The first thing the command loop must do is read a key sequence, which is a 
  9701. sequence of characters that translates into a command.  It does this by calling 
  9702. the function read-key-sequence.  Your Lisp code can also call this function 
  9703. (see Keyboard Input).  Lisp programs can also do input at a lower level with 
  9704. read-char or discard pending input with discard-input. 
  9705.  
  9706.  The key sequence is translated into a command through the keymaps of the 
  9707. current buffer.  See Keymaps, for information on how this is done.  The result 
  9708. should be a keyboard macro or an interactively callable function.  If the key 
  9709. is M-x, then it reads the name of another command, which is used instead.  This 
  9710. is done by the command execute-extended-command (see Interactive Call). 
  9711.  
  9712.  Once the command is read, it must be executed, which includes reading 
  9713. arguments to be given to it.  This is done by calling command-execute (see 
  9714. Interactive Call).  For commands written in Lisp, the interactive specification 
  9715. says how to read the arguments.  This may use the prefix argument ( see Prefix 
  9716. Command Arguments) or may read with prompting in the minibuffer (see 
  9717. Minibuffers).  For example, the command find-file has an interactive 
  9718. specification which says to read a file name using the minibuffer.  The 
  9719. command's function body does not use the minibuffer; if you call this command 
  9720. from Lisp code as a function, you must supply the file name string as an 
  9721. ordinary Lisp function argument. 
  9722.  
  9723.  If the command is a string (i.e., a keyboard macro) then the function 
  9724. execute-kbd-macro is used to execute it.  You can call this function yourself 
  9725. (see Keyboard Macros). 
  9726.  
  9727.  If a command runs away, typing C-g will terminate its execution immediately. 
  9728. This is called quitting (see Quitting). 
  9729.  
  9730.  
  9731. ΓòÉΓòÉΓòÉ 21.2. Defining Commands ΓòÉΓòÉΓòÉ
  9732.  
  9733.  A Lisp function becomes a command when its body contains, at top level, a form 
  9734. which calls the special form interactive.  This form does nothing when actually 
  9735. executed, but its presence serves as a flag to indicate that interactive 
  9736. calling is permitted.  Its argument controls the reading of arguments for an 
  9737. interactive call. 
  9738.  
  9739.  
  9740. ΓòÉΓòÉΓòÉ 21.2.1. Using interactive ΓòÉΓòÉΓòÉ
  9741.  
  9742.  This section describes how to write the interactive form that makes a Lisp 
  9743. function an interactively-callable command. 
  9744.  
  9745. -- Special Form: interactive arg-descriptor 
  9746. This special form declares that the function in which it appears is a command, 
  9747. and that it may therefore be called interactively (via M-x or by entering a key 
  9748. sequence bound to it).  The argument arg-descriptor declares the way the 
  9749. arguments to the command are to be computed when the command is called 
  9750. interactively. 
  9751.  
  9752. A command may be called from Lisp programs like any other function, but then 
  9753. the arguments are supplied by the caller and arg-descriptor has no effect. 
  9754.  
  9755. The interactive form has its effect because the command loop (actually, its 
  9756. subroutine call-interactively) scans through the function definition looking 
  9757. for it, before calling the function.  Once the function is called, all its body 
  9758. forms including the interactive form are executed, but at this time interactive 
  9759. simply returns nil without even evaluating its argument. 
  9760.  
  9761. There are three possibilities for the argument arg-descriptor: 
  9762.  
  9763. o It may be omitted or nil; then the command is called with no arguments.  This 
  9764.   leads quickly to an error if the command requires one or more arguments. 
  9765.  
  9766. o It may be a Lisp expression that is not a string; then it should be a form 
  9767.   that is evaluated to get a list of arguments to pass to the command. 
  9768.  
  9769. o It may be a string; then its contents should consist of a code character 
  9770.   followed by a prompt (if required for that code character).  The prompt ends 
  9771.   either with the end of the string or with a newline.  Here is a simple 
  9772.   example: 
  9773.  
  9774.     (interactive "bFrobnicate buffer: ")
  9775.  
  9776.   The code letter `b' says to read the name of an existing buffer, with 
  9777.   completion.  The buffer name will be the sole argument passed to the command. 
  9778.   The rest of the string is a prompt. 
  9779.  
  9780.   If there is a newline character in the string, it terminates the prompt. If 
  9781.   the string does not end there, then the rest of the string should contain 
  9782.   another code character and prompt, specifying another argument. Any number of 
  9783.   arguments may be specified in this way. 
  9784.  
  9785.   If the first character in the string is `*', then an error is signaled if the 
  9786.   buffer is read-only.  Otherwise, the following character is the first code 
  9787.   character. 
  9788.  
  9789.  
  9790. ΓòÉΓòÉΓòÉ 21.2.2. Code Characters for interactive ΓòÉΓòÉΓòÉ
  9791.  
  9792.  The code character descriptions below contain a number of key words, defined 
  9793. here as follows: 
  9794.  
  9795. Completion 
  9796.           Provide completion.  TAB, SPC, and RET perform name completion 
  9797.           because the argument is read using completing-read (see Completion). 
  9798.           ? displays a list of possible completions. 
  9799.  
  9800. Existing 
  9801.           Require the name of an existing object.  An invalid name is not 
  9802.           accepted; the commands to exit the minibuffer do not exit if the 
  9803.           current input is not valid. 
  9804.  
  9805. Default 
  9806.           A default value of some sort is used if the user enters no text in 
  9807.           the minibuffer.  The default depends on the code character. 
  9808.  
  9809. Prompt 
  9810.           A prompt immediately follows the code character.  The prompt ends 
  9811.           either with the end of the string or with a newline. 
  9812.  
  9813. No I/O 
  9814.           This code letter computes an argument without reading any input. 
  9815.           Therefore, it does not use a prompt string, and any prompt string you 
  9816.           supply is ignored. 
  9817.  
  9818.  Here are the code character descriptions for use with interactive: 
  9819.  
  9820. `a' 
  9821.           A function name (i.e., a symbol which is fboundp).  Existing, 
  9822.           Completion, Prompt. 
  9823.  
  9824. `b' 
  9825.           The name of an existing buffer.  By default, uses the name of the 
  9826.           current buffer (see Buffers).  Existing, Completion, Default, Prompt. 
  9827.  
  9828. `B' 
  9829.           A buffer name.  The buffer need not exist.  By default, uses the name 
  9830.           of a recently used buffer other than the current buffer.  Completion, 
  9831.           Prompt. 
  9832.  
  9833. `c' 
  9834.           A character.  The cursor does not move into the echo area.  Prompt. 
  9835.  
  9836. `C' 
  9837.           A command name (i.e., a symbol satisfying commandp).  Existing, 
  9838.           Completion, Prompt. 
  9839.  
  9840. `d' 
  9841.           The position of point as a number (see Point).  No I/O. 
  9842.  
  9843. `D' 
  9844.           A directory name.  The default is the current default directory of 
  9845.           the current buffer, default-directory (see System Environment). 
  9846.           Existing, Completion, Default, Prompt. 
  9847.  
  9848. `f' 
  9849.           A file name of an existing file (see File Names).  The default 
  9850.           directory is default-directory.  Existing, Completion, Default, 
  9851.           Prompt. 
  9852.  
  9853. `F' 
  9854.           A file name.  The file need not exist.  Completion, Default, Prompt. 
  9855.  
  9856. `k' 
  9857.           A key sequence (see Keymap Terms).  This keeps reading characters 
  9858.           until a command (or undefined command) is found in the current key 
  9859.           maps. The key sequence argument is represented as a string.  The 
  9860.           cursor does not move into the echo area.  Prompt. 
  9861.  
  9862.           This kind of input is used by commands such as describe-key and 
  9863.           global-set-key. 
  9864.  
  9865. `m' 
  9866.           The position of the mark as a number.  No I/O. 
  9867.  
  9868. `n' 
  9869.           A number read with the minibuffer.  If the input is not a number, the 
  9870.           user is asked to try again.  The prefix argument, if any, is not 
  9871.           used. Prompt. 
  9872.  
  9873. `N' 
  9874.           The raw prefix argument.  If the prefix argument is nil, then a 
  9875.           number is read as with n.  Requires a number.  Prompt. 
  9876.  
  9877. `p' 
  9878.           The numeric prefix argument.  (Note that this `p' is lower case.) No 
  9879.           I/O. 
  9880.  
  9881. `P' 
  9882.           The raw prefix argument.  (Note that this `P' is upper case.) See 
  9883.           Prefix Command Arguments.  No I/O. 
  9884.  
  9885. `r' 
  9886.           Point and the mark, as two numeric arguments, smallest first.  This 
  9887.           is the only code letter that specifies two successive arguments 
  9888.           rather than one.  No I/O. 
  9889.  
  9890. `s' 
  9891.           Arbitrary text, read in the minibuffer and returned as a string (see 
  9892.           Text from Minibuffer).  Terminate the input with either LFD or RET. 
  9893.           (C-q may be used to include either of these characters in the input.) 
  9894.           Prompt. 
  9895.  
  9896. `S' 
  9897.           An interned symbol whose name is read in the minibuffer.  Any 
  9898.           whitespace character terminates the input.  (Use C-q to include 
  9899.           whitespace in the string.)  Other characters that normally terminate 
  9900.           a symbol (e.g., parentheses and brackets) do not do so here.  Prompt. 
  9901.  
  9902. `v' 
  9903.           A variable declared to be a user option (i.e., satisfying 
  9904.           user-variable-p).  See High-Level Completion.  Existing, Completion, 
  9905.           Prompt. 
  9906.  
  9907. `x' 
  9908.           A Lisp object specified in printed representation, terminated with a 
  9909.           LFD or RET.  The object is not evaluated. See Object from Minibuffer. 
  9910.           Prompt. 
  9911.  
  9912. `X' 
  9913.           A Lisp form is read as with x, but then evaluated so that its value 
  9914.           becomes the argument for the command.  Prompt. 
  9915.  
  9916.  
  9917. ΓòÉΓòÉΓòÉ 21.2.3. Examples of Using interactive ΓòÉΓòÉΓòÉ
  9918.  
  9919.  Here are some examples of interactive: 
  9920.  
  9921. (defun foo1 ()                ; foo1 takes no arguments,
  9922.     (interactive)             ; just moves forward two words.
  9923.     (forward-word 2))
  9924.      => foo1
  9925.  
  9926. (defun foo2 (n)               ; foo2 takes one argument,
  9927.     (interactive "p")         ; which is the numeric prefix.
  9928.     (forward-word (* 2 n)))
  9929.      => foo2
  9930.  
  9931. (defun foo3 (n)               ; foo3 takes one argument,
  9932.     (interactive "nCount:")   ; which is read with the Minibuffer.
  9933.     (forward-word (* 2 n)))
  9934.      => foo3
  9935.  
  9936. (defun three-b (b1 b2 b3)
  9937.   "Select three existing buffers (prompting for them in
  9938. the Minibuffer).  Put them into three windows, selecting the
  9939. last one."
  9940.     (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
  9941.     (delete-other-windows)
  9942.     (split-window (selected-window) 8)
  9943.     (switch-to-buffer b1)
  9944.     (other-window 1)
  9945.     (split-window (selected-window) 8)
  9946.     (switch-to-buffer b2)
  9947.     (other-window 1)
  9948.     (switch-to-buffer b3))
  9949.      => three-b
  9950. (three-b "*scratch*" "declarations.texi" "*mail*")
  9951.      => nil
  9952.  
  9953.  
  9954. ΓòÉΓòÉΓòÉ 21.3. Interactive Call ΓòÉΓòÉΓòÉ
  9955.  
  9956.  After the command loop has translated a key sequence into a definition, it 
  9957. invokes that definition using the function command-execute.  If the definition 
  9958. is a function that is a command, command-execute calls call-interactively, 
  9959. which reads the arguments and calls the command.  You can also call these 
  9960. functions yourself. 
  9961.  
  9962. -- Function: commandp object 
  9963. Returns t if object is suitable for calling interactively; that is, if object 
  9964. is a command.  Otherwise, returns nil. 
  9965.  
  9966. The interactively callable objects include strings (treated as keyboard 
  9967. macros), lambda expressions that contain a top-level call to interactive, 
  9968. autoload objects that are declared as interactive (non-nil fourth argument to 
  9969. autoload), and some of the primitive functions. 
  9970.  
  9971. A symbol is commandp if its function definition is commandp. 
  9972.  
  9973. Keys and keymaps are not commands.  Rather, they are used to look up commands 
  9974. (see Keymaps). 
  9975.  
  9976. See documentation in Accessing Documentation, for a realistic example of using 
  9977. commandp. 
  9978.  
  9979. -- Function: call-interactively command &optional record-flag 
  9980. This function calls the interactively callable function command, reading 
  9981. arguments according to its interactive calling specifications. An error is 
  9982. signaled if command cannot be called interactively (i.e., it is not a command). 
  9983. Note that strings are not accepted, even though they are considered commands. 
  9984.  
  9985. If record-flag is non-nil, then this command and its arguments are 
  9986. unconditionally added to the list command-history. Otherwise, the command is 
  9987. added only if it uses the minibuffer to read an argument.  See Command History. 
  9988.  
  9989. -- Function: command-execute command &optional record-flag 
  9990. This function executes command as an editing command.  The argument command 
  9991. must satisfy the commandp predicate; i.e., it must be an interactively callable 
  9992. function or a string. 
  9993.  
  9994. A string as command is executed with execute-kbd-macro.  A function is passed 
  9995. to call-interactively, along with the optional record-flag. 
  9996.  
  9997. A symbol is handled by using its function definition in its place.  A symbol 
  9998. with an autoload definition counts as a command if it was declared to stand for 
  9999. an interactively callable function.  Such a definition is handled by loading 
  10000. the specified library and then rechecking the definition of the symbol. 
  10001.  
  10002. -- Command: execute-extended-command prefix-argument 
  10003. This primitive function reads a command name from the minibuffer using 
  10004. completing-read (see Completion).  Then it uses command-execute to call the 
  10005. specified command.  Whatever that command returns becomes the value of 
  10006. execute-extended-command. 
  10007.  
  10008. If the command asks for a prefix argument, the value prefix-argument is 
  10009. supplied.  If execute-extended-command is called interactively, the current raw 
  10010. prefix argument is used for prefix-argument, and thus passed on to whatever 
  10011. command is run. 
  10012.  
  10013. execute-extended-command is the normal definition of M-x, so it uses the string 
  10014. `M-x ' as a prompt.  (It would be better to take the prompt from the characters 
  10015. used to invoke execute-extended-command, but that is painful to implement.)  A 
  10016. description of the value of the prefix argument, if any, also becomes part of 
  10017. the prompt. 
  10018.  
  10019. (execute-extended-command 1)
  10020. ---------- Buffer: Minibuffer ----------
  10021. M-x forward-word RET
  10022. ---------- Buffer: Minibuffer ----------
  10023.      => t
  10024.  
  10025. -- Function: interactive-p 
  10026. This function returns t if the containing function (the one that called 
  10027. interactive-p) was called interactively, with call-interactively.  (It makes no 
  10028. difference whether call-interactively was called from Lisp or directly from the 
  10029. editor command loop.)  Note that if the containing function was called by Lisp 
  10030. evaluation (or with apply or funcall), then it was not called interactively. 
  10031.  
  10032. The usual application of interactive-p is for deciding whether to print an 
  10033. informative message.  As a special exception, interactive-p returns nil 
  10034. whenever a keyboard macro is being run.  This is to suppress the informative 
  10035. messages and speed execution of the macro. 
  10036.  
  10037. For example: 
  10038.  
  10039. (defun foo ()
  10040.   (interactive)
  10041.   (and (interactive-p)
  10042.        (message "foo")))
  10043.      => foo
  10044.  
  10045. (defun bar ()
  10046.   (interactive)
  10047.   (setq foobar (list (foo) (interactive-p))))
  10048.      => bar
  10049.  
  10050. ;; Type M-x foo.
  10051.      -| foo
  10052.  
  10053. ;; Type M-x bar.
  10054. ;; This does not print anything.
  10055.  
  10056. foobar
  10057.      => (nil t)
  10058.  
  10059.  
  10060. ΓòÉΓòÉΓòÉ 21.4. Information from the Command Loop ΓòÉΓòÉΓòÉ
  10061.  
  10062. The editor command loop sets several Lisp variables to keep status records for 
  10063. itself and for commands that are run. 
  10064.  
  10065. -- Variable: last-command 
  10066. This variable records the name of the previous command executed by the command 
  10067. loop (the one before the current command).  Normally the value is a symbol with 
  10068. a function definition, but this is not guaranteed. 
  10069.  
  10070. The value is set by copying the value of this-command when a command returns to 
  10071. the command loop, except when the command specifies a prefix argument for the 
  10072. following command. 
  10073.  
  10074. -- Variable: this-command 
  10075. This variable records the name of the command now being executed by editor 
  10076. command loop.  Like last-command, it is normally a symbol with a function 
  10077. definition. 
  10078.  
  10079. This variable is set by the command loop just before the command is run, and 
  10080. its value is copied into last-command when the command finishes (unless the 
  10081. command specifies a prefix argument for the following command). 
  10082.  
  10083. Some commands change the value of this variable during their execution, simply 
  10084. as a flag for whatever command runs next.  In particular, the functions that 
  10085. kill text set this-command to kill-region so that any kill commands immediately 
  10086. following will know to append the killed text to the previous kill. 
  10087.  
  10088. -- Function: this-command-keys 
  10089. This function returns a string containing the key sequence that invoked the 
  10090. present command, plus any previous commands that generated the prefix argument 
  10091. for this command. 
  10092.  
  10093. (this-command-keys) ;; Now type C-u C-x C-e.
  10094.      => "^U^X^E"
  10095.  
  10096. -- Variable: last-command-char 
  10097. This variable is set to the last character that was typed on the terminal and 
  10098. was part of a command.  The principal use of this variable is in 
  10099. self-insert-command, which uses it to decide which character to insert. 
  10100.  
  10101. last-command-char ;; Now type C-u C-x C-e.
  10102.      => 5
  10103.  
  10104. The value is 5 because that is the ASCII code for C-e. 
  10105.  
  10106. -- Variable: echo-keystrokes 
  10107. This variable determines how much time should elapse before command characters 
  10108. are echoed.  Its value must be an integer, which specifies the number of 
  10109. seconds to wait before echoing.  If the user types a prefix key (say C-x) and 
  10110. then delays this many seconds before continuing, the key C-x is echoed in the 
  10111. echo area.  Any subsequent characters in the same command will be echoed as 
  10112. well. 
  10113.  
  10114. If the value is zero, then command input is not echoed. 
  10115.  
  10116.  
  10117. ΓòÉΓòÉΓòÉ 21.5. Keyboard Input ΓòÉΓòÉΓòÉ
  10118.  
  10119.  The editor command loop reads keyboard input using read-key-sequence, which 
  10120. uses read-char.  These and other functions for keyboard input are also 
  10121. available for use in Lisp programs.  See also momentary-string-display in 
  10122. Temporary Displays, and sit-for in Waiting.  See Terminal Input, for functions 
  10123. and variables for controlling terminal input modes and debugging terminal 
  10124. input. 
  10125.  
  10126. -- Function: read-char 
  10127. This function reads a character from the command input (either from direct 
  10128. keyboard input or from an executing keyboard macro), and returns it. 
  10129.  
  10130. No message is displayed to indicate that keyboard input is expected.  If you 
  10131. want to display a message, call message first.  If cursor-in-echo-area is 
  10132. non-nil, then the cursor moves to the echo area, to the end of any message 
  10133. displayed there.  Otherwise the cursor does not move.  See The Echo Area. 
  10134.  
  10135. In the first example, the user types 1 (which is ASCII code 49).  The second 
  10136. example shows a keyboard macro definition that calls read-char from the 
  10137. minibuffer.  read-char reads the keyboard macro's very next character, which is 
  10138. 1.  The value of this function is displayed in the echo area by the command 
  10139. eval-expression. 
  10140.  
  10141. (read-char)
  10142.      => 49
  10143.  
  10144. (symbol-function 'foo)
  10145.      => "^[^[(read-char)^M1"
  10146. (execute-kbd-macro foo)
  10147.      -| 49
  10148.      => nil
  10149.  
  10150. -- Function: read-quoted-char &optional prompt 
  10151. This function is like read-char, except that if the first character read is an 
  10152. octal digit (0-7), it reads up to two more octal digits (but stopping if a 
  10153. non-octal digit is found) and returns the character represented by those digits 
  10154. as an octal number. 
  10155.  
  10156. Quitting is suppressed when the first character is read, so that the user can 
  10157. enter a C-g.  See Quitting. 
  10158.  
  10159. If prompt is supplied, it specifies a string for prompting the user.  The 
  10160. prompt string is always printed in the echo area and followed by a single `-'. 
  10161.  
  10162. In the following example, the user types in the octal number 177 (which is 127 
  10163. in decimal). 
  10164.  
  10165. (read-quoted-char "What character")
  10166.  
  10167. ---------- Echo Area ----------
  10168. What character-177
  10169. ---------- Echo Area ----------
  10170.  
  10171.      => 127
  10172.  
  10173. -- Function: read-key-sequence prompt 
  10174. This function reads a key sequence and returns it as a string.  It keeps 
  10175. reading characters until it has accumulated a full key sequence; that is, 
  10176. enough characters to specify a non-prefix command using the current local and 
  10177. global keymaps.  read-key-sequence is used by the command loop to read command 
  10178. input. 
  10179.  
  10180. If an input character is an upper case letter and has no definition, but the 
  10181. lower case equivalent is defined, then the character is converted to lower 
  10182. case.  Note that lookup-key does not perform case conversion in this way. 
  10183.  
  10184. Quitting is suppressed inside read-key-sequence.  In other words, a C-g typed 
  10185. while reading with this function is treated like any other character, and 
  10186. quit-flag is not set.  See Quitting. 
  10187.  
  10188. The argument prompt is either a string to be displayed in the echo area as a 
  10189. prompt, or nil, meaning that no prompt is displayed. 
  10190.  
  10191. In the example below, the prompt `?' is displayed in the echo area, and the 
  10192. user types C-x C-f. 
  10193.  
  10194. (read-key-sequence "?")
  10195.  
  10196. ---------- Echo Area ----------
  10197. ?C-x C-f
  10198. ---------- Echo Area ----------
  10199.  
  10200.      => "^X^F"
  10201.  
  10202. -- Variable: unread-command-char 
  10203. This variable holds a character waiting to be read as the next input from the 
  10204. command input stream, or to the integer -1 if no character is waiting.  The 
  10205. variable is used because in some cases an input function reads a character and 
  10206. then decides not to use it. Storing the character in this variable causes it to 
  10207. be processed normally by the command loop or when read-char is next called. 
  10208.  
  10209. For example, the function that governs prefix arguments reads any number of 
  10210. digits.  When it finds a non-digit character, it must unread the character so 
  10211. that it becomes input for the next command.  Likewise, incremental search uses 
  10212. this feature to unread a control character used to terminate the search. 
  10213.  
  10214. -- Function: input-pending-p 
  10215. This function determines whether command input is currently available. It 
  10216. returns immediately, with value t if there is input, nil otherwise.  On rare 
  10217. occasions it may return t when no input is available. 
  10218.  
  10219. -- Variable: last-input-char 
  10220.  This variable records the last terminal input character read, whether as part 
  10221. of a command or explicitly by a Lisp program. 
  10222.  
  10223.  In the example below, a character is read (the character 1, ASCII code 49). 
  10224. It becomes the value of last-input-char, while C-e (from the C-x C-e command 
  10225. used to evaluate this expression) remains the value of last-command-char. 
  10226.  
  10227. (progn (print (read-char))
  10228.        (print last-command-char)
  10229.        last-input-char)
  10230.      -| 49
  10231.      -| 5
  10232.      => 49
  10233.  
  10234. -- Function: discard-input 
  10235. This function discards the contents of the terminal input buffer and cancels 
  10236. any keyboard macro that might be in the process of definition. It returns nil. 
  10237.  
  10238. In the following example, the user may type a number of characters right after 
  10239. starting the evaluation of the form.  After the sleep-for finishes sleeping, 
  10240. any characters that have been typed are discarded. 
  10241.  
  10242. (progn (sleep-for 2)
  10243.   (discard-input))
  10244.      => nil
  10245.  
  10246.  
  10247. ΓòÉΓòÉΓòÉ 21.6. Quitting ΓòÉΓòÉΓòÉ
  10248.  
  10249.  Typing C-g while the command loop has run a Lisp function causes Emacs to quit 
  10250. whatever it is doing.  This means that control returns to the innermost active 
  10251. command loop. 
  10252.  
  10253.  Typing C-g while the command loop is waiting for keyboard input does not cause 
  10254. a quit; it acts as an ordinary input character.  In the simplest case, you 
  10255. cannot tell the difference, because C-g normally runs the command 
  10256. keyboard-quit, whose effect is to quit. However, when C-g follows a prefix key, 
  10257. the result is an undefined key.  The effect is to cancel the prefix key as well 
  10258. as any prefix argument. 
  10259.  
  10260.  In the minibuffer, C-g has a different definition: it aborts out of the 
  10261. minibuffer.  This means, in effect, that it exits the minibuffer and then 
  10262. quits.  (Simply quitting would return to the command loop within the 
  10263. minibuffer.)  The reason why C-g does not quit directly when the command reader 
  10264. is reading input is so that its meaning can be redefined in the minibuffer in 
  10265. this way.  C-g following a prefix key is not redefined in the minibuffer, and 
  10266. it has its normal effect of canceling the prefix key and prefix argument.  This 
  10267. too would not be possible if C-g quit directly. 
  10268.  
  10269.  C-g causes a quit by setting the variable quit-flag to a non-nil value.  Emacs 
  10270. checks this variable at appropriate times and quits if it is not nil.  Setting 
  10271. quit-flag non-nil in any way thus causes a quit. 
  10272.  
  10273.  At the level of C code, quits cannot happen just anywhere; only at the special 
  10274. places which check quit-flag.  The reason for this is that quitting at other 
  10275. places might leave an inconsistency in Emacs's internal state.  Because 
  10276. quitting is delayed until a safe place, quitting cannot make Emacs crash. 
  10277.  
  10278.  Certain functions such as read-key-sequence or read-quoted-char prevent 
  10279. quitting entirely even though they wait for input.  Instead of quitting, C-g 
  10280. serves as the requested input.  In the case of read-key-sequence, this serves 
  10281. to bring about the special behavior of C-g in the command loop.  In the case of 
  10282. read-quoted-char, this is so that C-q can be used to quote a C-g. 
  10283.  
  10284.  You can prevent quitting for a portion of a Lisp function by binding the 
  10285. variable inhibit-quit to a non-nil value.  Then, although C-g still sets 
  10286. quit-flag to t as usual, the usual result of this---a quit---is prevented. 
  10287. Eventually, inhibit-quit will become nil again, such as when its binding is 
  10288. unwound at the end of a let form.  At that time, if quit-flag is still non-nil, 
  10289. the requested quit happens immediately.  This behavior is ideal for a 
  10290. ``critical section'', where you wish to make sure that quitting does not happen 
  10291. within that part of the program. 
  10292.  
  10293.  In some functions (such as read-quoted-char), C-g is handled in a special way 
  10294. which does not involve quitting.  This is done by reading the input with 
  10295. inhibit-quit bound to t and setting quit-flag to nil before inhibit-quit 
  10296. becomes nil again.  This excerpt from the definition of read-quoted-char shows 
  10297. how this is done; it also shows that normal quitting is permitted after the 
  10298. first character of input. 
  10299.  
  10300. (defun read-quoted-char (&optional prompt)
  10301.   "...documentation..."
  10302.   (let ((count 0) (code 0) char)
  10303.     (while (< count 3)
  10304.       (let ((inhibit-quit (zerop count))
  10305.             (help-form nil))
  10306.         (and prompt (message "%s-" prompt))
  10307.         (setq char (read-char))
  10308.         (if inhibit-quit (setq quit-flag nil)))
  10309.       ...)
  10310.     (logand 255 code)))
  10311.  
  10312. -- Variable: quit-flag 
  10313. If this variable is non-nil, then Emacs quits immediately, unless inhibit-quit 
  10314. is non-nil.  Typing C-g sets quit-flag non-nil, regardless of inhibit-quit. 
  10315.  
  10316. -- Variable: inhibit-quit 
  10317. This variable determines whether Emacs should quit when quit-flag is set to a 
  10318. value other than nil.  If inhibit-quit is non-nil, then quit-flag has no 
  10319. special effect. 
  10320.  
  10321. -- Command: keyboard-quit 
  10322. This function signals the quit condition with (signal 'quit nil).  This is the 
  10323. same thing that quitting does.  (See signal in Errors.) 
  10324.  
  10325.  You can specify a character other than C-g to use for quitting. See the 
  10326. function set-input-mode in Terminal Input. 
  10327.  
  10328.  
  10329. ΓòÉΓòÉΓòÉ 21.7. Prefix Command Arguments ΓòÉΓòÉΓòÉ
  10330.  
  10331.  Most Emacs commands can use a prefix argument, a number specified before the 
  10332. command itself.  (Don't confuse prefix arguments with prefix keys.)  The prefix 
  10333. argument is represented by a value that is always available (though it may be 
  10334. nil, meaning there is no prefix argument).  Each command may use the prefix 
  10335. argument or ignore it. 
  10336.  
  10337.  There are two representations of the prefix argument: raw and numeric.  The 
  10338. editor command loop uses the raw representation internally, and so do the Lisp 
  10339. variables that store the information, but commands can request either 
  10340. representation. 
  10341.  
  10342.  Here are the possible values of a raw prefix argument: 
  10343.  
  10344. o nil, meaning there is no prefix argument.  Its numeric value is 1, but 
  10345.   numerous commands make a distinction between nil and the integer 1. 
  10346.  
  10347. o An integer, which stands for itself. 
  10348.  
  10349. o A list of one element, which is an integer.  This form of prefix argument 
  10350.   results from one or a succession of C-u's with no digits.  The numeric value 
  10351.   is the integer in the list, but some commands make a distinction between such 
  10352.   a list and an integer alone. 
  10353.  
  10354. o The symbol -.  This indicates that M-- or C-u - was typed, without following 
  10355.   digits.  The equivalent numeric value is -1, but some commands make a 
  10356.   distinction between the integer -1 and the symbol -. 
  10357.  
  10358. The various possibilities may be illustrated by calling the following function 
  10359. with various prefixes: 
  10360.  
  10361. (defun print-prefix (arg)
  10362.   "Print the value of the raw prefix arg at point."
  10363.   (interactive "P")
  10364.   (message "%s" arg))
  10365.  
  10366. Here are the results of calling print-prefix with various raw prefix arguments: 
  10367.  
  10368.         M-x print-prefix  -| nil
  10369.  
  10370. C-u     M-x print-prefix  -| (4)
  10371.  
  10372. C-u C-u M-x print-prefix  -| (16)
  10373.  
  10374. C-u 3   M-x print-prefix  -| 3
  10375.  
  10376. M-3     M-x print-prefix  -| 3      ; (Same as C-u 3.)
  10377.  
  10378. C-u -   M-x print-prefix  -| -
  10379.  
  10380. M- -    M-x print-prefix  -| -      ; (Same as C-u -.)
  10381.  
  10382. C-u -7  M-x print-prefix  -| -7
  10383.  
  10384. M- -7   M-x print-prefix  -| -7     ; (Same as C-u -7.)
  10385.  
  10386.  There are two variables used to store the prefix argument: prefix-arg and 
  10387. current-prefix-arg.  Commands such as universal-argument that set up prefix 
  10388. arguments for other commands store them in prefix-arg.  In contrast, 
  10389. current-prefix-arg conveys the prefix argument to the current command, so 
  10390. setting it has no effect on the prefix arguments for future commands. 
  10391.  
  10392.  Normally, commands specify which representation to use for the prefix 
  10393. argument, either numeric or raw, in the interactive declaration. (See 
  10394. Interactive Call.)  Alternatively, functions may look at the value of the 
  10395. prefix argument directly in the variable current-prefix-arg, but this is less 
  10396. clean. 
  10397.  
  10398.  Don't call universal-argument, digit-argument, or negative-argument unless you 
  10399. intend to let the user enter the prefix argument for the next command. 
  10400.  
  10401. -- Command: universal-argument 
  10402. This command reads input and specifies a prefix argument for the following 
  10403. command.  Don't call this command yourself unless you know what you are doing. 
  10404.  
  10405. -- Command: digit-argument arg 
  10406. This command adds to the prefix argument for the following command.  The 
  10407. argument arg is the raw prefix argument as it was before this command; it is 
  10408. used to compute the updated prefix argument.  Don't call this command yourself 
  10409. unless you know what you are doing. 
  10410.  
  10411. -- Command: negative-argument arg 
  10412. This command adds to the numeric argument for the next command.  The argument 
  10413. arg is the raw prefix argument as it was before this command; its value is 
  10414. negated to form the new prefix argument.  Don't call this command yourself 
  10415. unless you know what you are doing. 
  10416.  
  10417. -- Function: prefix-numeric-value arg 
  10418. This function returns the numeric meaning of a valid raw prefix argument value, 
  10419. arg.  The argument may be a symbol, a number, or a list. If it is nil, the 
  10420. value 1 is returned; if it is any other symbol, the value -1 is returned.  If 
  10421. it is a number, that number is returned; if it is a list, the car of that list 
  10422. (which should be a number) is returned. 
  10423.  
  10424. -- Variable: current-prefix-arg 
  10425. This variable is the value of the raw prefix argument for the current command. 
  10426. Commands may examine it directly, but the usual way to access it is with 
  10427. (interactive "P"). 
  10428.  
  10429. -- Variable: prefix-arg 
  10430. The value of this variable is the raw prefix argument for the next editing 
  10431. command.  Commands that specify prefix arguments for the following command work 
  10432. by setting this variable. 
  10433.  
  10434.  
  10435. ΓòÉΓòÉΓòÉ 21.8. Recursive Editing ΓòÉΓòÉΓòÉ
  10436.  
  10437.  The Emacs command loop is entered automatically when Emacs starts up. This 
  10438. top-level invocation of the command loop is never exited until the Emacs is 
  10439. killed.  Lisp programs can also invoke the command loop.  Since this makes more 
  10440. than one activation of the command loop, we call it recursive editing.  A 
  10441. recursive editing level has the effect of suspending whatever command invoked 
  10442. it and permitting the user to do arbitrary editing before resuming that 
  10443. command. 
  10444.  
  10445.  The commands available during recursive editing are the same ones available in 
  10446. the top-level editing loop and defined in the keymaps. Only a few special 
  10447. commands exit the recursive editing level; the others return to the recursive 
  10448. editing level when finished.  (The special commands for exiting are always 
  10449. available, but do nothing when recursive editing is not in progress.) 
  10450.  
  10451.  All command loops, including recursive ones, set up all-purpose error handlers 
  10452. so that an error in a command run from the command loop will not exit the loop. 
  10453.  
  10454.  Minibuffer input is a special kind of recursive editing.  It has a few special 
  10455. wrinkles, such as enabling display of the minibuffer and the minibuffer window, 
  10456. but fewer than you might suppose.  Certain keys behave differently in the 
  10457. minibuffer, but that is only because of the minibuffer's local map; if you 
  10458. switch windows, you get the usual Emacs commands. 
  10459.  
  10460.  To invoke a recursive editing level, call the function recursive-edit.  This 
  10461. function contains the command loop; it also contains a call to catch with tag 
  10462. exit, which makes it possible to exit the recursive editing level by throwing 
  10463. to exit (see Catch and Throw).  If you throw a value other than t, then 
  10464. recursive-edit returns normally to the function that called it.  The command 
  10465. C-M-c (exit-recursive-edit) does this. Throwing a t value causes recursive-edit 
  10466. to quit, so that control returns to the command loop one level up.  This is 
  10467. called aborting, and is done by C-] (abort-recursive-edit). 
  10468.  
  10469.  Most applications should not use recursive editing, except as part of using 
  10470. the minibuffer.  Usually it is more convenient for the user if you change the 
  10471. major mode of the current buffer temporarily to a special major mode, which has 
  10472. a command to go back to the previous mode.  (This technique is used by the w 
  10473. command in Rmail.)  Or, if you wish to give the user different text to edit 
  10474. ``recursively'', create and select a new buffer in a special mode.  In this 
  10475. mode, define a command to complete the processing and go back to the previous 
  10476. buffer.  (The m command in Rmail does this.) 
  10477.  
  10478.  Recursive edits are useful in debugging.  You can insert a call to debug into 
  10479. a function definition as a sort of breakpoint, so that you can look around when 
  10480. the function gets there.  debug invokes a recursive edit but also provides the 
  10481. other features of the debugger. 
  10482.  
  10483.  Recursive editing levels are also used when you type C-r in query-replace or 
  10484. use C-x q (kbd-macro-query). 
  10485.  
  10486. -- Function: recursive-edit 
  10487. This function invokes the editor command loop.  It is called automatically by 
  10488. the initialization of Emacs, to let the user begin editing.  When called from a 
  10489. Lisp program, it enters a recursive editing level. 
  10490.  
  10491.  In the following example, the function simple-rec first advances point one 
  10492. word, then enters a recursive edit, printing out a message in the echo area. 
  10493. The user can then do any editing desired, and then type C-M-c to exit and 
  10494. continue executing simple-rec. 
  10495.  
  10496. (defun simple-rec ()
  10497.   (forward-word 1)
  10498.   (message "Recursive edit in progress.")
  10499.   (recursive-edit)
  10500.   (forward-word 1))
  10501.      => simple-rec
  10502. (simple-rec)
  10503.      => nil
  10504.  
  10505. -- Command: exit-recursive-edit 
  10506. This function exits from the innermost recursive edit (including minibuffer 
  10507. input).  Its definition is effectively (throw 'exit nil). 
  10508.  
  10509. -- Command: abort-recursive-edit 
  10510. This function aborts the command that requested the innermost recursive edit 
  10511. (including minibuffer input), by signaling quit after exiting the recursive 
  10512. edit.  Its definition is effectively (throw 'exit t).  See Quitting. 
  10513.  
  10514. -- Command: top-level 
  10515. This function exits all recursive editing levels; it does not return a value, 
  10516. as it jumps completely out of any computation directly back to the main command 
  10517. loop. 
  10518.  
  10519. -- Function: recursion-depth 
  10520. This function returns the current depth of recursive edits.  When no recursive 
  10521. edit is active, it returns 0. 
  10522.  
  10523.  
  10524. ΓòÉΓòÉΓòÉ 21.9. Disabling Commands ΓòÉΓòÉΓòÉ
  10525.  
  10526.  Disabling a command marks the command as requiring user confirmation before it 
  10527. can be executed.  Disabling is used for commands which might be confusing to 
  10528. beginning users, to prevent them from using the commands by accident. 
  10529.  
  10530.  The low-level mechanism for disabling a command is to put a non-nil disabled 
  10531. property on the Lisp symbol for the command.  These properties are normally set 
  10532. up by the user's `.emacs' file with Lisp expressions such as this: 
  10533.  
  10534. (put 'upcase-region 'disabled t)
  10535.  
  10536. For a few commands, these properties are present by default and may be removed 
  10537. by the `.emacs' file. 
  10538.  
  10539.  If the value of the disabled property is a string, that string is included in 
  10540. the message printed when the command is used: 
  10541.  
  10542. (put 'delete-region 'disabled
  10543.      "Text deleted this way cannot be yanked back!\n")
  10544.  
  10545.  See Disabling, for the details on what happens when a disabled command is 
  10546. invoked interactively. Disabling a command has no effect on calling it as a 
  10547. function from Lisp programs. 
  10548.  
  10549. -- Command: enable-command command 
  10550. Allow command to be executed without special confirmation from now on.  The 
  10551. user's `.emacs' file is optionally altered so that this will apply to future 
  10552. sessions. 
  10553.  
  10554. -- Command: disable-command command 
  10555. Require special confirmation to execute command from now on.  The user's 
  10556. `.emacs' file is optionally altered so that this will apply to future sessions. 
  10557.  
  10558. -- Variable: disabled-command-hook 
  10559. The value of this variable is a function to be called instead of any command 
  10560. that is disabled (i.e., that has a non-nil disabled property).  By default, the 
  10561. value of disabled-command-hook is a function defined to ask the user whether to 
  10562. proceed. 
  10563.  
  10564.  
  10565. ΓòÉΓòÉΓòÉ 21.10. Command History ΓòÉΓòÉΓòÉ
  10566.  
  10567.  The command loop keeps a history of the complex commands that have been 
  10568. executed, to make it convenient to repeat these commands.  A complex command is 
  10569. one for which the interactive argument reading uses the minibuffer.  This 
  10570. includes any M-x command, any M-ESC command, and any command whose interactive 
  10571. specification reads an argument from the minibuffer.  Explicit use of the 
  10572. minibuffer during the execution of the command itself does not cause the 
  10573. command to be considered complex. 
  10574.  
  10575. -- Variable: command-history 
  10576. This variable's value is a list of recent complex commands, each represented as 
  10577. a form to evaluate.  It continues to accumulate all complex commands for the 
  10578. duration of the editing session, but all but the first (most recent) thirty 
  10579. elements are deleted when a garbage collection takes place (see Garbage 
  10580. Collection). 
  10581.  
  10582. command-history
  10583. => ((switch-to-buffer "chistory.texi")
  10584.     (describe-key "^X^[")
  10585.     (visit-tags-table "~/emacs/src/")
  10586.     (find-tag "repeat-complex-command"))
  10587.  
  10588.  There are a number of commands and even two entire modes devoted to 
  10589. facilitating the editing and recall of previous commands.  The commands 
  10590. repeat-complex-command, and list-command-history are described in the user 
  10591. manual ( see Repetition). 
  10592.  
  10593. -- Variable: repeat-complex-command-map 
  10594. The value of this variable is a sparse keymap used by the minibuffer inside of 
  10595. read-complex-command. 
  10596.  
  10597.  
  10598. ΓòÉΓòÉΓòÉ 21.11. Keyboard Macros ΓòÉΓòÉΓòÉ
  10599.  
  10600.  A keyboard macro is a canned sequence of keystrokes that can be considered a 
  10601. command and made the definition of a key.  Don't confuse keyboard macros with 
  10602. Lisp macros (see Macros). 
  10603.  
  10604. -- Function: execute-kbd-macro macro &optional count 
  10605. This function executes macro as a string of editor commands.  If macro is a 
  10606. string, then the characters in that string are executed exactly as if they had 
  10607. been typed as command input. 
  10608.  
  10609. If macro is a symbol, then its function definition is used in place of macro. 
  10610. If that is another symbol, this process repeats. Eventually the result should 
  10611. be a string.  If the result is neither a symbol nor a string, an error is 
  10612. signaled. 
  10613.  
  10614. The argument count is a repeat count; macro is executed that many times.  If 
  10615. count is omitted or nil, macro is executed once.  If it is 0, macro is executed 
  10616. over and over until it encounters an error or a failing search. 
  10617.  
  10618. -- Variable: last-kbd-macro 
  10619. This variable is the definition of the most recently defined keyboard macro. 
  10620. Its value is a string or nil. 
  10621.  
  10622. -- Variable: executing-macro 
  10623. This variable contains the string that defines the keyboard macro that is 
  10624. currently executing.  It is nil if no macro is currently executing. 
  10625.  
  10626. -- Variable: defining-kbd-macro 
  10627. This variable indicates whether a keyboard macro is being defined.  It is set 
  10628. to t by start-kbd-macro, and nil by end-kbd-macro.  It is not hard to use this 
  10629. variable to make a command behave differently when run from a keyboard macro 
  10630. (perhaps indirectly by calling interactive-p).  However, do not set this 
  10631. variable yourself. 
  10632.  
  10633.  The user-level commands for defining, running and editing keyboard macros 
  10634. include call-last-kbd-macro, insert-kbd-macro, start-kbd-macro, end-kbd-macro, 
  10635. kbd-macro-query, and name-last-kbd-macro.  They are described in the user's 
  10636. manual (see Keyboard Macros). 
  10637.  
  10638.  
  10639. ΓòÉΓòÉΓòÉ 22. Keymaps ΓòÉΓòÉΓòÉ
  10640.  
  10641.  The bindings between keyboard input and commands are recorded in data 
  10642. structures called keymaps.  Each binding in a keymap associates (or binds) an 
  10643. individual character either with another keymap or with a command.  When a 
  10644. character is bound to a keymap, that keymap is used to look up the next 
  10645. character typed; this continues until a command is found.  This process is 
  10646. called key lookup. 
  10647.  
  10648.  
  10649. ΓòÉΓòÉΓòÉ 22.1. Keymaps: Terminology ΓòÉΓòÉΓòÉ
  10650.  
  10651.  A keymap is a table mapping characters to definitions (which can be any Lisp 
  10652. objects, though only certain types are meaningful for execution by the command 
  10653. loop).  Given a character and a keymap, Emacs can get the character's 
  10654. definition. 
  10655.  
  10656.  A sequence of keyboard input characters that form a unit is called a key 
  10657. sequence, or key for short.  A sequence of one character is always a key 
  10658. sequence, and so are some multicharacter sequences. 
  10659.  
  10660.  A keymap determines a binding or definition for any key sequence.  If the key 
  10661. sequence is a single character, its binding is the definition of the character 
  10662. in the keymap.  The binding of a multicharacter key sequence is found by an 
  10663. iterative process: the binding of the first character is found, and must be a 
  10664. keymap; then the second character's binding is found in that keymap, and so on 
  10665. until all the characters in the key sequence are used up. 
  10666.  
  10667.  If the binding of a key sequence is a keymap, we call the key sequence a 
  10668. prefix key.  Otherwise, we call it a complete key (because no more characters 
  10669. can be added to it).  If the binding is nil, we call the key undefined. 
  10670. Examples of prefix keys are C-c, C-x, and C-x 4.  Examples of defined complete 
  10671. keys are X, RET, and C-x 4 C-f.  Examples of undefined complete keys are C-x 
  10672. C-g, and C-c 3.  See Prefix Keys, for more details. 
  10673.  
  10674.  The rule for finding the binding of a key sequence assumes that the 
  10675. intermediate bindings (found for the characters before the last) are all 
  10676. keymaps; if this is not so, the sequence of characters does not form a 
  10677. unit---it is not really a key sequence.  In other words, removing one or more 
  10678. characters from the end of any key must always yield a prefix key. For example, 
  10679. C-f C-f is not a key; C-f is not a prefix key, so a longer sequence starting 
  10680. with C-f cannot be a key.  Note that the set of possible multicharacter key 
  10681. sequences depends on the bindings for prefix keys; therefore, it can be 
  10682. different for different keymaps, and can change when bindings are changed. 
  10683. However, a one-character sequence is always a key sequence, because it does not 
  10684. depend on any prefix keys for its validity. 
  10685.  
  10686.  At any time, two primary keymaps are in use for finding key bindings: the 
  10687. global map, which is shared by all buffers, and the local keymap, which is 
  10688. usually associated with a specific major mode.  The local keymap bindings 
  10689. shadow (i.e., take precedence over) the corresponding global bindings.  See 
  10690. Global and Local Keymaps, for details. 
  10691.  
  10692.  
  10693. ΓòÉΓòÉΓòÉ 22.2. Creating Keymaps ΓòÉΓòÉΓòÉ
  10694.  
  10695.  A keymap can be represented as one of two kinds of Lisp object: a vector or a 
  10696. list.  A full keymap is a vector of length 128.  The binding for a character in 
  10697. such a keymap is found by indexing into the vector with the character as the 
  10698. index. 
  10699.  
  10700.  A sparse keymap is a list whose car is the symbol keymap, and whose remaining 
  10701. elements are cons cells of the form (char . binding).  It is called a sparse 
  10702. keymap because it stores only the entries which are significant.  Use a sparse 
  10703. keymap when you expect only a few entries.  (define-key automatically creates 
  10704. sparse keymaps for intermediate keymaps.) 
  10705.  
  10706.  Keymaps record directly only character codes less than 128; they are unable to 
  10707. handle directly the META characters, whose codes are from 128 to 255.  Instead, 
  10708. META characters are regarded for purposes of key lookup as sequences of two 
  10709. characters, the first of which is ESC (the usual value of meta-prefix-char). 
  10710. Thus, the key M-a is really represented as ESC a, and its global binding is 
  10711. found at the slot for `a' in esc-map. 
  10712.  
  10713.  Here as an example is the local keymap for Lisp mode, a sparse keymap. It 
  10714. defines C-c C-l as the run-lisp command, M-C-q as indent-sexp, and M-C-x as 
  10715. lisp-send-defun. 
  10716.  
  10717. lisp-mode-map
  10718. =>
  10719. (keymap
  10720.  (9 . lisp-indent-line)                 ; TAB
  10721.  (127 . backward-delete-char-untabify)  ; DEL
  10722.  (3 keymap
  10723.     (12 . run-lisp))                    ; C-c C-l
  10724.  (27 keymap
  10725.      (17 . indent-sexp)                 ; M-C-q, treated as ESC C-q
  10726.      (24 . lisp-send-defun)))           ; M-C-x, treated as ESC C-x
  10727.  
  10728. -- Function: keymapp object 
  10729.  This function returns t if object is a keymap, nil otherwise.  A keymap is 
  10730. either a vector of length 128, or a list with the form (keymap pairs...), where 
  10731. pairs stands for a series of associations, cons cells of the form (char . 
  10732. binding). 
  10733.  
  10734. (keymapp '(keymap))
  10735.     => t
  10736. (keymapp (current-global-map))
  10737.     => t
  10738.  
  10739. -- Function: make-keymap 
  10740.  This function creates and returns a new full keymap (i.e., a vector of length 
  10741. 128).  All entries in the keymap are nil, which means that no characters are 
  10742. defined. 
  10743.  
  10744. (make-keymap)
  10745.     => [nil nil nil ... nil nil]
  10746.  
  10747. -- Function: make-sparse-keymap 
  10748.  This function creates and returns a new sparse keymap with no entries. In this 
  10749. keymap, no characters are defined. 
  10750.  
  10751. (make-sparse-keymap)
  10752.     => (keymap)
  10753.  
  10754. -- Function: copy-keymap keymap 
  10755.  This function returns a copy of keymap.  Any keymaps which appear directly as 
  10756. bindings in keymap are also copied recursively, and so on to any number of 
  10757. levels.  However, recursive copying does not take place when the definition of 
  10758. a character is a symbol whose function definition is a keymap; the same symbol 
  10759. appears in the new copy. 
  10760.  
  10761. (setq map (copy-keymap (current-local-map)))
  10762. => (keymap
  10763.      (27 keymap         ; (This implements META characters.)
  10764.        (83 . center-paragraph)
  10765.        (115 . center-line))
  10766.      (9 . tab-to-tab-stop))
  10767.  
  10768. (eq map (current-local-map))
  10769.     => nil
  10770. (equal map (current-local-map))
  10771.     => t
  10772.  
  10773.  
  10774. ΓòÉΓòÉΓòÉ 22.3. Key Lookup ΓòÉΓòÉΓòÉ
  10775.  
  10776.  Key lookup is the process of finding the binding of a key sequence from a 
  10777. given keymap.  Actual execution of the definition is not part of key lookup. 
  10778.  
  10779.  When the key sequence consists of multiple characters, the characters are 
  10780. handled sequentially: the binding of the first character is found, and must be 
  10781. a keymap; then the second character's binding is found in that keymap, and so 
  10782. on until all the characters in the key sequence are used up.  (The binding thus 
  10783. found for the last character may or may not be a keymap.)  Thus, the process of 
  10784. key lookup is defined in terms of a simpler process for looking up a single 
  10785. character in a keymap.  How this is done depends on the type of object 
  10786. associated with the character in that keymap. 
  10787.  
  10788.  The value directly associated with a character in a keymap is called a keymap 
  10789. entry.  While any Lisp object may be stored in a keymap entry, only a few types 
  10790. of object make sense for key lookup.  Here is a list of them, and what they 
  10791. mean: 
  10792.  
  10793. nil 
  10794.           nil means that the characters used so far in the lookup form an 
  10795.           undefined key.  When a sparse keymap fails to mention a character, 
  10796.           that is equivalent to an entry of nil. 
  10797.  
  10798. keymap 
  10799.           The characters used so far in the lookup form a prefix key.  The next 
  10800.           character of the key sequence is looked up in keymap, which may be 
  10801.           full or sparse. 
  10802.  
  10803. command 
  10804.           The characters used so far in the lookup form a complete key, and 
  10805.           command is its definition. 
  10806.  
  10807. string 
  10808.           string represents a keyboard macro.  The characters used so far in 
  10809.           the lookup form a complete key, and string is its definition. (See 
  10810.           Keyboard Macros, for more information.) 
  10811.  
  10812. list 
  10813.           The meaning of a list depends on the types of the elements of the 
  10814.           list. 
  10815.  
  10816.    o If the car of list is the symbol keymap, then the list is a sparse keymap, 
  10817.      and is treated as a keymap (see above). 
  10818.  
  10819.    o If the car of list is lambda, then the list is a lambda expression.  This 
  10820.      is presumed to be a command, and is treated as such (see above). 
  10821.  
  10822.    o If the car of list is a keymap and the cdr is a character, then this entry 
  10823.      is an indirection to a slot in the other keymap.  When an indirect entry 
  10824.      is found in key lookup, it is immediately replaced by the entry in the 
  10825.      specified keymap for the specified character.  This permits you to define 
  10826.      one key as an alias for another key.  For example, an entry whose car is 
  10827.      the keymap called esc-map and whose cdr is 32 (the code for space) means, 
  10828.      ``Use the global definition of Meta-SPC, whatever that may be.'' 
  10829.  
  10830. symbol 
  10831.           The function definition of symbol is used in place of symbol.  If 
  10832.           that too is a symbol, then this process is repeated, any number of 
  10833.           times.  Ultimately this should lead to a definition which is a 
  10834.           keymap, a command or a string.  A list is allowed if it is a keymap 
  10835.           or a command, but indirect entries are not understood when found via 
  10836.           symbols. 
  10837.  
  10838.           Note that keymaps and strings are not valid functions, so a symbol 
  10839.           with a keymap or string as its function definition is likewise not 
  10840.           valid as a function.  It is, however, valid as a key binding.  If the 
  10841.           definition is a string, then the symbol is also valid as an argument 
  10842.           to command-execute (see Interactive Call). 
  10843.  
  10844.           The symbol undefined is worth special mention: it means to treat the 
  10845.           key as undefined.  Strictly speaking, the key is defined, and its 
  10846.           definition is the symbol undefined, but that command does the same 
  10847.           thing that is done automatically for an undefined key: it rings the 
  10848.           bell (by calling ding) but does not signal an error. 
  10849.  
  10850.           undefined is used in local keymaps to override a global key binding 
  10851.           and make the key undefined locally.  A local binding of nil would 
  10852.           fail to do this because it would not override the global binding. 
  10853.  
  10854. anything else 
  10855.           If any other type of object is found, the characters used so far in 
  10856.           the lookup form a complete key, and the object is its definition. 
  10857.  
  10858.  In short, a keymap entry may be a keymap, a command, a string, a symbol which 
  10859. leads to one of them, or an indirection or nil. Here is an example of a sparse 
  10860. keymap with two characters bound to commands and one bound to another keymap. 
  10861. This map is the normal value of emacs-lisp-mode-map.  Note that 9 is the code 
  10862. for TAB, 127 for DEL, 27 for ESC, 17 for C-q and 24 for C-x. 
  10863.  
  10864. (keymap (9 . lisp-indent-line)
  10865.         (127 . backward-delete-char-untabify)
  10866.         (27 keymap (17 . indent-sexp) (24 . eval-defun)))
  10867.  
  10868.  
  10869. ΓòÉΓòÉΓòÉ 22.4. Functions for Key Lookup ΓòÉΓòÉΓòÉ
  10870.  
  10871.  Here are the functions and variables pertaining to key lookup. 
  10872.  
  10873. -- Function: lookup-key keymap key 
  10874.  This function returns the definition of key in keymap.  If the string key is 
  10875. not a valid key sequence according to the prefix keys specified in keymap 
  10876. (which means it is ``too long'' and has extra characters at the end), then the 
  10877. value is a number, the number of characters at the front of key that compose a 
  10878. complete key. 
  10879.  
  10880.  All the other functions described in this chapter that look up keys use 
  10881. lookup-key. 
  10882.  
  10883. (lookup-key (current-global-map) "\C-x\C-f")
  10884.     => find-file
  10885. (lookup-key (current-global-map) "\C-x\C-f12345")
  10886.     => 2
  10887.  
  10888.  If key contains a meta-character, that character is implicitly replaced by a 
  10889. two-character sequence: the value of meta-prefix-char, followed by the 
  10890. corresponding non-meta character.  Thus, the first example below is handled by 
  10891. conversion into the second example. 
  10892.  
  10893. (lookup-key (current-global-map) "\M-f")
  10894.     => forward-word
  10895. (lookup-key (current-global-map) "\ef")
  10896.     => forward-word
  10897.  
  10898.  This function does not perform automatic downcasing like that of 
  10899. read-key-sequence (see Keyboard Input). 
  10900.  
  10901. -- Command: undefined 
  10902. Used in keymaps to undefine keys.  It calls ding, but does not cause an error. 
  10903.  
  10904. -- Variable: meta-prefix-char 
  10905.  This variable is the meta-prefix character code.  It is used when translating 
  10906. a meta-character to a two-character sequence so it can be looked up in a 
  10907. keymap.  For useful results, the value should be a prefix character (see Prefix 
  10908. Keys).  The default value is 27, which is the ASCII code for ESC. 
  10909.  
  10910.  As long as the value of meta-prefix-char remains 27, key lookup translates M-b 
  10911. into ESC b, which is normally defined as the backward-word command.  However, 
  10912. if you set meta-prefix-char to 24, the code for C-x, then Emacs will translate 
  10913. M-b into C-x b, and call the switch-to-buffer command. 
  10914.  
  10915. meta-prefix-char                    ; The default value.
  10916.      => 27
  10917. (key-binding "\M-b")
  10918.      => backward-word
  10919. ?\C-x                               ; The print representation
  10920.      => 24                          ; of a character.
  10921. (setq meta-prefix-char 24)
  10922.      => 24
  10923. (key-binding "\M-b")
  10924.      => switch-to-buffer            ; Now, typing M-b is
  10925.                                     ; like typing C-x b.
  10926.  
  10927. (setq meta-prefix-char 27)          ; Avoid confusion!
  10928.      => 27                          ; Restore the default value!
  10929.  
  10930.  
  10931. ΓòÉΓòÉΓòÉ 22.5. Prefix Keys ΓòÉΓòÉΓòÉ
  10932.  
  10933.  A prefix key has an associated keymap which defines what to do with key 
  10934. sequences that start with the prefix key.  For example, ctl-x-map is the keymap 
  10935. used for characters following the prefix key C-x.  Here is a list of the 
  10936. standard prefix keys of Emacs and their keymaps: 
  10937.  
  10938. o ctl-x-map is the variable name for the map used for characters that follow 
  10939.   C-x.  This map is also the function definition of Control-X-prefix. 
  10940.  
  10941. o ctl-x-4-map used is for characters that follow C-x 4. 
  10942.  
  10943. o esc-map is used for characters that follow ESC.  Thus, the global definitions 
  10944.   of all Meta characters are actually found here.  This map is also the 
  10945.   function definition of ESC-prefix. 
  10946.  
  10947. o help-map is used for characters that follow C-h. 
  10948.  
  10949. o mode-specific-map is for characters that follow C-c.  This map is not 
  10950.   actually mode specific; its name was chosen to be informative for the user in 
  10951.   C-h b (display-bindings), where it describes the main use of the C-c prefix 
  10952.   key. 
  10953.  
  10954.  The binding of a prefix key is the keymap to use for looking up the characters 
  10955. that follow the prefix key.  (It may instead be a symbol whose function 
  10956. definition is a keymap.  The effect is the same, but the symbol serves as a 
  10957. name for the prefix key.)  Thus, the binding of C-x is the symbol 
  10958. Control-X-prefix, whose function definition is the keymap for C-x commands. 
  10959. This keymap is also the value of ctl-x-map. 
  10960.  
  10961.  Prefix key definitions of this sort can appear in either the global map or a 
  10962. local map.  The definitions of C-c, C-x, C-h and ESC as prefix keys appear in 
  10963. the global map, so these prefix keys are always available.  Major modes can 
  10964. locally redefine a key as a prefix by putting a prefix key definition for it in 
  10965. the local map. 
  10966.  
  10967.  If a key is defined as a prefix in both the local map and the global, the two 
  10968. definitions are effectively merged: the commands defined in the local map's 
  10969. prefix definition take priority; those not defined there are taken from the 
  10970. global map. 
  10971.  
  10972.  In the following example, C-p is made a prefix key in the local keymap (so 
  10973. that C-p is identical to C-x).  Then the binding for C-p C-f is the function 
  10974. find-file, just like C-x C-f.  The key sequence C-p 6 is not found in either 
  10975. the local map or global map. 
  10976.  
  10977. (use-local-map (make-sparse-keymap))
  10978.     => nil
  10979. (local-set-key "\C-p" ctl-x-map)
  10980.     => nil
  10981. (key-binding "\C-p\C-f")
  10982.     => find-file
  10983.  
  10984. (key-binding "\C-p6")
  10985.     => nil
  10986.  
  10987. -- Function: define-prefix-command symbol 
  10988.  This function defines symbol as a prefix command: it creates a full keymap and 
  10989. stores it as symbol's function definition. Storing the symbol as the binding of 
  10990. a key makes the key a prefix key which has a name.  This function returns 
  10991. symbol. 
  10992.  
  10993.  It is convenient to store the keymap as the value of a variable as well.  In 
  10994. version 19, this function stores the keymap in both the function definition and 
  10995. value of symbol.  However, in version 18, only the function definition of 
  10996. symbol is set, not the value. 
  10997.  
  10998.  
  10999. ΓòÉΓòÉΓòÉ 22.6. Global and Local Keymaps ΓòÉΓòÉΓòÉ
  11000.  
  11001.  The global keymap holds the bindings of keys that are defined regardless of 
  11002. the current buffer, such as C-f.  The variable global-map holds this keymap. 
  11003.  
  11004.  Each buffer may have another keymap, its local keymap, which may contain new 
  11005. or overriding definitions for keys.  Each buffer records which local keymap is 
  11006. used with it. 
  11007.  
  11008.  Both the global and local keymaps are used to determine what command to 
  11009. execute when a key is entered.  The key lookup proceeds as described earlier 
  11010. (see Key Lookup), but Emacs first searches for the key in the local map; if 
  11011. Emacs does not find a local definition, Emacs then searches the global map. 
  11012.  
  11013.  Since every buffer that uses the same major mode normally uses the very same 
  11014. local keymap, it may appear as if the keymap is local to the mode.  A change to 
  11015. the local keymap of a buffer (using local-set-key, for example) will be seen 
  11016. also in the other buffers that share that keymap. 
  11017.  
  11018.  The local keymaps that are used for Lisp mode, C mode, and several other major 
  11019. modes exist even if they have not yet been used.  These local maps are the 
  11020. values of the variables lisp-mode-map, c-mode-map, and so on.  For most other 
  11021. modes, which are less frequently used, the local keymap is constructed only 
  11022. when the mode is used for the first time in a session. 
  11023.  
  11024.  The minibuffer has local keymaps, too; they contain various completion and 
  11025. exit commands.  See Minibuffers. 
  11026.  
  11027.  See Standard Keymaps, for a list of standard keymaps. 
  11028.  
  11029. -- Variable: global-map 
  11030.  This variable contains the default global keymap that maps Emacs keyboard 
  11031. input to commands.  Normally this keymap is the global keymap. The default 
  11032. global keymap is a full keymap that binds self-insert-command to all of the 
  11033. printing characters. 
  11034.  
  11035. -- Function: current-global-map 
  11036.  This function returns the current global keymap.  Normally, this is the same 
  11037. as the value of the global-map. 
  11038.  
  11039. (current-global-map)
  11040. => [set-mark-command beginning-of-line ... delete-backward-char]
  11041.  
  11042. -- Function: current-local-map 
  11043.  This function returns the current buffer's local keymap, or nil if it has 
  11044. none.  In the following example, the keymap for the `*scratch*' buffer (using 
  11045. Lisp Interaction mode) is a sparse keymap in which the entry for ESC, ASCII 
  11046. code 27, is another sparse keymap. 
  11047.  
  11048. (current-local-map)
  11049. => (keymap
  11050.     (10 . eval-print-last-sexp)
  11051.     (9 . lisp-indent-line)
  11052.     (127 . backward-delete-char-untabify)
  11053.     (27 keymap
  11054.         (24 . eval-defun)
  11055.         (17 . indent-sexp)))
  11056.  
  11057. -- Function: use-global-map keymap 
  11058.  This function makes keymap the new current global keymap. The keymap map must 
  11059. be a full keymap (a vector of length 128).  It returns nil. 
  11060.  
  11061.  It is very unusual to change the global keymap. 
  11062.  
  11063. -- Function: use-local-map keymap 
  11064.  This function makes keymap the new current local keymap of the current buffer. 
  11065. If keymap is nil, then there will be no local keymap.  It returns nil.  Most 
  11066. major modes use this function. 
  11067.  
  11068. -- Function: key-binding key 
  11069.  This function returns the definition for key in the current keymaps trying the 
  11070. current buffer's local map and then the global map. The result is nil if key is 
  11071. undefined in the keymaps. 
  11072.  
  11073. An error is signaled if key is not a string. 
  11074.  
  11075. (key-binding "\C-x\C-f")
  11076.     => find-file
  11077.  
  11078. -- Function: local-key-binding key 
  11079.  This function returns the definition for key in the current local keymap, or 
  11080. nil if it is undefined there. 
  11081.  
  11082. -- Function: global-key-binding key 
  11083.  This function returns the definition for command key in the current global 
  11084. keymap, or nil if it is undefined there. 
  11085.  
  11086.  
  11087. ΓòÉΓòÉΓòÉ 22.7. Changing Key Bindings ΓòÉΓòÉΓòÉ
  11088.  
  11089.  The way to rebind a key is to change its entry in a keymap.  You can change 
  11090. the global keymap, so that the change is effective in all buffers (except those 
  11091. that override the global definition with a local one).  Or you can change the 
  11092. current buffer's local map, which usually affects all buffers using the same 
  11093. major mode.  The global-set-key and local-set-key functions are convenient 
  11094. interfaces for these operations.  Or you can change bindings in any map by 
  11095. specifying it explicitly in define-key. 
  11096.  
  11097.  People often use global-set-key in their `.emacs' file for simple 
  11098. customization.  For example, 
  11099.  
  11100. (global-set-key "\C-x\C-\\" 'next-line)
  11101.  
  11102. redefines C-x C-\ to move down a line. 
  11103.  
  11104.  In writing the string for the key sequence to rebind, it is useful to use the 
  11105. special escape sequences for control and meta characters (see String Type).  In 
  11106. a string, the syntax `\C-' means that the following character is a control 
  11107. character and `\M-' means that the following character is a META character. 
  11108. Thus, the string "\M-x" is read as containing a single M-x, "\C-f" is read as 
  11109. containing a single C-f, and "\M-\C-x" and "\C-\M-x" are both read as 
  11110. containing a single C-M-x. 
  11111.  
  11112.  For the functions below, an error is signaled if keymap is not a keymap or if 
  11113. key is not a string representing a key sequence. 
  11114.  
  11115. -- Function: define-key keymap key definition 
  11116.  This function sets the binding for key in keymap.  (If key is more than one 
  11117. character long, the change is actually made in another keymap reached from 
  11118. keymap.)  The argument definition can be any Lisp object, but only certain 
  11119. types are meaningful.  (For a list of meaningful types, see Key Lookup.) The 
  11120. value returned by define-key is definition. 
  11121.  
  11122.  Every prefix of key must be a prefix key (i.e., bound to a keymap) or 
  11123. undefined; otherwise an error is signaled (with data (error "Key sequence key 
  11124. uses invalid prefix characters")). If some prefix of key is undefined, then 
  11125. define-key defines it as a prefix key so that the rest of key may be defined as 
  11126. specified. 
  11127.  
  11128.  In the following example, a sparse keymap is created and a number of bindings 
  11129. are added to it. 
  11130.  
  11131. (setq map (make-sparse-keymap))
  11132.     => (keymap)
  11133. (define-key map "\C-f" 'forward-char)
  11134.     => forward-char
  11135. map
  11136.     => (keymap (6 . forward-char))
  11137.  
  11138. ;; Build sparse submap for C-x and bind f in that.
  11139. (define-key map "\C-xf" 'forward-word)
  11140.     => forward-word
  11141. map
  11142. => (keymap
  11143.     (24 keymap                ; C-x
  11144.         (102 . forward-word)) ;      f
  11145.     (6 . forward-char))       ; C-f
  11146.  
  11147. ;; Bind C-p to the ctl-x-map.
  11148. (define-key map "\C-p" ctl-x-map)
  11149. => [nil ...  find-file ... backward-kill-sentence] ; ctl-x-map
  11150.  
  11151. ;; Bind C-f to foo in the ctl-x-map.
  11152. (define-key map "\C-p\C-f" 'foo)
  11153. => 'foo
  11154. map
  11155. => (keymap     ; Note foo in ctl-x-map.
  11156.     (16 . [nil ...  foo ... backward-kill-sentence])
  11157.     (24 keymap
  11158.         (102 . forward-word))
  11159.     (6 . forward-char))
  11160.  
  11161. Note that storing a new binding for C-p C-f actually works by changing an entry 
  11162. in ctl-x-map, and this has the effect of changing the bindings of both C-p C-f 
  11163. and C-x C-f in the default global map. 
  11164.  
  11165. -- Function: substitute-key-definition olddef newdef keymap 
  11166.  This function replaces olddef with newdef for any keys in keymap that were 
  11167. bound to olddef.  In other words, olddef is replaced with newdef wherever it 
  11168. appears.  It returns nil. 
  11169.  
  11170.  Prefix keymaps that appear within keymap are not checked recursively for keys 
  11171. bound to olddef; they are not changed at all. Perhaps it would be better to 
  11172. check nested keymaps recursively. 
  11173.  
  11174. (setq map '(keymap
  11175.             (?1 . olddef-1)
  11176.             (?2 . olddef-2)
  11177.             (?3 . olddef-1)))
  11178. => (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1))
  11179.  
  11180. (substitute-key-definition 'olddef-1 'newdef map)
  11181. => nil
  11182. map
  11183. => (keymap (49 . newdef) (50 . olddef-2) (51 . newdef))
  11184.  
  11185. ;; The following will redefine C-x C-f, if you do it in an
  11186. ;; Emacs with standard bindings.
  11187.  
  11188. (substitute-key-definition
  11189.  'find-file 'find-file-read-only (current-global-map))
  11190.  
  11191. -- Function: suppress-keymap keymap &optional nodigits 
  11192.  This function changes the contents of the full keymap keymap by replacing the 
  11193. self-insertion commands for numbers with the digit-argument function, unless 
  11194. nodigits is non-nil, and by replacing the functions for the rest of the 
  11195. printing characters with undefined.  This means that ordinary insertion of text 
  11196. is impossible in a buffer with a local keymap on which suppress-keymap has been 
  11197. called. 
  11198.  
  11199.  suppress-keymap returns nil. 
  11200.  
  11201. The suppress-keymap function does not make it impossible to modify a buffer, as 
  11202. it does not suppress commands such as yank and quote-insert.  To prevent any 
  11203. modification of a buffer, make it read-only (see Read Only Buffers). 
  11204.  
  11205.  Since this function modifies keymap, you would normally use it on a newly 
  11206. created keymap.  Operating on an existing keymap that is used for some other 
  11207. purpose is likely to cause trouble; for example, suppressing global-map would 
  11208. make it impossible to use most of Emacs. 
  11209.  
  11210.  Most often, suppress-keymap is used for initializing local keymaps of modes 
  11211. such as Rmail and Dired where insertion of text is not desirable and the buffer 
  11212. is read-only.  Here is an example taken from the file `emacs/lisp/dired.el', 
  11213. showing how the local keymap for Dired mode is set up: 
  11214.  
  11215.   ...
  11216.   (setq dired-mode-map (make-keymap))
  11217.   (suppress-keymap dired-mode-map)
  11218.   (define-key dired-mode-map "r" 'dired-rename-file)
  11219.   (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
  11220.   (define-key dired-mode-map "d" 'dired-flag-file-deleted)
  11221.   (define-key dired-mode-map "v" 'dired-view-file)
  11222.   (define-key dired-mode-map "e" 'dired-find-file)
  11223.   (define-key dired-mode-map "f" 'dired-find-file)
  11224.   ...
  11225.  
  11226.  
  11227. ΓòÉΓòÉΓòÉ 22.8. Commands for Binding Keys ΓòÉΓòÉΓòÉ
  11228.  
  11229.  This section describes some convenient interactive interfaces for changing key 
  11230. bindings.  They work by calling define-key. 
  11231.  
  11232. -- Command: global-set-key key definition 
  11233.  This function sets the binding of key in the current global map to definition. 
  11234.  
  11235. (global-set-key key definition)
  11236. ==
  11237. (define-key (current-global-map) key definition)
  11238.  
  11239. -- Command: global-unset-key key 
  11240.  This function removes the binding of key from the current global map. 
  11241.  
  11242. One use of this function is in preparation for defining a longer key which uses 
  11243. it implicitly as a prefix---which would not be allowed otherwise.  For example: 
  11244.  
  11245. (global-unset-key "\C-l")
  11246.     => nil
  11247. (global-set-key "\C-l\C-l" 'redraw-display)
  11248.     => nil
  11249.  
  11250. This function is implemented simply using define-key: 
  11251.  
  11252. (global-unset-key key)
  11253. ==
  11254. (define-key (current-global-map) key nil)
  11255.  
  11256. -- Command: local-set-key key definition 
  11257.  This function sets the binding of key in the current local keymap to 
  11258. definition. 
  11259.  
  11260. (local-set-key key definition)
  11261. ==
  11262. (define-key (current-local-map) key definition)
  11263.  
  11264. -- Command: local-unset-key key 
  11265.  This function removes the binding of key from the current local map. 
  11266.  
  11267. (local-unset-key key)
  11268. ==
  11269. (define-key (current-local-map) key nil)
  11270.  
  11271.  
  11272. ΓòÉΓòÉΓòÉ 22.9. Scanning Keymaps ΓòÉΓòÉΓòÉ
  11273.  
  11274.  This section describes functions used to scan all the current keymaps for the 
  11275. sake of printing help information. 
  11276.  
  11277. -- Function: accessible-keymaps keymap 
  11278.  This function returns a list of all the keymaps that can be accessed (via 
  11279. prefix keys) from keymap.  The list returned is an association list with 
  11280. elements of the form (key . map), where key is a prefix whose definition in 
  11281. keymap is map. 
  11282.  
  11283.  The elements of the alist are ordered so that the key increases in length. 
  11284. The first element is always ("" . keymap), because the specified keymap is 
  11285. accessible from itself with a prefix of no characters. 
  11286.  
  11287.  In the example below, the returned alist indicates that the key ESC, which is 
  11288. displayed as "^[", is a prefix key whose definition is the sparse keymap 
  11289. (keymap (83 . center-paragraph) (115 . foo)). 
  11290.  
  11291. (accessible-keymaps (current-local-map))
  11292. =>(("" keymap
  11293.       (27 keymap   ; Note this keymap for ESC is repeated below.
  11294.           (83 . center-paragraph)
  11295.           (115 . center-line))
  11296.       (9 . tab-to-tab-stop))
  11297.  
  11298.    ("^[" keymap
  11299.     (83 . center-paragraph)
  11300.     (115 . foo)))
  11301.  
  11302.  In the following example, C-h is a prefix key that uses a sparse keymap 
  11303. starting (118 . describe-variable) ....  Another prefix, C-x 4, uses the full 
  11304. keymap beginning [nil ...] (which happens to be ctl-x-4-map). 
  11305.  
  11306. (accessible-keymaps (current-global-map))
  11307. => (("" . [set-mark-command beginning-of-line ...
  11308.               delete-backward-char])
  11309.     ("^C" keymap (13 . x-flush-mouse-queue))
  11310.     ("^H" keymap (118 . describe-variable) ... (8 . help-for-help))
  11311.     ("^X" . [x-flush-mouse-queue  ... backward-kill-sentence])
  11312.     ("^[" . [mark-sexp backward-sexp ... backward-kill-word])
  11313.     ("^X4" . [nil ... find-file-other-window nil ... nil nil]))
  11314.  
  11315. -- Function: where-is-internal command &optional keymap firstonly 
  11316.  This function returns a list of key sequences (of any length) that are bound 
  11317. to command in keymap and the global keymap.  The argument command can be any 
  11318. object; it is compared with all keymap entries using eq.  If keymap is not 
  11319. supplied, then the global map alone is used. 
  11320.  
  11321.  If firstonly is non-nil, then the value is a single string representing the 
  11322. first key sequence found, rather than a list of all possible key sequences. 
  11323.  
  11324.  This function is used by where-is ( see Help). 
  11325.  
  11326. (where-is-internal 'describe-function)
  11327.     => ("\^hf" "\^hd")
  11328.  
  11329. -- Command: describe-bindings 
  11330.  This function creates a listing of all defined keys, and their definitions. 
  11331. The listing is put in a buffer named `*Help*', which is then displayed in a 
  11332. window. 
  11333.  
  11334.  A meta character is shown as ESC followed by the corresponding non-meta 
  11335. character.  Control characters are indicated with C-. 
  11336.  
  11337.  When several consecutive characters have the same definition, they are shown 
  11338. together, as `firstchar..lastchar'.  In this instance, you need to know the 
  11339. ASCII codes to understand which characters this means.  For example, in the 
  11340. default global map, the characters `SPC .. ~' are described by a single line. 
  11341. SPC is ASCII 32, ~ is ASCII 126, and the characters between them include all 
  11342. the normal printing characters, (e.g., letters, digits, punctuation, etc.); all 
  11343. these characters are bound to self-insert-command. 
  11344.  
  11345.  
  11346. ΓòÉΓòÉΓòÉ 23. Major and Minor Modes ΓòÉΓòÉΓòÉ
  11347.  
  11348.  A mode is a set of definitions that customize Emacs and can be turned on and 
  11349. off while you edit.  There are two varieties of modes: major modes, which are 
  11350. mutually exclusive and used for editing particular kinds of text, and minor 
  11351. modes, which provide features that may be enabled individually. 
  11352.  
  11353.  This chapter covers both major and minor modes, the way they are indicated in 
  11354. the mode line, and how they run hooks supplied by the user. Related topics such 
  11355. as keymaps and syntax tables are covered in separate chapters.  (See Keymaps, 
  11356. and Syntax Tables.) 
  11357.  
  11358.  
  11359. ΓòÉΓòÉΓòÉ 23.1. Major Modes ΓòÉΓòÉΓòÉ
  11360.  
  11361.  Major modes specialize Emacs for editing particular kinds of text. Each buffer 
  11362. has only one major mode at a time. 
  11363.  
  11364.  The least specialized major mode is called Fundamental mode. This mode has no 
  11365. mode-specific definitions or variable settings, so each Emacs command behaves 
  11366. in its default manner, and each option is in its default state.  All other 
  11367. major modes redefine various keys and options. For example, Lisp Interaction 
  11368. mode provides special key bindings for LFD (eval-print-last-sexp), TAB 
  11369. (lisp-indent-line), and other keys. 
  11370.  
  11371.  When you need to write several editing commands to help you perform a 
  11372. specialized editing task, creating a new major mode is usually a good idea.  In 
  11373. practice, writing a major mode is easy (in sharp contrast to writing a minor 
  11374. mode, which is often difficult). 
  11375.  
  11376.  If the new mode is similar to an old one, it is often unwise to modify the old 
  11377. one to serve two purposes, since it may become harder to use and maintain. 
  11378. Instead, copy and rename an existing major mode definition and alter it for its 
  11379. new function.  For example, Rmail Edit mode, which is in 
  11380. `emacs/lisp/rmailedit.el', is a major mode that is very similar to Text mode 
  11381. except that it provides three additional commands. Its definition is distinct 
  11382. from that of Text mode, but was derived from it. 
  11383.  
  11384.  Rmail Edit mode is an example of a case where one piece of text is put 
  11385. temporarily into a different major mode so it can be edited in a different way 
  11386. (with ordinary Emacs commands rather than Rmail).  In such cases, the temporary 
  11387. major mode usually has a command to switch back to the buffer's usual mode 
  11388. (Rmail mode, in this case).  You might be tempted to present the temporary 
  11389. redefinitions inside a recursive edit and restore the usual ones when the user 
  11390. exits; but this is a bad idea because it constrains the user's options when it 
  11391. is done in more than one buffer: recursive edits must be exited 
  11392. most-recently-entered first. Using alternative major modes avoids this 
  11393. limitation. See Recursive Editing. 
  11394.  
  11395.  The standard GNU Emacs Lisp library directory contains the code for several 
  11396. major modes, in files including `text-mode.el', `texinfo.el', `lisp-mode.el', 
  11397. `c-mode.el', and `rmail.el'.  You can look at these libraries to see how modes 
  11398. are written.  Text mode is perhaps the simplest major mode aside from 
  11399. Fundamental mode.  Rmail mode is a rather complicated, full-featured mode. 
  11400.  
  11401.  
  11402. ΓòÉΓòÉΓòÉ 23.1.1. Major Mode Conventions ΓòÉΓòÉΓòÉ
  11403.  
  11404.  The code for existing major modes follows various coding conventions, 
  11405. including conventions for local keymap and syntax table initialization, global 
  11406. names, and hooks.  Please keep these conventions in mind when you create a new 
  11407. major mode: 
  11408.  
  11409. o Define a command whose name ends in `-mode', with no arguments, that switches 
  11410.   to the new mode in the current buffer.  This command should set up the 
  11411.   keymap, syntax table, and local variables in an existing buffer without 
  11412.   changing the buffer's text. 
  11413.  
  11414. o Write a documentation string for this command which describes the special 
  11415.   commands available in this mode.  C-h m (describe-mode) will print this. 
  11416.  
  11417.   The documentation string may include the special documentation substrings, 
  11418.   `\[command]', `\{keymap}', and `\<keymap>', that enable the documentation to 
  11419.   adapt automatically to the user's own key bindings.  The describe-mode 
  11420.   function replaces these special documentation substrings with their current 
  11421.   meanings.  See Accessing Documentation. 
  11422.  
  11423. o The major mode command should set the variable major-mode to the major mode 
  11424.   command symbol.  This is how describe-mode discovers which documentation to 
  11425.   print. 
  11426.  
  11427. o The major mode command should set the variable mode-name to the ``pretty'' 
  11428.   name of the mode, as a string.  This appears in the mode line. 
  11429.  
  11430. o Since all global names are in the same name space, all the global variables, 
  11431.   constants, and functions that are part of the mode should have names that 
  11432.   start with the major mode name (or with an abbreviation of it if the name is 
  11433.   long). 
  11434.  
  11435. o The major mode should usually have its own keymap, which is used as the local 
  11436.   keymap in all buffers in that mode.  The major mode function should call 
  11437.   use-local-map to install this local map. See Global and Local Keymaps, for 
  11438.   more information. 
  11439.  
  11440.   This keymap should be kept in a global variable named modename-mode-map. 
  11441.   This variable is usually set up when the library that defines the mode is 
  11442.   loaded.  Use defvar to set the variable, so that it is not reinitialized if 
  11443.   it already has a value. (Such reinitialization could discard customizations 
  11444.   made by the user.) 
  11445.  
  11446. o The mode may have its own syntax table or may share one with other related 
  11447.   modes.  If it has its own syntax table, it should store this in a variable 
  11448.   named modename-mode-syntax-table.  The reasons for this are the same as for 
  11449.   using a keymap variable. See Syntax Tables. 
  11450.  
  11451. o The mode may have its own abbrev table or may share one with other related 
  11452.   modes.  If it has its own abbrev table, it should store this in a variable 
  11453.   named modename-mode-abbrev-table. See Abbrev Tables. 
  11454.  
  11455. o To give a variable a buffer-local binding, use make-local-variable in the 
  11456.   major mode command, not make-variable-buffer-local.  The latter function 
  11457.   would make the variable local to every buffer in which it is subsequently 
  11458.   set, which would affect buffers that do not use this mode.  It is undesirable 
  11459.   for a mode to have such global effects.  See Buffer-Local Variables. 
  11460.  
  11461. o If hooks are appropriate for the mode, the major mode command should run the 
  11462.   hooks after completing all other initialization so the user may further 
  11463.   customize any of the settings.  See Hooks. 
  11464.  
  11465. o If this mode is appropriate only for specially-prepared text, then the major 
  11466.   mode command symbol should have a property named mode-class with value 
  11467.   special, put on as follows: 
  11468.  
  11469.     (put 'funny-mode 'mode-class 'special)
  11470.  
  11471.   This tells Emacs that new buffers created while the current buffer has Funny 
  11472.   mode should not inherit Funny mode.  Modes such as Dired, Rmail, and Buffer 
  11473.   List use this feature. 
  11474.  
  11475. o If it is desirable that Emacs use the new mode by default after visiting 
  11476.   files with certain recognizable names, add an element to auto-mode-alist to 
  11477.   select the mode for those file names.  If you define the mode command to 
  11478.   autoload, you should add this element at the same time.  Otherwise, it is 
  11479.   sufficient to add the element in the file that contains the mode definition. 
  11480.   See Auto Major Mode. 
  11481.  
  11482. o In the documentation, you should provide a sample autoload form and a sample 
  11483.   auto-mode-alist addition that users can include in their `.emacs' files. 
  11484.  
  11485. o The top level forms in the file defining the mode should be written so that 
  11486.   they may be evaluated more than once without adverse consequences. Even if 
  11487.   you never load the file more than once, someone else will. 
  11488.  
  11489.  
  11490. ΓòÉΓòÉΓòÉ 23.1.2. Major Mode Examples ΓòÉΓòÉΓòÉ
  11491.  
  11492.  Text mode is perhaps the simplest mode besides Fundamental mode. Here are 
  11493. excerpts from  `text-mode.el' that illustrate many of the conventions listed 
  11494. above: 
  11495.  
  11496. ;; Create mode-specific tables.
  11497. (defvar text-mode-syntax-table nil
  11498.   "Syntax table used while in text mode.")
  11499.  
  11500. (if text-mode-syntax-table
  11501.     ()              ; Do not change the table if it is already set up.
  11502.   (setq text-mode-syntax-table (make-syntax-table))
  11503.   (set-syntax-table text-mode-syntax-table)
  11504.   (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  11505.   (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  11506.   (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  11507.  
  11508. (defvar text-mode-abbrev-table nil
  11509.   "Abbrev table used while in text mode.")
  11510. (define-abbrev-table 'text-mode-abbrev-table ())
  11511.  
  11512. (defvar text-mode-map nil "")   ; Create a mode-specific keymap.
  11513.  
  11514. (if text-mode-map
  11515.     ()              ; Do not change the keymap if it is already set up.
  11516.   (setq text-mode-map (make-sparse-keymap))
  11517.   (define-key text-mode-map "\t" 'tab-to-tab-stop)
  11518.   (define-key text-mode-map "\es" 'center-line)
  11519.   (define-key text-mode-map "\eS" 'center-paragraph))
  11520.  
  11521.  Here is the complete major mode function definition for Text mode: 
  11522.  
  11523. (defun text-mode ()
  11524.   "Major mode for editing text intended for humans to read.
  11525.  Special commands: \\{text-mode-map}
  11526. Turning on text-mode calls the value of the variable text-mode-hook,
  11527. if that value is non-nil."
  11528.   (interactive)
  11529.   (kill-all-local-variables)
  11530.   (use-local-map text-mode-map)     ; This provides the local keymap.
  11531.   (setq mode-name "Text")           ; This name goes into the mode line.
  11532.   (setq major-mode 'text-mode)      ; This is how describe-mode
  11533.                                     ;     finds the doc string to print.
  11534.   (setq local-abbrev-table text-mode-abbrev-table)
  11535.   (set-syntax-table text-mode-syntax-table)
  11536.   (run-hooks 'text-mode-hook))      ; Finally, this permits the user to
  11537.                                     ;     customize the mode with a hook.
  11538.  
  11539.  The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp Interaction mode) 
  11540. have more features than Text mode and the code is correspondingly more 
  11541. complicated.  Here are excerpts from `lisp-mode.el' that illustrate how these 
  11542. modes are written. 
  11543.  
  11544. ;; Create mode-specific table variables.
  11545. (defvar lisp-mode-syntax-table nil "")
  11546. (defvar emacs-lisp-mode-syntax-table nil "")
  11547. (defvar lisp-mode-abbrev-table nil "")
  11548.  
  11549. (if (not emacs-lisp-mode-syntax-table) ; Do not change the table
  11550.                                        ; if it is already set.
  11551.     (let ((i 0))
  11552.       (setq emacs-lisp-mode-syntax-table (make-syntax-table))
  11553.  
  11554.       ;; Set syntax of chars up to 0 to class of chars that are
  11555.       ;; part of symbol names but not words.
  11556.       ;; (The number 0 is 48 in the ascii character set.)
  11557.       (while (< i ?0)
  11558.         (modify-syntax-entry i "_   " emacs-lisp-mode-syntax-table)
  11559.         (setq i (1+ i)))
  11560.       ...
  11561.       ;; Set the syntax for other characters.
  11562.       (modify-syntax-entry ?  "    " emacs-lisp-mode-syntax-table)
  11563.       (modify-syntax-entry ?\t "    " emacs-lisp-mode-syntax-table)
  11564.       ...
  11565.       (modify-syntax-entry ?\( "()  " emacs-lisp-mode-syntax-table)
  11566.       (modify-syntax-entry ?\) ")(  " emacs-lisp-mode-syntax-table)
  11567.       ...))
  11568. ;; Create an abbrev table for lisp-mode.
  11569. (define-abbrev-table 'lisp-mode-abbrev-table ())
  11570.  
  11571.  Much code is shared among the three Lisp modes; the code is all in one 
  11572. library.  The following function sets various variables; it is called by each 
  11573. of the major Lisp mode functions: 
  11574.  
  11575. (defun lisp-mode-variables (lisp-syntax)
  11576.   ;; The lisp-syntax argument is nil in Emacs Lisp mode,
  11577.   ;; and t in the other two Lisp modes.
  11578.   (cond (lisp-syntax
  11579.          (if (not lisp-mode-syntax-table)
  11580.              ;; The Emacs Lisp mode syntax table always exists, but
  11581.              ;; the Lisp Mode syntax table is created the first time a
  11582.              ;; mode that needs it is called.  This is to save space.
  11583.              (progn (setq lisp-mode-syntax-table
  11584.                        (copy-syntax-table emacs-lisp-mode-syntax-table))
  11585.                     ;; Change some entries for Lisp mode.
  11586.                     (modify-syntax-entry ?\| "\"   "
  11587.                                          lisp-mode-syntax-table)
  11588.                     (modify-syntax-entry ?\[ "_   "
  11589.                                          lisp-mode-syntax-table)
  11590.                     (modify-syntax-entry ?\] "_   "
  11591.                                          lisp-mode-syntax-table)))
  11592.           (set-syntax-table lisp-mode-syntax-table)))
  11593.   (setq local-abbrev-table lisp-mode-abbrev-table)
  11594.   ...)
  11595.  
  11596.  Functions such as forward-word use the value of the paragraph-start variable. 
  11597. Since Lisp code is different from ordinary text, the paragraph-start variable 
  11598. needs to be set specially to handle Lisp.  Also, comments are indented in a 
  11599. special fashion in Lisp and the Lisp modes need their own mode-specific 
  11600. comment-indent-hook.  The code to set these variables is the rest of 
  11601. lisp-mode-variables. 
  11602.  
  11603.   (make-local-variable 'paragraph-start)
  11604.   (setq paragraph-start (concat "^$\\|" page-delimiter))
  11605.   ...
  11606.   (make-local-variable 'comment-indent-hook)
  11607.   (setq comment-indent-hook 'lisp-comment-indent))
  11608.  
  11609.  Each of the different Lisp modes has a slightly different keymap.  For 
  11610. example, Lisp mode binds C-c C-l to run-lisp, but the other Lisp modes do not. 
  11611. However, all Lisp modes have some commands in common.  The following function 
  11612. adds these common commands to a given keymap. 
  11613.  
  11614. (defun lisp-mode-commands (map)
  11615.   (define-key map "\e\C-q" 'indent-sexp)
  11616.   (define-key map "\177" 'backward-delete-char-untabify)
  11617.   (define-key map "\t" 'lisp-indent-line))
  11618.  
  11619.  Here is an example of using lisp-mode-commands to initialize a keymap, as part 
  11620. of the code for Emacs Lisp mode.  First defvar is used to declare a 
  11621. mode-specific keymap variable.  Then boundp tests whether the 
  11622. emacs-lisp-mode-map variable has a value (is not void).  If the variable does 
  11623. have a value, we do not change it. This lets the user customize the keymap if 
  11624. he or she so wishes. Otherwise, we initialize it to a new sparse keymap and 
  11625. install the default key bindings. 
  11626.  
  11627. (defvar emacs-lisp-mode-map () "")
  11628.  
  11629. (if emacs-lisp-mode-map
  11630.     ()
  11631.   (setq emacs-lisp-mode-map (make-sparse-keymap))
  11632.   (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
  11633.   (lisp-mode-commands emacs-lisp-mode-map))
  11634.  
  11635.  Finally, here is the complete major mode function definition for Emacs Lisp 
  11636. mode. 
  11637.  
  11638. (defun emacs-lisp-mode ()
  11639.   "Major mode for editing Lisp code to run in Emacs.
  11640. Commands:
  11641. Delete converts tabs to spaces as it moves back.
  11642. Blank lines separate paragraphs.  Semicolons start comments.
  11643. \\{emacs-lisp-mode-map}
  11644. Entry to this mode calls the value of emacs-lisp-mode-hook
  11645. if that value is non-nil."
  11646.   (interactive)
  11647.   (kill-all-local-variables)
  11648.   (use-local-map emacs-lisp-mode-map)    ; This provides the local keymap.
  11649.   (set-syntax-table emacs-lisp-mode-syntax-table)
  11650.   (setq major-mode 'emacs-lisp-mode)     ; This is how describe-mode
  11651.                                          ;   finds out what to describe.
  11652.   (setq mode-name "Emacs-Lisp")          ; This goes into the mode line.
  11653.   (lisp-mode-variables nil)              ; This define various variables.
  11654.   (run-hooks 'emacs-lisp-mode-hook))     ; This permits the user to use a
  11655.                                          ;   hook to customize the mode.
  11656.  
  11657.  
  11658. ΓòÉΓòÉΓòÉ 23.1.3. How Emacs Chooses a Major Mode Automatically ΓòÉΓòÉΓòÉ
  11659.  
  11660.  Based on information in the file name or in the file itself, Emacs 
  11661. automatically selects a major mode for the new buffer when a file is visited. 
  11662.  
  11663. -- Command: fundamental-mode 
  11664.  Fundamental mode is a major mode that is not specialized for anything in 
  11665. particular.  Other major modes are defined in effect by comparison with this 
  11666. one---their definitions say what to change, starting from Fundamental mode. 
  11667. The fundamental-mode function does not run any hooks, so it is not readily 
  11668. customizable. 
  11669.  
  11670. -- Command: normal-mode &optional find-file 
  11671.  This function establishes the proper major mode and local variable bindings 
  11672. for the current buffer.  First it calls set-auto-mode, then it runs 
  11673. hack-local-variables to parse, and bind or evaluate as appropriate, any local 
  11674. variables. 
  11675.  
  11676.  If the find-file argument to normal-mode is non-nil, normal-mode assumes that 
  11677. the find-file function is calling it.  In this case, if inhibit-local-variables 
  11678. is non-nil, it asks for confirmation before processing a local variables list. 
  11679. If you run normal-mode yourself, the argument find-file is normally nil, so 
  11680. confirmation is not requested. 
  11681.  
  11682.  normal-mode uses condition-case around the call to the major mode function, so 
  11683. errors are caught and reported as a `File mode specification error',  followed 
  11684. by the original error message. 
  11685.  
  11686. -- Function: set-auto-mode 
  11687.  This function selects the major mode that is appropriate for the current 
  11688. buffer.  It may base its decision on the value of the `-*-' line, on the 
  11689. visited file name (using auto-mode-alist), or on the value of a local 
  11690. variable).  However, this function does not look for the `mode:' local variable 
  11691. near the end of a file; the hack-local-variables function does that. See How 
  11692. Major Modes are Chosen. 
  11693.  
  11694. -- User Option: default-major-mode 
  11695.  This variable holds the default major mode for new buffers.  The standard 
  11696. value is fundamental-mode. 
  11697.  
  11698.  If the value of default-major-mode is nil, Emacs uses the (previously) current 
  11699. buffer's major mode for major mode of a new buffer.  However, if the major mode 
  11700. symbol has a mode-class property with value special, then it is not used for 
  11701. new buffers; Fundamental mode is used instead.  The modes that have this 
  11702. property are those such as Dired and Rmail that are useful only with text that 
  11703. has been specially prepared. 
  11704.  
  11705. -- Variable: initial-major-mode 
  11706.  The value of this variable determines the major mode of the initial 
  11707. `*scratch*' buffer.  The value should be a symbol that is a major mode command 
  11708. name.  The default value is lisp-interaction-mode. 
  11709.  
  11710. -- Variable: auto-mode-alist 
  11711.  This variable contains an association list of file name patterns (regular 
  11712. expressions; see Regular Expressions) and corresponding major mode functions. 
  11713. Usually, the file name patterns test for suffixes, such as `.el' and `.c', but 
  11714. this need not be the case.  Each element of the alist looks like (regexp . 
  11715. mode-function). 
  11716.  
  11717. For example, 
  11718.  
  11719. (("^/tmp/fol/" . text-mode)
  11720.  ("\\.texinfo$" . texinfo-mode)
  11721.  ("\\.texi$" . texinfo-mode)
  11722.  ("\\.el$" . emacs-lisp-mode)
  11723.  ("\\.c$" . c-mode)
  11724.  ("\\.h$" . c-mode)
  11725.  ...)
  11726.  
  11727.  When you visit a file whose full path name matches a regexp, set-auto-mode 
  11728. calls the corresponding mode-function.  This feature enables Emacs to select 
  11729. the proper major mode for most files. 
  11730.  
  11731.  Here is an example of how to prepend several pattern pairs to an existing 
  11732. auto-mode-alist.  (You might use this sort of expression in your `.emacs' 
  11733. file.) 
  11734.  
  11735. (setq auto-mode-alist
  11736.   (append
  11737.    '(("/\\.[^/]*$" . fundamental-mode)  ; Filename starts with a dot.
  11738.      ("[^\\./]*$" . fundamental-mode)   ; Filename has no dot.
  11739.      ("\\.C$" . c++-mode))
  11740.    auto-mode-alist))
  11741.  
  11742. -- Function: hack-local-variables &optional force 
  11743.  This function parses, and binds or evaluates as appropriate, any local 
  11744. variables for the current buffer. 
  11745.  
  11746.  If the variable inhibit-local-variables is non-nil, and force is nil, then the 
  11747. user is asked for confirmation if the buffer does contain local variable 
  11748. specifications.  A non-nil value of force is passed by normal-mode when it is 
  11749. called explicitly by the user. 
  11750.  
  11751. See Local Variables in Files, for the syntax of the local variables section of 
  11752. a file. 
  11753.  
  11754. -- User Option: inhibit-local-variables 
  11755.  When this variable is non-nil, hack-local-variables asks the user for 
  11756. confirmation before obeying a file's local-variables list. 
  11757.  
  11758.  
  11759. ΓòÉΓòÉΓòÉ 23.1.4. Getting Help about a Major Mode ΓòÉΓòÉΓòÉ
  11760.  
  11761.  The describe-mode function is used to provide information about major modes. 
  11762. It is normally called with C-h m.  The describe-mode function uses the value of 
  11763. major-mode, which is why every major mode function needs to set the major-mode 
  11764. variable. 
  11765.  
  11766. -- Command: describe-mode 
  11767.  This function displays the documentation of the current major mode. 
  11768.  
  11769.  The describe-mode function calls the documentation function using the value of 
  11770. major-mode as an argument.  Thus, it displays the documentation string of the 
  11771. major mode function. (See Accessing Documentation.) 
  11772.  
  11773. -- Variable: major-mode 
  11774.  This variable holds the symbol for the current buffer's major mode.  This 
  11775. symbol should be the name of the function that is called to initialize the 
  11776. mode.  The describe-mode function uses the documentation string of this symbol 
  11777. as the documentation of the major mode. 
  11778.  
  11779.  
  11780. ΓòÉΓòÉΓòÉ 23.2. Minor Modes ΓòÉΓòÉΓòÉ
  11781.  
  11782.  A minor mode provides features that users may enable or disable independently 
  11783. of the choice of major mode.  Minor modes can be enabled individually or in 
  11784. combination.  Minor modes would be better named ``Generally available, optional 
  11785. feature modes'' except that such a name is unwieldy. 
  11786.  
  11787.  A minor mode is not usually a modification of single major mode.  For example, 
  11788. auto-fill-mode and auto-justify-mode may be used in any major mode that permits 
  11789. text insertion.  To be general, a minor mode must be effectively independent of 
  11790. the things major modes do. 
  11791.  
  11792.  A minor mode is often much more difficult to implement than a major mode.  One 
  11793. reason is that you should be able to deactivate a minor mode and restore the 
  11794. environment of the major mode to the state it was in before the minor mode was 
  11795. activated. 
  11796.  
  11797.  Often the biggest problem in implementing a minor mode is finding a way to 
  11798. insert the necessary hook into the rest of Emacs.  For example, some minor 
  11799. modes, such as Auto Fill mode, change how text is inserted into a buffer. 
  11800. Without auto-fill-hook, Auto Fill mode would be implementable only at great 
  11801. pain and great cost in editing efficiency. 
  11802.  
  11803.  
  11804. ΓòÉΓòÉΓòÉ 23.2.1. Conventions for Writing Minor Modes ΓòÉΓòÉΓòÉ
  11805.  
  11806.  There are conventions for writing minor modes just as there are for major 
  11807. modes.  Several of the major mode conventions apply to minor modes as well: 
  11808. those regarding the name of the mode initialization function, the names of 
  11809. global symbols, and the use of keymaps and other tables. 
  11810.  
  11811.  In addition, there are several conventions that are specific to minor modes. 
  11812.  
  11813. o The minor mode should be represented by a symbol whose name ends in `-mode'. 
  11814.   This symbol should be both a command to turn the mode on or off and a 
  11815.   variable which records whether the mode is on. 
  11816.  
  11817.   This variable is used in conjunction with the minor-mode-alist to display the 
  11818.   minor mode name in the mode line.  It may also be directly responsible for 
  11819.   controlling the features of the minor mode. 
  11820.  
  11821.   If you want the minor mode to be enabled separately in each buffer, make the 
  11822.   variable buffer-local. 
  11823.  
  11824. o A minor mode command should accept one optional argument.  If the argument is 
  11825.   nil, the function should toggle the mode (turn it on if it is off, and off if 
  11826.   it is on).  Otherwise, the function should turn the mode on if the argument 
  11827.   is a positive integer, a symbol, or a list whose car is a positive integer; 
  11828.   it should turn the mode off otherwise.  (This convention has not been 
  11829.   implemented with full consistency in Emacs version 18.) 
  11830.  
  11831.   Here is an example taken from the definition of overwrite-mode: 
  11832.  
  11833.     (setq overwrite-mode
  11834.           (if (null arg) (not overwrite-mode)
  11835.             (> (prefix-numeric-value arg) 0)))
  11836.  
  11837. o Add an element to minor-mode-alist for each minor mode (see Mode Line 
  11838.   Variables).  This element should be a list of the following form: 
  11839.  
  11840.     (mode-variable string)
  11841.  
  11842.   Here mode-variable is the variable that indicates the enablement of the minor 
  11843.   mode, and string is a short string, starting with a space, to represent the 
  11844.   mode in the mode line.  These strings must be short so that there is room for 
  11845.   several of them at once. 
  11846.  
  11847.   When you add an element to minor-mode-alist, use assq to check for an 
  11848.   existing element, to avoid duplication.  For example: 
  11849.  
  11850.     (or (assq 'leif-mode minor-mode-alist)
  11851.         (setq minor-mode-alist
  11852.               (cons '(leif-mode " Leif") minor-mode-alist)))
  11853.  
  11854. o If the minor mode adds new key bindings to the local keymap, you should be 
  11855.   able to restore the keymap to its original value when you deactivate the 
  11856.   minor mode. 
  11857.  
  11858.  
  11859. ΓòÉΓòÉΓòÉ 23.2.2. Limitations of Minor Modes ΓòÉΓòÉΓòÉ
  11860.  
  11861.  It is very difficult to write a minor mode that responds to arbitrary 
  11862. self-inserting characters.  The principal problem is that self-insert-command, 
  11863. the command to insert the last key typed, is a primitive function written in C. 
  11864. It does not call any hooks, except in special cases. 
  11865.  
  11866.  Unfortunately, you cannot simply substitute your own definition of 
  11867. self-insert-command for the existing one, as you can with most functions.  This 
  11868. is a consequence of the way the editor command loop works: it checks whether a 
  11869. key is bound to self-insert-command and, if so, it calls the primitive 
  11870. self-insert-command function directly.  It does not check to see whether you 
  11871. have written another version of the function to substitute for it.  This is 
  11872. done for speed. (In general, if you substitute a Lisp function for a primitive, 
  11873. the C code within Emacs will continue to call the original primitive, but Lisp 
  11874. code will call your substitute Lisp function.) 
  11875.  
  11876.  Instead of attempting to replace the function definition for 
  11877. self-insert-command, you could rebind certain keys that call 
  11878. self-insert-command.  This can be made to work as long as no two minor modes 
  11879. try to rebind the same key.  In a minor mode that is global (affects all 
  11880. buffers), do the rebinding in the global map.  In a minor mode that is local to 
  11881. individual buffers, you will need to copy the local keymap (since it is usually 
  11882. shared with all the other buffers in the same major mode) and then make the 
  11883. change. 
  11884.  
  11885.  
  11886. ΓòÉΓòÉΓòÉ 23.3. Mode Line Format ΓòÉΓòÉΓòÉ
  11887.  
  11888.  Each Emacs window includes a mode line which displays status information about 
  11889. the buffer displayed in the window.  The mode line contains information about 
  11890. the buffer such as its name, associated file, depth of recursive editing, and 
  11891. the major and minor modes of the buffer. This section describes how the 
  11892. contents of the mode line are controlled. It is in the chapter on modes because 
  11893. much of the information displayed in the mode line relates to the enabled major 
  11894. and minor modes. 
  11895.  
  11896.  mode-line-format is a buffer-local variable that holds a template used to 
  11897. display the mode line of the current buffer.  All windows for the same buffer 
  11898. use the same mode-line-format and the mode lines will appear the same (except 
  11899. perhaps for the percentage of the file scrolled off the top). 
  11900.  
  11901.  The mode line of a window is normally updated whenever a different buffer is 
  11902. shown in the window, or when the buffer's modified-status changes from nil to t 
  11903. or vice-versa.  If you modify any of the variables referenced by 
  11904. mode-line-format, you may want to force an update of the mode line so as to 
  11905. display the new information. You can do this with the following expression: 
  11906.  
  11907. (set-buffer-modified-p (buffer-modified-p))
  11908.  
  11909.  The mode line is usually displayed in inverse video; see 
  11910. mode-line-inverse-video in Screen Attributes. 
  11911.  
  11912.  
  11913. ΓòÉΓòÉΓòÉ 23.3.1. The Data Structure of the Mode Line ΓòÉΓòÉΓòÉ
  11914.  
  11915.  The mode line contents are controlled by a data structure of lists, strings, 
  11916. symbols and numbers kept in the buffer-local variable mode-line-format.  The 
  11917. data structure is called a mode line construct, and it is built in recursive 
  11918. fashion out of simpler mode line constructs. 
  11919.  
  11920. -- Variable: mode-line-format 
  11921. The value of this variable is a mode line construct with overall responsibility 
  11922. for the mode line format.  The value of this variable controls which other 
  11923. variables are used to form the mode line text, and where they appear. 
  11924.  
  11925.  A mode line construct may be as simple as a fixed string of text, but it 
  11926. usually specifies how to use other variables to construct the text. Many of 
  11927. these variables are themselves defined to have mode line constructs as their 
  11928. values. 
  11929.  
  11930.  The default value of mode-line-format incorporates the values of variables 
  11931. such as mode-name and minor-mode-alist. Because of this, very few modes need to 
  11932. alter mode-line-format. For most purposes, it is sufficient to alter the 
  11933. variables referenced by mode-line-format. 
  11934.  
  11935.  A mode line construct may be a list, cons cell, symbol, or string.  If the 
  11936. value is a list, each element may be a list, a cons cell, a symbol, or a 
  11937. string. 
  11938.  
  11939. string 
  11940.           A string as a mode line construct is displayed verbatim in the mode 
  11941.           line except for %-constructs.  Decimal digits after the % specify the 
  11942.           field width for space filling on the right (i.e., the data is left 
  11943.           justified).  See %-Constructs. 
  11944.  
  11945. symbol 
  11946.           A symbol as a mode line construct stands for its value.  The value of 
  11947.           symbol is used in place of symbol unless symbol is t or nil, or is 
  11948.           void, in which case symbol is ignored. 
  11949.  
  11950.           There is one exception: if the value of symbol is a string, it is 
  11951.           processed verbatim in that the %-constructs are not recognized. 
  11952.  
  11953. (string rest...) or (list rest...) 
  11954.           A list whose first element is a string or list, means to concatenate 
  11955.           all the elements.  This is the most common form of mode line 
  11956.           construct. 
  11957.  
  11958. (symbol then else) 
  11959.           A list whose first element is a symbol is a conditional.  Its meaning 
  11960.           depends on the value of symbol.  If the value is non-nil, the second 
  11961.           element of the list (then) is processed recursively as a mode line 
  11962.           element.  But if the value of symbol is nil, the third element of the 
  11963.           list (if there is one) is processed recursively. 
  11964.  
  11965. (width rest...) 
  11966.           A list whose first element is an integer specifies truncation or 
  11967.           padding of the results of rest.  The remaining elements rest are 
  11968.           processed recursively as mode line constructs and concatenated 
  11969.           together.  Then the result is space filled (if width is positive) or 
  11970.           truncated (to -width columns, if width is negative) on the right. 
  11971.  
  11972.           For example, the usual way to show what percentage of a buffer is 
  11973.           above the top of the window is to use a list like this: (-3 .  "%p"). 
  11974.  
  11975.  If you do alter mode-line-format itself, the new value should use all the same 
  11976. variables that are used by the default value, rather than duplicating their 
  11977. contents or displaying the information in another fashion.  This permits 
  11978. customizations made by the user, by libraries (such as display-time) or by 
  11979. major modes via changes to those variables remain effective. 
  11980.  
  11981.  Here is an example of a mode-line-format that might be useful for shell-mode 
  11982. since it contains the hostname and default directory. 
  11983.  
  11984. (setq mode-line-format
  11985.   (list ""
  11986.    'mode-line-modified
  11987.    "%b--"
  11988.    (getenv "HOST")      ; One element is not constant.
  11989.    ":"
  11990.    'default-directory
  11991.    "   "
  11992.    'global-mode-string
  11993.    "   %[(" 'mode-name
  11994.    'minor-mode-alist
  11995.    "%n"
  11996.    'mode-line-process
  11997.    ")%]----"
  11998.    '(-3 . "%p")
  11999.    "-%-"))
  12000.  
  12001.  
  12002. ΓòÉΓòÉΓòÉ 23.3.2. Variables Used in the Mode Line ΓòÉΓòÉΓòÉ
  12003.  
  12004.  This section describes variables incorporated by the standard value of 
  12005. mode-line-format into the text of the mode line.  There is nothing inherently 
  12006. special about these variables; any other variables could have the same effects 
  12007. on the mode line if mode-line-format were changed to use them. 
  12008.  
  12009. -- Variable: mode-line-modified 
  12010.  This variable holds the mode-line construct for displaying whether the current 
  12011. buffer is modified. 
  12012.  
  12013.  The default value mode-line-modified is ("--%1*%1*-"). This means that the 
  12014. mode line displays `--**-' if the buffer is modified, `-----' if the buffer is 
  12015. not modified, and `--%%-' if the buffer is read only. 
  12016.  
  12017. Changing this variable does not force an update of the mode line. 
  12018.  
  12019. -- Variable: mode-line-buffer-identification 
  12020.  This variable identifies the buffer being displayed in the window. Its default 
  12021. value is `Emacs: %17b', which means that it displays `Emacs:' followed by the 
  12022. buffer name.  You may want to change this in modes such as Rmail that do not 
  12023. behave like a ``normal'' Emacs. 
  12024.  
  12025. -- Variable: global-mode-string 
  12026.  This variable holds a string that is displayed in the mode line for the use of 
  12027. display-time.  The `%M' construct substitutes the value of global-mode-string, 
  12028. but this is obsolete, since the variable is included directly in the mode line. 
  12029.  
  12030. -- Variable: mode-name 
  12031.  This buffer-local variable holds the ``pretty'' name of the current buffer's 
  12032. major mode.  Each major mode should set this variable so that the mode name 
  12033. will appear in the mode line. 
  12034.  
  12035. -- Variable: minor-mode-alist 
  12036.  This variable holds an association list whose elements specify how the mode 
  12037. line should indicate that a minor mode is active.  Each element of the 
  12038. minor-mode-alist should be a two-element list: 
  12039.  
  12040. (minor-mode-variable mode-line-string)
  12041.  
  12042.  The string mode-line-string is included in the mode line when the value of 
  12043. minor-mode-variable is non-nil and not otherwise.  These strings should begin 
  12044. with spaces so that they don't run together.  Conventionally, the 
  12045. minor-mode-variable for a specific mode is set to a non-nil value when that 
  12046. minor mode is activated. 
  12047.  
  12048. The default value of minor-mode-alist is: 
  12049.  
  12050. minor-mode-alist
  12051. => ((abbrev-mode " Abbrev")
  12052.     (overwrite-mode " Ovwrt")
  12053.     (auto-fill-hook " Fill")
  12054.     (defining-kbd-macro " Def"))
  12055.  
  12056. (Note that in version 19, auto-fill-hook will be renamed to 
  12057. auto-fill-function.) 
  12058.  
  12059.  minor-mode-alist is not buffer-local.  The variables mentioned in the alist 
  12060. should be buffer-local if the minor mode can be enabled separately in each 
  12061. buffer. 
  12062.  
  12063. -- Variable: mode-line-process 
  12064. This buffer-local variable contains the mode line information on process status 
  12065. in modes used for communicating with subprocesses.  It is displayed immediately 
  12066. following the major mode name, with no intervening space.  For example, its 
  12067. value in the `*shell*' buffer is (": %s"), which allows the shell to display 
  12068. its status along with the major mode as: `(Shell: run)'.  Normally this 
  12069. variable is nil. 
  12070.  
  12071. -- Variable: default-mode-line-format 
  12072.  This variable holds the default mode-line-format for buffers that do not 
  12073. override it.  This is the same as (default-value 'mode-line-format). 
  12074.  
  12075.  The default value of default-mode-line-format is: 
  12076.  
  12077. (""
  12078.  mode-line-modified
  12079.  mode-line-buffer-identification
  12080.  "   "
  12081.  global-mode-string
  12082.  "   %[("
  12083.  mode-name
  12084.  minor-mode-alist
  12085.  "%n"
  12086.  mode-line-process
  12087.  ")%]----"
  12088.  (-3 . "%p")
  12089.  "-%-")
  12090.  
  12091.  
  12092. ΓòÉΓòÉΓòÉ 23.3.3. %-Constructs in the Mode Line ΓòÉΓòÉΓòÉ
  12093.  
  12094.  The following table lists the recognized %-constructs and what they mean. 
  12095.  
  12096. %b 
  12097.           the current buffer name, using the buffer-name function. 
  12098.  
  12099. %f 
  12100.           the visited file name, using the buffer-file-name function. 
  12101.  
  12102. %* 
  12103.           `%' if the buffer is read only (see buffer-read-only); 
  12104.           `*' if the buffer is modified (see buffer-modified-p); 
  12105.           `-' otherwise. 
  12106.  
  12107. %s 
  12108.           the status of the subprocess belonging to the current buffer, using 
  12109.           process-status. 
  12110.  
  12111. %p 
  12112.           the percent of the buffer above the top of window, or `Top', `Bottom' 
  12113.           or `All'. 
  12114.  
  12115. %n 
  12116.           `Narrow' when narrowing is in effect; nothing otherwise (see 
  12117.           narrow-to-region in Narrowing). 
  12118.  
  12119. %[ 
  12120.           an indication of the depth of recursive editing levels (not counting 
  12121.           minibuffer levels): one `[' for each editing level. 
  12122.  
  12123. %] 
  12124.           one `]' for each recursive editing level (not counting minibuffer 
  12125.           levels). 
  12126.  
  12127. %% 
  12128.           the character `%'---this is how to include a literal `%' in a string 
  12129.           in which %-constructs are allowed. 
  12130.  
  12131. %- 
  12132.           dashes sufficient to fill the remainder of the mode line. 
  12133.  
  12134. The following two %-constructs are still supported but are obsolete since use 
  12135. of the mode-name and global-mode-string variables will produce the same 
  12136. results. 
  12137.  
  12138. %m 
  12139.           the value of mode-name. 
  12140.  
  12141. %M 
  12142.           the value of global-mode-string. Currently, only display-time 
  12143.           modifies global-mode-string. 
  12144.  
  12145.  
  12146. ΓòÉΓòÉΓòÉ 23.4. Hooks ΓòÉΓòÉΓòÉ
  12147.  
  12148.  A hook is a variable whose value is a hook function (or a list of hook 
  12149. functions) to be called by parts of Emacs on certain defined occasions.  The 
  12150. purpose of hooks is to facilitate customization, and the value of a hook is 
  12151. most often set up in the `.emacs' file, but it may be changed by programs.  The 
  12152. function or functions used in a hook may be any of the valid kinds of functions 
  12153. that funcall accepts (see What Is a Function). 
  12154.  
  12155.  Most modes run hooks as the last step of initialization.  This makes it easy 
  12156. for a user to customize the behavior of the mode, by overriding the local 
  12157. variable assignments already made by the mode.  But hooks may also be used in 
  12158. other contexts.  For example, the functions named by find-file-not-found-hooks 
  12159. are called whenever a file is not found by find-file. 
  12160.  
  12161.  For example, you can put the following expression in your `.emacs' file if you 
  12162. want to turn on Auto Fill mode when in Lisp Interaction mode: 
  12163.  
  12164. (setq lisp-interaction-mode-hook 'turn-on-auto-fill)
  12165.  
  12166.  The next example shows how to use a hook to customize the way Emacs formats C 
  12167. code.  (People often have strong personal preferences for one format compared 
  12168. to another.)  Here the hook function is an anonymous lambda expression. 
  12169.  
  12170. (setq c-mode-hook
  12171.       (function (lambda ()
  12172.                   (setq c-indent-level 4
  12173.                         c-argdecl-indent 0
  12174.                         c-label-offset -4
  12175.                         c-continued-statement-indent 0
  12176.                         c-brace-offset 0
  12177.                         comment-column 40))))
  12178.  
  12179. (setq c++-mode-hook c-mode-hook)
  12180.  
  12181.  Finally, here is an example of how to use the Text mode hook to provide a 
  12182. customized mode line for buffers in Text mode, displaying the default directory 
  12183. in addition to the standard components of the mode line.  (This may cause the 
  12184. mode line to run out of space if you have very long path names or display the 
  12185. time and load.) 
  12186.  
  12187. (setq text-mode-hook
  12188.       (function (lambda ()
  12189.                   (setq mode-line-format
  12190.                         '(mode-line-modified
  12191.                           "Emacs: %14b"
  12192.                           "  "
  12193.                           default-directory
  12194.                           " "
  12195.                           global-mode-string
  12196.                           "%[("
  12197.                           mode-name
  12198.                           minor-mode-alist
  12199.                           "%n"
  12200.                           mode-line-process
  12201.                           ") %]---"
  12202.                           (-3 . "%p")
  12203.                           "-%-")))))
  12204.  
  12205.  See Standard Hooks, for a list of standard hook variables. 
  12206.  
  12207.  Most hook variables are initially void.  This has no effect on examples such 
  12208. as the previous ones, where the hook variable is set without reference to any 
  12209. previous value.  However, if you want to add an element to a hook variable 
  12210. which you use as a list of functions, you need to make sure the variable is not 
  12211. void.  Here is how to do it using defvar: 
  12212.  
  12213. (defvar foo-hook nil)
  12214. (or (memq 'my-hook foo-hook)
  12215.     (setq foo-hook (cons 'my-hook foo-hook)))
  12216.  
  12217.  At the appropriate time, Emacs uses the run-hooks function to run the hooks 
  12218. you have specified. 
  12219.  
  12220. -- Function: run-hooks &rest hookvar 
  12221. This function takes one or more hook names as arguments and runs each one in 
  12222. turn.  Each hookvar argument should be a symbol that is a hook variable.  These 
  12223. arguments are processed in the order specified. 
  12224.  
  12225. If a hook variable has a non-nil value, that value may be a function or a list 
  12226. of functions.  If the value is a function (either a lambda expression or a 
  12227. symbol with a function definition), it is called.  If it is a list, the 
  12228. elements are called, in order. The hook functions are called with no arguments. 
  12229.  
  12230. For example: 
  12231.  
  12232. (run-hooks 'emacs-lisp-mode-hook)
  12233.  
  12234. Major mode functions use this function to call any hooks defined by the user. 
  12235.  
  12236.  
  12237. ΓòÉΓòÉΓòÉ 24. Documentation ΓòÉΓòÉΓòÉ
  12238.  
  12239.  GNU Emacs Lisp has convenient on-line help facilities, most of which derive 
  12240. their information from the documentation strings associated with functions and 
  12241. variables.  This chapter describes how to write good documentation strings for 
  12242. your Lisp programs, as well as how to write programs to access documentation. 
  12243.  
  12244.  Note that the documentation strings for Emacs are not the same thing as the 
  12245. Emacs manual.  Manuals have their own source files, written in the Texinfo 
  12246. language; documentation strings are specified in the definitions of the 
  12247. functions and variables they apply to.  A collection of documentation strings 
  12248. is not sufficient as a manual because a good manual is not organized in that 
  12249. fashion; it is organized in terms of topics of discussion. 
  12250.  
  12251.  
  12252. ΓòÉΓòÉΓòÉ 24.1. Documentation Basics ΓòÉΓòÉΓòÉ
  12253.  
  12254.  A documentation string is written using the Lisp syntax for strings, with 
  12255. double-quote characters surrounding the text of the string.  This is because it 
  12256. really is a Lisp string object.  The string serves as documentation when it is 
  12257. written in the proper place in the definition of a function or variable.  In a 
  12258. function definition, the documentation string follows the argument list.  In a 
  12259. variable definition, the documentation string follows the initial value of the 
  12260. variable. 
  12261.  
  12262.  When you write a documentation string, make the first line a complete sentence 
  12263. (or two complete sentences) since some commands, such as apropos, print only 
  12264. the first line of a multi-line documentation string.  Also, you should not 
  12265. indent the second line of a documentation string, if you have one, because that 
  12266. looks odd when you use C-h f (describe-function) or C-h v (describe-variable). 
  12267.  
  12268.  Documentation strings may contain several special substrings, which stand for 
  12269. key bindings to be looked up in the current keymaps when the documentation is 
  12270. displayed.  This allows documentation strings to refer to the keys for related 
  12271. commands and be accurate even when a user rearranges the key bindings.  (See 
  12272. Accessing Documentation.) 
  12273.  
  12274.  Within the Lisp world, a documentation string is kept with the function or 
  12275. variable that it describes: 
  12276.  
  12277. o The documentation for a function is stored in the function definition itself 
  12278.   (see Lambda Expressions).  The function documentation knows how to extract 
  12279.   it. 
  12280.  
  12281. o The documentation for a variable is stored on the variable's property list 
  12282.   under the property name variable-documentation.  The function 
  12283.   documentation-property knows how to extract it. 
  12284.  
  12285.  However, to save space, the documentation for preloaded functions and 
  12286. variables (including primitive functions and autoloaded functions) are stored 
  12287. in the `emacs/etc/DOC-version' file.  Both the documentation and the 
  12288. documentation-property functions know how to access `emacs/etc/DOC-version', 
  12289. and the process is transparent to the user.  In this case, the documentation 
  12290. string is replaced with an integer offset into the `emacs/etc/DOC-version' 
  12291. file.  Keeping the documentation strings out of the Emacs core image saves a 
  12292. significant amount of space. See Building Emacs. 
  12293.  
  12294.  For information on the uses of documentation strings, see where-is-internal 
  12295. and describe-bindings in Global and Local Keymaps.  Also, see Help. 
  12296.  
  12297.  The `emacs/etc' directory contains two utilities for printing the 
  12298. `emacs/etc/DOC-version' file in hardcopy.  These are `sorted-doc.c' and 
  12299. `digest-doc.c'. 
  12300.  
  12301.  
  12302. ΓòÉΓòÉΓòÉ 24.2. Access to Documentation Strings ΓòÉΓòÉΓòÉ
  12303.  
  12304. -- Function: documentation-property symbol property 
  12305.  This function returns the documentation string that is recorded symbol's 
  12306. property list under property property.  This uses the function get, but does 
  12307. more than that: it also retrieves the string from the file 
  12308. `emacs/etc/DOC-version' if necessary, and runs substitute-command-keys to 
  12309. substitute the actual (current) key bindings. 
  12310.  
  12311. (documentation-property 'command-line-processed
  12312.    'variable-documentation)
  12313.      => "t once command line has been processed"
  12314. (symbol-plist 'command-line-processed)
  12315.      => (variable-documentation 188902)
  12316.  
  12317. -- Function: documentation function 
  12318.  This function returns the documentation string of function.  If the 
  12319. documentation string is stored in the `emacs/etc/DOC-version' file, this 
  12320. function will access it there. 
  12321.  
  12322.  In addition, documentation runs substitute-command-keys on the resulting 
  12323. string, so the value contains the actual (current) key bindings. 
  12324.  
  12325.  The function documentation signals a void-function error unless function has a 
  12326. function definition.  However, function does not need to have a documentation 
  12327. string.  If there is no documentation string, documentation returns nil. 
  12328.  
  12329.  Here is an example of using documentation and documentation-property to 
  12330. display the documentation strings for several symbols in a `*Help*' buffer. 
  12331.  
  12332. (defun describe-symbols (pattern)
  12333.   "Describe the Emacs Lisp symbols matching PATTERN.
  12334. All symbols that have PATTERN in their name are described
  12335. in the *Help* buffer."
  12336.   (interactive "sDescribe symbols matching: ")
  12337.   (let ((describe-func
  12338.          (function
  12339.           (lambda (s)
  12340.             ;; Print description of symbol.
  12341.             (if (fboundp s)             ; It is a function.
  12342.                 (princ
  12343.                  (format "%s\t%s\n%s\n\n" s
  12344.                          (if (commandp s)
  12345.                              (concat "Command: "
  12346.                                      (or (mapconcat
  12347.                                           'key-description
  12348.                                           (where-is-internal s)
  12349.                                           " ")))
  12350.                            "Function")
  12351.                          (or (documentation s)
  12352.                              "not documented"))))
  12353.  
  12354.             (if (boundp s)              ; It is a variable.
  12355.                 (princ
  12356.                  (format "%s\t%s\n%s\n\n" s
  12357.                          (if (user-variable-p s)
  12358.                              "Option " "Variable")
  12359.                          (or (documentation-property
  12360.                                s 'variable-documentation)
  12361.                              "not documented")))))))
  12362.          sym-list)
  12363.  
  12364.     ;; Build a list of symbols that match pattern.
  12365.     (mapatoms (function
  12366.                (lambda (sym)
  12367.                  (if (string-match pattern (symbol-name sym))
  12368.                      (setq sym-list (cons sym sym-list))))))
  12369.  
  12370.     ;; Display the data.
  12371.     (with-output-to-temp-buffer "*Help*"
  12372.       (mapcar describe-func (sort sym-list 'string<))
  12373.       (print-help-return-message))))
  12374.  
  12375.  The describe-symbols function works like apropos, but provides more 
  12376. information. 
  12377.  
  12378. (describe-symbols "goal")
  12379.  
  12380. ---------- Buffer: *Help* ----------
  12381. goal-column     Option
  12382. *Semipermanent goal column for vertical motion,
  12383. as set by C-x C-n, or nil.
  12384.  
  12385. set-goal-column Command: C-x C-n
  12386. Set the current horizontal position as a goal for C-n and C-p.
  12387. Those commands will move to this position in the line moved to
  12388. rather than trying to keep the same horizontal position.
  12389. With a non-nil argument, clears out the goal column
  12390. so that C-n and C-p resume vertical motion.
  12391.  
  12392. temporary-goal-column   Variable
  12393. Current goal column for vertical motion.
  12394. It is the column where point was at the start of current run
  12395. of vertical motion commands.
  12396. ---------- Buffer: *Help* ----------
  12397.  
  12398. -- Function: Snarf-documentation filename 
  12399.  This function is used only during Emacs initialization, just before the 
  12400. runnable Emacs is dumped.  It finds the file offsets of the documentation 
  12401. strings stored in the file filename, and records them in the in-core function 
  12402. definitions and variable property lists in place of the actual strings.  See 
  12403. Building Emacs. 
  12404.  
  12405.  The file filename is found in the `emacs/etc' directory (usually filename is 
  12406. "DOC-version").  When the dumped Emacs is later executed, the same file is 
  12407. found in the exec-directory (see Subprocess Creation). 
  12408.  
  12409.  
  12410. ΓòÉΓòÉΓòÉ 24.3. Substituting Key Bindings in Documentation ΓòÉΓòÉΓòÉ
  12411.  
  12412. -- Function: substitute-command-keys string 
  12413.  This function returns string with certain special substrings replaced by the 
  12414. actual (current) key bindings are listed.  This permits the documentation to be 
  12415. displayed with accurate information about key bindings.  (The key bindings may 
  12416. be changed by the user between the time Emacs is built and the time that the 
  12417. documentation is asked for.) 
  12418.  
  12419.  This table lists the forms of the special substrings and what they are 
  12420. replaced with: 
  12421.  
  12422. \[command] 
  12423.           is replaced either by a keystroke sequence that will invoke command, 
  12424.           or by `M-x command' if command is not bound to any key sequence. 
  12425.  
  12426. \{mapvar} 
  12427.           is replaced by a summary (made by describe-bindings) of the value of 
  12428.           mapvar, taken as a keymap. 
  12429.  
  12430. \<mapvar> 
  12431.           makes this call to substitute-command-keys use the value of mapvar as 
  12432.           the keymap for future `\[command]' substrings.  This special string 
  12433.           does not produce any replacement text itself; it only affects the 
  12434.           replacements done later. 
  12435.  
  12436. *Note:* each `\' must be doubled when written in a string in Emacs Lisp. 
  12437.  
  12438.  Here are examples of the special substrings: 
  12439.  
  12440. (substitute-command-keys
  12441.    "To abort recursive edit, type: \\[abort-recursive-edit]")
  12442.  
  12443. => "To abort recursive edit, type: C-]"
  12444.  
  12445. (substitute-command-keys
  12446.    "The keys that are defined for the minibuffer here are:
  12447.   \\{minibuffer-local-must-match-map}")
  12448.  
  12449. => "The keys that are defined for the minibuffer here are:
  12450.  
  12451. ?               minibuffer-completion-help
  12452. SPC             minibuffer-complete-word
  12453. TAB             minibuffer-complete
  12454. LFD             minibuffer-complete-and-exit
  12455. RET             minibuffer-complete-and-exit
  12456. C-g             abort-recursive-edit
  12457. "
  12458.  
  12459. (substitute-command-keys
  12460.    "To abort a recursive edit from the minibuffer, type\
  12461.  \\<minibuffer-local-must-match-map>\\[abort-recursive-edit].")
  12462. => "To abort a recursive edit from the minibuffer, type C-g."
  12463.  
  12464.  
  12465. ΓòÉΓòÉΓòÉ 24.4. Describing Characters for Help Messages ΓòÉΓòÉΓòÉ
  12466.  
  12467.  These functions convert characters or strings to textual descriptions. These 
  12468. descriptions are useful for including arbitrary text characters or key 
  12469. sequences in messages, because they convert non-printing characters to 
  12470. sequences of printing characters.  The description of a printing character is 
  12471. the character itself. 
  12472.  
  12473. -- Function: key-description string 
  12474.  This function returns a string containing the Emacs standard notation for the 
  12475. keyboard characters in string.  See the examples for single-key-description. 
  12476.  
  12477. -- Function: single-key-description character 
  12478.  This function returns a string describing character in the standard Emacs 
  12479. notation for keyboard input.  A normal printing character is represented by 
  12480. itself, but a control character turns into a string starting with `C-', a meta 
  12481. character turns into a string starting with `M-', and space, linefeed, etc. are 
  12482. transformed to `SPC', `LFD', etc. 
  12483.  
  12484. (single-key-description ?\C-x)
  12485.      => "C-x"
  12486. (key-description "\C-x \M-y \n \t \r \f123")
  12487.      => "C-x SPC M-y SPC LFD SPC TAB SPC RET SPC C-l 1 2 3"
  12488.  
  12489. -- Function: text-char-description character 
  12490.  This function returns a string describing character in the standard Emacs 
  12491. notation for characters that appear in text---like single-key-description, 
  12492. except that that control characters are represented with a leading caret (which 
  12493. is how control characters in Emacs buffers are usually displayed). 
  12494.  
  12495. (text-char-description ?\C-c)
  12496.      => "^C"
  12497. (text-char-description ?\M-m)
  12498.      => "M-m"
  12499. (text-char-description ?\C-\M-m)
  12500.      => "M-^M"
  12501.  
  12502.  
  12503. ΓòÉΓòÉΓòÉ 24.5. Help Functions ΓòÉΓòÉΓòÉ
  12504.  
  12505.  Emacs provides a variety of on-line help functions, all accessible to the user 
  12506. as subcommands of the prefix C-h.  For more information about them, see Help. 
  12507. Here we describe some program-level interfaces to the same information. 
  12508.  
  12509. -- Command: apropos regexp &optional predicate noprint 
  12510.  This function finds all symbols whose names contain a match for the regular 
  12511. expression regexp, and returns a list of them.  Normally it displays the 
  12512. symbols in a buffer named `*Help*', each with a one-line description.  If 
  12513. noprint is non-nil, it does not display them, but just returns the list. 
  12514.  
  12515.  If predicate is non-nil, it should be a function to be called on each symbol 
  12516. that has matched regexp.  Only symbols for which predicate returns a non-nil 
  12517. value are listed or displayed. 
  12518.  
  12519.  When you call apropos interactively, it prompts for regexp in the minibuffer. 
  12520.  
  12521.  In the first of the following examples, apropos finds all the symbols with 
  12522. names containing `exec'.  They are returned but not displayed.  In the second 
  12523. example, it finds and returns only those symbols that are also commands; in 
  12524. addition, they are then displayed in the `*Help*' buffer. 
  12525.  
  12526. (apropos "exec" nil t)
  12527.      => (Buffer-menu-execute command-execute exec-directory
  12528.     exec-path execute-extended-command execute-kbd-macro
  12529.     executing-kbd-macro executing-macro)
  12530.  
  12531. (apropos "exec" 'commandp)
  12532.      => (Buffer-menu-execute execute-extended-command)
  12533.  
  12534. ---------- Buffer: *Help* ----------
  12535. Buffer-menu-execute
  12536.   Function: Save and/or delete buffers marked with
  12537.   M-x Buffer-menu-save or M-x Buffer-menu-delete commands.
  12538. execute-extended-command      ESC x
  12539.   Function: Read function name, then read its arguments and call it.
  12540. ---------- Buffer: *Help* ----------
  12541.  
  12542.  The command C-h a (command-apropos) calls apropos, but specifies a predicate 
  12543. to restrict the output to symbols that are commands.  The call to apropos looks 
  12544. like this: 
  12545.  
  12546. (apropos string 'commandp)
  12547.  
  12548. -- Command: help-command 
  12549.  This command is not a function, but rather a symbol which is equivalent to the 
  12550. keymap called help-map.  It is defined in `help.el' as follows: 
  12551.  
  12552. (define-key global-map "\C-h" 'help-command)
  12553. (fset 'help-command help-map)
  12554.  
  12555. -- Variable: help-map 
  12556.  The value of this variable is a local keymap for characters following the Help 
  12557. key, C-h. 
  12558.  
  12559. -- Function: print-help-return-message &optional function 
  12560.  This function builds a string which is a message explaining how to restore the 
  12561. previous state of the windows after a help command.  After building the 
  12562. message, it applies function to it if function is non-nil.  Otherwise it calls 
  12563. message to display it in the echo area. 
  12564.  
  12565. This function expects to be called inside a with-output-to-temp-buffer special 
  12566. form, and expects standard-output to have the value bound by that special form. 
  12567. For an example of its use, see the example in the section describing the 
  12568. documentation function (see Accessing Documentation). 
  12569.  
  12570. The constructed message will have one of the forms shown below. 
  12571.  
  12572. ---------- Echo Area ----------
  12573. Type C-x 1 to remove help window.
  12574. ---------- Echo Area ----------
  12575.  
  12576. ---------- Echo Area ----------
  12577. Type C-x 4 b RET to restore old contents of help window.
  12578. ---------- Echo Area ----------
  12579.  
  12580. -- Variable: help-char 
  12581.  The value of this variable is the character that Emacs recognizes as meaning 
  12582. Help.  When Emacs reads this character (which is usually 8, the value of C-h), 
  12583. Emacs evaluates (eval help-form), and displays the result if it is a string. 
  12584. If help-form's value is nil, this character is read normally. 
  12585.  
  12586. -- Variable: help-form 
  12587.  The value of this variable is a form to execute when the character help-char 
  12588. is read.  If the form returns a string, that string is displayed.  If help-form 
  12589. is nil, then the help character is not recognized. 
  12590.  
  12591.  Entry to the minibuffer binds this variable to the value of 
  12592. minibuffer-help-form. 
  12593.  
  12594.  The following two functions are found in the library `helper'. They are for 
  12595. modes that want to provide help without relinquishing control, such as the 
  12596. ``electric'' modes.  You must load that library with (require 'helper) in order 
  12597. to use them.  Their names begin with `Helper' to distinguish them from the 
  12598. ordinary help functions. 
  12599.  
  12600. -- Command: Helper-describe-bindings 
  12601.  This command pops up a window displaying a help buffer containing a listing of 
  12602. all of the key bindings from both the local and global keymaps. It works by 
  12603. calling describe-bindings. 
  12604.  
  12605. -- Command: Helper-help 
  12606.  This command provides help for the current mode.  It prompts the user in the 
  12607. minibuffer with the message `Help (Type ? for further options)', and then 
  12608. provides assistance in finding out what the key bindings are, and what the mode 
  12609. is intended for.  It returns nil. 
  12610.  
  12611.  This can be customized by changing the map Helper-help-map. 
  12612.  
  12613.  
  12614. ΓòÉΓòÉΓòÉ 25. Files ΓòÉΓòÉΓòÉ
  12615.  
  12616.  In Emacs, you can find, create, view, save, and otherwise work with files and 
  12617. file directories.  This chapter describes most of the file-related functions of 
  12618. Emacs Lisp, but a few others are described in Buffers, and those related to 
  12619. backups and auto-saving are described in Backups and Auto-Saving. 
  12620.  
  12621.  
  12622. ΓòÉΓòÉΓòÉ 25.1. Visiting Files ΓòÉΓòÉΓòÉ
  12623.  
  12624.  Visiting a file means reading a file into a buffer.  Once this is done, we say 
  12625. that the buffer is visiting that file, and call the file ``the visited file'' 
  12626. of the buffer. 
  12627.  
  12628.  A file and a buffer are two different things.  A file is information recorded 
  12629. permanently in the computer (unless you delete it).  A buffer, on the other 
  12630. hand, is information inside of Emacs that will vanish at the end of the editing 
  12631. session (or when you kill the buffer).  Usually, a buffer contains information 
  12632. that you have copied from a file; then we say the buffer is visiting that file. 
  12633. The copy in the buffer is what you modify with editing commands.  Such changes 
  12634. to the buffer do not change the file; therefore, to make the changes permanent, 
  12635. you must save the buffer, which means copying the altered buffer contents back 
  12636. into the file. 
  12637.  
  12638.  In spite of the distinction between files and buffers, people often refer to a 
  12639. file when they mean a buffer and vice-versa.  Indeed, we say, ``I am editing a 
  12640. file,'' rather than, ``I am editing a buffer which I will soon save as a file 
  12641. of the same name.''  Humans do not usually need to make the distinction 
  12642. explicit.  When dealing with a computer program, however, it is good to keep 
  12643. the distinction in mind. 
  12644.  
  12645.  
  12646. ΓòÉΓòÉΓòÉ 25.1.1. Functions for Visiting Files ΓòÉΓòÉΓòÉ
  12647.  
  12648.  This section describes the functions normally used to visit files. For 
  12649. historical reasons, these functions have names starting with `find-' rather 
  12650. than `visit-'.  See Buffer File Name, for functions and variables that access 
  12651. the visited file name of a buffer or that find an existing buffer by its 
  12652. visited file name. 
  12653.  
  12654. -- Command: find-file filename 
  12655.  This function reads the file filename into a buffer and displays that buffer 
  12656. in the selected window so that the user can edit it. 
  12657.  
  12658. The body of the find-file function is very simple and looks like this: 
  12659.  
  12660. (switch-to-buffer (find-file-noselect filename))
  12661.  
  12662. (See switch-to-buffer in Displaying Buffers.) 
  12663.  
  12664.  When find-file is called interactively, it prompts for filename in the 
  12665. minibuffer. 
  12666.  
  12667. -- Function: find-file-noselect filename 
  12668.  This function is the guts of all the file-visiting functions.  It reads a file 
  12669. into a buffer and returns the buffer.  You may then make the buffer current or 
  12670. display it in a window if you wish, but this function does not do so. 
  12671.  
  12672.  If no buffer is currently visiting filename, then one is created and the file 
  12673. is visited.  If filename does not exist, the buffer is left empty, and 
  12674. find-file-noselect displays the message `New file' in the echo area. 
  12675.  
  12676.  If a buffer is already visiting filename, then find-file-noselect uses that 
  12677. buffer rather than creating a new one.  However, it does verify that the file 
  12678. has not changed since it was last visited or saved in that buffer.  If the file 
  12679. has changed, then this function asks the user whether to reread the changed 
  12680. file.  If the user says `yes', any changes previously made in the buffer will 
  12681. be lost. 
  12682.  
  12683.  The find-file-noselect function calls after-find-file after the file is read 
  12684. in (see Subroutines of Visiting).  The after-find-file function sets the buffer 
  12685. major mode, parses local variables, warns the user if there exists an auto-save 
  12686. file more recent than the file just visited, and finishes by running the 
  12687. functions in find-file-hooks. 
  12688.  
  12689.  The find-file-noselect function returns the buffer that is visiting the file 
  12690. filename. 
  12691.  
  12692. (find-file-noselect "/etc/fstab")
  12693.      => #<buffer fstab>
  12694.  
  12695. -- Command: find-alternate-file filename 
  12696.  This function reads the file filename into a buffer and selects it, killing 
  12697. the buffer current at the time the command is run.  It is useful if you have 
  12698. visited the wrong file by mistake, so that you can get rid of the buffer that 
  12699. you did not want to create, at the same time as you visit the file you 
  12700. intended. 
  12701.  
  12702.  When this function is called interactively, it prompts for filename. 
  12703.  
  12704. -- Command: find-file-other-window filename 
  12705.  This function visits the file filename and displays its buffer in a window 
  12706. other than the selected window.  If there are two or more windows on the 
  12707. screen, then the window that is not selected is used.  If there is only one 
  12708. window, it is split.  The function returns nil. 
  12709.  
  12710.  When this function is called interactively, it prompts for filename. 
  12711.  
  12712. -- Command: find-file-read-only filename 
  12713.  This function visits the file named filename and selects its buffer, just like 
  12714. find-file, but it marks the buffer as read-only.  See Read Only Buffers, for 
  12715. related functions and variables. 
  12716.  
  12717.  When this function is called interactively, it prompts for filename. 
  12718.  
  12719. -- Command: view-file filename 
  12720.  This function views filename in View mode, returning to the previous buffer 
  12721. when done.  View mode is a mode that allows you to skim rapidly through the 
  12722. file but does not let you modify it. 
  12723.  
  12724.  After loading the file, view-file calls the value of view-hook if that is 
  12725. non-nil. 
  12726.  
  12727.  When this function is called interactively, it prompts for filename. 
  12728.  
  12729. -- Variable: find-file-hooks 
  12730.  The value of this variable is a list of functions to be called after a file is 
  12731. visited.  The file's local-variables specification (if any) will have been 
  12732. processed before the hooks are run.  The buffer visiting the file is current 
  12733. when the hook functions are run. 
  12734.  
  12735. -- Variable: find-file-not-found-hooks 
  12736.  The value of this variable is a list of functions to be called when find-file 
  12737. or find-file-noselect is passed a nonexistent filename.  These functions are 
  12738. called as soon as the error is detected.  buffer-file-name is already set up. 
  12739. The functions are called in the order given, until one of them returns non-nil. 
  12740.  
  12741.  
  12742. ΓòÉΓòÉΓòÉ 25.1.2. Subroutines of Visiting ΓòÉΓòÉΓòÉ
  12743.  
  12744.  The find-file-noselect function uses the create-file-buffer and 
  12745. after-find-file functions as subroutines.  Sometimes it is useful to call them 
  12746. directly. 
  12747.  
  12748. -- Function: create-file-buffer filename 
  12749. This function creates a suitably named buffer for visiting filename, and 
  12750. returns it.  The string filename (sans directory) is used unchanged if that 
  12751. name is free; otherwise, a string such as `<2>' is appended to get an unused 
  12752. name.  See also Creating Buffers. 
  12753.  
  12754. *Note:* create-file-buffer does not associate the new buffer with a file and 
  12755. does not make it the current buffer. 
  12756.  
  12757. (create-file-buffer "foo")
  12758.      => #<buffer foo>
  12759. (create-file-buffer "foo")
  12760.      => #<buffer foo<2>>
  12761. (create-file-buffer "foo")
  12762.      => #<buffer foo<3>>
  12763.  
  12764.  This function is used by find-file-noselect. 
  12765.  
  12766. -- Function: after-find-file &optional error warn 
  12767.  This function is called by find-file-noselect and by the default revert 
  12768. function (see Reverting).  It sets the buffer major mode, and parses local 
  12769. variables (see Auto Major Mode). 
  12770.  
  12771.   If there was an error in opening the file, the calling function should pass 
  12772. error a non-nil value.  In that case, after-find-file issues a warning: `(New 
  12773. File)'.  Note that, for serious errors, you would not even call 
  12774. after-find-file. Only ``file not found'' errors get here with a non-nil error. 
  12775.  
  12776.  If warn is non-nil, then this function issues a warning if an auto-save file 
  12777. exists and is more recent than the visited file. 
  12778.  
  12779.  The last thing after-find-file does is call all the functions in 
  12780. find-file-hooks. 
  12781.  
  12782.  
  12783. ΓòÉΓòÉΓòÉ 25.2. Saving Buffers ΓòÉΓòÉΓòÉ
  12784.  
  12785.  When you edit a file in Emacs, you are actually working on a buffer that is 
  12786. visiting that file---that is, the contents of the file are copied into the 
  12787. buffer and the copy is what you edit.  Changes to the buffer do not change the 
  12788. file until you save the buffer, which means copying the contents of the buffer 
  12789. into the file. 
  12790.  
  12791. -- Command: save-buffer &optional backup-option 
  12792.  This function saves the contents of the current buffer in its visited file if 
  12793. the buffer has been modified since it was last visited or saved. Otherwise it 
  12794. does nothing. 
  12795.  
  12796.  save-buffer is responsible for making backup files.  Normally, backup-option 
  12797. is nil, and save-buffer makes a backup file only if this is the first save or 
  12798. if the buffer was previously modified.  Other values for backup-option request 
  12799. the making of backup files in other circumstances: 
  12800.  
  12801. o With an argument of 4 or 64, reflecting 1 or 3 C-u's, the save-buffer 
  12802.   function marks this version of the file to be backed up when the buffer is 
  12803.   next saved. 
  12804.  
  12805. o With an argument of 16 or 64, reflecting 2 or 3 C-u's, the save-buffer 
  12806.   function unconditionally backs up the previous version of the file before 
  12807.   saving it. 
  12808.  
  12809. -- Command: save-buffers-kill-emacs &optional kill-silently-p 
  12810.  This function offers to save each buffer that needs to be saved, and then 
  12811. kills the Emacs job.  With a non-nil value of the optional kill-silently-p 
  12812. argument, it unconditionally and silently saves all the file-visiting buffers, 
  12813. and then kills the job. 
  12814.  
  12815. The save-buffers-kill-emacs function is defined as follows: 
  12816.  
  12817. (defun save-buffers-kill-emacs (&optional arg)
  12818.   "Offer to save each buffer, then kill this Emacs fork..."
  12819.   (interactive "P")
  12820.   (save-some-buffers arg t)
  12821.   (kill-emacs))
  12822.  
  12823. -- Command: save-some-buffers &optional save-silently-p exiting 
  12824.  This command saves some modified file-visiting buffers.  Normally it asks the 
  12825. user about each buffer.  If the function is called with a non-nil value of the 
  12826. optional save-silently-p argument, this function saves all the file-visiting 
  12827. buffers without querying the user. 
  12828.  
  12829.  The optional exiting argument, if non-nil, requests this function to offer 
  12830. also to save certain other buffers that are not visiting files.  These are 
  12831. buffers that have a non-nil local value of buffer-offer-save.  (A user who says 
  12832. yes to saving one of these will be asked to specify a file name to use.)  The 
  12833. save-buffers-kill-emacs function passes a non-nil value for this argument. 
  12834.  
  12835. -- Variable: buffer-offer-save 
  12836.  When this variable is non-nil in a buffer, Emacs offers to save the buffer on 
  12837. exit even if the buffer is not visiting a file.  The variable is automatically 
  12838. local in all buffers.  Normally, Mail mode (used for editing outgoing mail) 
  12839. sets this to t. 
  12840.  
  12841. -- Command: write-file filename 
  12842.  This function writes the current buffer into file filename, makes the buffer 
  12843. visit that file, and marks it not modified.  The buffer is renamed to 
  12844. correspond to filename unless that name is already in use. 
  12845.  
  12846. -- Variable: write-file-hooks 
  12847.  The value of this variable is a list of functions to be called before writing 
  12848. out a buffer to its visited file.  If one of them returns non-nil, the file is 
  12849. considered already written and the rest of the functions are not called, nor is 
  12850. the usual code for writing the file executed. 
  12851.  
  12852.  If the file-precious-flag variable is nil, the file is moved to the backup 
  12853. file before any of the hooks are called.  If none of the hooks actually write 
  12854. the file, but one does return non-nil, the file will not exist, although the 
  12855. backup will. 
  12856.  
  12857.  Here is an example showing how to add an element to write-file-hooks but avoid 
  12858. adding it twice: 
  12859.  
  12860. (or (memq 'my-write-file-hook write-file-hooks)
  12861.     (setq write-file-hooks
  12862.           (cons 'my-write-file-hook write-file-hooks)))
  12863.  
  12864. -- Variable: file-precious-flag 
  12865.  If this variable is non-nil, then save-buffer protects against I/O errors 
  12866. while saving by renaming the original file to a temporary name before writing 
  12867. the new contents of the file.  If the new contents are successfully written, 
  12868. the renamed original file is deleted. Otherwise, it is renamed back to the 
  12869. original name.  This procedure prevents problems such as a lack of disk space 
  12870. from resulting in an invalid file. 
  12871.  
  12872. Some modes set this non-nil locally in particular buffers. 
  12873.  
  12874. -- User Option: require-final-newline 
  12875.  This variable determines whether files may be written out that do not end with 
  12876. a newline.  If the value of the variable is t, then Emacs silently puts a 
  12877. newline at the end of the file whenever the buffer being saved does not already 
  12878. end in one.  If the value of the variable is non-nil, but not t, then Emacs 
  12879. asks the user whether to add a newline each time the case arises. 
  12880.  
  12881.  If the value of the variable is nil, then Emacs doesn't add newlines at all. 
  12882. nil is the default value, but a few major modes change it to t. 
  12883.  
  12884.  
  12885. ΓòÉΓòÉΓòÉ 25.3. Reading from Files ΓòÉΓòÉΓòÉ
  12886.  
  12887.  You can copy a file directly from the disk and insert it into a buffer using 
  12888. the insert-file-contents function, or its interactive variant, insert-file. 
  12889.  
  12890. -- Command: insert-file filename 
  12891.  This function inserts the contents of file filename into the current buffer 
  12892. after point, and sets the mark at the end of the inserted text.  An error is 
  12893. signaled if filename is not the name of a file that can be read.  This function 
  12894. is for interactive use and does little more than call insert-file-contents. 
  12895.  
  12896. -- Function: insert-file-contents filename &optional visit 
  12897.  This function inserts the contents of file filename into the current buffer 
  12898. after point. It returns a list of the absolute file name and the length of the 
  12899. data inserted.  An error is signaled if filename is not the name of a file that 
  12900. can be read. 
  12901.  
  12902.  If visit is non-nil, it also marks the buffer as unmodified and sets up 
  12903. various fields in the buffer so that it is visiting the file filename: these 
  12904. include the buffer's visited file name and its last save file modtime.  This 
  12905. feature is used by find-file-noselect and you should probably not use it 
  12906. yourself. 
  12907.  
  12908.  
  12909. ΓòÉΓòÉΓòÉ 25.4. Writing to Files ΓòÉΓòÉΓòÉ
  12910.  
  12911.  You can write the contents of a buffer, or part of a buffer, directly to a 
  12912. file on disk using the append-to-file and write-region functions.  Don't use 
  12913. these functions to write to files that are being visited; that could cause 
  12914. confusion in the mechanisms for visiting. 
  12915.  
  12916. -- Command: append-to-file start end filename 
  12917.  This function appends the contents of the region delimited by start and end in 
  12918. the current buffer to the end of file filename.  If that file does not exist, 
  12919. it is created.  This function returns nil. 
  12920.  
  12921.  An error is signaled if filename specifies a nonwritable file, or a 
  12922. nonexistent file in a directory where files cannot be created. 
  12923.  
  12924. -- Command: write-region start end filename &optional append visit 
  12925. This function writes the region (of the current buffer) delimited by start and 
  12926. end into the file specified by filename. 
  12927.  
  12928. If append is non-nil, then the region is appended to the existing file contents 
  12929. (if any). 
  12930.  
  12931. If visit is t, then Emacs establishes an association between the buffer and the 
  12932. file: the buffer is then visiting that file. It also sets the last file 
  12933. modification time for the current buffer to filename's modtime, and marks the 
  12934. buffer as not modified.  This feature is used by write-file and you should 
  12935. probably not use it yourself. 
  12936.  
  12937. Normally, this function displays a message `Wrote file filename' in the echo 
  12938. area.  If visit is neither t nor nil, then this message is inhibited.  This 
  12939. feature is useful for programs that use files for internal purposes, files 
  12940. which the user does not need to know about. 
  12941.  
  12942.  
  12943. ΓòÉΓòÉΓòÉ 25.5. File Locks ΓòÉΓòÉΓòÉ
  12944.  
  12945.  When two users edit the same file at the same time, they are likely to 
  12946. interfere with each other.  Emacs tries to prevent this situation from arising 
  12947. by recording a file lock when a file is being modified. Emacs can then detect 
  12948. the first attempt to modify a buffer visiting a file that is locked by another 
  12949. Emacs job, and ask the user what to do. 
  12950.  
  12951.  File locks do not work properly when multiple machines can share filesystems, 
  12952. such as with NFS.  Perhaps a better file locking system will be implemented in 
  12953. the future.  When file locks do not work, it is possible for two users to make 
  12954. changes simultaneously, but Emacs will still be able to warn the user who saves 
  12955. second.  Also, the detection of modification of a buffer visiting a file 
  12956. changed on disk catches some cases of simultaneous editing; see Modification 
  12957. Time. 
  12958.  
  12959. -- Function: file-locked-p filename 
  12960.  This function returns nil if the file filename is not locked by this Emacs 
  12961. process.  It returns t if it is locked by this Emacs, and it returns the name 
  12962. of the user who has locked it if it is locked by someone else. 
  12963.  
  12964. (file-locked-p "foo")
  12965.      => nil
  12966.  
  12967. -- Function: lock-buffer &optional filename 
  12968.  This function locks the file filename, if the current buffer is modified.  The 
  12969. argument filename defaults to the current buffer's visited file.  Nothing is 
  12970. done if the current buffer is not visiting a file, or is not modified. 
  12971.  
  12972. -- Function: unlock-buffer 
  12973. This function unlocks the file being visited in the current buffer, if the 
  12974. buffer is modified.  If the buffer is not modified, then the file should not be 
  12975. locked, so this function does nothing.  It also does nothing if the current 
  12976. buffer is not visiting a file. 
  12977.  
  12978. -- Function: ask-user-about-lock file other-user 
  12979. This function is called when the user tries to modify file, but it is locked by 
  12980. another user name other-user.  The value it returns controls what Emacs will do 
  12981. with the file: 
  12982.  
  12983. o A value of t tells Emacs to grab the lock on the file.  Then this user may 
  12984.   edit the file and other-user loses the lock. 
  12985.  
  12986. o A value of nil tells Emacs to ignore the lock and let this user edit the file 
  12987.   anyway. 
  12988.  
  12989. o This function may instead signal a file-locked error, in which case the 
  12990.   change to the buffer which the user was about to make does not take place. 
  12991.  
  12992.   The error message for this error looks like this: 
  12993.  
  12994.     error--> File is locked: file other-user
  12995.  
  12996.   where file is the name of the file and other-user is the name of the user who 
  12997.   has locked the file. 
  12998.  
  12999.  The default definition of this function asks the user to choose what to do. 
  13000. If you wish, you can replace the ask-user-about-lock function with your own 
  13001. version that decides in another way.  The code for its usual definition is in 
  13002. `userlock.el'. 
  13003.  
  13004.  
  13005. ΓòÉΓòÉΓòÉ 25.6. Information about Files ΓòÉΓòÉΓòÉ
  13006.  
  13007.  The functions described in this section are similar in as much as they all 
  13008. operate on strings which are interpreted as file names.  All have names that 
  13009. begin with the word `file'.  These functions all return information about 
  13010. actual files or directories, so their arguments must all exist as actual files 
  13011. or directories unless otherwise noted. 
  13012.  
  13013.  Most of the file-oriented functions take a single argument, filename, which 
  13014. must be a string.  The file name is expanded using expand-file-name, so `~' is 
  13015. handled correctly, as are relative file names (including `../').  Environment 
  13016. variable substitutions, such as `$HOME', are not recognized by these functions. 
  13017.  
  13018.  
  13019. ΓòÉΓòÉΓòÉ 25.6.1. Testing Accessibility ΓòÉΓòÉΓòÉ
  13020.  
  13021.  These functions test for permission to access a file in specific ways. 
  13022.  
  13023. -- Function: file-exists-p filename 
  13024.  This function returns t if a file named filename appears to exist.  This does 
  13025. not mean you can necessarily read the file, only that you can find out its 
  13026. attributes.  (On Unix, this is true if the file exists and you have execute 
  13027. permission on the containing directories, regardless of the protection of the 
  13028. file itself.) 
  13029.  
  13030.  If the file does not exist, or if fascist access control policies prevent you 
  13031. from finding the attributes of the file, this function returns nil. 
  13032.  
  13033. -- Function: file-readable-p filename 
  13034.  This function returns t if a file named filename exists and you can read it. 
  13035. It returns nil otherwise. 
  13036.  
  13037. (file-readable-p "files.texi")
  13038.      => t
  13039. (file-exists-p "/usr/spool/mqueue")
  13040.      => t
  13041. (file-readable-p "/usr/spool/mqueue")
  13042.      => nil
  13043.  
  13044. -- Function: file-writable-p filename 
  13045.  This function returns t if filename can be written or created by you.  It is 
  13046. writable if the file exists and you can write it. It is creatable if the file 
  13047. does not exist, but the specified directory does exist and you can write in 
  13048. that directory.  file-writable-p returns nil otherwise. 
  13049.  
  13050.  In the third example below, `foo' is not writable because the parent directory 
  13051. does not exist, even though the user could create it. 
  13052.  
  13053. (file-writable-p "~rms/foo")
  13054.      => t
  13055. (file-writable-p "/foo")
  13056.      => nil
  13057. (file-writable-p "~rms/no-such-dir/foo")
  13058.      => nil
  13059.  
  13060. -- Function: file-newer-than-file-p filename1 filename2 
  13061.  This functions returns t if the file filename1 is newer than file filename2. 
  13062. If filename1 does not exist, it returns nil.  If filename2 does not exist, it 
  13063. returns t. 
  13064.  
  13065.  In the following example, assume that the file `aug-19' was written on the 
  13066. 19th, and `aug-20' was written on the 20th.  The file `no-file' doesn't exist 
  13067. at all. 
  13068.  
  13069. (file-newer-than-file-p "aug-19" "aug-20")
  13070.      => nil
  13071. (file-newer-than-file-p "aug-20" "aug-19")
  13072.      => t
  13073. (file-newer-than-file-p "aug-19" "no-file")
  13074.      => t
  13075. (file-newer-than-file-p "no-file" "aug-19")
  13076.      => nil
  13077.  
  13078.  
  13079. ΓòÉΓòÉΓòÉ 25.6.2. Distinguishing Kinds of Files ΓòÉΓòÉΓòÉ
  13080.  
  13081.  This section describes how to distinguish directories and symbolic links from 
  13082. ordinary files. 
  13083.  
  13084. -- Function: file-symlink-p filename 
  13085.  If filename is a symbolic link, the file-symlink-p function returns the file 
  13086. name to which it is linked.  This may be the name of a text file, a directory, 
  13087. or even another symbolic link, or of no file at all. 
  13088.  
  13089.  If filename is not a symbolic link (or there is no such file), file-symlink-p 
  13090. returns nil. 
  13091.  
  13092. (file-symlink-p "foo")
  13093.      => nil
  13094. (file-symlink-p "sym-link")
  13095.      => "foo"
  13096. (file-symlink-p "sym-link2")
  13097.      => "sym-link"
  13098. (file-symlink-p "/bin")
  13099.      => "/pub/bin"
  13100.  
  13101. -- Function: file-directory-p filename 
  13102.  This function returns t if filename is the name of an existing directory, nil 
  13103. otherwise. 
  13104.  
  13105. (file-directory-p "~rms")
  13106.      => t
  13107. (file-directory-p "~rms/lewis/files.texi")
  13108.      => nil
  13109. (file-directory-p "~rms/lewis/no-such-file")
  13110.      => nil
  13111. (file-directory-p "$HOME")
  13112.      => nil
  13113. (file-directory-p (substitute-in-file-name "$HOME"))
  13114.      => t
  13115.  
  13116.  
  13117. ΓòÉΓòÉΓòÉ 25.6.3. Other Information about Files ΓòÉΓòÉΓòÉ
  13118.  
  13119.  This section describes the functions for getting detailed information about a 
  13120. file, other than its contents.  This information includes the mode bits that 
  13121. control access permission, the owner and group numbers, the number of names, 
  13122. the inode number, the size, and the times of access and modification. 
  13123.  
  13124. -- Function: file-modes filename 
  13125.  This function returns the mode bits of filename, as an integer. The mode bits 
  13126. are also called the file permissions, and they specify access control in the 
  13127. usual Unix fashion.  If the low-order bit is 1, then the file is executable by 
  13128. all users, if the second lowest-order bit is 1, then the file is writable by 
  13129. all users, etc. 
  13130.  
  13131.  The highest value returnable is 4095 (7777 octal), meaning that everyone has 
  13132. read, write, and execute permission, that the suid bit is set for both others 
  13133. and group, and that the sticky bit is set. 
  13134.  
  13135. (file-modes "~/junk/diffs")
  13136.      => 492               ; decimal integer
  13137. (format "%o" 492)
  13138.      => 754               ; convert to octal
  13139.  
  13140. (set-file-modes "~/junk/diffs" 438)
  13141.      => nil
  13142.  
  13143. (format "%o" 438)
  13144.      => 666               ; convert to octal
  13145.  
  13146. % ls -l diffs
  13147.   -rw-rw-rw-  1 lewis    0    3063 Oct 30 16:00 diffs
  13148.  
  13149. -- Function: file-nlinks filename 
  13150.  This functions returns the number of names (i.e., hard links) that file 
  13151. filename has.  If the file does not exist, then this function returns nil. 
  13152. Note that symbolic links have no effect on this function, because they are not 
  13153. considered to be names of the files they link to. 
  13154.  
  13155. % ls -l foo*
  13156. -rw-rw-rw-  2 rms             4 Aug 19 01:27 foo
  13157. -rw-rw-rw-  2 rms             4 Aug 19 01:27 foo1
  13158.  
  13159. (file-nlinks "foo")
  13160.      => 2
  13161. (file-nlinks "doesnt-exist")
  13162.      => nil
  13163.  
  13164. -- Function: file-attributes filename 
  13165.  This function returns a list of attributes of file filename.  If the specified 
  13166. file cannot be opened, it returns nil. 
  13167.  
  13168.  The elements of the list, in order, are: 
  13169.  
  13170.  1. t for a directory, a string for a symbolic link (the name linked to), or 
  13171.     nil for a text file. 
  13172.  
  13173.  2. The number of names the file has.  Alternate names, also known as hard 
  13174.     links, can be created with add-name-to-file ( see Changing File 
  13175.     Attributes). 
  13176.  
  13177.  3. The file's uid. 
  13178.  
  13179.  4. The file's gid. 
  13180.  
  13181.  5. The time of last access, as a list of two integers. The first integer has 
  13182.     the high-order 16 bits of time, the second has the low 16 bits. 
  13183.  
  13184.  6. The time of last modification as a list of two integers (as above). 
  13185.  
  13186.  7. The time of last status change as a list of two integers (as above). 
  13187.  
  13188.  8. The size of the file in bytes. 
  13189.  
  13190.  9. The file's modes, as a string of ten letters or dashes as in `ls -l'. 
  13191.  
  13192. 10. t if the file's gid would change if file were deleted and recreated; nil 
  13193.     otherwise. 
  13194.  
  13195. 11. The file's inode number. 
  13196.  
  13197. For example, here are the file attributes for `files.texi': 
  13198.  
  13199. (file-attributes "files.texi")
  13200.      =>  (nil
  13201.           1
  13202.           2235
  13203.           75
  13204.           (8489 20284)
  13205.           (8489 20284)
  13206.           (8489 20285)
  13207.           14906
  13208.           "-rw-rw-rw-"
  13209.           nil
  13210.           20920)
  13211.  
  13212. and here is how the result is interpreted: 
  13213.  
  13214. nil 
  13215.           is neither a directory nor a symbolic link. 
  13216.  
  13217.           has only one name (the name `files.texi' in the current default 
  13218.           directory). 
  13219.  
  13220. 2235 
  13221.           is owned by the user with uid 2235. 
  13222.  
  13223. 75 
  13224.           is in the group with gid 75. 
  13225.  
  13226. (8489 20284) 
  13227.           was last accessed on Aug 19 00:09.  Unfortunately, you cannot convert 
  13228.           this number into a time string in Emacs. 
  13229.  
  13230. (8489 20284) 
  13231.           was last accessed on Aug 19 00:09. 
  13232.  
  13233. (8489 20285) 
  13234.           last had its inode changed on Aug 19 00:09. 
  13235.  
  13236. 14906 
  13237.           is 14906 characters long. 
  13238.  
  13239. "-rw-rw-rw-" 
  13240.           has a mode of read and write access for the owner, group, and world. 
  13241.  
  13242. nil 
  13243.           would retain the same gid if it were recreated. 
  13244.  
  13245. 20920 
  13246.           has an inode number of 20920. 
  13247.  
  13248.  
  13249. ΓòÉΓòÉΓòÉ 25.7. Contents of Directories ΓòÉΓòÉΓòÉ
  13250.  
  13251.  A directory is a kind of file that contains other files entered under various 
  13252. names.  Directories are a feature of the file system. 
  13253.  
  13254.  Emacs can list the names of the files in a directory as a Lisp list, or 
  13255. display the names in a buffer using the ls shell command.  In the latter case, 
  13256. it can optionally display information about each file, depending on the value 
  13257. of switches passed to the ls command. 
  13258.  
  13259. -- Function: directory-files directory &optional full-name match-regexp 
  13260. This function returns a list of the names of the files in the directory 
  13261. directory. 
  13262.  
  13263. If full-name is non-nil, the function returns the files' absolute file names. 
  13264. Otherwise, it returns just the names relative to the specified directory. 
  13265.  
  13266. If match-regexp is non-nil, function returns only those file names that contain 
  13267. that regular expression---the other file names are discarded from the list. 
  13268.  
  13269. (directory-files "~lewis")
  13270.      => ("#foo#" "#foo.el#" "." ".."
  13271.          "dired-mods.el" "files.texi" "files.texi.~1~")
  13272.  
  13273.  An error is signaled if directory is not the name of a directory that can be 
  13274. read. 
  13275.  
  13276. -- Function: file-name-all-versions file dirname 
  13277.  This function returns a list of all versions of the file named file in 
  13278. directory dirname. 
  13279.  
  13280. -- Command: list-directory filespec &optional verbose 
  13281.  This command displays a list of files in or matching filespec. It calls the 
  13282. shell command ls, passing it options under the control of verbose. 
  13283.  
  13284.  The argument filespec may be either a directory name or a file name containing 
  13285. optional wildcards.  Wildcards are processed by the shell. 
  13286.  
  13287.  The options passed to ls are the value of list-directory-verbose-switches if 
  13288. verbose is non-nil; list-directory-brief-switches otherwise. Interactively, the 
  13289. raw prefix argument is used for verbose. 
  13290.  
  13291. -- Variable: list-directory-brief-switches 
  13292.  This variable contains switches for list-directory to pass to ls for a short 
  13293. or ``brief'' listing.  The default value is "-CF". 
  13294.  
  13295. -- Variable: list-directory-verbose-switches 
  13296.  This variable contains switches for list-directory to pass to ls for a verbose 
  13297. or ``long'' listing.  The default value is "-l". 
  13298.  
  13299.  
  13300. ΓòÉΓòÉΓòÉ 25.8. Changing File Names and Attributes ΓòÉΓòÉΓòÉ
  13301.  
  13302.  The functions in this section rename, copy, delete, link, and set the modes of 
  13303. files. 
  13304.  
  13305.  In the functions that have an argument newname, if a file by the name of 
  13306. newname already exists, the actions taken depend on the value of the argument 
  13307. ok-if-already-exists: 
  13308.  
  13309. o A file-already-exists error is signaled if ok-if-already-exists is nil. 
  13310.  
  13311. o Confirmation is requested if ok-if-already-exists is a number. 
  13312.  
  13313. o No confirmation is requested if ok-if-already-exists is any other value, in 
  13314.   which case the old file is removed. 
  13315.  
  13316. -- Function: add-name-to-file oldname newname &optional ok-if-already-exists 
  13317.  This function gives the file named oldname the additional name newname.  This 
  13318. means that newname will be a new ``hard link'' to oldname. 
  13319.  
  13320.  In the first part of the following example, we list two files, `foo' and 
  13321. `foo3'. 
  13322.  
  13323. % ls -l fo*
  13324. -rw-rw-rw-  1 rms            29 Aug 18 20:32 foo
  13325. -rw-rw-rw-  1 rms            24 Aug 18 20:31 foo3
  13326.  
  13327. Then we evaluate the form (add-name-to-file "~/lewis/foo" "~/lewis/foo2"). 
  13328. Again we list the files.  This shows two names, `foo' and `foo2'. 
  13329.  
  13330. (add-name-to-file "~/lewis/foo1" "~/lewis/foo2")
  13331.      => nil
  13332.  
  13333. % ls -l fo*
  13334. -rw-rw-rw-  2 rms            29 Aug 18 20:32 foo
  13335. -rw-rw-rw-  2 rms            29 Aug 18 20:32 foo2
  13336. -rw-rw-rw-  1 rms            24 Aug 18 20:31 foo3
  13337.  
  13338.  Finally, we evaluate (add-name-to-file "~/lewis/foo" "~/lewis/foo3" t), and 
  13339. list the files again.  Now there are three names for one file: `foo', `foo2', 
  13340. and `foo3'.  The old contents of `foo3' are lost. 
  13341.  
  13342. (add-name-to-file "~/lewis/foo1" "~/lewis/foo3")
  13343.      => nil
  13344.  
  13345. % ls -l fo*
  13346. -rw-rw-rw-  3 rms            29 Aug 18 20:32 foo
  13347. -rw-rw-rw-  3 rms            29 Aug 18 20:32 foo2
  13348. -rw-rw-rw-  3 rms            29 Aug 18 20:32 foo3
  13349.  
  13350.  This function is meaningless on VMS, where multiple names for one file are not 
  13351. allowed. 
  13352.  
  13353.  See also file-nlinks in Information about Files. 
  13354.  
  13355. -- Command: rename-file filename newname &optional ok-if-already-exists 
  13356. This command renames the file filename as newname. 
  13357.  
  13358. If filename has additional names aside from filename, it continues to have 
  13359. those names.  In fact, adding the name newname with add-name-to-file and then 
  13360. deleting filename has the same effect as renaming, aside from momentary 
  13361. intermediate states. 
  13362.  
  13363.  In an interactive call, this function prompts for filename and newname in the 
  13364. minibuffer; also, it requests confirmation if newname already exists. 
  13365.  
  13366. -- Command: copy-file oldname newname &optional ok-if-exists time 
  13367.  This command copies the file oldname to newname.  An error is signaled if 
  13368. oldname does not exist. 
  13369.  
  13370.  If time is non-nil, then this functions gives the new file the same 
  13371. last-modified time that the old one has.  (This works on only some operating 
  13372. systems.) 
  13373.  
  13374.  In an interactive call, this function prompts for filename and newname in the 
  13375. minibuffer; also, it requests confirmation if newname already exists. 
  13376.  
  13377. -- Command: delete-file filename 
  13378.  This command deletes the file filename, like the shell command `rm filename'. 
  13379. If the file has multiple names, it continues to exist under the other names. 
  13380.  
  13381.  A suitable kind of file-error error is signaled if the file does not exist, or 
  13382. is not deletable.  (In Unix, a file is deletable if its directory is writable.) 
  13383.  
  13384. -- Command: make-symbolic-link filename newname  &optional ok-if-exists 
  13385.  This command makes a symbolic link to filename, named newname.  This is like 
  13386. the shell command `ln -s filename newname'. 
  13387.  
  13388.  In an interactive call, filename and newname are read in the minibuffer, and 
  13389. ok-if-exists is set to the numeric prefix argument. 
  13390.  
  13391. -- Function: set-file-modes filename mode 
  13392.  This function sets mode bits of filename to mode (which must be a integer). 
  13393. Only the 12 low bits of mode are used. 
  13394.  
  13395.  
  13396. ΓòÉΓòÉΓòÉ 25.9. File Names ΓòÉΓòÉΓòÉ
  13397.  
  13398.  Files are generally referred to by their names, in Emacs as elsewhere. File 
  13399. names in Emacs are represented as strings.  The functions that operate on a 
  13400. file all expect a file name argument. 
  13401.  
  13402.  In addition to operating on files themselves, Emacs Lisp programs often need 
  13403. to operate on the names; i.e., to take them apart and to use part of a name to 
  13404. construct related file names.  This section describes how to manipulate file 
  13405. names. 
  13406.  
  13407.  The functions in this section do not actually access files, so they can 
  13408. operate on file names that do not refer to an existing file or directory. 
  13409.  
  13410.  On VMS, all these functions understand both VMS file name syntax and Unix 
  13411. syntax.  This is so that all the standard Lisp libraries can specify file names 
  13412. in Unix syntax and work properly on VMS without change. 
  13413.  
  13414.  
  13415. ΓòÉΓòÉΓòÉ 25.9.1. File Name Components ΓòÉΓòÉΓòÉ
  13416.  
  13417.  The operating system groups files into directories.  To specify a file, you 
  13418. must specify the directory, and the file's name in that directory.  Therefore, 
  13419. a file name in Emacs is considered to have two main parts: the directory name 
  13420. part, and the nondirectory part (or file name within the directory).  Either 
  13421. part may be empty.  Concatenating these two parts reproduces the original file 
  13422. name. 
  13423.  
  13424.  On Unix, the directory part is everything up to and including the last slash; 
  13425. the nondirectory part is the rest.  The rules in VMS syntax are complicated. 
  13426.  
  13427.  For some purposes, the nondirectory part is further subdivided into the name 
  13428. and the version number.  On Unix, only backup files have version numbers in 
  13429. their names; on VMS, every file has a version number, but most of the time the 
  13430. file name actually used in Emacs omits the version number.  Version numbers are 
  13431. found mostly in directory lists. 
  13432.  
  13433. -- Function: file-name-directory filename 
  13434.  This function returns the directory part of filename (or nil if filename does 
  13435. not include a directory part).  On Unix, the function returns a string ending 
  13436. in a slash.  On VMS, it returns a string ending in one of the three characters 
  13437. `:', `]', or `>'. 
  13438.  
  13439. (file-name-directory "lewis/foo")     ; Unix example
  13440.      => "lewis/"
  13441. (file-name-directory "foo")           ; Unix example
  13442.      => nil
  13443. (file-name-directory "[X]FOO.TMP")    ; VMS example
  13444.      => "[X]"
  13445.  
  13446. -- Function: file-name-nondirectory filename 
  13447.  This function returns the nondirectory part of filename. 
  13448.  
  13449. (file-name-nondirectory "lewis/foo")
  13450.      => "foo"
  13451. (file-name-nondirectory "foo")
  13452.      => "foo"
  13453. ;; The following example is accurate only on VMS.
  13454. (file-name-nondirectory "[X]FOO.TMP")
  13455.      => "FOO.TMP"
  13456.  
  13457. -- Function: file-name-sans-versions filename 
  13458.  This function returns filename without any file version numbers, backup 
  13459. version numbers, or trailing tildes. 
  13460.  
  13461. (file-name-sans-versions "~rms/foo.~1~")
  13462.      => "~rms/foo"
  13463. (file-name-sans-versions "~rms/foo~")
  13464.      => "~rms/foo"
  13465. (file-name-sans-versions "~rms/foo")
  13466.      => "~rms/foo"
  13467. ;; The following example applies to VMS only.
  13468. (file-name-sans-versions "foo;23")
  13469.      => "foo"
  13470.  
  13471.  
  13472. ΓòÉΓòÉΓòÉ 25.9.2. Directory Names ΓòÉΓòÉΓòÉ
  13473.  
  13474.  A directory name is the name of a directory.  A directory is a kind of file, 
  13475. and it has a file name, which is related to the directory name but not 
  13476. identical to it.  (This is not quite the same as the usual Unix terminology.) 
  13477. These two different names for the same entity are related by a syntactic 
  13478. transformation.  On Unix, this is simple: a directory name ends in a slash, 
  13479. whereas the directory's name as a file lacks that slash.  On VMS, the 
  13480. relationship is more complicated. 
  13481.  
  13482.  The difference between a directory name and its name as a file is subtle but 
  13483. crucial.  When an Emacs variable or function argument is described as being a 
  13484. directory name, a file name of a directory is not acceptable. 
  13485.  
  13486.  All of these functions take a single argument, filename, which must be a 
  13487. string.  Environment variable substitutions such as `$HOME', and the symbols 
  13488. `~', and `..', are not expanded.  Use expand-file-name or 
  13489. substitute-in-file-name for that (see File Name Expansion). 
  13490.  
  13491. -- Function: file-name-as-directory filename 
  13492.  This function returns a string representing filename in a form that the 
  13493. operating system will interpret as the name of a directory.  In Unix, this 
  13494. means that a slash is appended to the string.  On VMS, the function converts a 
  13495. string of the form `[X]Y.DIR.1' to the form `[X.Y]'. 
  13496.  
  13497. (file-name-as-directory "~rms/lewis")
  13498.      => "~rms/lewis/"
  13499.  
  13500. -- Function: directory-file-name dirname 
  13501.  This function returns a string representing dirname in a form that the 
  13502. operating system will interpret as the name of a file.  On Unix, this means 
  13503. that a final slash is removed from the string.  On VMS, the function converts a 
  13504. string of the form `[X.Y]' to `[X]Y.DIR.1'. 
  13505.  
  13506. (directory-file-name "~lewis/")
  13507.      => "~lewis"
  13508.  
  13509.  
  13510. ΓòÉΓòÉΓòÉ 25.9.3. Absolute and Relative File Names ΓòÉΓòÉΓòÉ
  13511.  
  13512.  All the directories in the file system form a tree starting at the root 
  13513. directory.  A file name can specify all the directory names starting from the 
  13514. root of the tree; then it is called an absolute file name.  Or it can specify 
  13515. the position of the file in the tree relative to a default directory; then it 
  13516. is called an relative file name.  On Unix, an absolute file name starts with a 
  13517. slash or a tilde (`~'), and a relative one does not.  The rules on VMS are 
  13518. complicated. 
  13519.  
  13520. -- Function: file-name-absolute-p filename 
  13521.  This function returns t if file filename is an absolute file name, nil 
  13522. otherwise.  On VMS, this function understands both Unix syntax and VMS syntax. 
  13523.  
  13524. (file-name-absolute-p "~rms/foo")
  13525.      => t
  13526. (file-name-absolute-p "rms/foo")
  13527.      => nil
  13528. (file-name-absolute-p "$HOME")
  13529.      => nil
  13530. (file-name-absolute-p "/user/rms/foo")
  13531.      => t
  13532.  
  13533.  
  13534. ΓòÉΓòÉΓòÉ 25.9.4. Functions that Expand Filenames ΓòÉΓòÉΓòÉ
  13535.  
  13536.  Expansion of a file name means converting a relative file name to an absolute 
  13537. one.  Since this is done relative to a default directory, you must specify the 
  13538. default directory name as well as the file name to be expanded.  Expansion also 
  13539. canonicalizes file names by eliminating redundancies such as `./' and 
  13540. `name/../'. 
  13541.  
  13542. -- Function: expand-file-name filename &optional directory 
  13543.  This function converts filename to an absolute file name.  If directory is 
  13544. supplied, it is the directory to start with if filename is relative. 
  13545. Otherwise, the current buffer's value of default-directory is used.  For 
  13546. example: 
  13547.  
  13548. (expand-file-name "foo")
  13549.      => "/xcssun/users/rms/lewis/foo"
  13550. (expand-file-name "../foo")
  13551.      => "/xcssun/users/rms/foo"
  13552. (expand-file-name "foo" "/usr/spool")
  13553.      => "/usr/spool/foo"
  13554. (expand-file-name "$HOME/foo")
  13555.      => "/xcssun/users/rms/lewis/$HOME/foo"
  13556.  
  13557.  Filenames containing `.' or `..' are simplified to their canonical form: 
  13558.  
  13559. (expand-file-name "bar/../foo")
  13560.      => "/xcssun/users/rms/lewis/foo"
  13561.  
  13562.  `~/' is expanded into the user's home directory.  A `/' or `~' following a `/' 
  13563. is taken to be the start of an absolute file name that overrides what precedes 
  13564. it, so everything before that `/' or `~' is deleted.  For example: 
  13565.  
  13566. (expand-file-name "/a1/gnu//usr/local/lib/emacs/etc/MACHINES")
  13567.      => "/usr/local/lib/emacs/etc/MACHINES"
  13568. (expand-file-name "/a1/gnu/~/foo")
  13569.      => "/xcssun/users/rms/foo"
  13570.  
  13571. In both cases, `/a1/gnu/' has been discarded because an absolute file name 
  13572. follows it. 
  13573.  
  13574.  Note that expand-file-name does not expand environment variables; that is done 
  13575. only by substitute-in-file-name. 
  13576.  
  13577. -- Variable: default-directory 
  13578.  The value of this buffer-local variable is the default directory for the 
  13579. current buffer.  It is local in every buffer. expand-file-name uses the default 
  13580. directory when its second argument is nil. 
  13581.  
  13582.  On Unix systems, the value is always a string ending with a slash. 
  13583.  
  13584. default-directory
  13585.      => "/user/lewis/manual/"
  13586.  
  13587. -- Function: substitute-in-file-name filename 
  13588.  This function replaces environment variables names in filename with the values 
  13589. to which they are set by the operating system. Following standard Unix shell 
  13590. syntax, `$' is the prefix to substitute an environment variable value. 
  13591.  
  13592.  The environment variable name is the series of alphanumeric characters 
  13593. (including underscores) that follow the `$'.  If the character following the 
  13594. `$' is a `{', then the variable name is everything up to the matching `}'. 
  13595.  
  13596. Here we assume that the environment variable HOME, which holds the user's home 
  13597. directory name, has the value `/xcssun/users/rms'. 
  13598.  
  13599. (substitute-in-file-name "$HOME/foo")
  13600.      => "/xcssun/users/rms/foo"
  13601.  
  13602. If a `~' or a `/' appears following a `/', after substitution, everything 
  13603. before the following `/' is discarded: 
  13604.  
  13605. (substitute-in-file-name "bar/~/foo")
  13606.      => "~/foo"
  13607. (substitute-in-file-name "/usr/local/$HOME/foo")
  13608.      => "/xcssun/users/rms/foo"
  13609.  
  13610. On VMS, `$' substitution is not done, so this function does nothing on VMS 
  13611. except discard superfluous initial components as shown above. 
  13612.  
  13613.  
  13614. ΓòÉΓòÉΓòÉ 25.9.5. Generating Unique File Names ΓòÉΓòÉΓòÉ
  13615.  
  13616.  Some programs need to write temporary files.  Here is the usual way to 
  13617. construct a name for such a file: 
  13618.  
  13619. (concat "/tmp/" (make-temp-name name-of-application))
  13620.  
  13621. The directory `/tmp/' is chosen because that is the standard place on Unix for 
  13622. temporary files.  The task of make-temp-name is to prevent two different users 
  13623. or two different jobs from trying to use the same name. 
  13624.  
  13625. -- Function: make-temp-name string 
  13626. This function generates string that can be used as a unique name. The name will 
  13627. start with the prefix string, and finish with a number that is different in 
  13628. each Emacs job. 
  13629.  
  13630. (make-temp-name "foo")
  13631.      => "foo021304"
  13632. (make-temp-name "foo")
  13633.      => "foo021304"
  13634.  
  13635. To prevent conflicts among different application libraries run in the same 
  13636. Emacs, each application should have its own string.  The number added to the 
  13637. end of the name distinguishes between the same application running in different 
  13638. Emacses. 
  13639.  
  13640.  
  13641. ΓòÉΓòÉΓòÉ 25.9.6. File Name Completion ΓòÉΓòÉΓòÉ
  13642.  
  13643.  This section describes low-level subroutines for completing a file name.  For 
  13644. other completion functions, see Completion. 
  13645.  
  13646. -- Function: file-name-all-completions partial-filename directory 
  13647.  This function returns a list of all possible completions for a file whose name 
  13648. starts with partial-filename in directory directory.  The order of the 
  13649. completions is the order of the files in the directory, which is unpredictable 
  13650. and conveys no useful information. 
  13651.  
  13652.  The argument partial-filename must be a file name containing no directory part 
  13653. and no slash.  The current buffer's default directory is prepended to 
  13654. directory, if directory is not an absolute file name. 
  13655.  
  13656.  In the following example, suppose that the current default directory, 
  13657. `~rms/lewis', has five files whose names begin with `f': `foo', `file~', 
  13658. `file.c', `file.c.~1~', and `file.c.~2~'. 
  13659.  
  13660. (file-name-all-completions "f" "")
  13661.      => ("foo" "file~" "file.c.~2~" "file.c.~1~" "file.c")
  13662.  
  13663. (file-name-all-completions "fo" "")
  13664.      => ("foo")
  13665.  
  13666. -- Function: file-name-completion filename directory 
  13667.  This function completes the file name filename in directory directory.  It 
  13668. returns the longest prefix common to all file names in directory directory that 
  13669. start with filename. 
  13670.  
  13671.  If only one match exists and filename matches it exactly, the function returns 
  13672. t.  The function returns nil if directory directory contains no name starting 
  13673. with filename. 
  13674.  
  13675.  In the following example, suppose that the current default directory has five 
  13676. files whose names begin with `f': `foo', `file~', `file.c', `file.c.~1~', and 
  13677. `file.c.~2~'. 
  13678.  
  13679. (file-name-completion "fi" "")
  13680.      => "file"
  13681.  
  13682. (file-name-completion "file.c.~1" "")
  13683.      => "file.c.~1~"
  13684.  
  13685. (file-name-completion "file.c.~1~" "")
  13686.      => t
  13687.  
  13688. (file-name-completion "file.c.~3" "")
  13689.      => nil
  13690.  
  13691. -- User Option: completion-ignored-extensions 
  13692.  file-name-completion usually ignores file names that end in any string in this 
  13693. list.  It does not ignore them when all the possible completions end in one of 
  13694. these suffixes or when a buffer showing all possible completions is displayed. 
  13695.  
  13696.  A typical value might look like this: 
  13697.  
  13698. completion-ignored-extensions
  13699.      => (".o" ".elc" "~" ".dvi")
  13700.  
  13701.  
  13702. ΓòÉΓòÉΓòÉ 26. Backups and Auto-Saving ΓòÉΓòÉΓòÉ
  13703.  
  13704.  Backup files and auto-save files are two methods by which Emacs tries to 
  13705. protect the user from the consequences of crashes or of the user's own errors. 
  13706. Auto-saving preserves the text from earlier in the current editing session; 
  13707. backup files preserve file contents prior to the current session. 
  13708.  
  13709.  
  13710. ΓòÉΓòÉΓòÉ 26.1. Backup Files ΓòÉΓòÉΓòÉ
  13711.  
  13712.  A backup file is a copy of the old contents of a file you are editing.  Emacs 
  13713. makes a backup file the first time you save a buffer into its visited file. 
  13714. Normally, this means that the backup file contains the contents of the file as 
  13715. it was before the current editing session.  The contents of the backup file 
  13716. normally remain unchanged once it exists. 
  13717.  
  13718.  Backups are usually made by renaming the visited file to a new name. 
  13719. Optionally, you can specify that backup files should be made by copying the 
  13720. visited file.  This choice makes a difference for files with multiple names; it 
  13721. also can affect whether the edited file remains owned by the original owner or 
  13722. becomes owned by the user editing it. 
  13723.  
  13724.  By default, Emacs makes a single backup file for each file edited. You can 
  13725. alternatively request numbered backups; then each new backup file gets a new 
  13726. name.  You can delete old numbered backups when you don't want them any more, 
  13727. or Emacs can delete them automatically. 
  13728.  
  13729.  
  13730. ΓòÉΓòÉΓòÉ 26.1.1. Making Backup Files ΓòÉΓòÉΓòÉ
  13731.  
  13732. -- Function: backup-buffer 
  13733.  This function makes a backup of the file visited by the current buffer, if 
  13734. appropriate.  It is called by save-buffer before saving the buffer the first 
  13735. time. 
  13736.  
  13737. -- Variable: buffer-backed-up 
  13738.  This buffer-local variable indicates whether this buffer's file has been 
  13739. backed up on account of this buffer.  If it is non-nil, then the backup file 
  13740. has been written.  Otherwise, the file should be backed up when it is next 
  13741. saved (if backup files are enabled). 
  13742.  
  13743. -- Variable: make-backup-files 
  13744.  This variable determines whether or not backup files will be created. If it is 
  13745. non-nil, then Emacs will create a backup of each file when it is saved for the 
  13746. first time. 
  13747.  
  13748.  The following example shows how to change the make-backup-files variable only 
  13749. in the `RMAIL' buffer and not elsewhere.  Setting it nil stops Emacs from 
  13750. making backups of the `RMAIL' file, which may save disk space.  (You would put 
  13751. this code in your `.emacs' file.) 
  13752.  
  13753. (setq rmail-mode-hook
  13754.       (function (lambda ()
  13755.                   (make-local-variable 'make-backup-files)
  13756.                   (setq make-backup-files nil)))
  13757.  
  13758.  
  13759. ΓòÉΓòÉΓòÉ 26.1.2. Backup by Renaming or by Copying? ΓòÉΓòÉΓòÉ
  13760.  
  13761.  There are two ways that Emacs can make a backup file: 
  13762.  
  13763. o Emacs can rename the original file so that it becomes a backup file, and then 
  13764.   write the buffer being saved into a new file.  In this case, any other names 
  13765.   (i.e., hard links) of the original file will now refer to the backup file. 
  13766.   The new file will be owned by the user doing the editing, and its group will 
  13767.   be the default for the user or the directory. 
  13768.  
  13769. o Emacs can copy the original file into a backup file, and then overwrite the 
  13770.   original file with new contents.  In this case, any other names (i.e., hard 
  13771.   links) of the original file will still refer to the current version of the 
  13772.   file.  The file's owner and group will be unchanged. 
  13773.  
  13774.  The first method, renaming, is the default. 
  13775.  
  13776.  The variable backup-by-copying, if non-nil, says to use the second method, 
  13777. which is to copy the original file and overwrite it with the new buffer 
  13778. contents.  The variable file-precious-flag, if non-nil, also has this effect 
  13779. (as a sideline of its main significance).  See Saving Buffers. 
  13780.  
  13781.  The variables backup-by-copying-when-linked and 
  13782. backup-by-copying-when-mismatch, if non-nil, cause the second method to be used 
  13783. in certain special cases.  They have no effect on the treatment of files that 
  13784. don't fall into the special cases. 
  13785.  
  13786. -- Variable: backup-by-copying 
  13787.  This variable controls whether to make backup files by copying.  If it is 
  13788. non-nil, then Emacs always copies the current contents of the file into the 
  13789. backup file before writing the buffer to be saved to the file.  (In many 
  13790. circumstances, this has the same effect as file-precious-flag.) 
  13791.  
  13792. -- Variable: backup-by-copying-when-linked 
  13793.  This variable controls whether to make backups by copying for files with 
  13794. multiple names (hard links).  If it is non-nil, then Emacs will use copying to 
  13795. create backups for those files. 
  13796.  
  13797.  This variable is significant only if backup-by-copying is nil, since copying 
  13798. is always used when that variable is non-nil. 
  13799.  
  13800. -- Variable: backup-by-copying-when-mismatch 
  13801.  This variable controls whether to make backups by copying when renaming would 
  13802. cause either the owner or the group of the file to change.  If it is non-nil 
  13803. then Emacs will create backups by copying in such cases. 
  13804.  
  13805.  The value has no effect when renaming would not result in changing the owner 
  13806. or group of the file; that is, for files which are owned by the user and whose 
  13807. group matches the default for a new file created there by the user. 
  13808.  
  13809.  This variable is significant only if backup-by-copying is nil, since copying 
  13810. is always used when that variable is non-nil. 
  13811.  
  13812.  
  13813. ΓòÉΓòÉΓòÉ 26.1.3. Making and Deleting Numbered Backup Files ΓòÉΓòÉΓòÉ
  13814.  
  13815.  If a file's name is `foo', the names of its numbered backup versions are 
  13816. `foo.~v~', for various integers v, like this: `foo.~1~', `foo.~2~', `foo.~3~', 
  13817. ..., `foo.~259~', and so on. 
  13818.  
  13819. -- User Option: version-control 
  13820.  This variable controls whether to make a single non-numbered backup file or 
  13821. multiple numbered backups. 
  13822.  
  13823. nil 
  13824.           Make numbered backups if the visited file already has numbered 
  13825.           backups; otherwise, do not. 
  13826.  
  13827. never 
  13828.           Do not make numbered backups. 
  13829.  
  13830. anything else 
  13831.           Do make numbered backups. 
  13832.  
  13833.  The use of numbered backups ultimately leads to a large number of backup 
  13834. versions, which must then be deleted.  Emacs can do this automatically. 
  13835.  
  13836. -- User Option: kept-new-versions 
  13837.  The value of this variable is the number of oldest versions to keep when a new 
  13838. numbered backup is made.  The newly made backup is included in the count.  The 
  13839. default value is 2. 
  13840.  
  13841. -- User Option: kept-old-versions 
  13842.  The value of this variable is the number of oldest versions to keep when a new 
  13843. numbered backup is made.  The default value is 2. 
  13844.  
  13845. -- User Option: dired-kept-versions 
  13846.  This variable plays a role in Dired's dired-clean-directory (.) command like 
  13847. that played by kept-old-versions when a backup file is made.  The default value 
  13848. is 2. 
  13849.  
  13850.  If there are backups numbered 1, 2, 3, 5, and 7, and both of these variables 
  13851. have the value 2, then the backups numbered 1 and 2 will be kept as old 
  13852. versions and those numbered 5 and 7 will be kept as new versions; backup 
  13853. version 3 will be deleted.  The function find-backup-file-name is responsible 
  13854. for determining which backup versions to delete, but does not delete them 
  13855. itself. 
  13856.  
  13857. -- User Option: trim-versions-without-asking 
  13858.  If this variable is non-nil, then excess backup versions are deleted silently. 
  13859. Otherwise, the user is asked whether to delete them. 
  13860.  
  13861.  
  13862. ΓòÉΓòÉΓòÉ 26.1.4. Naming Backup Files ΓòÉΓòÉΓòÉ
  13863.  
  13864.  The functions in this section are documented mainly because you can customize 
  13865. the naming conventions for backup files by redefining them. 
  13866.  
  13867. -- Function: backup-file-name-p filename 
  13868. This function returns a non-nil value if filename is a possible name for a 
  13869. backup file.  A file with the name filename need not exist; the function just 
  13870. checks the name. 
  13871.  
  13872. (backup-file-name-p "foo")
  13873.      => nil
  13874. (backup-file-name-p "foo~")
  13875.      => 3
  13876.  
  13877. The standard definition of this function is as follows: 
  13878.  
  13879. (defun backup-file-name-p (file)
  13880.   "Return non-nil if FILE is a backup file name (numeric or not)..."
  13881.   (string-match "~$" file))
  13882.  
  13883. Thus, the function returns a non-nil value if the file name ends with a `~' 
  13884.  
  13885. This simple expression is placed in a separate function to make it easy to 
  13886. redefine for customization. 
  13887.  
  13888. -- Function: make-backup-file-name filename 
  13889. This function returns a string which is the name to use for a non-numbered 
  13890. backup file for file filename.  On Unix, this is just filename with a tilde 
  13891. appended. 
  13892.  
  13893. The standard definition of this function is as follows: 
  13894.  
  13895. (defun make-backup-file-name (file)
  13896.   "Create the non-numeric backup file name for FILE..."
  13897.   (concat file "~"))
  13898.  
  13899. You can change the backup file naming convention by redefining this function. 
  13900. In the following example, make-backup-file-name is redefined to prepend a `.' 
  13901. as well as to append a tilde. 
  13902.  
  13903. (defun make-backup-file-name (filename)
  13904.   (concat "." filename "~"))
  13905.  
  13906. (make-backup-file-name "backups.texi")
  13907.      => ".backups.texi~"
  13908.  
  13909. If you do redefine make-backup-file-name, be sure to redefine 
  13910. backup-file-name-p and find-backup-file-name as well. 
  13911.  
  13912. -- Function: find-backup-file-name filename 
  13913.  This function computes the file name for a new backup file for filename.  It 
  13914. may also propose certain existing backup files for deletion. 
  13915. find-backup-file-name returns a list whose car is the name for the new backup 
  13916. file and whose cdr is a list of backup files whose deletion is proposed. 
  13917.  
  13918.  Two variables called kept-old-versions and kept-new-versions determine which 
  13919. old backup versions will be kept (by excluding them from the list of backup 
  13920. files ripe for deletion).  See Numbered Backups. 
  13921.  
  13922.  In this example, `~rms/foo.~5~' is the name to use for the new backup file, 
  13923. and `~rms/foo.~3~' is an ``excess'' version that the caller should consider 
  13924. deleting now. 
  13925.  
  13926. (find-backup-file-name "~rms/foo")
  13927.      => ("~rms/foo.~5~" "~rms/foo.~3~")
  13928.  
  13929.  
  13930. ΓòÉΓòÉΓòÉ 26.2. Auto-Saving ΓòÉΓòÉΓòÉ
  13931.  
  13932.  Emacs periodically saves all files that you are visiting; this is called 
  13933. auto-saving.  Auto-saving prevents you from losing more than a limited amount 
  13934. of work if the system crashes.  By default, auto-saves happen every 300 
  13935. keystrokes. See Auto-Saving: Protection Against Disasters, for information on 
  13936. auto-save for users.  Here we describe the functions used to implement 
  13937. auto-saving and the variables that control them. 
  13938.  
  13939. -- Variable: buffer-auto-save-file-name 
  13940.  This buffer-local variable is the name of the file used for auto-saving the 
  13941. current buffer.  It is nil if the buffer should not be auto-saved. 
  13942.  
  13943. buffer-auto-save-file-name
  13944. => "/xcssun/users/rms/lewis/#files.texi#"
  13945.  
  13946. -- Command: auto-save-mode arg 
  13947.  When used interactively without an argument, this command is a toggle switch: 
  13948. it turns on auto-saving of the current buffer if it is off, and vice-versa. 
  13949. With an argument arg, the command turns auto-saving on if the value of arg is 
  13950. t, a nonempty list, or a positive integer.  Otherwise, it turns auto-saving 
  13951. off. 
  13952.  
  13953. -- Function: auto-save-file-name-p filename 
  13954.  This function returns a non-nil value if filename is a string that could be 
  13955. the name of an auto-save file.  It works based on knowledge of the naming 
  13956. convention for auto-save files: a name that begins and ends with hash marks 
  13957. (`#') is a possible auto-save file name.  The argument filename should not 
  13958. contain a directory part. 
  13959.  
  13960. (make-auto-save-file-name)
  13961.      => "/xcssun/users/rms/lewis/#files.texi#"
  13962. (auto-save-file-name-p "#files.texi#")
  13963.      => 0
  13964. (auto-save-file-name-p "files.texi")
  13965.      => nil
  13966.  
  13967.  The standard definition of this function is as follows: 
  13968.  
  13969. (defun auto-save-file-name-p (filename)
  13970.   "Return non-nil if FILENAME can be yielded by..."
  13971.   (string-match "^#.*#$" filename))
  13972.  
  13973.  This function exists so that you can customize it if you wish to change the 
  13974. naming convention for auto-save files.  If you redefine it, be sure to redefine 
  13975. make-auto-save-file-name correspondingly. 
  13976.  
  13977. -- Function: make-auto-save-file-name 
  13978.  This function returns the file name to use for auto-saving the current buffer. 
  13979. This is just the file name with hash marks (`#') appended and prepended to it. 
  13980. This function does not look at the variable auto-save-visited-file-name; that 
  13981. should be checked before this function is called. 
  13982.  
  13983. (make-auto-save-file-name)
  13984.      => "/xcssun/users/rms/lewis/#backup.texi#"
  13985.  
  13986.  The standard definition of this function is as follows: 
  13987.  
  13988. (defun make-auto-save-file-name ()
  13989.   "Return file name to use for auto-saves of current buffer..."
  13990.   (if buffer-file-name
  13991.       (concat (file-name-directory buffer-file-name)
  13992.               "#"
  13993.               (file-name-nondirectory buffer-file-name)
  13994.               "#")
  13995.     (expand-file-name (concat "#%" (buffer-name) "#"))))
  13996.  
  13997.  This exists as a separate function so that you can redefine it to customize 
  13998. the naming convention for auto-save files.  Be sure to change 
  13999. auto-save-file-name-p in a corresponding way. 
  14000.  
  14001. -- Variable: auto-save-visited-file-name 
  14002.  If this variable is non-nil, Emacs will auto-save buffers in the files they 
  14003. are visiting.  That is, the auto-save is done in the same file which you are 
  14004. editing.  Normally, this variable is nil, so auto-save files have distinct 
  14005. names that are created by make-auto-save-file-name. 
  14006.  
  14007.  When you change the value of this variable, the value does not take effect 
  14008. until the next time auto-save mode is reenabled in any given buffer.  If 
  14009. auto-save mode is already enabled, auto-saves continue to go in the same file 
  14010. name until auto-save-mode is called again. 
  14011.  
  14012. -- Function: recent-auto-save-p 
  14013.  This function returns t if the current buffer has been auto-saved since the 
  14014. last time it was read in or saved. 
  14015.  
  14016. -- Function: set-buffer-auto-saved 
  14017.  This function marks the current buffer as auto-saved.  The buffer will not be 
  14018. auto-saved again until the buffer text is changed again.  The function returns 
  14019. nil. 
  14020.  
  14021. -- User Option: auto-save-interval 
  14022.  The value of this variable is the number of characters that Emacs reads from 
  14023. the keyboard between auto-saves.  Each time this many more characters are read, 
  14024. auto-saving is done for all buffers in which it is enabled. 
  14025.  
  14026. -- User Option: auto-save-default 
  14027.  If this variable is non-nil, buffers that are visiting files have auto-saving 
  14028. enabled by default.  Otherwise, they do not. 
  14029.  
  14030. -- Command: do-auto-save &optional no-message 
  14031.  This function auto-saves all buffers that need to be auto-saved. This is all 
  14032. buffers for which auto-saving is enabled and that have been changed since the 
  14033. last time they were auto-saved. 
  14034.  
  14035.  Normally, if any buffers are auto-saved, a message `Auto-saving...' is 
  14036. displayed in the echo area while auto-saving is going on.  However, if 
  14037. no-message is non-nil, the message is inhibited. 
  14038.  
  14039. -- Function: delete-auto-save-file-if-necessary 
  14040.  This function deletes the auto-save file for the current buffer if variable 
  14041. delete-auto-save-files is non-nil.  It is called every time a buffer is saved. 
  14042.  
  14043. -- Variable: delete-auto-save-files 
  14044.  This variable is used by the function delete-auto-save-file-if-necessary.  If 
  14045. it is non-nil, Emacs will delete auto-save files when a true save is done (in 
  14046. the visited file).  This saves on disk space and unclutters your directory. 
  14047.  
  14048. -- Function: rename-auto-save-file 
  14049.  This function adjusts the current buffer's auto-save file name if the visited 
  14050. file name has changed.  It also renames an existing auto-save file.  If the 
  14051. visited file name has not changed, this function does nothing. 
  14052.  
  14053.  
  14054. ΓòÉΓòÉΓòÉ 26.3. Reverting ΓòÉΓòÉΓòÉ
  14055.  
  14056.  If you have made extensive changes to a file and then change your mind about 
  14057. them, you can get rid of them by reading in the previous version of the file 
  14058. with the revert-buffer command. See Reverting a Buffer. 
  14059.  
  14060. -- Command: revert-buffer &optional no-auto-save-offer-p noconfirm 
  14061.  This command replaces the buffer text with the text of the visited file on 
  14062. disk.  This action undoes all changes since the file was visited or saved. 
  14063.  
  14064.  When the value of the no-auto-save-offer-p argument is nil, and the latest 
  14065. auto-save file is more recent than the visited file, revert-buffer asks the 
  14066. user whether to use that instead.  Otherwise, it always uses the latest backup 
  14067. file.  This argument is the numeric prefix argument when the function is called 
  14068. interactively. 
  14069.  
  14070.  When the value of the noconfirm argument is non-nil, revert-buffer does not 
  14071. ask for confirmation for the reversion action.  This means that the buffer 
  14072. contents are deleted and replaced by the text from the file on the disk, with 
  14073. no further opportunities for the user to prevent it. 
  14074.  
  14075.  Since reverting works by deleting the entire text of the buffer and inserting 
  14076. the file contents, all the buffer's markers are relocated to point at the 
  14077. beginning of the buffer.  This is not ``correct'', but then, there is no way to 
  14078. determine what would be correct.  It is not possible to determine, from the 
  14079. text before and after, which characters after reversion correspond to which 
  14080. characters before. 
  14081.  
  14082.  If the value of the revert-buffer-function variable is non-nil, it is called 
  14083. as a function with no arguments to do the work. 
  14084.  
  14085. -- Variable: revert-buffer-function 
  14086.  The value of this variable is the function to use to revert this buffer; but 
  14087. if the value of this variable is nil, then the revert-buffer function carries 
  14088. out its default action.  Modes such as Dired mode, in which the text being 
  14089. edited does not consist of a file's contents but can be regenerated in some 
  14090. other fashion, give this variable a buffer-local value that is a function to 
  14091. regenerate the contents. 
  14092.  
  14093. -- Command: recover-file filename 
  14094.  This function visits filename, but gets the contents from its last auto-save 
  14095. file.  This is useful after the system has crashed, to resume editing the same 
  14096. file without losing all the work done in the previous session. 
  14097.  
  14098.  An error is signaled if there is no auto-save file for filename, or if 
  14099. filename is newer than its auto-save file.  If filename does not exist, but its 
  14100. auto-save file does, then the auto-save file is read as usual.  This last 
  14101. situation may occur if you visited a nonexistent file and never actually saved 
  14102. it. 
  14103.  
  14104.  
  14105. ΓòÉΓòÉΓòÉ 27. Buffers ΓòÉΓòÉΓòÉ
  14106.  
  14107.  A buffer is a Lisp object containing text to be edited.  Buffers are used to 
  14108. hold the contents of files that are being visited; there may also be buffers 
  14109. which are not visiting files.  While several buffers may exist at one time, 
  14110. exactly one buffer is designated the current buffer at any time.  Most editing 
  14111. commands act on the contents of the current buffer.  Each buffer, including the 
  14112. current buffer, may or may not be displayed in any windows. 
  14113.  
  14114.  
  14115. ΓòÉΓòÉΓòÉ 27.1. Buffer Basics ΓòÉΓòÉΓòÉ
  14116.  
  14117.  A buffer is a Lisp object containing text to be edited.  Buffers are used to 
  14118. hold the contents of files that are being visited; there may also be buffers 
  14119. which are not visiting files.  While several buffers may exist at one time, 
  14120. exactly one buffer is designated the current buffer at any time.  Most editing 
  14121. commands act on the contents of the current buffer.  Each buffer, including the 
  14122. current buffer, may or may not be displayed in any windows. 
  14123.  
  14124.  Buffers in Emacs editing are objects which have distinct names and hold text 
  14125. that can be edited.  Buffers appear to Lisp programs as a special data type. 
  14126. The contents of a buffer may be viewed as an extendible string; insertions and 
  14127. deletions may occur in any part of the buffer.  See Text. 
  14128.  
  14129.  A Lisp buffer object contains numerous pieces of information.  Some of this 
  14130. information is directly accessible to the programmer through variables, while 
  14131. other information is only accessible through special-purpose functions.  For 
  14132. example, the width of a tab character is directly accessible through a 
  14133. variable, while the value of point is accessible only through a primitive 
  14134. function. 
  14135.  
  14136.  Buffer-specific information that is directly accessible is stored in 
  14137. buffer-local variable bindings, which are variable values that are effective 
  14138. only in a particular buffer.  This feature allows each buffer to override the 
  14139. values of certain variables.  Most major modes override variables such as 
  14140. fill-column or comment-column in this way.  For more information about 
  14141. buffer-local variables and functions related to them, see Buffer-Local 
  14142. Variables. 
  14143.  
  14144.  For functions and variables related to visiting files in buffers, see Visiting 
  14145. Files and Saving Buffers.  For functions and variables related to the display 
  14146. of buffers in windows, see Buffers and Windows. 
  14147.  
  14148. -- Function: bufferp object 
  14149.  This function returns t if object is a buffer, nil otherwise. 
  14150.  
  14151.  
  14152. ΓòÉΓòÉΓòÉ 27.2. Buffer Names ΓòÉΓòÉΓòÉ
  14153.  
  14154.  Each buffer has a unique name, which is a string.  The buffer name may be used 
  14155. in place of the buffer object in many functions that operate on buffers. 
  14156. Buffers that are generally ephemeral and uninteresting to the user have names 
  14157. starting with a space, which prevents them from being listed by the 
  14158. list-buffers or buffer-menu commands. 
  14159.  
  14160.  Many of the following functions accept either a buffer or a buffer name (a 
  14161. string) as an argument.  Any argument called buffer-or-name is of this sort, 
  14162. and an error is signaled if it is neither a string nor a buffer.  Any argument 
  14163. called buffer is required to be an actual buffer object, not a name. 
  14164.  
  14165. -- Function: buffer-name &optional buffer 
  14166.  This function returns the name of buffer as a string.  If buffer is not 
  14167. supplied, it defaults to the current buffer. 
  14168.  
  14169.  If buffer-name returns nil, it means that buffer has been killed.  See Killing 
  14170. Buffers. 
  14171.  
  14172. (buffer-name)
  14173.      => "buffers.texi"
  14174.  
  14175. (setq foo (get-buffer "temp"))
  14176.      => #<buffer temp>
  14177. (kill-buffer foo)
  14178.      => nil
  14179. (buffer-name foo)
  14180.      => nil
  14181. foo
  14182.      => #<killed buffer>
  14183.  
  14184. -- Command: rename-buffer newname 
  14185.  This function renames the current buffer to newname.  An error is signaled if 
  14186. newname is not a string, or if there is already a buffer with that name.  The 
  14187. function returns nil. 
  14188.  
  14189.  One application of this command is to rename the `*shell*' buffer to some 
  14190. other name, thus making it possible to create a second shell buffer under the 
  14191. name `*shell*'. 
  14192.  
  14193. -- Function: get-buffer buffer-or-name 
  14194.  This function returns the buffer specified by buffer-or-name. If 
  14195. buffer-or-name is a string and there is no buffer with that name, the value is 
  14196. nil.  If buffer-or-name is a buffer, it is returned as given.  (That is not 
  14197. very useful, so the argument is usually a name.)  For example: 
  14198.  
  14199. (setq b (get-buffer "lewis"))
  14200.      => #<buffer lewis>
  14201. (get-buffer b)
  14202.      => #<buffer lewis>
  14203. (get-buffer "Frazzle-nots")
  14204.      => nil
  14205.  
  14206.  
  14207. ΓòÉΓòÉΓòÉ 27.3. Buffer File Name ΓòÉΓòÉΓòÉ
  14208.  
  14209.  The buffer file name is the name of the file that is visited in that buffer. 
  14210. When a buffer is not visiting a file, its buffer file name is nil.  Most of the 
  14211. time, the buffer name is the same as the nondirectory part of the buffer file 
  14212. name, but the buffer file name and the buffer name are distinct and can be set 
  14213. independently. See Visiting Files. 
  14214.  
  14215. -- Function: buffer-file-name &optional buffer 
  14216.  This function returns the absolute file name of the file that buffer is 
  14217. visiting.  If buffer is not visiting any file, buffer-file-name returns nil. 
  14218. If buffer is not supplied, it defaults to the current buffer. 
  14219.  
  14220. (buffer-file-name (other-buffer))
  14221.      => "/usr/user/lewis/manual/files.texi"
  14222.  
  14223. -- Variable: buffer-file-name 
  14224.  This buffer-local variable contains the name of the file being visited in the 
  14225. current buffer, or nil if it is not visiting a file. 
  14226.  
  14227. buffer-file-name
  14228.      => "/usr/user/lewis/manual/buffers.texi"
  14229.  
  14230.  It is risky to change this variable's value without doing various other 
  14231. things.  See the definition of set-visited-file-name in `files.el'; some of the 
  14232. things done there, such as changing the buffer name, are not necessary, but 
  14233. others are essential to avoid confusing Emacs. 
  14234.  
  14235. -- Function: get-file-buffer filename 
  14236.  This function returns the buffer visiting file filename.  If there is no such 
  14237. buffer, it returns nil.  The argument filename, which must be a string, is 
  14238. expanded ( see File Name Expansion), then compared against the visited file 
  14239. names of all live buffers. 
  14240.  
  14241. (get-file-buffer "buffers.texi")
  14242. => #<buffer buffers.texi>
  14243.  
  14244.  In unusual circumstances, there can be more than one buffer visiting the same 
  14245. file name.  In such cases, this function returns the first such buffer in the 
  14246. buffer list. 
  14247.  
  14248. -- Command: set-visited-file-name filename 
  14249.  If filename is a non-empty string, this function changes the name of the file 
  14250. visited in current buffer to filename.  (If the buffer had no visited file, 
  14251. this gives it one.)  The next time the buffer is saved it will go in the 
  14252. newly-specified file.  The buffer is always marked as modified, since it does 
  14253. not (as far as Emacs knows) match the contents of filename, even if it matched 
  14254. the former visited file. 
  14255.  
  14256.  If filename is nil or the empty string, that stands for ``no visited file''. 
  14257. In this case, set-visited-file-name marks the buffer as having no visited file. 
  14258.  
  14259.  When set-visited-file-name is called interactively, it prompts for filename in 
  14260. the minibuffer. 
  14261.  
  14262.  See also clear-visited-file-modtime and verify-visited-file-modtime in Buffer 
  14263. Modification. 
  14264.  
  14265.  
  14266. ΓòÉΓòÉΓòÉ 27.4. Buffer Modification ΓòÉΓòÉΓòÉ
  14267.  
  14268.  Emacs keeps a flag called the modified flag for each buffer, to record whether 
  14269. you have changed the text of the buffer.  This flag is set to t whenever you 
  14270. alter the contents of the buffer, and cleared to nil when you save it.  Thus, 
  14271. the flag shows whether there are unsaved changes.  The flag value is normally 
  14272. shown in the mode line (see Mode Line Variables), and controls saving ( see 
  14273. Saving Buffers) and auto-saving (see Auto-Saving). 
  14274.  
  14275.  Some Lisp programs set the flag explicitly.  For example, the Lisp function 
  14276. set-visited-file-name sets the flag to t, because the text does not match the 
  14277. newly-visited file, even if it is unchanged from the file formerly visited. 
  14278.  
  14279.  The functions that modify the contents of buffers are described in Text. 
  14280.  
  14281. -- Function: buffer-modified-p &optional buffer 
  14282.  This function returns t if the buffer buffer has been modified since it was 
  14283. last read in from a file or saved, or nil otherwise.  If buffer is not 
  14284. supplied, the current buffer is tested. 
  14285.  
  14286. -- Function: set-buffer-modified-p flag 
  14287.  This function marks the current buffer as modified if flag is non-nil, or as 
  14288. unmodified if the flag is nil. 
  14289.  
  14290.  Another effect of calling this function is to cause unconditional redisplay of 
  14291. the mode line for the current buffer.  In fact, the standard way to force 
  14292. redisplay of the mode line is as follows: 
  14293.  
  14294. (set-buffer-modified-p (buffer-modified-p))
  14295.  
  14296. -- Command: not-modified 
  14297.  This command marks the current buffer as unmodified, and not needing to be 
  14298. saved.  Don't use this function in programs, since it prints a message; use 
  14299. set-buffer-modified-p (above) instead. 
  14300.  
  14301.  
  14302. ΓòÉΓòÉΓòÉ 27.5. Comparison of Modification Time ΓòÉΓòÉΓòÉ
  14303.  
  14304.  Suppose that you visit a file and make changes in its buffer, and meanwhile 
  14305. the file itself is changed on disk.  At this point, saving the buffer would 
  14306. overwrite the changes in the file.  Occasionally this may be what you want, but 
  14307. usually it would lose valuable information.  Emacs therefore checks the file's 
  14308. modification time using the functions described below before saving the file. 
  14309.  
  14310. -- Function: verify-visited-file-modtime buffer 
  14311.  This function compares Emacs's record of the modification time for the file 
  14312. that the buffer is visiting against the actual modification time of the file as 
  14313. recorded by the operating system.  The two will be the same unless some other 
  14314. process has written the file since Emacs visited or saved it. 
  14315.  
  14316.  The function returns t if the last actual modification time and Emacs's 
  14317. recorded modification time are the same, nil otherwise. 
  14318.  
  14319. -- Function: clear-visited-file-modtime 
  14320.  This function clears out the record of the last modification time of the file 
  14321. being visited by the current buffer.  As a result, the next attempt to save 
  14322. this buffer will not complain of a discrepancy in file modification times. 
  14323.  
  14324.  This function is called in set-visited-file-name and other exceptional places 
  14325. where the usual test to avoid overwriting a changed file should not be done. 
  14326.  
  14327. -- Function: ask-user-about-supersession-threat fn 
  14328.  This function is used to ask a user how to proceed after an attempt to modify 
  14329. an obsolete buffer.  An obsolete buffer is an unmodified buffer for which the 
  14330. associated file on disk is newer than the last save-time of the buffer.  This 
  14331. means some other program has probably altered the file. 
  14332.  
  14333.  This function is called automatically by Emacs on the proper occasions.  It 
  14334. exists so you can customize Emacs by redefining it. See the file `userlock.el' 
  14335. for the standard definition. 
  14336.  
  14337.  Depending on the user's answer, the function may return normally, in which 
  14338. case the modification of the buffer proceeds, or it may signal a 
  14339. file-supersession error with data (fn), in which case the proposed buffer 
  14340. modification is not allowed. 
  14341.  
  14342.  See also the file locking mechanism in File Locks. 
  14343.  
  14344.  
  14345. ΓòÉΓòÉΓòÉ 27.6. Read-Only Buffers ΓòÉΓòÉΓòÉ
  14346.  
  14347.  A buffer may be designated as read-only.  This means that the buffer's 
  14348. contents may not be modified, although you may change your view of the contents 
  14349. by scrolling, narrowing, or widening, etc. 
  14350.  
  14351.  Read-only buffers are used in two kinds of situations: 
  14352.  
  14353. o A buffer visiting a file is made read-only if the file is write-protected. 
  14354.  
  14355.   Here, the purpose is to show the user that editing the buffer with the aim of 
  14356.   saving it in the file may be futile or undesirable.  The user who wants to 
  14357.   change the buffer text despite this can do so after clearing the read-only 
  14358.   flag with the function toggle-read-only. 
  14359.  
  14360. o Modes such as Dired and Rmail make buffers read-only when altering the 
  14361.   contents with the usual editing commands is probably a mistake. 
  14362.  
  14363.   The special commands of the mode in question bind buffer-read-only to nil 
  14364.   (with let) around the places where they change the text. 
  14365.  
  14366. -- Variable: buffer-read-only 
  14367.  This buffer-local variable specifies whether the buffer is read-only. The 
  14368. buffer is read-only if this variable is non-nil. 
  14369.  
  14370. -- Command: toggle-read-only 
  14371.  This command changes whether the current buffer is read-only.  It is intended 
  14372. for interactive use; don't use it in programs.  At any given point in a 
  14373. program, you should know whether you want the read-only flag on or off; so you 
  14374. can set buffer-read-only explicitly to the proper value, t or nil. 
  14375.  
  14376. -- Function: barf-if-buffer-read-only 
  14377.  This function signals a buffer-read-only error if the current buffer is 
  14378. read-only.  See Interactive Call, for another way to signal an error if the 
  14379. current buffer is read-only. 
  14380.  
  14381.  
  14382. ΓòÉΓòÉΓòÉ 27.7. The Buffer List ΓòÉΓòÉΓòÉ
  14383.  
  14384.  The buffer list is a list of all buffers that have not been killed.  The order 
  14385. of the buffers in the list is based primarily on how recently each buffer has 
  14386. been displayed in the selected window.  Several functions, notably 
  14387. other-buffer, make use of this ordering. 
  14388.  
  14389. -- Function: buffer-list 
  14390.  This function returns a list of all buffers, including those whose names begin 
  14391. with a space.  The elements are actual buffers, not their names. 
  14392.  
  14393. (buffer-list)
  14394.      => (#<buffer buffers.texi> #<buffer  *Minibuf-1*>
  14395.          #<buffer buffer.c>  #<buffer *Help*> #<buffer TAGS>)
  14396.  
  14397. ;; Note that the name of the minibuffer begins with a space!
  14398.  
  14399. (mapcar (function buffer-name) (buffer-list))
  14400. => ("buffers.texi" " *Minibuf-1*" "buffer.c" "*Help*" "TAGS")
  14401.  
  14402.  This list is a copy of a list used inside Emacs; modifying it has no effect on 
  14403. the buffers. 
  14404.  
  14405. -- Function: other-buffer &optional buffer-or-name 
  14406.  This function returns the first buffer in the buffer list other than 
  14407. buffer-or-name.  Usually this is the buffer most recently shown in the selected 
  14408. window, aside from buffer-or-name.  Buffers are moved to the front of the list 
  14409. when they are selected and to the end when they are buried.  Buffers whose 
  14410. names start with a space are not even considered. 
  14411.  
  14412.  If buffer-or-name is not supplied (or if it is not a buffer), then 
  14413. other-buffer returns the first buffer on the buffer list that is not visible in 
  14414. any window. 
  14415.  
  14416.  If no suitable buffer exists, the buffer `*scratch*' is returned (and created, 
  14417. if necessary). 
  14418.  
  14419. -- Command: list-buffers &optional files-only 
  14420.  This function displays a listing of the names of existing buffers.  It clears 
  14421. the buffer `*Buffer List*', then inserts the listing into that buffer and 
  14422. displays it in a window.  list-buffers is intended for interactive use, and is 
  14423. described fully in The GNU Emacs Manual.  It returns nil. 
  14424.  
  14425. -- Command: bury-buffer &optional buffer-or-name 
  14426.  This function puts buffer-or-name at the end of the buffer list without 
  14427. changing the order of any of the other buffers on the list. This buffer 
  14428. therefore becomes the least desirable candidate for other-buffer to return, and 
  14429. appears last in the list displayed by list-buffers. 
  14430.  
  14431.  If buffer-or-name is the current buffer, then it is replaced in the selected 
  14432. window by the buffer chosen using other-buffer.  If the buffer is displayed in 
  14433. a window other than the selected one, it remains there. 
  14434.  
  14435.  If buffer-or-name is not supplied, it defaults to the current buffer.  This is 
  14436. what happens in an interactive call. 
  14437.  
  14438.  
  14439. ΓòÉΓòÉΓòÉ 27.8. Creating Buffers ΓòÉΓòÉΓòÉ
  14440.  
  14441.  This section describes the two primitives for creating buffers. 
  14442. get-buffer-create creates a buffer if it finds no existing buffer; 
  14443. generate-new-buffer always creates a new buffer, and gives it a unique name. 
  14444.  
  14445.  Two other functions to create buffers are with-output-to-temp-buffer (see 
  14446. Temporary Displays) and create-file-buffer (see Visiting Files). 
  14447.  
  14448. -- Function: get-buffer-create name 
  14449.  This function returns a buffer named name.  If such a buffer already exists, 
  14450. it is returned.  If such a buffer does not exist, one is created and returned. 
  14451. The buffer does not become the current buffer---this function does not change 
  14452. which buffer is current. 
  14453.  
  14454.  An error is signaled if name is not a string. 
  14455.  
  14456. (get-buffer-create "foo")
  14457.      => #<buffer foo>
  14458.  
  14459.  The major mode for the new buffer is chosen according to the value of 
  14460. default-major-mode.  See Auto Major Mode. 
  14461.  
  14462. -- Function: generate-new-buffer name 
  14463.  This function returns a newly created, empty buffer.  If there is no buffer 
  14464. named name, then that is the name of the new buffer.  If there is a buffer with 
  14465. that name, then suffixes of the form `<n>' are added to name, where n stands 
  14466. for successive integers starting with 2.  New suffixes are tried until an 
  14467. unused name is found. 
  14468.  
  14469.  An error is signaled if name is not a string. 
  14470.  
  14471. (generate-new-buffer "bar")
  14472.      => #<buffer bar>
  14473. (generate-new-buffer "bar")
  14474.      => #<buffer bar<2>>
  14475. (generate-new-buffer "bar")
  14476.      => #<buffer bar<3>>
  14477.  
  14478.  The major mode for the new buffer is chosen according to the value of 
  14479. default-major-mode.  See Auto Major Mode. 
  14480.  
  14481.  
  14482. ΓòÉΓòÉΓòÉ 27.9. Killing Buffers ΓòÉΓòÉΓòÉ
  14483.  
  14484.  Killing a buffer makes its name unknown to Emacs and makes its space available 
  14485. for other use. 
  14486.  
  14487.  The buffer object for the buffer which has been killed remains in existence as 
  14488. long as anything refers to it, but it is specially marked so that you cannot 
  14489. make it current or display it.  Killed buffers retain their identity, however; 
  14490. two distinct buffers, when killed, remain distinct according to eq. 
  14491.  
  14492.  The buffer-name of a killed buffer is nil.  You can use this feature to test 
  14493. whether a buffer has been killed: 
  14494.  
  14495. (defun killed-buffer-p (buffer)
  14496.   "Return t if BUFFER is killed."
  14497.   (not (buffer-name buffer)))
  14498.  
  14499. -- Command: kill-buffer buffer-or-name 
  14500.  This function kills the buffer buffer-or-name, freeing all its memory for use 
  14501. as space for other buffers.  (In Emacs version 18, the memory is not returned 
  14502. to the operating system.)  It returns nil. 
  14503.  
  14504.  Any processes that have this buffer as the process-buffer are sent the SIGHUP 
  14505. signal, which normally causes them to terminate. (The usual meaning of SIGHUP 
  14506. is that a dialup line has been disconnected.)  See Deleting Processes. 
  14507.  
  14508.  If the buffer is visiting a file when kill-buffer is called and the buffer has 
  14509. not been saved since it was last modified, the user is asked to confirm before 
  14510. the buffer is killed.  This is done even if kill-buffer is not called 
  14511. interactively.  To prevent the request for confirmation, clear the modified 
  14512. flag before calling kill-buffer.  See Buffer Modification. 
  14513.  
  14514. (kill-buffer "foo.unchanged")
  14515.      => nil
  14516. (kill-buffer "foo.changed")
  14517.  
  14518. ---------- Buffer: Minibuffer ----------
  14519. Buffer foo.changed modified; kill anyway? (yes or no) yes
  14520. ---------- Buffer: Minibuffer ----------
  14521.  
  14522.      => nil
  14523.  
  14524.  
  14525. ΓòÉΓòÉΓòÉ 27.10. The Current Buffer ΓòÉΓòÉΓòÉ
  14526.  
  14527.  There are in general many buffers in an Emacs session.  At any time, one of 
  14528. them is designated as the current buffer.  This is the buffer in which most 
  14529. editing takes place, because most of the primitives for examining or changing 
  14530. text in a buffer operate implicitly on the current buffer (see Text).  Normally 
  14531. the buffer that is displayed on the screen in the selected window is the 
  14532. current buffer, but this is not always so: a Lisp program can designate any 
  14533. buffer as current temporarily in order to operate on its contents, without 
  14534. changing what is displayed on the screen. 
  14535.  
  14536.  The way to designate a current buffer in a Lisp program is by calling 
  14537. set-buffer.  The specified buffer remains current until a new one is 
  14538. designated. 
  14539.  
  14540.  When an editing command returns to the editor command loop, the command loop 
  14541. designates the buffer displayed in the selected window as current, to prevent 
  14542. confusion: the buffer that the cursor is in, when Emacs reads a command, is the 
  14543. one to which the command will apply. (See Command Loop.)  Therefore, set-buffer 
  14544. is not usable for switching visibly to a different buffer so that the user can 
  14545. edit it. For this, you must use the functions described in Displaying Buffers. 
  14546.  
  14547.  However, Lisp functions that change to a different current buffer should not 
  14548. rely on the command loop to set it back afterwards.  Editing commands written 
  14549. in Emacs Lisp can be called from other programs as well as from the command 
  14550. loop.  It is convenient for the caller if the subroutine does not change which 
  14551. buffer is current (unless, of course, that is the subroutine's purpose). 
  14552. Therefore, you should normally use set-buffer within a save-excursion that will 
  14553. restore the current buffer when your program is done (see Excursions).  Here is 
  14554. an example, the code for the command append-to-buffer (with the documentation 
  14555. string abridged): 
  14556.  
  14557. (defun append-to-buffer (buffer start end)
  14558.   "Append to specified buffer the text of the region..."
  14559.   (interactive "BAppend to buffer: \nr")
  14560.   (let ((oldbuf (current-buffer)))
  14561.     (save-excursion
  14562.       (set-buffer (get-buffer-create buffer))
  14563.       (insert-buffer-substring oldbuf start end))))
  14564.  
  14565. In this function, a local variable is bound to the current buffer, and then 
  14566. save-excursion records the values of point, the mark, and the original buffer. 
  14567. Next, set-buffer makes another buffer current. Finally, insert-buffer-substring 
  14568. copies the string from the original current buffer to the new current buffer. 
  14569.  
  14570.  If the buffer appended to happens to be displayed in some window, then the 
  14571. next redisplay will show how its text has changed.  Otherwise, you will not see 
  14572. the change immediately on the screen.  The buffer becomes current temporarily 
  14573. during the execution of the command, but this does not cause it to be 
  14574. displayed. 
  14575.  
  14576. -- Function: current-buffer 
  14577.  This function returns the current buffer. 
  14578.  
  14579. (current-buffer)
  14580.      => #<buffer buffers.texi>
  14581.  
  14582. -- Function: set-buffer buffer-or-name 
  14583.  This function makes buffer-or-name the current buffer.  However, it does not 
  14584. display the buffer in the currently selected window or in any other window. 
  14585. This means that the user cannot necessarily see the buffer, but Lisp programs 
  14586. can in any case work on it. 
  14587.  
  14588.   This function returns the buffer identified by buffer-or-name. An error is 
  14589. signaled if buffer-or-name does not identify an existing buffer. 
  14590.  
  14591.  
  14592. ΓòÉΓòÉΓòÉ 28. Windows ΓòÉΓòÉΓòÉ
  14593.  
  14594.  This chapter describes most of the functions and variables related to Emacs 
  14595. windows.  See Emacs Display, for information on how text is displayed in 
  14596. windows. 
  14597.  
  14598.  
  14599. ΓòÉΓòÉΓòÉ 28.1. Basic Concepts of Emacs Windows ΓòÉΓòÉΓòÉ
  14600.  
  14601.  A window is the physical area of the screen in which a buffer is displayed. 
  14602. The term is also used to refer to a Lisp object which represents that screen 
  14603. area in Emacs Lisp.  It should be clear from the context which is meant. 
  14604.  
  14605.  There is always at least one window displayed on the screen, and there is 
  14606. exactly one window that we call the selected window.  The cursor is in the 
  14607. selected window.  The selected window's buffer is usually the current buffer 
  14608. (except when set-buffer has been used.)  See Current Buffer. 
  14609.  
  14610.  For all intents, a window only exists while it is displayed on the terminal. 
  14611. Once removed from the display, the window is effectively deleted and should not 
  14612. be used, even though there may still be references to it from other Lisp 
  14613. objects.  (See Deleting Windows.) 
  14614.  
  14615.  Each window has the following attributes: 
  14616.  
  14617. o window height 
  14618.  
  14619. o window width 
  14620.  
  14621. o window edges with respect to the screen 
  14622.  
  14623. o the buffer it displays 
  14624.  
  14625. o position within the buffer at the upper left of the window 
  14626.  
  14627. o the amount of horizontal scrolling, in columns 
  14628.  
  14629. o point 
  14630.  
  14631. o the mark 
  14632.  
  14633. o how recently the window was selected 
  14634.  
  14635.  Applications use multiple windows for a variety of reasons, but most often to 
  14636. give different views of the same information.  In Rmail, for example, you can 
  14637. move through a summary buffer in one window while the other window shows 
  14638. messages one at a time as they are reached. 
  14639.  
  14640.  Use of the word ``window'' to refer to a view of a buffer was established long 
  14641. ago in Emacs.  The metaphor was inspired by how you look out a house 
  14642. window---at part (or sometimes all) of an overall view. You see part (or 
  14643. sometimes all) of a buffer through an Emacs window.  In Emacs, each window may 
  14644. look on a different view, like different windows of a house. 
  14645.  
  14646.  The term ``window'' as used in this manual means something different from the 
  14647. term as used in a window system like X Windows.  In this manual, the term 
  14648. ``window'' refers to the nonoverlapping subdivisions of the Emacs display.  If 
  14649. Emacs is displaying on a window system, the Emacs display may itself be one X 
  14650. window among many on the screen.  But Emacs version 18 knows nothing of this. 
  14651.  
  14652.  For those familiar with windowing systems, Emacs's windows are rectangles 
  14653. tiled onto the rectangle of the screen, and every portion of the screen is part 
  14654. of some window, except (sometimes) the minibuffer area.  This limitation helps 
  14655. avoid wasting the historically scarce resource of screen space.  It also works 
  14656. well with character-only terminals.  Because of the way in which Emacs creates 
  14657. new windows and resizes them, you can't create every conceivable tiling on an 
  14658. Emacs screen.  See Splitting Windows.  Also, see Size of Window. 
  14659.  
  14660.  See Emacs Display, for information on how the contents of the window's buffer 
  14661. are displayed in the window. 
  14662.  
  14663. -- Function: windowp object 
  14664.  This function returns t if object is a window. 
  14665.  
  14666.  
  14667. ΓòÉΓòÉΓòÉ 28.2. Splitting Windows ΓòÉΓòÉΓòÉ
  14668.  
  14669.  The functions described here are the primitives used to split a window into 
  14670. two windows.  Two higher level functions sometimes split a window, but not 
  14671. always: pop-to-buffer and display-buffer (see Displaying Buffers). 
  14672.  
  14673.  The functions described here do not accept a buffer as an argument. They let 
  14674. the two ``halves'' of the split window display the same buffer previously 
  14675. visible in the window that was split. 
  14676.  
  14677. -- Function: one-window-p &optional no-mini 
  14678. This function returns non-nil if there is only one window.  The argument 
  14679. no-mini, if non-nil, means don't count the minibuffer even if it is active; 
  14680. otherwise, the minibuffer window is included, if active, in the total number of 
  14681. windows which is compared against one. 
  14682.  
  14683. -- Command: split-window &optional window size horizontal 
  14684. This function splits window into two windows.  The original window window 
  14685. remains the selected window, but occupies only part of its former screen area. 
  14686. The rest is occupied by a newly created window which is returned as the value 
  14687. of this function. 
  14688.  
  14689.  If horizontal is non-nil, then window splits side by side, keeping the 
  14690. leftmost size columns and giving the rest of the columns to the new window. 
  14691. Otherwise, it splits into halves one above the other, keeping the upper size 
  14692. lines and giving the rest of the lines to the new window.  The original window 
  14693. is therefore the right-hand or upper of the two, and the new window is the 
  14694. left-hand or lower. 
  14695.  
  14696.  If window is omitted or nil, then the selected window is split.  If size is 
  14697. omitted or nil, then window is divided evenly into two parts.  (If there is an 
  14698. odd line, it is allocated to the new window.)  When split-window is called 
  14699. interactively, all its arguments are nil. 
  14700.  
  14701.  The following example starts with one window on a screen that is 50 lines high 
  14702. by 80 columns wide; then the window is split. 
  14703.  
  14704. (setq w (selected-window))
  14705.      => #<window 8 on windows.texi>
  14706. (window-edges)                  ; Edges in order: left--top--right--bottom
  14707.      => (0 0 80 50)
  14708.  
  14709. (setq w2 (split-window w 15))   ; Returns window created
  14710.      => #<window 28 on windows.texi>
  14711. (window-edges w2)
  14712.      => (0 15 80 50)            ; Bottom window; top is line 15
  14713. (window-edges w)
  14714.      => (0 0 80 15)             ; Top window
  14715.  
  14716. The screen looks like this: 
  14717.  
  14718.          __________
  14719.         |          |  line 0
  14720.         |    w     |
  14721.         |__________|
  14722.         |          |  line 15
  14723.         |    w2    |
  14724.         |__________|
  14725.                       line 50
  14726.  column 0   column 80
  14727.  
  14728. Next, the top window is split horizontally: 
  14729.  
  14730. (setq w3 (split-window w 35 t))
  14731.      => #<window 32 on windows.texi>
  14732. (window-edges w3)
  14733.      => (35 0 80 15)  ; Left edge at column 35
  14734. (window-edges w)
  14735.      => (0 0 35 15)   ; Right edge at column 35
  14736. (window-edges w2)
  14737.      => (0 15 80 50)  ; Bottom window unchanged
  14738.  
  14739. Now, the screen looks like this: 
  14740.  
  14741.      column 35
  14742.          __________
  14743.         |   |      |  line 0
  14744.         | w |  w3  |
  14745.         |___|______|
  14746.         |          |  line 15
  14747.         |    w2    |
  14748.         |__________|
  14749.                       line 50
  14750.  column 0   column 80
  14751.  
  14752. -- Command: split-window-vertically size 
  14753.  This function splits the selected window into two windows, one above the 
  14754. other, leaving the selected window with size lines. 
  14755.  
  14756.  This function is simply an interface to split-windows. Here is the complete 
  14757. function definition for it: 
  14758.  
  14759. (defun split-window-vertically (&optional arg)
  14760.   "Split selected window into two windows, one above the other..."
  14761.   (interactive "P")
  14762.   (split-window nil (and arg (prefix-numeric-value arg))))
  14763.  
  14764. -- Command: split-window-horizontally size 
  14765.  This function splits the selected window into two windows side-by-side, 
  14766. leaving the selected window with size columns. 
  14767.  
  14768.  This function is simply an interface to split-windows.  Here is the complete 
  14769. definition for split-window-horizontally (except for part of the documentation 
  14770. string): 
  14771.  
  14772. (defun split-window-horizontally (&optional arg)
  14773.   "Split selected window into two windows side by side..."
  14774.   (interactive "P")
  14775.   (split-window nil (and arg (prefix-numeric-value arg)) t))
  14776.  
  14777.  
  14778. ΓòÉΓòÉΓòÉ 28.3. Deleting Windows ΓòÉΓòÉΓòÉ
  14779.  
  14780.  A deleted window no longer appears on the screen.  In Emacs version 18, the 
  14781. space it took up on the screen is divided proportionally among all siblings; in 
  14782. version 19, the space is given to one adjacent sibling. 
  14783.  
  14784. -- Command: delete-window &optional window 
  14785.  This function removes window from the display.  If window is omitted, then the 
  14786. selected window is deleted.  An error is signaled if there is only one window 
  14787. when delete-window is called. 
  14788.  
  14789. *Warning:* erroneous information or fatal errors may result from using a 
  14790. deleted window.  Use (window-point window) to test whether a window has been 
  14791. deleted; it yields nil for a deleted window. 
  14792.  
  14793.  This function returns nil. 
  14794.  
  14795.  When delete-window is called interactively, window defaults to the selected 
  14796. window. 
  14797.  
  14798. -- Command: delete-other-windows &optional window 
  14799.  This function makes window the only window on the screen by deleting all the 
  14800. other windows.  If window is omitted or nil, then the selected window is used 
  14801. by default. 
  14802.  
  14803.  The result is nil. 
  14804.  
  14805. -- Command: delete-windows-on buffer 
  14806.  This function deletes all windows showing buffer.  If there are no windows 
  14807. showing buffer, then this function does nothing.  If all windows are showing 
  14808. buffer (including the case where there is only one window), then the screen 
  14809. reverts to having a single window showing the buffer chosen by other-buffer. 
  14810. See The Buffer List. 
  14811.  
  14812.  If there are several windows showing different buffers, then those showing 
  14813. buffer are removed, and the others are expanded to fill the void. 
  14814.  
  14815.  The result is nil. 
  14816.  
  14817.  
  14818. ΓòÉΓòÉΓòÉ 28.4. Selecting Windows ΓòÉΓòÉΓòÉ
  14819.  
  14820.  When a window is selected, the buffer in the window becomes the current 
  14821. buffer, and the cursor will appear in it. 
  14822.  
  14823. -- Function: selected-window 
  14824.  This function returns the selected window.  This is the window in which the 
  14825. cursor appears and to which many commands apply. 
  14826.  
  14827. -- Function: select-window window 
  14828.  This function makes window the selected window.  The cursor then appears in 
  14829. window (on redisplay).  The buffer being displayed in window is immediately 
  14830. designated the current buffer. 
  14831.  
  14832.  The return value is window. 
  14833.  
  14834. (setq w (next-window))
  14835. (select-window w)
  14836.      => #<window 65 on windows.texi>
  14837.  
  14838.  The following functions choose one of the windows on the screen, offering 
  14839. various criteria for the choice. 
  14840.  
  14841. -- Function: get-lru-window 
  14842.  This function returns the window least recently ``used'' (that is, selected). 
  14843. The selected window is always the most recently used window. 
  14844.  
  14845.  The selected window can be the least recently used window if it is the only 
  14846. window.  A newly created window becomes the least recently used window until it 
  14847. is selected.  The minibuffer window is not considered a candidate. 
  14848.  
  14849. -- Function: get-largest-window 
  14850.  This function returns the window with the largest area (height times width). 
  14851. If there are no side-by-side windows, then this is the window with the most 
  14852. lines.  The minibuffer window is not considered a candidate. 
  14853.  
  14854.  If there are two windows of the same size, then the function returns the 
  14855. window which is first in the cyclic ordering of windows (see following 
  14856. section), starting from the selected window. 
  14857.  
  14858.  
  14859. ΓòÉΓòÉΓòÉ 28.5. Cycling Ordering of Windows ΓòÉΓòÉΓòÉ
  14860.  
  14861.  When you use the command C-x o (other-window) to select the next window, it 
  14862. moves through all the windows on the screen in a specific cyclic order.  For 
  14863. any given configuration of windows, this order never varies.  It is called the 
  14864. cyclic ordering of windows. 
  14865.  
  14866.  This ordering generally goes from top to bottom, and from left to right.  But 
  14867. it may go down first or go right first, depending on the order in which the 
  14868. screen, or the windows within the screen, were split. 
  14869.  
  14870.  If the screen was first split vertically (into windows one above each other), 
  14871. and then the subwindows were split horizontally, then the ordering is left to 
  14872. right in the top, and then left to right in the next lower part of the screen, 
  14873. and so on.  If the screen was first split horizontally, the ordering is top to 
  14874. bottom in the left part, and so on. In general, within each set of siblings at 
  14875. any level in the window tree, the order is left to right, or top to bottom. 
  14876.  
  14877. -- Function: next-window window &optional minibuf 
  14878. This function returns the window following window in the cyclic ordering of 
  14879. windows.  This is the window which C-x o would select if done when window is 
  14880. selected.  If window is the only window visible, then this function returns 
  14881. window. 
  14882.  
  14883. The value of the argument minibuf determines whether the minibuffer is included 
  14884. in the window order.  Normally, when minibuf is nil, the minibuffer is included 
  14885. if it is currently active; this is the behavior of C-x o. 
  14886.  
  14887. If minibuf is t, then the cyclic ordering includes the minibuffer window even 
  14888. if it is not active.  If minibuf is neither t nor nil, then the minibuffer 
  14889. window is not included even if it is active.  (The minibuffer window is active 
  14890. while the minibuffer is in use.  See Minibuffers.) 
  14891.  
  14892. This example shows two windows, which both happen to be displaying the same 
  14893. buffer: 
  14894.  
  14895. (selected-window)
  14896.      => #<window 56 on windows.texi>
  14897. (next-window (selected-window))
  14898.      => #<window 52 on windows.texi>
  14899. (next-window (next-window (selected-window)))
  14900.      => #<window 56 on windows.texi>
  14901.  
  14902. -- Function: previous-window window 
  14903.  This function returns the window preceding window in the cyclic ordering of 
  14904. windows. 
  14905.  
  14906. -- Command: other-window count 
  14907.  This function selects the countth next window in the cyclic order.  If count 
  14908. is negative, then it selects the -countth preceding window.  It returns nil. 
  14909.  
  14910.  In an interactive call, count is the numeric prefix argument. 
  14911.  
  14912.  
  14913. ΓòÉΓòÉΓòÉ 28.6. Buffers and Windows ΓòÉΓòÉΓòÉ
  14914.  
  14915.  This section describes low-level functions to examine windows or to show 
  14916. buffers in windows in a precisely controlled fashion. See Displaying Buffers, 
  14917. for related functions that find a window to use and specify a buffer for it. 
  14918. The functions described there are easier to use than these, but they employ 
  14919. heuristics in choosing or creating a window; use these functions when you need 
  14920. complete control. 
  14921.  
  14922. -- Function: set-window-buffer window buffer-or-name 
  14923.  This function makes window display buffer-or-name as its contents.  It returns 
  14924. nil. 
  14925.  
  14926. (set-window-buffer (selected-window) "foo")
  14927.      => nil
  14928.  
  14929. -- Function: window-buffer &optional window 
  14930.  This function returns the buffer that window is displaying.  If window is 
  14931. omitted, then this function returns the buffer for the selected window. 
  14932.  
  14933. (window-buffer)
  14934.      => #<buffer windows.texi>
  14935.  
  14936. -- Function: get-buffer-window buffer-or-name 
  14937.  This function returns a window currently displaying buffer-or-name, or nil if 
  14938. there is none.  If there are several such windows, then the function returns 
  14939. the first one in the cyclic ordering of windows, starting from the selected 
  14940. window. See Cyclic Window Ordering. 
  14941.  
  14942. -- Command: replace-buffer-in-windows buffer 
  14943.  This function replaces buffer with some other buffer in all windows displaying 
  14944. it.  The other buffer used is chosen with other-buffer.  In the usual 
  14945. applications of this function, you don't care which other buffer is used; you 
  14946. just want to make sure that buffer is off the screen. 
  14947.  
  14948.  This function returns nil. 
  14949.  
  14950.  
  14951. ΓòÉΓòÉΓòÉ 28.7. Displaying Buffers in Windows ΓòÉΓòÉΓòÉ
  14952.  
  14953.  In this section we describe convenient functions that choose a window 
  14954. automatically and use it to display a specified buffer.  These functions can 
  14955. also split an existing window in certain circumstances.  We also describe 
  14956. variables that parameterize the heuristics used for choosing a window. See 
  14957. Buffers and Windows, for low-level functions that give you more precise 
  14958. control. 
  14959.  
  14960.  Do not use the functions in this section in order to make a buffer current so 
  14961. that a Lisp program can access or modify it; they are too drastic for that 
  14962. purpose, since they change the display of buffers on the screen, which is 
  14963. gratuitous and will surprise the user.  Instead, use set-buffer (see Current 
  14964. Buffer) and save-excursion (see Excursions), which designate buffers as current 
  14965. for programmed access without affecting the display of buffers in windows. 
  14966.  
  14967. -- Command: switch-to-buffer buffer-or-name &optional norecord 
  14968.  This function makes buffer-or-name the current buffer, and also displays the 
  14969. buffer in the selected window.  This means that a human can see the buffer and 
  14970. subsequent keyboard commands will apply to it. Contrast this with set-buffer, 
  14971. which makes buffer-or-name the current buffer but does not display it in the 
  14972. selected window. See Current Buffer. 
  14973.  
  14974.  If buffer-or-name does not identify an existing buffer, then a new buffer by 
  14975. that name is created. 
  14976.  
  14977.  Normally the specified buffer is put at the front of the buffer list. This 
  14978. affects the operation of other-buffer.  However, if norecord is non-nil, this 
  14979. is not done. See The Buffer List. 
  14980.  
  14981.  The switch-to-buffer function is often used interactively, as the binding of 
  14982. C-x b.  It is also used frequently in programs.  It always returns nil. 
  14983.  
  14984. -- Command: switch-to-buffer-other-window buffer-or-name 
  14985.  This function makes buffer-or-name the current buffer and displays it in a 
  14986. window not currently selected.  It then selects that window.  The handling of 
  14987. the buffer is the same as in switch-to-buffer. 
  14988.  
  14989.  The previously selected window is absolutely never used to display the buffer. 
  14990. If it is the only window, then it is split to make a distinct window for this 
  14991. purpose.  If the selected window is already displaying the buffer, then it 
  14992. continues to do so, but another window is nonetheless found to display it in as 
  14993. well. 
  14994.  
  14995. -- Function: pop-to-buffer buffer-or-name &optional other-window 
  14996.  This function makes buffer-or-name the current buffer and switches to it in 
  14997. some window, preferably not the window previously selected.  The ``popped-to'' 
  14998. window becomes the selected window. 
  14999.  
  15000.  If the variable pop-up-windows is non-nil, windows may be split to create a 
  15001. new window that is different from the original window. 
  15002.  
  15003.  If other-window is non-nil, pop-to-buffer finds or creates another window even 
  15004. if buffer-or-name is already visible in the selected window.  Thus 
  15005. buffer-or-name could end up displayed in two windows.  On the other hand, if 
  15006. buffer-or-name is already displayed in the selected window and other-window is 
  15007. nil, then the selected window is considered sufficient display for 
  15008. buffer-or-name, so that nothing needs to be done. 
  15009.  
  15010.  If buffer-or-name is a string that does not name an existing buffer, a buffer 
  15011. by that name is created. 
  15012.  
  15013.  An example use of this function is found at the end of Filter Functions. 
  15014.  
  15015. -- Function: display-buffer buffer-or-name &optional not-this-window 
  15016.  This function makes buffer-or-name appear in some window, like pop-to-buffer, 
  15017. but it does not select that window and does not make the buffer current.  The 
  15018. identity of the selected window is unaltered by this function. 
  15019.  
  15020.  If not-this-window is non-nil, it means that the specified buffer should be 
  15021. displayed in a window other than the selected one, even if it is already on 
  15022. display in the selected window.  This can cause the buffer to appear in two 
  15023. windows at once.  Otherwise, if buffer-or-name is already being displayed in 
  15024. any window, that is good enough, so this function does nothing. 
  15025.  
  15026.  If the variable pop-up-windows is non-nil, windows can be split to display the 
  15027. buffer.  If there are multiple windows, display-buffer will split the largest 
  15028. window if it has more than the number of lines specified by the variable 
  15029. split-height-threshold. 
  15030.  
  15031.  display-buffer returns the window chosen to display buffer-or-name. 
  15032.  
  15033. -- User Option: pop-up-windows 
  15034.  This variable controls whether display-buffer makes new windows.  If it is 
  15035. non-nil and there is only one window on the screen, then that window is split. 
  15036. If it is nil, then display-buffer does not split the single window, but rather 
  15037. replaces its buffer. 
  15038.  
  15039.  This variable also affects pop-to-buffer, which uses display-buffer as a 
  15040. subroutine. 
  15041.  
  15042. -- User Option: split-height-threshold 
  15043.  This variable determines when display-buffer may split a window, if there are 
  15044. multiple windows.  display-buffer splits the largest window if it has at least 
  15045. this many lines. 
  15046.  
  15047.  If there is only one window, it is split regardless of this value, provided 
  15048. pop-up-windows is non-nil. 
  15049.  
  15050.  
  15051. ΓòÉΓòÉΓòÉ 28.8. Window Point ΓòÉΓòÉΓòÉ
  15052.  
  15053.  Each window has its own value of point, independent of the value of point in 
  15054. other windows displaying the same buffer.  This makes it useful to have 
  15055. multiple windows showing one buffer. 
  15056.  
  15057. o The window point is established when a window is first created; it is 
  15058.   initialized from the buffer's point, or from the window point of another 
  15059.   window opened on the buffer if such a window exists. 
  15060.  
  15061. o Selecting a window sets the value of point in its buffer to the window's 
  15062.   value of point.  Conversely, deselecting a window copies the buffer's value 
  15063.   of point into the window.  Thus, when you switch between windows that display 
  15064.   a given buffer, the point value for the selected window is in effect in the 
  15065.   buffer, while the point values for the other windows are stored in those 
  15066.   windows. 
  15067.  
  15068. o As long as the selected window displays the current buffer, the window's 
  15069.   point and the buffer's point always move together; they remain equal. 
  15070.  
  15071. o See Positions, for more details on positions. 
  15072.  
  15073.  As far as the user is concerned, point is where the cursor is, and when the 
  15074. user switches to another buffer, the cursor jumps to the position of point in 
  15075. that buffer. 
  15076.  
  15077. -- Function: window-point window 
  15078.  This function returns the current position of point in window. For a 
  15079. nonselected window, this is the value point would have (in that window's 
  15080. buffer) if that window were selected. 
  15081.  
  15082.  When window is the selected window and its buffer is also the current buffer, 
  15083. the value returned is the same as point in that buffer. 
  15084.  
  15085.  Strictly speaking, it would be more correct to return the ``top-level'' value 
  15086. of point, outside of any save-excursion forms.  But that value is hard to find. 
  15087.  
  15088. -- Function: set-window-point window position 
  15089.  This function positions point in window at position position in window's 
  15090. buffer. 
  15091.  
  15092.  
  15093. ΓòÉΓòÉΓòÉ 28.9. The Display-Start Position ΓòÉΓòÉΓòÉ
  15094.  
  15095.  Each window contains a marker used to keep track of a buffer position which 
  15096. specifies where in the buffer display should start.  This position is called 
  15097. the display-start position of the window.  The character after this position is 
  15098. the one that appears at the upper left corner of the window.  It is usually, 
  15099. but not inevitably, at the beginning of a text line. 
  15100.  
  15101. -- Function: window-start &optional window 
  15102.  This function returns the display-start position of window window.  If window 
  15103. is nil, the selected window is used. 
  15104.  
  15105. (window-start)
  15106.      => 7058
  15107.  
  15108.  For a more complicated example of use, see the description of count-lines in 
  15109. Text Lines. 
  15110.  
  15111. -- Function: set-window-start window position &optional noforce 
  15112.  This function sets the display-start position of window to position in 
  15113. window's buffer. 
  15114.  
  15115.  The display routines insist that the position of point be visible when a 
  15116. buffer is displayed.  Normally, they change the display-start position (that 
  15117. is, scroll the window) whenever necessary to make point visible. However, if 
  15118. you specify the start position with this function with nil for noforce, it 
  15119. means you want display to start at position even if that would put the location 
  15120. of point off the screen.  What the display routines do in this case is move 
  15121. point instead, to the left margin on the middle line in the window. 
  15122.  
  15123.  For example, if point is 1 and you attempt to set the start of the window to 
  15124. 2, then the position of point would be ``above'' the top of the window.  The 
  15125. display routines would automatically move point if it is still 1 when redisplay 
  15126. occurs.  Here is an example: 
  15127.  
  15128. ;; Here is what `foo' looks like before executing
  15129. ;; the set-window-start expression.
  15130.  
  15131. ---------- Buffer: foo ----------
  15132. -!-This is the contents of buffer foo.
  15133. 2
  15134. 3
  15135. 4
  15136. 5
  15137. 6
  15138. ---------- Buffer: foo ----------
  15139.  
  15140. (set-window-start (selected-window) (1+ (window-start)))
  15141.  
  15142. ;; Here is what `foo' looks like after executing
  15143. ;; the set-window-start expression.
  15144.  
  15145. ---------- Buffer: foo ----------
  15146. his is the contents of buffer foo.
  15147. 2
  15148. 3
  15149. -!-4
  15150. 5
  15151. 6
  15152. ---------- Buffer: foo ----------
  15153.  
  15154.      => 2
  15155.  
  15156.  However, when noforce is non-nil, set-window-start does nothing if the 
  15157. specified start position would make point invisible. 
  15158.  
  15159.  This function returns position, regardless of whether the noforce option 
  15160. caused that position to be overruled. 
  15161.  
  15162. -- Function: pos-visible-in-window-p &optional position window 
  15163.  This function returns t if position is within the range of text currently 
  15164. visible on the screen in window.  It returns nil if position is scrolled 
  15165. vertically out of view.  The argument position defaults to the current position 
  15166. of point; window, to the selected window.  Here is an example: 
  15167.  
  15168. (or (pos-visible-in-window-p (point) (selected-window))
  15169.     (recenter 0))
  15170.  
  15171.  The pos-visible-in-window-p function considers only vertical scrolling.  It 
  15172. returns t if position is out of view only because window has been scrolled 
  15173. horizontally. See Horizontal Scrolling. 
  15174.  
  15175.  
  15176. ΓòÉΓòÉΓòÉ 28.10. Vertical Scrolling ΓòÉΓòÉΓòÉ
  15177.  
  15178.  Vertical scrolling means moving the text up or down in a window.  It works by 
  15179. changing the value of the window's display-start location.  It may also change 
  15180. the value of window-point to keep it on the screen. 
  15181.  
  15182.  In the commands scroll-up and scroll-down, the directions ``up'' and ``down'' 
  15183. refer to the motion of the text in the buffer at which you are looking through 
  15184. the window.  Imagine that the text is written on a long roll of paper and that 
  15185. the scrolling commands move the paper up and down.  Thus, if you are looking at 
  15186. text in the middle of a buffer and repeatedly call scroll-down, you will 
  15187. eventually see the beginning of the buffer. 
  15188.  
  15189.  Some people have urged that the opposite convention be used: they imagine that 
  15190. the window moves over text that remains in place.  Then ``down'' commands would 
  15191. take you to the end of the buffer.  This view is more consistent with the 
  15192. actual relationship between windows and the text in the buffer, but it is less 
  15193. like what the user sees.  The position of a window on the terminal does not 
  15194. move, and short scrolling commands clearly move the text up or down on the 
  15195. screen.  We have chosen names that fit the user's point of view. 
  15196.  
  15197.  The scrolling functions (aside from scroll-other-window) will have 
  15198. unpredictable results if the current buffer is different from the buffer that 
  15199. is displayed in the selected window. See Current Buffer. 
  15200.  
  15201. -- Command: scroll-up &optional count 
  15202.  This function scrolls the text in the selected window upward count lines.  If 
  15203. count is negative, scrolling is actually downward. 
  15204.  
  15205.  If count is nil (or omitted), then the length of the scroll is 
  15206. next-screen-context-lines lines less than the usable height of the window (not 
  15207. counting its mode line). 
  15208.  
  15209.  scroll-up returns nil. 
  15210.  
  15211. -- Command: scroll-down &optional count 
  15212.  This function scrolls the text in the selected window downward count lines. 
  15213. If count is negative, scrolling is actually upward. 
  15214.  
  15215.  If count is omitted or nil, then the length of the scroll is 
  15216. next-screen-context-lines lines less than the usable height of the window. 
  15217.  
  15218.  scroll-down returns nil. 
  15219.  
  15220. -- Command: scroll-other-window &optional count 
  15221.  This function scrolls the text in another window upward count lines.  Negative 
  15222. values of count, or nil, are handled as in scroll-up. 
  15223.  
  15224.  The window that is scrolled is normally the one following the selected window 
  15225. in the cyclic ordering of windows---the window that next-window would return. 
  15226. See Cyclic Window Ordering. 
  15227.  
  15228.  If the selected window is the minibuffer, the next window is normally the one 
  15229. at the top left corner.  However, you can specify the window to scroll by 
  15230. binding the variable minibuffer-scroll-window.  This variable has no effect 
  15231. when any other window is selected. See Minibuffer Misc. 
  15232.  
  15233.  When the minibuffer is active, it is the next window if the selected window is 
  15234. the one at the bottom right corner.  In this case, scroll-other-window will 
  15235. attempt to scroll the minibuffer.  If the minibuffer contains just one line, 
  15236. that line will be redisplayed after the echo area momentarily displays the 
  15237. message ``Beginning of buffer''. 
  15238.  
  15239. -- User Option: scroll-step 
  15240. This variable controls how scrolling is done automatically when point moves off 
  15241. the screen.  If the value is zero, then the text is scrolled so that point is 
  15242. centered vertically in the window.  If the value is a positive integer n, then 
  15243. if it is possible to bring point back on screen by scrolling n lines in either 
  15244. direction, that is done; otherwise, point is centered vertically as usual.  The 
  15245. default value is zero. 
  15246.  
  15247. -- User Option: next-screen-context-lines 
  15248.  The value of this variable is the number of lines of continuity to retain when 
  15249. scrolling by full screens.  For example, when scroll-up executes, this many 
  15250. lines that were visible at the bottom of the window move to the top of the 
  15251. window.  The default value is 2. 
  15252.  
  15253. -- Command: recenter &optional count 
  15254.  This function scrolls the selected window to put the text where point is 
  15255. located at a specified screen position. 
  15256.  
  15257.  If count is a nonnegative number, it puts the line containing point count 
  15258. lines down from the top of the window.  If count is a negative number, then it 
  15259. counts upward from the bottom of the window, so that -1 stands for the last 
  15260. usable line in the window. If count is a non-nil list, then it stands for the 
  15261. line in the middle of the window. 
  15262.  
  15263.  If count is nil, then it puts the line containing point in the middle of the 
  15264. window, then clears and redisplays the entire screen. 
  15265.  
  15266.  When recenter is called interactively, Emacs sets count to the raw prefix 
  15267. argument.  Thus, typing C-u as the prefix sets the count to a non-nil list, 
  15268. while typing C-u 4 sets count to 4, which positions the current line four lines 
  15269. from the top. 
  15270.  
  15271.  Typing C-u 0 C-l positions the current line at the top of the window.  This 
  15272. action is so handy that some people bind the command to a function key.  For 
  15273. example, 
  15274.  
  15275. (defun line-to-top-of-window ()
  15276.   "Scroll the selected window up so current line moves to the top.
  15277. Replaces three keystroke sequence C-u 0 C-l."
  15278.   (interactive)
  15279.   (recenter 0))
  15280.  
  15281. (global-set-key "\C-cl" 'line-to-top-of-window)
  15282.  
  15283.  
  15284. ΓòÉΓòÉΓòÉ 28.11. Horizontal Scrolling ΓòÉΓòÉΓòÉ
  15285.  
  15286.  Because we read English first from top to bottom and second from left to 
  15287. right, horizontal scrolling is not like vertical scrolling.  Vertical scrolling 
  15288. involves selection of a contiguous portion of text to display. Horizontal 
  15289. scrolling causes part of each line to go off screen.  The amount of horizontal 
  15290. scrolling is therefore specified as a number of columns rather than as a 
  15291. position in the buffer.  It has nothing to do with the display-start position 
  15292. returned by window-start. 
  15293.  
  15294.  Usually, no horizontal scrolling is in effect; then the leftmost column is at 
  15295. the left edge of the window.  In this state, scrolling to the right is 
  15296. meaningless, since there is no data to the left of the screen to be revealed by 
  15297. it, so it is not allowed.  Scrolling to the left is allowed; it causes the 
  15298. first columns of text to go off the edge of the window and can reveal 
  15299. additional columns on the right that were truncated before.  Once a window has 
  15300. a nonzero amount of leftward horizontal scrolling, you can scroll it back to 
  15301. the right, but only so far as to reduce the net horizontal scroll to zero. 
  15302. There is no limit to how far left you can scroll, but eventually all the text 
  15303. will disappear off the left edge. 
  15304.  
  15305. -- Command: scroll-left count 
  15306.  This function scrolls the selected window count columns to the left (or to the 
  15307. right if count is negative).  The return value is the total amount of leftward 
  15308. horizontal scrolling in effect after the change---just like the value returned 
  15309. by window-hscroll. 
  15310.  
  15311. -- Command: scroll-right count 
  15312.  This function scrolls the selected window count columns to the right  (or to 
  15313. the left if count is negative).  The return value is the total amount of 
  15314. leftward horizontal scrolling in effect after the change---just like the value 
  15315. returned by window-hscroll. 
  15316.  
  15317.  Once you scroll a window as far right as it can go, back to its normal 
  15318. position where the total leftward scrolling is zero, attempts to scroll any 
  15319. farther have no effect. 
  15320.  
  15321. -- Function: window-hscroll &optional window 
  15322.  This function returns the total leftward horizontal scrolling of window---the 
  15323. number of columns by which the text in window is scrolled left past the left 
  15324. margin. 
  15325.  
  15326.  The value is never negative.  It is zero when no horizontal scrolling has been 
  15327. done in window (which is usually the case). 
  15328.  
  15329.  If window is nil, the selected window is used. 
  15330.  
  15331. (window-hscroll)
  15332.      => 0
  15333. (scroll-left 5)
  15334.      => 5
  15335. (window-hscroll)
  15336.      => 5
  15337.  
  15338. -- Function: set-window-hscroll window columns 
  15339.  This function sets the number of columns from the left margin that window is 
  15340. scrolled to the value of columns.  The argument columns should be zero or 
  15341. positive; if not, it is taken as zero. 
  15342.  
  15343.  The value returned is columns. 
  15344.  
  15345. (set-window-hscroll (selected-window) 10)
  15346.      => 10
  15347.  
  15348.  Here is how you can determine whether a given position position is off the 
  15349. screen due to horizontal scrolling: 
  15350.  
  15351. (save-excursion
  15352.   (goto-char position)
  15353.   (and
  15354.    (>= (- (current-column) (window-hscroll window)) 0)
  15355.    (< (- (current-column) (window-hscroll window))
  15356.       (window-width window))))
  15357.  
  15358.  
  15359. ΓòÉΓòÉΓòÉ 28.12. The Size of a Window ΓòÉΓòÉΓòÉ
  15360.  
  15361.  An Emacs window is rectangular, and its size information consists of the 
  15362. height (the number of lines) and the width (the number of character positions 
  15363. in each line).  The mode line is included in the height.  For a window that 
  15364. does not abut the right hand edge of the screen, the column of `|' characters 
  15365. that separates it from the window on the right is included in the width. 
  15366.  
  15367.  The following three functions return size information about a window: 
  15368.  
  15369. -- Function: window-height &optional window 
  15370.  This function returns the number of lines in window, including its mode line. 
  15371. If window fills the entire screen, this is one less than the value of 
  15372. (screen-height) (since the last line is always reserved for the minibuffer). 
  15373.  
  15374.  If window is nil, the function uses the selected window. 
  15375.  
  15376. (window-height)
  15377.      => 23
  15378. (split-window-vertically)
  15379.      => #<window 4 on windows.texi>
  15380. (window-height)
  15381.      => 11
  15382.  
  15383. -- Function: window-width &optional window 
  15384.  This function returns the number of columns in window.  If window fills the 
  15385. entire screen, this is the same as the value of (screen-width). 
  15386.  
  15387.  If window is nil, the function uses the selected window. 
  15388.  
  15389. (window-width)
  15390.      => 80
  15391.  
  15392. -- Function: window-edges &optional window 
  15393.  This function returns a list of the edge coordinates of window. If window is 
  15394. nil, the selected window is used. 
  15395.  
  15396.  The order of the list is (left top right bottom), all elements relative to 0, 
  15397. 0 at the top left corner of the screen.  The element right of the value is one 
  15398. more than the rightmost column used by window, and bottom is one more than the 
  15399. bottommost row used by window and its mode-line. 
  15400.  
  15401.  Here is the result obtained on a typical 24-line terminal with just one 
  15402. window: 
  15403.  
  15404. (window-edges (selected-window))
  15405.      => (0 0 80 23)
  15406.  
  15407.  If window is at the upper left corner of the screen, right and bottom are the 
  15408. same as the values returned by (window-width) and (window-height) respectively, 
  15409. and top and bottom are zero.  For example, the edges of the following window 
  15410. are `0 0 5 8'.  Assuming that the screen has more than 8 columns, the last 
  15411. column of the window (column 7) holds a border rather than text.  The last row 
  15412. (row 4) holds the mode line, shown here with `xxxxxxxxx'. 
  15413.  
  15414.            0
  15415.            _______
  15416.         0 |       |
  15417.           |       |
  15418.           |       |
  15419.           |       |
  15420.           xxxxxxxxx  4
  15421.  
  15422.                   7
  15423.  
  15424.  When there are side-by-side windows, any window not at the right edge of the 
  15425. screen has a border in its last column.  This border counts as one column in 
  15426. the width of the window.  A window never includes a border on its left, since 
  15427. the border there belongs to the window to the left. 
  15428.  
  15429.  In the following example, let's imagine that the screen is 7 columns wide. 
  15430. Then the edges of the left window are `0 0 4 3' and the edges of the right 
  15431. window are `4 0 7 3'. 
  15432.  
  15433.            ___ ___
  15434.           |   |   |
  15435.           |   |   |
  15436.           xxxxxxxxx
  15437.  
  15438.            0  34  7
  15439.  
  15440.  
  15441. ΓòÉΓòÉΓòÉ 28.13. Changing the Size of a Window ΓòÉΓòÉΓòÉ
  15442.  
  15443.  The window size functions fall into two classes: high-level commands that 
  15444. change the size of windows and low-level functions that access window size. 
  15445. Emacs does not permit overlapping windows or gaps between windows, so resizing 
  15446. one window affects other windows. 
  15447.  
  15448. -- Command: enlarge-window size &optional horizontal 
  15449.  This function makes the selected window size lines bigger, stealing lines from 
  15450. neighboring windows.  It generally tries to steal equal numbers of lines from 
  15451. the other windows.  If a window from which lines are stolen shrinks below 
  15452. window-min-height, then that window disappears. 
  15453.  
  15454.  If horizontal is non-nil, then this function makes window wider by size 
  15455. columns, stealing columns as it does lines.  If a window from which lines are 
  15456. stolen shrinks below window-min-width, then that window disappears. 
  15457.  
  15458.  If the screen is smaller than size lines (or columns), then the function makes 
  15459. the window occupy the entire height (or width) of the screen. 
  15460.  
  15461.  If size is negative, this function shrinks the window by -size lines.  If it 
  15462. becomes shorter than window-min-height, it disappears. 
  15463.  
  15464.  enlarge-window returns nil. 
  15465.  
  15466. -- Command: enlarge-window-horizontally columns 
  15467.  This function makes the selected window columns wider. It could be defined as 
  15468. follows: 
  15469.  
  15470. (defun enlarge-window-horizontally (columns)
  15471.   (enlarge-window columns t))
  15472.  
  15473. -- Command: shrink-window size &optional horizontal 
  15474.  This function is like enlarge-window but negates the argument size, making the 
  15475. selected window smaller by giving lines (or columns) to the other windows.  If 
  15476. the window shrinks below window-min-height or window-min-width, then it 
  15477. disappears. 
  15478.  
  15479. If size is negative, the window is enlarged by -size lines. 
  15480.  
  15481. -- Command: shrink-window-horizontally columns 
  15482.  This function makes the selected window columns narrower. It could be defined 
  15483. as follows: 
  15484.  
  15485. (defun shrink-window-horizontally (columns)
  15486.   (shrink-window columns t))
  15487.  
  15488.  The following two variables constrain the window size changing functions to a 
  15489. minimum height and width. 
  15490.  
  15491. -- User Option: window-min-height 
  15492.  The value of this variable determines how short a window may become before it 
  15493. disappears.  A window disappears when it becomes smaller than 
  15494. window-min-height, and no window may be created that is smaller. The absolute 
  15495. minimum height is two (allowing one line for the mode line, and one line for 
  15496. the buffer display).  Actions which change window sizes reset this variable to 
  15497. two if it is less than two.  The default value is 4. 
  15498.  
  15499. -- User Option: window-min-width 
  15500.  The value of this variable determines how narrow a window may become before it 
  15501. disappears.  A window disappears when it becomes narrower than 
  15502. window-min-width, and no window may be created that is narrower. The absolute 
  15503. minimum width is one; any value below that is ignored.  The default value is 
  15504. 10. 
  15505.  
  15506.  
  15507. ΓòÉΓòÉΓòÉ 28.14. Window Configurations ΓòÉΓòÉΓòÉ
  15508.  
  15509.  Window configurations record entire screen layouts---all windows, their sizes, 
  15510. which buffers they contain, what part of each buffer is displayed, and the 
  15511. values of point and the mark.  You can bring back an entire previous screen 
  15512. layout by restoring a window configuration that you had previously saved. 
  15513.  
  15514. -- Function: current-window-configuration 
  15515.  This function returns a new object representing Emacs's current window 
  15516. configuration, namely the number of windows, their sizes and current buffers, 
  15517. which window is the selected window, and for each window the displayed buffer, 
  15518. the display-start position, and the positions of point and the mark.  An 
  15519. exception is made for point in the current buffer, whose value is not saved. 
  15520.  
  15521. -- Function: set-window-configuration configuration 
  15522.  This function restores the configuration of Emacs's windows and buffers to the 
  15523. state specified by configuration.  The argument configuration must be a value 
  15524. that was previously returned by current-window-configuration. 
  15525.  
  15526.  Here is a way of using this function to get the same effect as 
  15527. save-window-excursion: 
  15528.  
  15529. (let ((config (current-window-configuration)))
  15530.   (unwind-protect
  15531.       (progn (split-window-vertically nil)
  15532.              ...)
  15533.     (set-window-configuration config)))
  15534.  
  15535. -- Special Form: save-window-excursion forms... 
  15536.  This special form executes forms in sequence, preserving window sizes and 
  15537. contents, including the value of point and the portion of the buffer which is 
  15538. visible.  However, it does not restore the value of point in the current 
  15539. buffer; use save-excursion for that. 
  15540.  
  15541.  The return value is the value of the final form in forms. For example: 
  15542.  
  15543. (split-window)
  15544.      => #<window 25 on control.texi>
  15545. (setq w (selected-window))
  15546.      => #<window 19 on control.texi>
  15547. (save-window-excursion
  15548.   (delete-other-windows w)
  15549.   (switch-to-buffer "foo")
  15550.   'do-something)
  15551.      => do-something
  15552.   ;; The screen is now split again.
  15553.  
  15554.  Primitives to look inside of window configurations would make sense, but none 
  15555. are implemented.  It is not clear they are useful enough to be worth 
  15556. implementing. 
  15557.  
  15558.  
  15559. ΓòÉΓòÉΓòÉ 29. Positions ΓòÉΓòÉΓòÉ
  15560.  
  15561.  A position is the index of a character in the text of buffer. More precisely, 
  15562. a position identifies the place between two characters (or before the first 
  15563. character, or after the last character), so we can speak of the character 
  15564. before or after a given position.  However, the character after a position is 
  15565. often said to be ``at'' that position. 
  15566.  
  15567.  Positions are usually represented as integers starting from 1, but can also be 
  15568. represented as markers---special objects which relocate automatically when text 
  15569. is inserted or deleted so they stay with the surrounding characters.  See 
  15570. Markers. 
  15571.  
  15572.  
  15573. ΓòÉΓòÉΓòÉ 29.1. Point ΓòÉΓòÉΓòÉ
  15574.  
  15575.  Point is a special buffer position used by many editing commands, including 
  15576. the self-inserting typed characters and text insertion functions.  Other 
  15577. commands move point through the text to allow editing and insertion at 
  15578. different places. 
  15579.  
  15580.  Like other positions, point designates a place between two characters (or 
  15581. before the first character, or after the last character), rather than a 
  15582. particular character.  Many terminals display the cursor over the character 
  15583. that immediately follows point; on such terminals, point is actually before the 
  15584. character on which the cursor sits. 
  15585.  
  15586.  The value of point is a number between 1 and the buffer size plus 1. If 
  15587. narrowing is in effect (see Narrowing), then point is constrained to fall 
  15588. within the accessible portion of the buffer (possibly at one end of it). 
  15589.  
  15590.  Each buffer has its own value of point, which is independent of the value of 
  15591. point in other buffers.  Each window also has a value of point, which is 
  15592. independent of the value of point in other windows on the same buffer.  This is 
  15593. why point can have different values in various windows that display the same 
  15594. buffer.  When a buffer appears in only one window, the buffer's point and the 
  15595. window's point normally have the same value, so the distinction is rarely 
  15596. important.  See Window Point, for more details. 
  15597.  
  15598. -- Function: point 
  15599.  This function returns the position of point in the current buffer, as an 
  15600. integer. 
  15601.  
  15602. (point)
  15603.      => 175
  15604.  
  15605. -- Function: point-min 
  15606.  This function returns the minimum accessible value of point in the current 
  15607. buffer.  This is 1, unless narrowing is in effect, in which case it is the 
  15608. position of the start of the region that you narrowed to.  (See Narrowing.) 
  15609.  
  15610. -- Function: point-max 
  15611.  This function returns the maximum accessible value of point in the current 
  15612. buffer.  This is (1+ (buffer-size)), unless narrowing is in effect, in which 
  15613. case it is the position of the end of the region that you narrowed to.  (See 
  15614. Narrowing). 
  15615.  
  15616. -- Function: buffer-end flag 
  15617.  This function returns (point-min) if flag is less than 1, (point-max) 
  15618. otherwise.  The argument flag must be a number. 
  15619.  
  15620. -- Function: buffer-size 
  15621.  This function returns the total number of characters in the current buffer. 
  15622. In the absence of any narrowing (see Narrowing), point-max returns a value one 
  15623. larger than this. 
  15624.  
  15625. (buffer-size)
  15626.      => 35
  15627. (point-max)
  15628.      => 36
  15629.  
  15630. -- Variable: buffer-saved-size 
  15631.  The value of this buffer-local variable is the former length of the current 
  15632. buffer, as of the last time it was read in, saved or auto-saved. 
  15633.  
  15634.  
  15635. ΓòÉΓòÉΓòÉ 29.2. Motion ΓòÉΓòÉΓòÉ
  15636.  
  15637.  Motion functions change the value of point, either relative to the current 
  15638. value of point, relative to the beginning or end of the buffer, or relative to 
  15639. the edges of the selected window. 
  15640.  
  15641.  
  15642. ΓòÉΓòÉΓòÉ 29.2.1. Motion by Characters ΓòÉΓòÉΓòÉ
  15643.  
  15644.  These functions move point based on a count of characters. goto-char is a 
  15645. fundamental primitive because it is the way to move point to a specified 
  15646. position. 
  15647.  
  15648. -- Command: goto-char position 
  15649. This function sets point in the current buffer to the value position.  If 
  15650. position is less than 1, then point is set to the beginning of the buffer.  If 
  15651. it is greater than the length of the buffer, then point is set to the end of 
  15652. the buffer. 
  15653.  
  15654. If narrowing is in effect, then the position is still measured from the 
  15655. beginning of the buffer, but point cannot be moved outside of the accessible 
  15656. portion.  Therefore, if position is too small, point is set to the beginning of 
  15657. the accessible portion of the text; if position is too large, point is set to 
  15658. the end. 
  15659.  
  15660. When this function is called interactively, position is the numeric prefix 
  15661. argument, if provided; otherwise it is read from the minibuffer. 
  15662.  
  15663. goto-char returns position. 
  15664.  
  15665. -- Command: forward-char &optional count 
  15666. This function moves point forward, towards the end of the buffer, count 
  15667. characters (or backward, towards the beginning of the buffer, if count is 
  15668. negative).  If the function attempts to move point past the beginning or end of 
  15669. the buffer (or the limits of the accessible portion, when narrowing is in 
  15670. effect), an error is signaled with error code beginning-of-buffer or 
  15671. end-of-buffer. 
  15672.  
  15673. In an interactive call, count is the numeric prefix argument. 
  15674.  
  15675. -- Command: backward-char &optional count 
  15676. This function moves point backward, towards the beginning of the buffer, count 
  15677. characters (or forward, towards the end of the buffer, if count is negative). 
  15678. If the function attempts to move point past the beginning or end of the buffer 
  15679. (or the limits of the accessible portion, when narrowing is in effect), an 
  15680. error is signaled with error code beginning-of-buffer or end-of-buffer. 
  15681.  
  15682. In an interactive call, count is the numeric prefix argument. 
  15683.  
  15684.  
  15685. ΓòÉΓòÉΓòÉ 29.2.2. Motion by Words ΓòÉΓòÉΓòÉ
  15686.  
  15687.  These functions for parsing words use the syntax table to decide whether a 
  15688. given character is part of a word.  See Syntax Tables. 
  15689.  
  15690. -- Command: forward-word count 
  15691. This function moves point forward count words (or backward if count is 
  15692. negative).  Normally it returns t.  If this motion encounters the beginning or 
  15693. end of the buffer, or the limits of the accessible portion when narrowing is in 
  15694. effect, point stops there and the value is nil. 
  15695.  
  15696. In an interactive call, count is set to the numeric prefix argument. 
  15697.  
  15698. -- Command: backward-word count 
  15699. This function just like forward-word, except that it moves backward until 
  15700. encountering the front of a word, rather than forward. 
  15701.  
  15702. In an interactive call, count is set to the numeric prefix argument. 
  15703.  
  15704. This function is rarely used in programs, as it is more efficient to call 
  15705. forward-word with negative argument. 
  15706.  
  15707.  
  15708. ΓòÉΓòÉΓòÉ 29.2.3. Motion to an End of the Buffer ΓòÉΓòÉΓòÉ
  15709.  
  15710.  To move point to the beginning of the buffer, write: 
  15711.  
  15712. (goto-char (point-min))
  15713.  
  15714. Likewise, to move to the end of the buffer, use: 
  15715.  
  15716. (goto-char (point-max))
  15717.  
  15718.  Here are two commands which users use to do these things.  They are documented 
  15719. here to warn you not to use them in Lisp programs, because they set the mark 
  15720. and display messages in the echo area. 
  15721.  
  15722. -- Command: beginning-of-buffer &optional n 
  15723. This function moves point to the beginning of the buffer (or the limits of the 
  15724. accessible portion, when narrowing is in effect), setting the mark at the 
  15725. previous position.  If n is non-nil, then it puts point n tenths of the way 
  15726. from the beginning of the buffer. 
  15727.  
  15728. In an interactive call, n is the numeric prefix argument, if provided; 
  15729. otherwise n defaults to nil. 
  15730.  
  15731. Don't use this function in Lisp programs! 
  15732.  
  15733. -- Command: end-of-buffer &optional n 
  15734. This function moves point to the end of the buffer (or the limits of the 
  15735. accessible portion, when narrowing is in effect), setting the mark at the 
  15736. previous position.  If n is non-nil, then it puts point n tenths of the way 
  15737. from the end. 
  15738.  
  15739. In an interactive call, n is the numeric prefix argument, if provided; 
  15740. otherwise n defaults to nil. 
  15741.  
  15742. Don't use this function in Lisp programs! 
  15743.  
  15744.  
  15745. ΓòÉΓòÉΓòÉ 29.2.4. Motion by Text Lines ΓòÉΓòÉΓòÉ
  15746.  
  15747.  Text lines are portions of the buffer delimited by newline characters, which 
  15748. are regarded as part of the previous line.  The first text line begins at the 
  15749. beginning of the buffer, and the last text line ends at the end of the buffer 
  15750. whether or not the last character is a newline. The division of the buffer into 
  15751. text lines is not affected by the width of the window, or by how tabs and 
  15752. control characters are displayed. 
  15753.  
  15754. -- Command: goto-line line 
  15755. This function moves point to the front of the lineth line, counting from line 1 
  15756. at beginning of buffer.  If line is less than 1, then point is set to the 
  15757. beginning of the buffer.  If line is greater than the number of lines in the 
  15758. buffer, then point is set to the end of the last line of the buffer. 
  15759.  
  15760. If narrowing is in effect, then line still counts from the beginning of the 
  15761. buffer, but point cannot go outside the accessible portion.  So point is set at 
  15762. the beginning or end of the accessible portion of the text if the line number 
  15763. specifies a position that is inaccessible. 
  15764.  
  15765. The return value of goto-line is the difference between line and the line 
  15766. number of the line to which point actually was able move (before taking account 
  15767. of any narrowing).  Thus, the value is positive if the scan encounters the end 
  15768. of the buffer. 
  15769.  
  15770. In an interactive call, line is the numeric prefix argument if one has been 
  15771. provided.  Otherwise line is read in the minibuffer. 
  15772.  
  15773. -- Command: beginning-of-line &optional count 
  15774. This function moves point to the beginning of the current line.  With an 
  15775. argument count not nil or 1, it moves forward count-1 lines and then to the 
  15776. beginning of the line. 
  15777.  
  15778. If this function reaches the end of the buffer (or of the accessible portion, 
  15779. if narrowing is in effect), it positions point at the beginning of the last 
  15780. line.  No error is signaled. 
  15781.  
  15782. -- Command: end-of-line &optional count 
  15783. This function moves point to the end of the current line.  With an argument 
  15784. count not nil or 1, it moves forward count-1 lines and then to the end of the 
  15785. line. 
  15786.  
  15787. If this function reaches the end of the buffer (or of the accessible portion, 
  15788. if narrowing is in effect), it positions point at the end of the last line.  No 
  15789. error is signaled. 
  15790.  
  15791. -- Command: forward-line &optional count 
  15792. This function moves point forward count lines, to the beginning of the line. 
  15793. If count is negative, it moves point -count lines backward, to the beginning of 
  15794. the line. 
  15795.  
  15796. If the beginning or end of the buffer (or of the accessible portion) is 
  15797. encountered before that many lines are found, then point stops at the beginning 
  15798. or end.  No error is signaled. 
  15799.  
  15800. forward-line returns the difference between count and the number of lines 
  15801. actually moved.  If you attempt to move down five lines from the beginning of a 
  15802. buffer that has only three lines, point will positioned at the end of the last 
  15803. line, and the value will be 2. 
  15804.  
  15805. In an interactive call, count is the numeric prefix argument. 
  15806.  
  15807. -- Function: count-lines start end 
  15808. This function returns the number of lines between the positions start and end 
  15809. in the current buffer.  If start and end are equal, then it returns 0. 
  15810. Otherwise it returns at least 1, even if start and end are on the same line. 
  15811. This is because the text between them, considered in isolation, must contain at 
  15812. least one line unless it is empty. 
  15813.  
  15814. Here is an example of using count-lines: 
  15815.  
  15816. (defun current-line ()
  15817.   "Return the vertical position of point in the selected window.
  15818. Top line is 0.  Counts each text line only once, even if it wraps."
  15819.   (+ (count-lines (window-start) (point))
  15820.      (if (= (current-column) 0) 1 0)
  15821.      -1))
  15822.  Also see the functions bolp and eolp in Near Point. 
  15823.  
  15824. These functions do not move point, but test whether it is already at the 
  15825. beginning or end of a line. 
  15826.  
  15827.  
  15828. ΓòÉΓòÉΓòÉ 29.2.5. Motion by Screen Lines ΓòÉΓòÉΓòÉ
  15829.  
  15830.  The line functions in the previous section count text lines, delimited only by 
  15831. newline characters.  By contrast, these functions count screen lines, which are 
  15832. defined by the way the text appears on the screen.  A text line is a single 
  15833. screen line if it is short enough to fit the width of the selected window, but 
  15834. otherwise it may occupy several screen lines. 
  15835.  
  15836.  In some cases, text lines are truncated on the screen rather than continued 
  15837. onto additional screen lines.  Then vertical-motion moves point just like 
  15838. forward-line.  See Truncation. 
  15839.  
  15840.  Because the width of a given string depends on the flags which control the 
  15841. appearance of certain characters, vertical-motion will behave differently on a 
  15842. given piece of text found in different buffers.  It will even act differently 
  15843. in different windows showing the same buffer, because the width may differ and 
  15844. so may the truncation flag. See Control Char Display. 
  15845.  
  15846. -- Function: vertical-motion count 
  15847. This function moves point to the start of the screen line count screen lines 
  15848. down from the screen line containing point.  If count is negative, it moves up 
  15849. instead. 
  15850.  
  15851. This function returns the number of lines moved.  The value may be less in 
  15852. absolute value than count if the beginning or end of the buffer was reached. 
  15853.  
  15854. -- Command: move-to-window-line count 
  15855. This function moves point with respect to the text currently displayed in the 
  15856. selected window.  Point is moved to the beginning of the screen line count 
  15857. screen lines from the top of the window.  If count is negative, point moves 
  15858. either to the beginning of the line -count lines from the bottom or else to the 
  15859. last line of the buffer if the buffer ends above the specified screen position. 
  15860.  
  15861. If count is nil, then point moves to the beginning of the line in the middle of 
  15862. the window.  If the absolute value of count is greater than the size of the 
  15863. window, then point moves to the place which would appear on that screen line if 
  15864. the window were tall enough. This will probably cause the next redisplay to 
  15865. scroll to bring that location onto the screen. 
  15866.  
  15867. In an interactive call, count is the numeric prefix argument. 
  15868.  
  15869. The value returned is the window line number, with the top line in the window 
  15870. numbered 0. 
  15871.  
  15872.  
  15873. ΓòÉΓòÉΓòÉ 29.2.6. The User-Level Vertical Motion Commands ΓòÉΓòÉΓòÉ
  15874.  
  15875.  A goal column is useful if you want to edit text such as a table in which you 
  15876. want to move point to a certain column on each line.  The goal column affects 
  15877. the vertical text line motion commands, next-line and previous-line. See Basic 
  15878. Editing Commands. 
  15879.  
  15880. -- User Option: goal-column 
  15881. This variable holds an explicitly specified goal column for vertical line 
  15882. motion commands.  If it is an integer, it specifies a column, and these 
  15883. commands try to move to that column on each line.  If it is nil, then the 
  15884. commands set their own goal columns.  Any other value is invalid. 
  15885.  
  15886. -- Variable: temporary-goal-column 
  15887. This variable holds the temporary goal column during a sequence of consecutive 
  15888. vertical line motion commands.  It is overridden by goal-column if that is 
  15889. non-nil.  It is set each time a vertical motion command is invoked, unless the 
  15890. previous command was also a vertical motion command. 
  15891.  
  15892. -- User Option: track-eol 
  15893. This variable controls how the vertical line motion commands operate when 
  15894. starting at the end of a line.  If track-eol is non-nil, then vertical motion 
  15895. starting at the end of a line will keep to the ends of lines.  This means 
  15896. moving to the end of each line moved onto.  The value of track-eol has no 
  15897. effect if point is not at the end of a line when the first vertical motion 
  15898. command is given. 
  15899.  
  15900. track-eol has its effect by causing temporary-goal-column to be set to 9999 
  15901. instead of to the current column. 
  15902.  
  15903. -- Command: set-goal-column unset 
  15904. This command sets the variable goal-column to specify a permanent goal column 
  15905. for the vertical line motion commands.  If unset is nil, then goal-column is 
  15906. set to the current column of point.  If unset is non-nil, then goal-column is 
  15907. set to nil. 
  15908.  
  15909. This function is intended for interactive use; and in an interactive call, 
  15910. unset is the raw prefix argument. 
  15911.  
  15912.  
  15913. ΓòÉΓòÉΓòÉ 29.2.7. Moving over Lists and Other Balanced Expressions ΓòÉΓòÉΓòÉ
  15914.  
  15915.  Here are several functions concerned with balanced-parenthesis expressions 
  15916. (also called sexps in connection with moving across them in Emacs).  The syntax 
  15917. table controls how these functions interpret various characters; see Syntax 
  15918. Tables. See Parsing Expressions, for lower-level primitives for scanning sexps 
  15919. or parts of sexps.  For user-level commands, see Lists and Sexps. 
  15920.  
  15921. -- Command: forward-list arg 
  15922. Move forward across arg balanced groups of parentheses. (Other syntatic 
  15923. entities such as words or paired string quotes are ignored.) 
  15924.  
  15925. -- Command: backward-list arg 
  15926. Move backward across arg balanced groups of parentheses. (Other syntatic 
  15927. entities such as words or paired string quotes are ignored.) 
  15928.  
  15929. -- Command: up-list arg 
  15930. Move forward out of arg levels of parentheses. A negative argument means move 
  15931. backward but still to a less deep spot. 
  15932.  
  15933. -- Command: down-list arg 
  15934. Move forward down arg levels of parentheses.  A negative argument means move 
  15935. backward but still go down arg level. 
  15936.  
  15937. -- Command: forward-sexp arg 
  15938. Move forward across arg balanced expressions. Balanced expressions include both 
  15939. those delimited by parentheses and other kinds, such as words and string 
  15940. constants.  For example, 
  15941.  
  15942. ---------- Buffer: foo ----------
  15943. (concat-!- "foo " (car x) y z)
  15944. ---------- Buffer: foo ----------
  15945.  
  15946. (forward-sexp 3)
  15947.      => nil
  15948.  
  15949. ---------- Buffer: foo ----------
  15950. (concat "foo " (car x) y-!- z)
  15951. ---------- Buffer: foo ----------
  15952.  
  15953. -- Command: backward-sexp arg 
  15954. Move backward across arg balanced expressions. 
  15955.  
  15956.  
  15957. ΓòÉΓòÉΓòÉ 29.2.8. Skipping Characters ΓòÉΓòÉΓòÉ
  15958.  
  15959.  The following two functions move point over a specified set of characters. 
  15960. For example, they are often used to skip whitespace. 
  15961.  
  15962. -- Function: skip-chars-forward character-set &optional limit 
  15963. This function moves point in the current buffer forward, skipping over a given 
  15964. set of characters.  Emacs first examines the character following point; if it 
  15965. matches character-set, then point is advanced and the next character is 
  15966. examined.  This continues until a character is found that does not match.  The 
  15967. function returns nil. 
  15968.  
  15969. The argument character-set is like the inside of a `[...]' in a regular 
  15970. expression except that `]' is never special and `\' quotes `^', `-' or `\'. 
  15971. Thus, "a-zA-Z" skips over all letters, stopping before the first nonletter, and 
  15972. "^a-zA-Z" skips nonletters stopping before the first letter.  See Regular 
  15973. Expressions. 
  15974.  
  15975. If limit is supplied (it must be a number or a marker), it specifies the 
  15976. maximum position in the buffer that point can be skipped to.  Point will stop 
  15977. at or before limit. 
  15978.  
  15979. In the following example, point is initially located directly before the `T'. 
  15980. After the form is evaluated, point is located at the end of that line (between 
  15981. the `t' of `hat' and the newline).  The function skips all letters and spaces, 
  15982. but not newlines. 
  15983.  
  15984. ---------- Buffer: foo ----------
  15985. I read "-!-The cat in the hat
  15986. comes back" twice.
  15987. ---------- Buffer: foo ----------
  15988.  
  15989. (skip-chars-forward "a-zA-Z ")
  15990.      => nil
  15991.  
  15992. ---------- Buffer: foo ----------
  15993. I read "The cat in the hat-!-
  15994. comes back" twice.
  15995. ---------- Buffer: foo ----------
  15996.  
  15997. -- Function: skip-chars-backward character-set &optional limit 
  15998. This function moves point backward, skipping characters that match 
  15999. character-set.  It just like skip-chars-forward except for the direction of 
  16000. motion. 
  16001.  
  16002.  
  16003. ΓòÉΓòÉΓòÉ 29.3. Excursions ΓòÉΓòÉΓòÉ
  16004.  
  16005.  It is often useful to move point ``temporarily'' within a localized portion of 
  16006. the program, or to switch buffers temporarily.  This is called an excursion, 
  16007. and it is done with the save-excursion special form.  This construct saves the 
  16008. current buffer and its values of point and the mark so they can be restored 
  16009. after the completion of the excursion. 
  16010.  
  16011.  The forms for saving and restoring the configuration of windows are described 
  16012. elsewhere (see Window Configurations). 
  16013.  
  16014. -- Special Form: save-excursion forms... 
  16015. The save-excursion special form saves the identity of the current buffer and 
  16016. the values of point and the mark in it, evaluates forms, and finally restores 
  16017. the buffer and its saved values of point and the mark. All three saved values 
  16018. are restored even in case of an abnormal exit via throw or error (see Nonlocal 
  16019. Exits). 
  16020.  
  16021. The save-excursion special form is the standard way to switch buffers or move 
  16022. point within one part of a program and avoid affecting the rest of the program. 
  16023. It is used more than 500 times in the Lisp sources of Emacs. 
  16024.  
  16025. The values of point and the mark for other buffers are not saved by 
  16026. save-excursion, so any changes made to point and the mark in the other buffers 
  16027. will remain in effect after save-excursion exits. 
  16028.  
  16029. Likewise, save-excursion does not restore window-buffer correspondences altered 
  16030. by functions such as switch-to-buffer. One way to restore these 
  16031. correspondences, and the selected window, is to use save-window-excursion 
  16032. inside save-excursion (see Window Configurations). 
  16033.  
  16034. The value returned by save-excursion is the result of the last of forms, or nil 
  16035. if no forms are given. 
  16036.  
  16037. (save-excursion
  16038.   forms)
  16039. ==
  16040. (let ((old-buf (current-buffer))
  16041.       (old-pnt (point-marker))
  16042.       (old-mark (copy-marker (mark-marker))))
  16043.   (unwind-protect
  16044.       (progn forms)
  16045.     (set-buffer old-buf)
  16046.     (goto-char old-pnt)
  16047.     (set-marker (mark-marker) old-mark)))
  16048.  
  16049.  
  16050. ΓòÉΓòÉΓòÉ 29.4. Narrowing ΓòÉΓòÉΓòÉ
  16051.  
  16052.  Narrowing means limiting the text addressable by Emacs editing commands to a 
  16053. limited range of characters in a buffer.  The text that remains addressable is 
  16054. called the accessible portion of the buffer. 
  16055.  
  16056.  Narrowing is specified with two buffer positions which become the beginning 
  16057. and end of the accessible portion.  For most editing commands these positions 
  16058. replace the values of the beginning and end of the buffer.  While narrowing is 
  16059. in effect, no text outside the accessible portion is displayed, and point 
  16060. cannot move outside the accessible portion. 
  16061.  
  16062.  Values such as positions or line numbers which usually count from the 
  16063. beginning of the buffer continue to do so, but the functions which use them 
  16064. will refuse to operate on text that is inaccessible. 
  16065.  
  16066.  The commands for saving buffers are unaffected by narrowing; the entire buffer 
  16067. is saved regardless of the any narrowing. 
  16068.  
  16069. -- Command: narrow-to-region start end 
  16070. This function sets the accessible portion of the current buffer to start at 
  16071. start and end at end.  Both arguments should be character positions. 
  16072.  
  16073. In an interactive call, start and end are set to the bounds of the current 
  16074. region (point and the mark, with the smallest first). 
  16075.  
  16076. -- Command: narrow-to-page move-count 
  16077. This function sets the accessible portion of the current buffer to include just 
  16078. the current page.  An optional first argument move-count non-nil means to move 
  16079. forward or backward by move-count pages and then narrow. 
  16080.  
  16081. In an interactive call, move-count is set to the numeric prefix argument. 
  16082.  
  16083. -- Command: widen 
  16084. This function cancels any narrowing in the current buffer, so that the entire 
  16085. contents are accessible.  This is called widening. It is equivalent to the 
  16086. following expression: 
  16087.  
  16088. (narrow-to-region 1 (1+ (buffer-size)))
  16089.  
  16090. -- Special Form: save-restriction forms... 
  16091. This special form saves the current bounds of the accessible portion, evaluates 
  16092. forms, and finally restores the saved bounds, thus restoring the same state of 
  16093. narrowing (or absence thereof) formerly in effect.  The state of narrowing is 
  16094. restored even in the event of an abnormal exit via throw or error (see Nonlocal 
  16095. Exits).  Therefore, this construct is a clean way to narrow a buffer 
  16096. temporarily. 
  16097.  
  16098. The value returned by save-restriction is that returned by the last of forms, 
  16099. or nil if no forms were given. 
  16100.  
  16101. *Note:* it is easy to make a mistake when using save-restriction.  Read the 
  16102. entire description here before you try it. 
  16103.  
  16104. Point and the mark are not restored by this special form; use save-excursion 
  16105. for that.  If you use both save-restriction and save-excursion together, 
  16106. save-excursion should come first (on the outside).  Otherwise, the old point 
  16107. value would be restored with temporary narrowing still in effect.  If the old 
  16108. point value were outside the limits of the temporary narrowing, this would fail 
  16109. to restore it accurately. 
  16110.  
  16111. The save-restriction special form records the values of the beginning and end 
  16112. of the accessible portion as distances from the beginning and end of the 
  16113. buffer.  In other words, it records the amount of inaccessible text before and 
  16114. after the accessible portion. 
  16115.  
  16116. This technique yields correct results if the body of the form does further 
  16117. narrowing.  However, save-restriction can become confused if the body widens 
  16118. and then makes changes outside the area of the saved narrowing.  When this is 
  16119. what you want to do, save-restriction is not the right tool for the job.  Here 
  16120. is what you must do instead: 
  16121.  
  16122. (let ((beg (point-min-marker))
  16123.       (end (point-max-marker)))
  16124.   (unwind-protect
  16125.       (progn body)
  16126.     (narrow-to-region beg end)))
  16127.  
  16128. Here is a simple example of correct use of save-restriction: 
  16129.  
  16130. ---------- Buffer: foo ----------
  16131. This is the contents of foo
  16132. This is the contents of foo
  16133. This is the contents of foo-!-
  16134. ---------- Buffer: foo ----------
  16135.  
  16136. (save-excursion
  16137.   (save-restriction
  16138.     (goto-char 1)
  16139.     (forward-line 2)
  16140.     (narrow-to-region 1 (point))
  16141.     (goto-char (point-min))
  16142.     (replace-string "foo" "bar")))
  16143.  
  16144. ---------- Buffer: foo ----------
  16145. This is the contents of bar
  16146. This is the contents of bar
  16147. This is the contents of foo-!-
  16148. ---------- Buffer: foo ----------
  16149.  
  16150.  
  16151. ΓòÉΓòÉΓòÉ 30. Markers ΓòÉΓòÉΓòÉ
  16152.  
  16153.  A marker is a Lisp object used to specify a position in a buffer relative to 
  16154. the surrounding text.  A marker changes its offset from the beginning of the 
  16155. buffer automatically whenever text is inserted or deleted, so that it stays 
  16156. with the two characters on either side of it. 
  16157.  
  16158.  
  16159. ΓòÉΓòÉΓòÉ 30.1. Overview of Markers ΓòÉΓòÉΓòÉ
  16160.  
  16161.  A marker specifies a buffer and a position in that buffer.  The marker can be 
  16162. used to represent a position in the functions that require one, just as an 
  16163. integer could be used.  See Positions, for a complete description of positions. 
  16164.  
  16165.  A marker has two attributes: the marker position, and the marker buffer.  The 
  16166. marker position is an integer which is equivalent (at the moment) to the marker 
  16167. as a position in that buffer; however, as text is inserted or deleted in the 
  16168. buffer, the marker is relocated, so that its integer equivalent changes.  The 
  16169. idea is that a marker positioned between two characters in a buffer will remain 
  16170. between those two characters despite any changes made to the contents of the 
  16171. buffer; thus, a marker's offset from the beginning of a buffer may change often 
  16172. during the life of the marker. 
  16173.  
  16174.  If the text around a marker is deleted, the marker is repositioned between the 
  16175. characters immediately before and after the deleted text.  If text is inserted 
  16176. at the position of a marker, the marker remains in front of the new text unless 
  16177. it is inserted with insert-before-markers (see Insertion).  When text is 
  16178. inserted or deleted somewhere before the marker position (not next to the 
  16179. marker), the marker moves back and forth with the two neighboring characters. 
  16180.  
  16181.  When a buffer is modified, all of its markers must be checked so that they can 
  16182. be relocated if necessary.  This slows processing in a buffer with a large 
  16183. number of markers.  For this reason, it is a good idea to make a marker point 
  16184. nowhere if you are sure you don't need it any more. Unreferenced markers will 
  16185. eventually be garbage collected, but until then will continue to be updated if 
  16186. they do point somewhere. 
  16187.  
  16188.  Because it is quite common to perform arithmetic operations on a marker 
  16189. position, most of the arithmetic operations (including + and -) accept markers 
  16190. as arguments.  In such cases, the current position of the marker is used. 
  16191.  
  16192. Here are examples of creating markers, setting markers, and moving point to 
  16193. markers: 
  16194.  
  16195. ;; Make a new marker that initially does not point anywhere:
  16196. (setq m1 (make-marker))
  16197.      => #<marker in no buffer>
  16198.  
  16199. ;; Set m1 to point between the 100th and 101st characters.
  16200. ;; in the current buffer:
  16201. (set-marker m1 100)
  16202.      => #<marker at 100 in markers.texi>
  16203.  
  16204. ;; Now insert one character at the beginning of the buffer:
  16205. (goto-char (point-min))
  16206.      => 1
  16207. (insert "Q")
  16208.      => nil
  16209.  
  16210. ;; m1 is updated appropriately.
  16211. m1
  16212.      => #<marker at 101 in markers.texi>
  16213.  
  16214. ;; Two markers that point to the same position
  16215. ;; are not eq, but they are equal.
  16216. (setq m2 (copy-marker m1))
  16217.      => #<marker at 101 in markers.texi>
  16218. (eq m1 m2)
  16219.      => nil
  16220. (equal m1 m2)
  16221.      => t
  16222.  
  16223. ;; When you are finished using a marker, make it point nowhere.
  16224. (set-marker m1 nil)
  16225.      => #<marker in no buffer>
  16226.  
  16227.  
  16228. ΓòÉΓòÉΓòÉ 30.2. Predicates on Markers ΓòÉΓòÉΓòÉ
  16229.  
  16230.  You can test an object to see whether it is a marker, or whether it is either 
  16231. an integer or a marker.  The latter test is useful when you are using the 
  16232. arithmetic functions that work with both markers and integers. 
  16233.  
  16234. -- Function: markerp object 
  16235.  This function returns t if object is a marker, nil otherwise.  In particular, 
  16236. integers are not markers, even though many functions will accept either a 
  16237. marker or an integer. 
  16238.  
  16239. -- Function: integer-or-marker-p object 
  16240.  This function returns t if object is an integer or a marker, nil otherwise. 
  16241.  
  16242.  
  16243. ΓòÉΓòÉΓòÉ 30.3. Functions That Create Markers ΓòÉΓòÉΓòÉ
  16244.  
  16245.  When you create a new marker, you can make it point nowhere, or point to the 
  16246. present position of point, or to the beginning or end of the accessible portion 
  16247. of the buffer, or to the same place as another given marker. 
  16248.  
  16249. -- Function: make-marker 
  16250.  This functions returns a newly allocated marker that does not point anywhere. 
  16251.  
  16252. (make-marker)
  16253.      => #<marker in no buffer>
  16254.  
  16255. -- Function: point-marker 
  16256.  This function returns a new marker that points to the present position of 
  16257. point in the current buffer.  See Point.  For an example, see copy-marker, 
  16258. below. 
  16259.  
  16260. -- Function: point-min-marker 
  16261.  This function returns a new marker that points to the beginning of the 
  16262. accessible portion of the buffer.  This will be the beginning of the buffer 
  16263. unless narrowing is in effect.  See Narrowing. 
  16264.  
  16265. -- Function: point-max-marker 
  16266.  This function returns a new marker that points to the end of the accessible 
  16267. portion of the buffer.  This will be the end of the buffer unless narrowing is 
  16268. in effect.  See Narrowing. 
  16269.  
  16270. Here are examples of this function and point-min-marker, shown in a buffer 
  16271. containing a version of the source file for the text of this chapter. 
  16272.  
  16273. (point-min-marker)
  16274.      => #<marker at 1 in markers.texi>
  16275. (point-max-marker)
  16276.      => #<marker at 15573 in markers.texi>
  16277.  
  16278. (narrow-to-region 100 200)
  16279.      => nil
  16280. (point-min-marker)
  16281.      => #<marker at 100 in markers.texi>
  16282. (point-max-marker)
  16283.      => #<marker at 200 in markers.texi>
  16284.  
  16285. -- Function: copy-marker marker-or-integer 
  16286.  If passed a marker as its argument, copy-marker returns a new marker that 
  16287. points to the same place and the same buffer as does marker-or-integer.  If 
  16288. passed an integer as its argument, copy-marker returns a new marker that points 
  16289. to position marker-or-integer in the current buffer. 
  16290.  
  16291.  If passed an argument that is an integer whose value is less than 1, 
  16292. copy-marker returns a new marker that points to the beginning of the current 
  16293. buffer.  If passed an argument that is an integer whose value is greater than 
  16294. the length of the buffer, then copy-marker returns a new marker that points to 
  16295. the end of the buffer. 
  16296.  
  16297.  An error is signaled if marker is neither a marker nor an integer. 
  16298.  
  16299. (setq p (point-marker))
  16300.      => #<marker at 2139 in markers.texi>
  16301.  
  16302. (setq q (copy-marker p))
  16303.      => #<marker at 2139 in markers.texi>
  16304.  
  16305. (eq p q)
  16306.      => nil
  16307.  
  16308. (equal p q)
  16309.      => t
  16310.  
  16311. (copy-marker 0)
  16312.      => #<marker at 1 in markers.texi>
  16313.  
  16314. (copy-marker 20000)
  16315.      => #<marker at 7572 in markers.texi>
  16316.  
  16317.  
  16318. ΓòÉΓòÉΓòÉ 30.4. Information from Markers ΓòÉΓòÉΓòÉ
  16319.  
  16320.  This section describes the functions for accessing the components of a marker 
  16321. object. 
  16322.  
  16323. -- Function: marker-position marker 
  16324.  This function returns the position that marker points to, or nil if it points 
  16325. nowhere. 
  16326.  
  16327. -- Function: marker-buffer marker 
  16328.  This function returns the buffer that marker points into, or nil if it points 
  16329. nowhere. 
  16330.  
  16331. (setq m (make-marker))
  16332.      => #<marker in no buffer>
  16333. (marker-position m)
  16334.      => nil
  16335. (marker-buffer m)
  16336.      => nil
  16337.  
  16338. (set-marker m 3770 (current-buffer))
  16339.      => #<marker at 3770 in markers.texi>
  16340. (marker-buffer m)
  16341.      => #<buffer markers.texi>
  16342. (marker-position m)
  16343.      => 3770
  16344.  
  16345.  Two distinct markers will be found equal (even though not eq) to each other if 
  16346. they have the same position and buffer, or if they both point nowhere. 
  16347.  
  16348.  
  16349. ΓòÉΓòÉΓòÉ 30.5. Changing Markers ΓòÉΓòÉΓòÉ
  16350.  
  16351.  This section describes how to change the position of an existing marker.  When 
  16352. you do this, be sure you know whether the marker is used outside of your 
  16353. program, and, if so, what effects will result from moving it---otherwise, 
  16354. confusing things may happen in other parts of Emacs. 
  16355.  
  16356. -- Function: set-marker marker position &optional buffer 
  16357.  This function moves marker to position in buffer.  If buffer is not provided, 
  16358. it defaults to the current buffer. 
  16359.  
  16360.  If position is less than 1, set-marker moves marker to the beginning of the 
  16361. buffer.  If the value of position is greater than the size of the buffer, 
  16362. set-marker moves marker to the end of the buffer.  If position is nil or a 
  16363. marker that points nowhere, then marker is set to point nowhere. 
  16364.  
  16365.  The value returned is marker. 
  16366.  
  16367. (setq m (point-marker))
  16368.      => #<marker at 4714 in markers.texi>
  16369. (set-marker m 55)
  16370.      => #<marker at 55 in markers.texi>
  16371. (setq b (get-buffer "foo"))
  16372.      => #<buffer foo>
  16373. (set-marker m 0 b)
  16374.      => #<marker at 1 in foo>
  16375.  
  16376. -- Function: move-marker marker position &optional buffer 
  16377.  This is another name for set-marker. 
  16378.  
  16379.  
  16380. ΓòÉΓòÉΓòÉ 30.6. The Mark ΓòÉΓòÉΓòÉ
  16381.  
  16382.  A special marker in each buffer is designated the mark.  It records a position 
  16383. for the user for the sake of commands such as C-w and C-x TAB.  Lisp programs 
  16384. should set the mark only to values that have a potential use to the user, and 
  16385. never for their own internal purposes.  For example, the replace-regexp command 
  16386. sets the mark to the value of point before doing any replacements, because this 
  16387. enables the user to move back there conveniently after the replace is finished. 
  16388.  
  16389.  Many commands are designed so that when called interactively they operate on 
  16390. the text between point and the mark.  If you are writing such a command, don't 
  16391. examine the mark directly; instead, use interactive with the `r' specification. 
  16392. This will provide the values of point and the mark as arguments to the command 
  16393. in an interactive call, but will permit other Lisp programs to specify 
  16394. arguments explicitly.  See Interactive Codes. 
  16395.  
  16396.  Each buffer has its own value of the mark that is independent of the value of 
  16397. the mark in other buffers.  When a buffer is created, the mark exists but does 
  16398. not point anywhere.  We consider this state as ``the absence of a mark in that 
  16399. buffer''. 
  16400.  
  16401.  In addition to the mark, each buffer has a mark ring which is a list of 
  16402. markers that are the previous values of the mark.  When editing commands change 
  16403. the mark, they should normally save the old value of the mark on the mark ring. 
  16404. The mark ring may contain no more than the maximum number of entries specified 
  16405. by the variable mark-ring-max; excess entries are discarded on a 
  16406. first-in-first-out basis. 
  16407.  
  16408. -- Function: mark 
  16409.  This function returns the position of the current buffer's mark as an integer. 
  16410. nil is returned if the mark is not yet set for this buffer. 
  16411.  
  16412. -- Function: mark-marker 
  16413.  This function returns the current buffer's mark.  This the very marker which 
  16414. records the mark location inside Emacs, not a copy.  Therefore, changing this 
  16415. marker's position will directly affect the position of the mark. Don't do it 
  16416. unless that is the effect you want. 
  16417.  
  16418. (setq m (mark-marker))
  16419.      => #<marker at 3420 in markers.texi>
  16420. (set-marker m 100)
  16421.      => #<marker at 100 in markers.texi>
  16422. (mark-marker)
  16423.      => #<marker at 100 in markers.texi>
  16424.  
  16425. Like any marker, this marker can be set to point at any buffer you like. We 
  16426. don't recommend that you make it point at any buffer other than the one of 
  16427. which it is the mark.  If you do, it will yield perfectly consistent, if rather 
  16428. odd, results. 
  16429.  
  16430. -- Command: set-mark-command jump 
  16431.  If jump is nil, this command sets the mark to the value of point and pushes 
  16432. the previous value of the mark on the mark ring.  The message `Mark set' is 
  16433. also displayed in the echo area. 
  16434.  
  16435.  If jump is not nil, this command sets point to the value of the mark, and sets 
  16436. the mark to the previous saved mark value, which is popped off the mark ring. 
  16437.  
  16438.  This function is only intended for interactive use. 
  16439.  
  16440. -- Function: set-mark position 
  16441.  This function sets the mark to position. The old value of the mark is not 
  16442. pushed onto the mark ring. 
  16443.  
  16444.  *Note:* use this function only if you want the user to see that the mark has 
  16445. moved, and you want the previous mark position to be lost. Normally, when a new 
  16446. mark is set, the old one should go on the mark-ring, which is why most 
  16447. applications should use push-mark and pop-mark, not set-mark. 
  16448.  
  16449.  Novice Emacs Lisp programmers often try to use the mark for the wrong 
  16450. purposes.  The mark saves a location for the user's convenience.  An editing 
  16451. command should not alter the mark unless altering the mark is part of the 
  16452. user-level functionality of the command.  (And, in that case, this effect 
  16453. should be documented.)  To remember a location for internal use in the Lisp 
  16454. program, store it in a Lisp variable.  For example: 
  16455.  
  16456.    (let ((beg (point)))
  16457.       (forward-line 1)
  16458.       (delete-region beg (point))).
  16459.  
  16460. -- Variable: mark-ring 
  16461.  The value of this buffer-local variable is the list of saved former marks of 
  16462. the current buffer, most recent first. 
  16463.  
  16464. mark-ring
  16465. => (#<marker at 11050 in markers.texi>
  16466.     #<marker at 10832 in markers.texi>
  16467.     ...)
  16468.  
  16469. -- User Option: mark-ring-max 
  16470.  The value of this variable is the maximum size of mark-ring. If more marks 
  16471. than this are pushed onto the mark-ring, it discards marks on a first-in, 
  16472. first-out basis. 
  16473.  
  16474. -- Function: push-mark &optional position nomsg 
  16475.  This function sets the current buffer's mark to position, and pushes a copy of 
  16476. the previous mark onto mark-ring.  If position is nil, then the value of point 
  16477. is used. push-mark returns nil. 
  16478.  
  16479.  A `Mark set' message is displayed unless nomsg is non-nil. 
  16480.  
  16481. -- Function: pop-mark 
  16482.  This function pops off the top element of mark-ring and makes that mark become 
  16483. the buffer's actual mark.  This does not change the buffer's point and does 
  16484. nothing if mark-ring is empty. 
  16485.  
  16486.  The return value is not useful. 
  16487.  
  16488.  
  16489. ΓòÉΓòÉΓòÉ 30.7. The Region ΓòÉΓòÉΓòÉ
  16490.  
  16491.  The text between point and the mark is known as the region. Various functions 
  16492. operate on text delimited by point and the mark, but only those functions 
  16493. specifically related to the region itself are described here. 
  16494.  
  16495. -- Function: region-beginning 
  16496.  This function returns the position of the beginning of the region (as an 
  16497. integer).  This is the position of either point or the mark, whichever is 
  16498. smaller. 
  16499.  
  16500.  If the mark does not point anywhere, an error is signaled. 
  16501.  
  16502. -- Function: region-end 
  16503.  This function returns the position of the end of the region (as an integer). 
  16504. This is the position of either point or the mark, whichever is larger. 
  16505.  
  16506.  If the mark does not point anywhere, an error is signaled. 
  16507.  
  16508.  Few programs need to use the region-beginning and region-end functions.  A 
  16509. command designed to operate on a region should instead use interactive with the 
  16510. `r' specification, so that the same function can be called with explicit bounds 
  16511. arguments from programs.  (See Interactive Codes.) 
  16512.  
  16513.  
  16514. ΓòÉΓòÉΓòÉ 31. Text ΓòÉΓòÉΓòÉ
  16515.  
  16516.  This chapter describes the functions that deal with the text in a buffer. 
  16517. Most examine, insert or delete text in the current buffer, often in the 
  16518. vicinity of point.  Many are interactive.  All the functions that change the 
  16519. text provide for undoing the changes (see Undo). 
  16520.  
  16521.  Many text-related functions operate on a region of text defined by two buffer 
  16522. positions passed in arguments named start and end. These arguments should be 
  16523. either markers (see Markers) or or numeric character positions (see Positions). 
  16524. The order of these arguments does not matter; it is all right for start to be 
  16525. the end of the region and end the beginning.  For example, (delete-region 1 10) 
  16526. and (delete-region 10 1) perform identically.  An args-out-of-range error is 
  16527. signaled if either start or end is outside the accessible portion of the 
  16528. buffer.  In an interactive call, point and the mark are used for these 
  16529. arguments. 
  16530.  
  16531.  Throughout this chapter, ``text'' refers to the characters in the buffer. 
  16532.  
  16533.  
  16534. ΓòÉΓòÉΓòÉ 31.1. Examining Text Near Point ΓòÉΓòÉΓòÉ
  16535.  
  16536.  Many functions are provided to look at the characters around point. Several 
  16537. simple functions are described here.  See also looking-at in Searching and 
  16538. Matching. 
  16539.  
  16540. -- Function: char-after position 
  16541.  This function returns the character in the current buffer at (i.e., 
  16542. immediately after) position position.  If position is out of range for this 
  16543. purpose, either before the beginning of the buffer, or at or beyond the end, 
  16544. than the value is nil. 
  16545.  
  16546.  Remember that point is always between characters, and the terminal cursor 
  16547. normally appears over the character following point.  Therefore, the character 
  16548. returned by char-after is the character the cursor is over. 
  16549.  
  16550.  In the following example, assume that the first character in the buffer is 
  16551. `@': 
  16552.  
  16553. (char-to-string (char-after 1))
  16554.      => "@"
  16555.  
  16556. -- Function: following-char 
  16557.  This function returns the character following point in the current buffer. 
  16558. This is similar to (char-after (point)).  However, point is at the end of the 
  16559. buffer, then the result of following-char is 0. 
  16560.  
  16561.  In this example, point is between the `a' and the `c'. 
  16562.  
  16563. ---------- Buffer: foo ----------
  16564. Gentlemen may cry ``Pea-!-ce! Peace!,'' but there is no peace.
  16565. ---------- Buffer: foo ----------
  16566.  
  16567. (char-to-string (preceding-char))
  16568.      => "a"
  16569. (char-to-string (following-char))
  16570.      => "c"
  16571.  
  16572. -- Function: preceding-char 
  16573.   This function returns the character preceding point in the current buffer. 
  16574. See above, under following-char, for an example.  If point is at the beginning 
  16575. of the buffer, then the result of preceding-char is 0. 
  16576.  
  16577. -- Function: bobp 
  16578.  This function returns t if point is at the beginning of the buffer.  If 
  16579. narrowing is in effect, this means the beginning of the accessible portion of 
  16580. the text.  See also point-min in Point. 
  16581.  
  16582. -- Function: eobp 
  16583.  This function returns t if point is at the end of the buffer. If narrowing is 
  16584. in effect, this means the end of accessible portion of the text.  See also 
  16585. point-max in See Point. 
  16586.  
  16587. -- Function: bolp 
  16588.  This function returns t if point is at the beginning of a line. See Text 
  16589. Lines. 
  16590.  
  16591. -- Function: eolp 
  16592.  This function returns t if point is at the end of a line. The end of the 
  16593. buffer is always considered the end of a line. 
  16594.  
  16595.  
  16596. ΓòÉΓòÉΓòÉ 31.2. Examining Buffer Contents ΓòÉΓòÉΓòÉ
  16597.  
  16598.  This section describes two functions that allow a Lisp program to convert any 
  16599. portion of the text in the buffer into a string. 
  16600.  
  16601. -- Function: buffer-substring start end 
  16602.  This function returns a string containing a copy of the text of the region 
  16603. defined by positions start and end in the current buffer.  If the arguments are 
  16604. not positions in the accessible portion of the buffer, Emacs signals an 
  16605. args-out-of-range error. 
  16606.  
  16607.  It is not necessary for start to be less than end; the arguments can be given 
  16608. in either order.  But most often the smaller argument is written first. 
  16609.  
  16610. ---------- Buffer: foo ----------
  16611. This is the contents of buffer foo
  16612.  
  16613. ---------- Buffer: foo ----------
  16614.  
  16615. (buffer-substring 1 10)
  16616. => "This is t"
  16617. (buffer-substring (point-max) 10)
  16618. => "he contents of buffer foo
  16619. "
  16620.  
  16621. -- Function: buffer-string 
  16622.  This function returns the contents of the accessible portion of the current 
  16623. buffer as a string.  This is the portion between (point-min) and (point-max) 
  16624. (see Narrowing). 
  16625.  
  16626. ---------- Buffer: foo ----------
  16627. This is the contents of buffer foo
  16628.  
  16629. ---------- Buffer: foo ----------
  16630.  
  16631. (buffer-string)
  16632.      => "This is the contents of buffer foo
  16633. "
  16634.  
  16635.  
  16636. ΓòÉΓòÉΓòÉ 31.3. Insertion ΓòÉΓòÉΓòÉ
  16637.  
  16638.  Insertion takes place at point.  Markers pointing at positions after the 
  16639. insertion point are relocated with the surrounding text (see Markers).  When a 
  16640. marker points at the place of insertion, it is normally not relocated, so that 
  16641. it points to the beginning of the inserted text; however, when 
  16642. insert-before-markers is used, all such markers are relocated to point after 
  16643. the inserted text. 
  16644.  
  16645.  Point may end up either before or after inserted text, depending on the 
  16646. function used.  If point is left after the inserted text, we speak of insertion 
  16647. before point. 
  16648.  
  16649.  Each of these functions signals an error if the current buffer is read-only. 
  16650.  
  16651. -- Function: insert &rest args 
  16652. This function inserts the strings and/or characters args into the current 
  16653. buffer, at point, moving point forward.  An error is signaled unless all args 
  16654. are either strings or characters.  The value is nil. 
  16655.  
  16656. -- Function: insert-before-markers &rest args 
  16657. This function inserts the strings and/or characters args into the current 
  16658. buffer, at point, moving point forward.  An error is signaled unless all args 
  16659. are either strings or characters.  The value is nil. 
  16660.  
  16661. This function is unlike the other insertion functions in that a marker whose 
  16662. position initially equals point is relocated to come after the newly inserted 
  16663. text. 
  16664.  
  16665. -- Function: insert-char character count 
  16666. This function inserts count instances of character into the current buffer 
  16667. before point.  count must be a number, and character must be a character.  The 
  16668. value is nil. 
  16669.  
  16670. -- Function: insert-buffer-substring from-buffer-or-name start end 
  16671. This function inserts a substring of the contents of buffer from-buffer-or-name 
  16672. (which must already exist) into the current buffer before point.  The text 
  16673. inserted consists of the characters in the region defined by start and end. 
  16674. The value is nil. 
  16675.  
  16676. In this example, the form is executed with buffer `bar' as the current buffer. 
  16677. We assume that buffer `bar' is initially empty. 
  16678.  
  16679. ---------- Buffer: foo ----------
  16680. We hold these truths to be self-evident, that all
  16681. ---------- Buffer: foo ----------
  16682.  
  16683. (insert-buffer-substring "foo" 1 20)
  16684.      => nil
  16685.  
  16686. ---------- Buffer: bar ----------
  16687. We hold these truth
  16688. ---------- Buffer: bar ----------
  16689.  
  16690.  
  16691. ΓòÉΓòÉΓòÉ 31.4. User-Level Insertion Commands ΓòÉΓòÉΓòÉ
  16692.  
  16693.  This section describes higher-level commands for inserting text, commands 
  16694. intended primarily for the user but useful also in Lisp programs. 
  16695.  
  16696. -- Command: insert-buffer from-buffer-or-name 
  16697. This function inserts the entire contents of from-buffer-or-name (which must 
  16698. exist) into the current buffer after point.  It leaves the mark after the 
  16699. inserted text.  The value is unpredictable. 
  16700.  
  16701. -- Command: quoted-insert count 
  16702. This function reads the next input character verbatim and inserts it. It is 
  16703. primarily useful for inserting control characters.  You may also type up to 3 
  16704. octal digits, to insert a character with that code. 
  16705.  
  16706. The argument count is the number of these characters to insert. An error is 
  16707. signaled if count is not a number. 
  16708.  
  16709. This function is primarily for interactive use; there is no reason to use it in 
  16710. a program except for installing it on a keymap.  It returns nil. 
  16711.  
  16712. -- Command: self-insert-command count 
  16713. This function inserts the last character typed count times and returns nil. 
  16714. This is the function that most printing characters are bound to.  In routine 
  16715. use, self-insert-command is the most frequently called function in Emacs, but 
  16716. programs rarely use it except to install it on a keymap. 
  16717.  
  16718. In an interactive call, count is the numeric prefix argument. 
  16719.  
  16720. This function calls auto-fill-hook if the current column number is greater than 
  16721. the value of fill-column and the character inserted is a space (see Auto 
  16722. Filling). 
  16723.  
  16724. This function performs abbrev expansion if Abbrev mode (see Abbrevs) is enabled 
  16725. and the inserted character does not have word-constituent syntax (see Syntax 
  16726. Class Table). 
  16727.  
  16728. This function is also responsible for calling the blink-paren-hook when the 
  16729. inserted character has close parenthesis syntax (see Blinking). 
  16730.  
  16731. -- Command: newline &optional number-of-newlines 
  16732. This function inserts newlines into the current buffer before point. If 
  16733. number-of-newlines is supplied, that many newline characters are inserted. 
  16734.  
  16735. In Auto Fill mode, newline can break the preceding line if number-of-newlines 
  16736. is not supplied.  When this happens, it actually inserts two newlines at 
  16737. different places: one at point, and another earlier in the line.  newline does 
  16738. not auto-fill if number-of-newlines is non-nil. 
  16739.  
  16740. The value returned is nil.  In an interactive call, count is the numeric prefix 
  16741. argument. 
  16742.  
  16743. -- Command: split-line 
  16744. This function splits the current line, moving the portion of the line after 
  16745. point down vertically, so that it is on the next line directly below where it 
  16746. was before.  Whitespace is inserted as needed at the beginning of the lower 
  16747. line, using the indent-to function. split-line returns the position of point. 
  16748.  
  16749. Programs hardly ever use this function. 
  16750.  
  16751. -- Command: open-line count 
  16752. This function inserts count newlines into the current buffer after point, 
  16753. leaving point where it was. 
  16754.  
  16755. In an interactive call, count is the numeric prefix argument. Programs hardly 
  16756. ever use this function.  The value is unpredictable. 
  16757.  
  16758. -- Command: overwrite-mode argument 
  16759. This function turns Overwrite mode on or off.  If argument is nil then the mode 
  16760. is toggled.  Otherwise, if argument is a positive number (greater than zero), 
  16761. then the mode is turned on; any other argument turns it off. 
  16762.  
  16763. When Overwrite mode is on, self-inserting graphic characters replace existing 
  16764. text character for character, and do not push the existing text to the right. 
  16765.  
  16766. This function affects primarily self-insert-command. 
  16767.  
  16768. In an interactive call, argument is set to the raw prefix argument.  The return 
  16769. value of overwrite-mode is unpredictable. 
  16770.  
  16771. -- Variable: overwrite-mode 
  16772. Overwrite mode is in effect when this variable is non-nil.  It is automatically 
  16773. made buffer-local when set in any fashion. 
  16774.  
  16775.  
  16776. ΓòÉΓòÉΓòÉ 31.5. Deletion of Text ΓòÉΓòÉΓòÉ
  16777.  
  16778.  All of the deletion functions operate on the current buffer, and all return a 
  16779. value of nil.  In addition to these functions, you can also delete text using 
  16780. the ``kill'' functions that save it in the kill ring for the user; some of 
  16781. these functions save text in the kill ring in some cases but not in the usual 
  16782. case.  See The Kill Ring. 
  16783.  
  16784. -- Function: erase-buffer 
  16785. This function deletes the entire text of the current buffer, leaving it empty. 
  16786. If the buffer is read-only, it signals a buffer-read-only error.  Otherwise the 
  16787. text is deleted with no confirmation required. The value is always nil. 
  16788.  
  16789. As a safety measure, this function is not interactively callable. 
  16790.  
  16791. -- Command: delete-region start end 
  16792. This function deletes the text in the current buffer in the region defined by 
  16793. start and end.  The value is nil. 
  16794.  
  16795. -- Command: delete-char count &optional killp 
  16796. This function deletes count characters directly after point, or before point if 
  16797. count is negative.  If killp is non-nil, then it saves the deleted characters 
  16798. in the kill ring. 
  16799.  
  16800. In an interactive call, count is the numeric prefix argument, and killp is the 
  16801. unprocessed prefix argument.  Therefore, if a prefix argument is supplied, the 
  16802. text is saved in the kill ring.  If no prefix argument is supplied, then one 
  16803. character is deleted, but not saved in the kill ring. 
  16804.  
  16805. The value returned is always nil. 
  16806.  
  16807. -- Command: delete-backward-char count &optional killp 
  16808. This function deletes count characters directly before point, or after point if 
  16809. count is negative.  If killp is non-nil, then it saves the deleted characters 
  16810. in the kill ring. 
  16811.  
  16812. In an interactive call, count is the numeric prefix argument, and killp is the 
  16813. unprocessed prefix argument.  Therefore, if a prefix argument is supplied, the 
  16814. text is saved in the kill ring.  If no prefix argument is supplied, then one 
  16815. character is deleted, but not saved in the kill ring. 
  16816.  
  16817. The value returned is always nil. 
  16818.  
  16819. -- Command: backward-delete-char-untabify count &optional killp 
  16820. This function deletes count characters backward, changing tabs into spaces. 
  16821. When the next character to be deleted is a tab, it is first replaced with the 
  16822. proper number of spaces to preserve alignment and then one of those spaces is 
  16823. deleted instead of the tab.  If killp is non-nil, then the command saves the 
  16824. deleted characters in the kill ring. 
  16825.  
  16826. If count is negative, then tabs are not changed to spaces, and the characters 
  16827. are deleted by calling delete-backward-char with count. 
  16828.  
  16829. In an interactive call, count is the numeric prefix argument, and killp is the 
  16830. unprocessed prefix argument.  Therefore, if a prefix argument is supplied, the 
  16831. text is saved in the kill ring.  If no prefix argument is supplied, then one 
  16832. character is deleted, but not saved in the kill ring. 
  16833.  
  16834. The value returned is always nil. 
  16835.  
  16836.  
  16837. ΓòÉΓòÉΓòÉ 31.6. User-Level Deletion Commands ΓòÉΓòÉΓòÉ
  16838.  
  16839.  This section describes higher-level commands for deleting text, commands 
  16840. intended primarily for the user but useful also in Lisp programs. 
  16841.  
  16842. -- Command: delete-horizontal-space 
  16843. This function deletes all spaces and tabs around point.  It returns nil. 
  16844.  
  16845. In the following examples, assume that delete-horizontal-space is called four 
  16846. times, once on each line, with point between the second and third characters on 
  16847. the line. 
  16848.  
  16849. ---------- Buffer: foo ----------
  16850. I -!-thought
  16851. I -!-     thought
  16852. We-!- thought
  16853. Yo-!-u thought
  16854. ---------- Buffer: foo ----------
  16855.  
  16856. (delete-horizontal-space)   ; Four times.
  16857.      => nil
  16858.  
  16859. ---------- Buffer: foo ----------
  16860. Ithought
  16861. Ithought
  16862. Wethought
  16863. You thought
  16864. ---------- Buffer: foo ----------
  16865.  
  16866. -- Command: delete-indentation &optional join-following-p 
  16867. This function joins the line point is on to the previous line, deleting any 
  16868. whitespace at the join and in some cases replacing it with one space.  If 
  16869. join-following-p is non-nil, delete-indentation joins this line to following 
  16870. line instead. The value is nil. 
  16871.  
  16872. In the example below, point is located on the line starting `events', and it 
  16873. makes no difference if there are trailing spaces in the preceding line. 
  16874.  
  16875. ---------- Buffer: foo ----------
  16876. When in the course of human
  16877. -!-    events, it becomes necessary
  16878. ---------- Buffer: foo ----------
  16879.  
  16880. (delete-indentation)
  16881.      => nil
  16882.  
  16883. ---------- Buffer: foo ----------
  16884. When in the course of human-!- events, it becomes necessary
  16885. ---------- Buffer: foo ----------
  16886.  
  16887. After the lines are joined, the function fixup-whitespace is responsible for 
  16888. deciding whether to leave a space at the junction. 
  16889.  
  16890. -- Function: fixup-whitespace 
  16891. This function replaces white space between the objects on either side of point 
  16892. with either one space or no space as appropriate.  It returns nil. 
  16893.  
  16894. The appropriate amount of space is none at the beginning or end of the line. 
  16895. Otherwise, it is one space except when point is before a character with close 
  16896. parenthesis syntax or after a character with open parenthesis or 
  16897. expression-prefix syntax. See Syntax Class Table. 
  16898.  
  16899. In the example below, point is at the beginning of the second line when 
  16900. fixup-whitespace is called the first time.  It is located directly after the 
  16901. `(' for the second invocation. 
  16902.  
  16903. ---------- Buffer: foo ----------
  16904. This has too many spaces
  16905. -!-     at the front of this line
  16906. This has too many spaces at the start of (-!-   this list)
  16907. ---------- Buffer: foo ----------
  16908.  
  16909. (fixup-whitespace)
  16910.      => nil
  16911. (fixup-whitespace)
  16912.      => nil
  16913.  
  16914. ---------- Buffer: foo ----------
  16915. This has too many spaces
  16916. at the front of this line
  16917. This has too many spaces at the start of (this list)
  16918. ---------- Buffer: foo ----------
  16919.  
  16920. -- Command: just-one-space 
  16921. This command replaces any spaces and tabs around point with a single space.  It 
  16922. returns nil. 
  16923.  
  16924. -- Command: delete-blank-lines 
  16925. This function deletes blank lines surrounding point.  If point is on a blank 
  16926. line with one or more blank lines before or after it, then all but one of them 
  16927. are deleted.  If point is on an isolated blank line, then it is deleted.  If 
  16928. point is on a nonblank line, the command deletes all blank lines following it. 
  16929.  
  16930. A blank line is defined as a line containing only tabs and spaces. 
  16931.  
  16932. delete-blank-lines returns nil. 
  16933.  
  16934.  
  16935. ΓòÉΓòÉΓòÉ 31.7. The Kill Ring ΓòÉΓòÉΓòÉ
  16936.  
  16937.  Kill functions delete text like the deletion functions, but save it so that 
  16938. the user can reinsert it by yanking.  Most of these functions have `kill-' in 
  16939. their name.  By contrast, the functions whose names start with `delete-' 
  16940. normally do not save text for yanking (though they can still be undone); these 
  16941. are ``deletion'' functions. 
  16942.  
  16943.  Most of the kill commands are primarily for interactive use, and are not 
  16944. described here.  What we do describe are the functions provided for use in 
  16945. writing such commands.  When deleting text for internal purposes within a Lisp 
  16946. function, you should normally use deletion functions, so as not to disturb the 
  16947. kill ring contents.  See Deletion. 
  16948.  
  16949.  Emacs saves the last several batches of killed text in a list.  We call it the 
  16950. kill ring because, in yanking, the elements are considered to be in a cyclic 
  16951. order.  The list is kept in the variable kill-ring, and can be operated on with 
  16952. the usual functions for lists; there are also specialized functions, described 
  16953. in this section, which treat it as a ring. 
  16954.  
  16955.  Some people think use of the word ``kill'' in Emacs is unfortunate, since it 
  16956. refers to processes which specifically do not destroy the entities ``killed''. 
  16957. This is in sharp contrast to ordinary life, in which death is permanent and 
  16958. ``killed'' entities do not come back to life.  Therefore, other metaphors have 
  16959. been proposed.  For example, the term ``cut ring'' makes sense to people who, 
  16960. in pre-computer days, used scissors and paste to cut up and rearrange 
  16961. manuscripts.  However, it would be difficult to change now. 
  16962.  
  16963.  
  16964. ΓòÉΓòÉΓòÉ 31.7.1. Data Structures in the Kill Ring ΓòÉΓòÉΓòÉ
  16965.  
  16966.  Killed text is kept as strings in a list.  A short kill ring, for example, 
  16967. might look like this: 
  16968.  
  16969. ("some text" "a different piece of text" "yet more text")
  16970.  
  16971.  Functions that push more text into the list make the text in question into a 
  16972. string (using buffer-substring), add the string to the front of the list, and 
  16973. then look at the length of the list.  If the length is longer than the value of 
  16974. kill-ring-max, the last entry in the list is dropped off when the new entry is 
  16975. put on. 
  16976.  
  16977.  The kill-ring-yank-pointer global variable points to the kill ring entry that 
  16978. a yank function will copy.  Several functions move this pointer from one entry 
  16979. to another, and a user can thereby specify which entry to copy. 
  16980.  
  16981.  Here is a diagram that shows the variable kill-ring-yank-pointer pointing to 
  16982. the second entry in the kill ring ("some text" "a different piece of text" "yet 
  16983. more text"). 
  16984.  
  16985. kill-ring       kill-ring-yank-pointer
  16986.   |               |
  16987.   |     ___ ___    --->  ___ ___      ___ ___
  16988.    --> |___|___|------> |___|___|--> |___|___|--> nil
  16989.          |                |            |
  16990.          |                |            |
  16991.          |                |             -->"yet more text"
  16992.          |                |
  16993.          |                 --> "a different piece of text"
  16994.          |
  16995.           --> "some text"
  16996.  
  16997. (This circumstance occurs after C-y (yank) is immediately followed by M-y 
  16998. (yank-pop).) 
  16999.  
  17000.  Both kill-ring and kill-ring-yank-pointer are Lisp variables whose values are 
  17001. normally lists.  The word ``pointer'' in the name of the kill-ring-yank-pointer 
  17002. indicates that the variable's purpose is to identify one element of the list 
  17003. that will be used by default by the next yank command.  The value of 
  17004. kill-ring-yank-pointer is always eq to one of the links in the kill ring list. 
  17005. The element it identifies is the car of that link. 
  17006.  
  17007.  Moving kill-ring-yank-pointer to a different link is called rotating the kill 
  17008. ring.  The functions that do this treat the kill ring (which is a list) as 
  17009. ring; that is to say, a change that would otherwise move the pointer past the 
  17010. end of the list (which would be useless) instead moves the pointer to the first 
  17011. link on the list. Likewise, moving back from the first link goes to the last 
  17012. one. 
  17013.  
  17014.  kill-region is the primitive method of killing text.  Any command that calls 
  17015. this function is a ``kill command'' (and should probably have the word ``kill'' 
  17016. in its name).  kill-region puts the newly killed text in a new element at the 
  17017. beginning of the kill-ring list, and then sets kill-ring-yank-pointer to point 
  17018. to the first link of the list, which contains the first element. Consequently, 
  17019. the next yank command will yank the text just killed.  In this situation, 
  17020. kill-ring and kill-ring-yank-pointer are eq to each other. 
  17021.  
  17022.  When kill commands are interwoven with other commands, the killed portions of 
  17023. text are put into separate entries in the kill ring.  But when two or more kill 
  17024. commands are executed in sequence, the text killed by the second (or third, 
  17025. etc.) kill command is appended to the text killed by the first command so as to 
  17026. make one entry in the kill ring. The kill-region function uses the last-command 
  17027. variable to keep track of whether the previous was a kill command, and in such 
  17028. cases appends the killed text to the most recent entry. 
  17029.  
  17030.  
  17031. ΓòÉΓòÉΓòÉ 31.7.2. Functions for Killing ΓòÉΓòÉΓòÉ
  17032.  
  17033. -- Command: kill-region start end 
  17034.  This function kills the text in the region defined by start and end.  The text 
  17035. is deleted but saved in the kill ring.  The value is always nil. 
  17036.  
  17037.  In an interactive call, start and end are point and the mark. 
  17038.  
  17039. -- Command: kill-line &optional count 
  17040.  This function kills the rest of the line following point, not including the 
  17041. newline.  If point is directly before a newline, or if there is only whitespace 
  17042. between point and the newline, then it kills the whitespace and newline. 
  17043.  
  17044.  If count is supplied, then the command kills that many lines (including the 
  17045. newline).  (This makes executing (kill-line 2) different from executing 
  17046. (kill-line) twice.)  If count is negative, then kill-line kills lines 
  17047. backwards. 
  17048.  
  17049.  In an interactive call, count is the raw prefix argument (which then gets 
  17050. converted to a number if non-nil).  The value is always nil. 
  17051.  
  17052. -- Command: zap-to-char count character 
  17053. In Emacs version 18, this function kills the text from point up to but not 
  17054. including the specified character.  Thus, if the cursor is at the beginning of 
  17055. this sentence and the character is `s', `Thu' is deleted.  If the argument is 
  17056. 2, `Thus, if the cur' is deleted, up to but not including the `s' in `cursor'. 
  17057.  
  17058. In Emacs version 19, this function will kill all text in the region from point 
  17059. up to and including the next count occurrences of character.  Thus, in the 
  17060. example shown in the previous paragraph, the terminating `s' will be removed. 
  17061.  
  17062. The version 18 implementation kills text to the end of the buffer if the 
  17063. specified character is not found, but the version 19 implementation will simply 
  17064. signal an error. 
  17065.  
  17066. The function scans backward from point if count is negative.  The value is 
  17067. always nil. 
  17068.  
  17069. -- Command: copy-region-as-kill start end 
  17070.  This function saves the region defined by start and end on the kill ring, but 
  17071. does not delete the text from the buffer.  It returns nil. 
  17072.  
  17073.  In an interactive call, start and end are point and the mark. 
  17074.  
  17075.  
  17076. ΓòÉΓòÉΓòÉ 31.7.3. Functions for Yanking ΓòÉΓòÉΓòÉ
  17077.  
  17078. -- Command: yank &optional arg 
  17079.  This function inserts the text in the first entry in the kill ring directly 
  17080. before point.  After the yank, the mark is positioned at the beginning and 
  17081. point is positioned after the end of the inserted text. 
  17082.  
  17083.  If arg is a list (which occurs interactively when the user types C-u with no 
  17084. digits), then yank inserts the text as described above, but puts point before 
  17085. the yanked text and puts the mark after it.  If arg is a number, then yank 
  17086. inserts the argth most recently killed text. 
  17087.  
  17088.  yank does not alter the contents of the kill ring or rotate it. It returns 
  17089. nil. 
  17090.  
  17091. -- Command: yank-pop arg 
  17092. This function replaces the just-yanked text with another batch of killed 
  17093. text---another element of the kill ring. 
  17094.  
  17095. This command is allowed only immediately after a yank or a yank-pop.  At such a 
  17096. time, the region contains text that was just inserted by the previous yank. 
  17097. yank-pop deletes that text and inserts in its place a different stretch of 
  17098. killed text.  The text that is deleted is not inserted into the kill ring, 
  17099. since it is already in the kill ring somewhere. 
  17100.  
  17101.  If arg is nil, then the existing region contents are replaced with the 
  17102. previous element of the kill ring.  If arg is numeric, then the arg'th previous 
  17103. kill is the replacement.  If arg is negative, a more recent kill is the 
  17104. replacement. 
  17105.  
  17106.  The sequence of kills in the kill ring wraps around, so that after the oldest 
  17107. one comes the newest one, and before the newest one goes the oldest. 
  17108.  
  17109.  The value is always nil. 
  17110.  
  17111.  
  17112. ΓòÉΓòÉΓòÉ 31.7.4. Internals of the Kill Ring ΓòÉΓòÉΓòÉ
  17113.  
  17114.  This section describes the lower levels of the kill ring. 
  17115.  
  17116. -- Variable: kill-ring 
  17117.  List of killed text sequences, most recently killed first. 
  17118.  
  17119. -- Variable: kill-ring-yank-pointer 
  17120.  This variable's value indicates which element of the kill ring is the 
  17121. ``front'' of the ring.  More precisely, the value is a sublist of the value of 
  17122. kill-ring, and its car is the kill string at the front of the ring.  Rotating 
  17123. the ring works by changing kill-ring-yank-pointer, and does not actually change 
  17124. the value of kill-ring. 
  17125.  
  17126.  Commands which do change the kill ring also copy the new kill ring value into 
  17127. this variable.  The effect is to rotate the ring so that the newly killed text 
  17128. is at front. 
  17129.  
  17130. -- Command: rotate-yank-pointer count 
  17131.  This function rotates the kill ring count positions, which means setting 
  17132. kill-ring-yank-pointer to some other link in the kill ring list.  It returns 
  17133. the new value of kill-ring-yank-pointer. 
  17134.  
  17135. -- User Option: kill-ring-max 
  17136.  The value of this variable is the maximum length to which the kill ring can 
  17137. grow, before elements are thrown away on a first-in, first-out basis.  The 
  17138. default value for kill-ring-max is 30. 
  17139.  
  17140.  
  17141. ΓòÉΓòÉΓòÉ 31.8. Undo ΓòÉΓòÉΓòÉ
  17142.  
  17143.  Most buffers have an undo stack which records all changes made to the buffer's 
  17144. text so that they can be undone.  (In general, all buffers have undo stacks 
  17145. except special-purpose buffers for which Emacs assumes that undoing is not 
  17146. useful.)  The size of an undo stack is limited, so large changes or a large 
  17147. number of changes cannot be undone. 
  17148.  
  17149.  Undoing an old change is itself a change, and is added to the undo stack. 
  17150. However, you are not limited to undoing just the single most recent change; you 
  17151. can keep undoing older and older changes, even as the undo's themselves are 
  17152. being added to the stack. 
  17153.  
  17154. -- Command: undo &optional arg 
  17155.  This is a user-level command to undo some previous changes.  It uses undo-more 
  17156. and undo-start.  By repeating this command you can undo earlier and earlier 
  17157. changes, until the information in the undo stack is used up.  A numeric 
  17158. argument serves as a repeat count. The value is unpredictable. 
  17159.  
  17160. -- Function: undo-boundary 
  17161.  This function places a boundary between units of undo.  The undo command stops 
  17162. at such a boundary, and successive undo commands will undo to earlier and 
  17163. earlier boundaries.  The return value is nil. 
  17164.  
  17165.  The editor command loop automatically creates an undo boundary between 
  17166. keystroke commands.  Thus, each undo normally undoes the effects of one 
  17167. command.  Calling this function explicitly is useful for splitting the effects 
  17168. of a command into more than one unit.  For example, query-replace calls this 
  17169. function after each replacement so that the user can undo individual 
  17170. replacements one by one. 
  17171.  
  17172. -- Function: undo-more count 
  17173.  This function is used to undo count additional units of undo. It is not safe 
  17174. if the buffer has been changed in any fashion other than undo since the last 
  17175. call to undo-start.  Multiple calls to undo-more have a cumulative effect, 
  17176. undoing farther back in time. The return value is nil. 
  17177.  
  17178. -- Function: undo-start 
  17179.  This function prepares to undo one or more units of undo describing the most 
  17180. recent changes to the current buffer.  It does not actually undo anything (or 
  17181. change the buffer at all); only undo-more does that.  It returns nil. 
  17182.  
  17183.  One use of this function is to break a sequence of undo's, so a subsequent 
  17184. call to undo-more will undo the recent run of undoing, rather than extend it 
  17185. into the past. 
  17186.  
  17187.  The command undo calls undo-start whenever the previous command was not an 
  17188. undo. 
  17189.  
  17190. -- Command: buffer-enable-undo &optional buffer-or-name 
  17191.  This function assigns an undo stack for buffer buffer-or-name, so that 
  17192. subsequent changes can be undone.  If no argument is supplied, then the current 
  17193. buffer is used.  If the buffer already has an undo stack, nothing is changed. 
  17194. This function returns nil. 
  17195.  
  17196.  In an interactive call, buffer-or-name is the current buffer. You cannot 
  17197. specify any other buffer. 
  17198.  
  17199. -- Function: buffer-flush-undo buffer 
  17200.  This function deassigns the undo stack of the buffer buffer, so that it will 
  17201. not take up space.  As a result, it is no longer possible to undo either 
  17202. previous changes or any subsequent changes. If the buffer already has no undo 
  17203. stack, then this function has no effect. 
  17204.  
  17205.  This function returns nil.  It cannot be called interactively. 
  17206.  
  17207.  
  17208. ΓòÉΓòÉΓòÉ 31.9. Filling ΓòÉΓòÉΓòÉ
  17209.  
  17210.  Filling means adjusting the lengths of lines (by moving words between them) so 
  17211. that they are nearly (but no greater than) a specified maximum width. 
  17212. Additionally, lines can be justified, which means that spaces are inserted 
  17213. between words to make the line exactly the specified width.  The width is 
  17214. controlled by the variable fill-column.  For ease of reading, lines should be 
  17215. no longer than 70 or so columns. 
  17216.  
  17217.  You can use Auto Fill mode (see Auto Filling) to fill text automatically as 
  17218. you insert it, but changes to existing text may leave it improperly filled. 
  17219. Then you must fill the text explicitly. 
  17220.  
  17221.  Most of the functions in this section return values that are not meaningful. 
  17222.  
  17223. -- Command: fill-paragraph justify-flag 
  17224.   This function fills the paragraph at or after point.  If justify-flag is 
  17225. non-nil, each line is justified as well. 
  17226.  
  17227. -- Command: fill-region start end &optional justify-flag 
  17228.  This function fills each of the paragraphs in the region from start to end. 
  17229. It justifies as well if justify-flag is non-nil.  (In an interactive call, this 
  17230. is true if there is a prefix argument.) 
  17231.  
  17232.  The variable paragraph-separate controls how to distinguish paragraphs. 
  17233.  
  17234. -- Command: fill-individual-paragraphs start end &optional justify-flag 
  17235. mail-flag 
  17236.  This function fills each paragraph in the region according to its individual 
  17237. fill prefix.  Thus, if the lines of a paragraph are indented with spaces, the 
  17238. filled paragraph will continue to be indented in the same fashion. 
  17239.  
  17240.  The first two arguments, start and end, are the beginning and end of the 
  17241. region that will be filled.  The third and fourth arguments, justify-flag and 
  17242. mail-flag, are optional.  If justify-flag is non-nil, the paragraphs are 
  17243. justified as well as filled.  If mail-flag is non-nil, the function is told 
  17244. that it is operating on a mail message and therefore should not fill the header 
  17245. lines. 
  17246.  
  17247. -- Command: fill-region-as-paragraph start end &optional justify-flag 
  17248.  This function considers a region of text as a paragraph and fills it. If the 
  17249. region was made up of many paragraphs, the blank lines between paragraphs are 
  17250. removed.  This function justifies as well as filling when justify-flag is 
  17251. non-nil.  In an interactive call, any prefix argument requests justification. 
  17252.  
  17253. -- Command: justify-current-line 
  17254.  This function inserts spaces between the words of the current line so that the 
  17255. line ends exactly at fill-column.  It returns nil. 
  17256.  
  17257. -- User Option: fill-column 
  17258.  This buffer-local variable specifies the maximum width of filled lines.  Its 
  17259. value should be an integer, which is a number of columns. All the filling, 
  17260. justification and centering commands are affected by this variable, including 
  17261. Auto Fill mode (see Auto Filling). 
  17262.  
  17263.  As a practical matter, if you are writing text for other people to read, you 
  17264. should set fill-column to no more than 70.  Otherwise the line will be too long 
  17265. for people to read comfortably, and this can make the text seem clumsy. 
  17266.  
  17267. -- Variable: default-fill-column 
  17268.  The value of this variable is the default value for fill-column in buffers 
  17269. that do not override it.  This is the same as (default-value 'fill-column). 
  17270.  
  17271.  The default value for default-fill-column is 70. 
  17272.  
  17273.  
  17274. ΓòÉΓòÉΓòÉ 31.10. Auto Filling ΓòÉΓòÉΓòÉ
  17275.  
  17276.  Filling breaks text into lines that are no more than a specified number of 
  17277. columns wide.  Filled lines end between words, and therefore may have to be 
  17278. shorter than the maximum width. 
  17279.  
  17280.  Auto Fill mode is a minor mode in which Emacs fills lines automatically as 
  17281. text as inserted.  This section describes the hook and the two variables used 
  17282. by Auto Fill mode.  For a description of functions that you can call manually 
  17283. to fill and justify text, see Filling. 
  17284.  
  17285. -- Variable: auto-fill-hook 
  17286.  The value of this variable should be a function (of no arguments) to be called 
  17287. after self-inserting a space at a column beyond fill-column.  It may be nil, in 
  17288. which case nothing special is done. 
  17289.  
  17290.  The default value for auto-fill-hook is do-auto-fill, a function whose sole 
  17291. purpose is to implement the usual strategy for breaking a line. 
  17292.  
  17293.  Since auto-fill-hook is not called by the run-hooks function, it will be 
  17294. renamed auto-fill-function in Version 19. 
  17295.  
  17296.  
  17297. ΓòÉΓòÉΓòÉ 31.11. Sorting Text ΓòÉΓòÉΓòÉ
  17298.  
  17299.  The sorting commands described in this section all rearrange text in a buffer. 
  17300. This is in contrast to the function sort, which rearranges the order of the 
  17301. elements of a list (see Rearrangement). The values returned by these commands 
  17302. are not meaningful. 
  17303.  
  17304. -- Command: sort-regexp-fields reverse record-regexp key-regexp start end 
  17305.  This command sorts the region between start and end alphabetically as 
  17306. specified by record-regexp and key-regexp. If reverse is a negative integer, 
  17307. then sorting is in reverse order. 
  17308.  
  17309.  Alphabetical sorting means that two sort keys are compared by comparing the 
  17310. first characters of each, the second characters of each, and so on.  If a 
  17311. mismatch is found, it means that the sort keys are unequal; the sort key whose 
  17312. character is less at the point of first mismatch is the lesser sort key.  The 
  17313. individual characters are compared according to their numerical values.  Since 
  17314. Emacs uses the ASCII character set, the ordering in that set determines 
  17315. alphabetical order. 
  17316.  
  17317.  The value of the record-regexp argument specifies the textual units or records 
  17318. that should be sorted.  At the end of each record, a search is done for this 
  17319. regular expression, and the text that matches it is the next record.  For 
  17320. example, the regular expression `^.+$', which matches lines with at least one 
  17321. character besides a newline, would make each such line into a sort record. See 
  17322. Regular Expressions, for a description of the syntax and meaning of regular 
  17323. expressions. 
  17324.  
  17325.  The value of the key-regexp argument specifies what part of each record is to 
  17326. be compared against the other records.  The key-regexp could match the whole 
  17327. record, or only a part.  In the latter case, the rest of the record has no 
  17328. effect on the sorted order of records, but it is carried along when the record 
  17329. moves to its new position. 
  17330.  
  17331.  The key-regexp argument can refer to the text matched by a subexpression of 
  17332. record-regexp, or it can be a regular expression on its own. 
  17333.  
  17334.  If key-regexp is: 
  17335.  
  17336. `\digit' 
  17337.           then the text matched by the digitth `\(...\)' parenthesis grouping 
  17338.           in record-regexp is used for sorting. 
  17339.  
  17340. `\&' 
  17341.           then the whole record is used for sorting. 
  17342.  
  17343. a regular expression 
  17344.           then the function searches for a match for the regular expression 
  17345.           within the record.  If such a match is found, it is used for sorting. 
  17346.           If a match for key-regexp is not found within a record then that 
  17347.           record is ignored, which means its position in the buffer is not 
  17348.           changed.  (The other records may move around it.) 
  17349.  
  17350.  For example, if you plan to sort all the lines in the region by the first word 
  17351. on each line starting with the letter `f', you should set record-regexp to 
  17352. `^.*$' and set key-regexp to `\<f\w*\>'.  The resulting expression looks like 
  17353. this: 
  17354.  
  17355. (sort-regexp-fields nil "^.*$" "\\<f\\w*\\>"
  17356.                     (region-beginning)
  17357.                     (region-end))
  17358.  
  17359.  If you call sort-regexp-fields interactively, you are prompted for 
  17360. record-regexp and key-regexp in the minibuffer. 
  17361.  
  17362. -- Command: sort-subr reverse nextrecfun endrecfun &optional startkeyfun 
  17363. endkeyfun 
  17364.  This command is the general text sorting routine that divides a buffer into 
  17365. records and sorts them.  The functions sort-lines, sort-paragraphs, sort-pages, 
  17366. sort-fields, sort-regexp-fields and sort-numeric-fields all use sort-subr. 
  17367.  
  17368.  To understand how sort-subr works, consider the whole accessible portion of 
  17369. the buffer as being divided into disjoint pieces called sort records.  A 
  17370. portion of each sort record (perhaps all of it) is designated as the sort key. 
  17371. The records are rearranged in the buffer in order by their sort keys.  The 
  17372. records may or may not be contiguous. 
  17373.  
  17374.  Usually, the records are rearranged in order of ascending sort key. If the 
  17375. first argument to the sort-subr function, reverse, is non-nil, the sort records 
  17376. are rearranged in order of descending sort key. 
  17377.  
  17378.  The next four arguments to sort-subr are functions that are called to move 
  17379. point across a sort record.  They are called many times from within sort-subr. 
  17380.  
  17381.  1. nextrecfun is called with point at the end of a record.  This function 
  17382.     moves point to the start of the next record.  The first record is assumed 
  17383.     to start at the position of point when sort-subr is called.  (Therefore, 
  17384.     you should usually move point to the beginning of the buffer before calling 
  17385.     sort-subr.) 
  17386.  
  17387.  2. endrecfun is called with point within a record.  It moves point to the end 
  17388.     of the record. 
  17389.  
  17390.  3. startkeyfun is called to move point from the start of a record to the start 
  17391.     of the sort key.  This argument is optional.  If supplied, the function 
  17392.     should either return a non-nil value to be used as the sort key, or return 
  17393.     nil to indicate that the sort key is in the buffer starting at point.  In 
  17394.     the latter case, and endkeyfun will be called to find the end of the sort 
  17395.     key. 
  17396.  
  17397.  4. endkeyfun is called to move point from the start of the sort key to the end 
  17398.     of the sort key.  This argument is optional.  If startkeyfun returns nil 
  17399.     and this argument is omitted (or nil), then the sort key extends to the end 
  17400.     of the record.  There is no need for endkeyfun if startkeyfun returns a 
  17401.     non-nil value. 
  17402.  
  17403.  As an example of sort-subr, here is the complete function definition for 
  17404. sort-lines: 
  17405.  
  17406. (defun sort-lines (reverse beg end)
  17407.   "Sort lines in region alphabetically; arg means reverse order.
  17408. Called from a program, there are three arguments:
  17409. REVERSE (non-nil means reverse order),
  17410. and BEG and END (the region to sort)."
  17411.   (interactive "P\nr")
  17412.   (save-restriction
  17413.     (narrow-to-region beg end)
  17414.     (goto-char (point-min))
  17415.     (sort-subr reverse 'forward-line 'end-of-line)))
  17416.  
  17417. Here forward-line moves point to the start of the next record, and end-of-line 
  17418. moves point to the end of record.  We do not pass the arguments startkeyfun and 
  17419. endkeyfun, because the entire record is used as the sort key. 
  17420.  
  17421. The sort-paragraphs function is very much the same, except that its sort-subr 
  17422. call looks like this: 
  17423.  
  17424. (sort-subr reverse
  17425.            (function (lambda () (skip-chars-forward "\n \t\f")))
  17426.            'forward-paragraph)))
  17427.  
  17428. -- Command: sort-lines reverse start end 
  17429.  This command sorts lines in the region between start and end alphabetically. 
  17430. If reverse is non-nil, the sort is in reverse order. 
  17431.  
  17432. -- Command: sort-paragraphs reverse start end 
  17433.  This command sorts paragraphs in the region between start and end 
  17434. alphabetically.  If reverse is non-nil, the sort is in reverse order. 
  17435.  
  17436. -- Command: sort-pages reverse start end 
  17437.  This command sorts pages in the region between start and end alphabetically. 
  17438. If reverse is non-nil, the sort is in reverse order. 
  17439.  
  17440. -- Command: sort-fields field start end 
  17441.  This command sorts lines in the region between start and end, comparing them 
  17442. alphabetically by the fieldth field of each line.  Fields are separated by 
  17443. whitespace and numbered starting from 1.  If field is negative, sorting is by 
  17444. the -fieldth field from the end of the line.  This command is useful for 
  17445. sorting tables. 
  17446.  
  17447. -- Command: sort-numeric-fields field start end 
  17448.  This command sorts lines in the region between start and end, comparing them 
  17449. numerically by the fieldth field of each line.  Fields are separated by 
  17450. whitespace and numbered starting from 1.  The specified field must contain a 
  17451. number in each line of the region.  If field is negative, sorting is by the 
  17452. -fieldth field from the end of the line.  This command is useful for sorting 
  17453. tables. 
  17454.  
  17455. -- Command: sort-columns reverse &optional beg end 
  17456.  This command sorts the lines in the region between beg and end, comparing them 
  17457. alphabetically by a certain range of columns. For the purpose of this command, 
  17458. the region includes the entire line that point is in and the entire line 
  17459. containing end.  The column positions of beg and end bound the range of columns 
  17460. to sort on. 
  17461.  
  17462.  If reverse is non-nil, the sort is in reverse order. 
  17463.  
  17464.  One unusual thing about this command is that the entire line containing point, 
  17465. and the entire line containing the mark, are included in the region sorted. 
  17466.  
  17467.  Note that sort-columns uses the sort utility program, and so cannot work 
  17468. properly on text containing tab characters.  Use M-x untabify to convert tabs 
  17469. to spaces before sorting.  The sort-columns function doesn't work in VMS, 
  17470. because the subprocess facilities are lacking. 
  17471.  
  17472.  
  17473. ΓòÉΓòÉΓòÉ 31.12. Indentation ΓòÉΓòÉΓòÉ
  17474.  
  17475.  The indentation functions are used to examine, move to, and change whitespace 
  17476. that is at the beginning of a line.  Some of the functions can also change 
  17477. whitespace elsewhere on a line.  Indentation always counts from zero at the 
  17478. left margin. 
  17479.  
  17480.  
  17481. ΓòÉΓòÉΓòÉ 31.12.1. Indentation Primitives ΓòÉΓòÉΓòÉ
  17482.  
  17483.  This section describes the primitive functions used to count and insert 
  17484. indentation.  The functions in the following sections use these primitives. 
  17485.  
  17486. -- Function: current-indentation 
  17487.  This function returns the indentation of the current line, which is the 
  17488. horizontal position of the first nonblank character.  If the contents are 
  17489. entirely blank, then this is the horizontal position of the end of the line. 
  17490.  
  17491. -- Command: indent-to column &optional minimum 
  17492.  This function indents from point with tabs and spaces until column is reached. 
  17493. If minimum is specified and non-nil, then at least that many spaces are 
  17494. inserted even if this requires going beyond column.  The value is the column at 
  17495. which the inserted indentation ends. 
  17496.  
  17497. -- User Option: indent-tabs-mode 
  17498.  If this variable is non-nil, indentation functions can insert tabs as well as 
  17499. spaces.  Otherwise, they insert only spaces.  Setting this variable 
  17500. automatically makes it local to the current buffer. 
  17501.  
  17502.  
  17503. ΓòÉΓòÉΓòÉ 31.12.2. Indentation Controlled by Major Mode ΓòÉΓòÉΓòÉ
  17504.  
  17505.  An important function of each major mode is to customize the TAB key to indent 
  17506. properly for the language being edited.  This section describes the mechanism 
  17507. of the TAB key and how to control it. The functions in this section return 
  17508. unpredictable values. 
  17509.  
  17510. -- Variable: indent-line-function 
  17511.  This variable's value is the function to be used by TAB (and various commands) 
  17512. to indent the current line.  The command indent-according-to-mode does no more 
  17513. than call this function. 
  17514.  
  17515.  In Lisp mode, the value is the symbol lisp-indent-line; in C mode, 
  17516. c-indent-line; in Fortran mode, fortran-indent-line. In Fundamental mode, Text 
  17517. mode, and many other modes with no standard for indentation, the value is 
  17518. indent-to-left-margin (which is the default value). 
  17519.  
  17520. -- Command: indent-according-to-mode 
  17521.  This command calls the function in indent-line-function to indent the current 
  17522. line in a way appropriate for the current major mode. 
  17523.  
  17524. -- Command: indent-for-tab-command 
  17525.  This command calls the function in indent-line-function to indent the current 
  17526. line, except that if that function is indent-to-left-margin, insert-tab is 
  17527. called instead. 
  17528.  
  17529. -- Variable: left-margin 
  17530.  This variable is the column to which the default indent-line-function will 
  17531. indent.  (That function is indent-to-left-margin.)  In Fundamental mode, LFD 
  17532. indents to this column.  This variable automatically becomes buffer-local when 
  17533. set in any fashion. 
  17534.  
  17535. -- Function: indent-to-left-margin 
  17536.  This is the default indent-line-function, used in Fundamental mode, Text mode, 
  17537. etc.  Its effect is to adjust the indentation at the beginning of the current 
  17538. line to the value specified by the variable left-margin.  This may involve 
  17539. either inserting or deleting whitespace. 
  17540.  
  17541. -- Command: newline-and-indent 
  17542.  This function inserts a newline, then indents the new line (the one following 
  17543. the newline just inserted) according to the major mode. 
  17544.  
  17545.  Indentation is done using the current indent-line-function.  In programming 
  17546. language modes, this is the same thing TAB does, but in some text modes, where 
  17547. TAB inserts a tab, newline-and-indent indents to the column specified by 
  17548. left-margin. 
  17549.  
  17550. -- Command: reindent-then-newline-and-indent 
  17551.  This command reindents the current line, inserts a newline at point, and then 
  17552. reindents the new line (the one following the newline just inserted). 
  17553.  
  17554. Indentation of both lines is done according to the current major mode; this 
  17555. means that the current value of indent-line-function is called.  In programming 
  17556. language modes, this is the same thing TAB does, but in some text modes, where 
  17557. TAB inserts a tab, reindent-then-newline-and-indent indents to the column 
  17558. specified by left-margin. 
  17559.  
  17560.  
  17561. ΓòÉΓòÉΓòÉ 31.12.3. Indenting an Entire Region ΓòÉΓòÉΓòÉ
  17562.  
  17563.  This section describes commands which indent all the lines in the region. 
  17564. They return unpredictable values. 
  17565.  
  17566. -- Command: indent-region start end to-column 
  17567.  This command indents each nonblank line starting between start (inclusive) and 
  17568. end (exclusive).  If to-column is nil, indent-region indents each nonblank line 
  17569. by calling the current mode's indentation function, the value of 
  17570. indent-line-function. 
  17571.  
  17572.  If to-column is non-nil, it should be an integer specifying the number of 
  17573. columns of indentation; then this function gives each line exactly that much 
  17574. indentation, by either adding or deleting whitespace. 
  17575.  
  17576. -- Variable: indent-region-function 
  17577.  The value of this variable is a function that can be used by indent-region as 
  17578. a short cut.  You should design the function so that it will produce the same 
  17579. results as indenting the lines of the region one by one (but presumably 
  17580. faster). 
  17581.  
  17582.  If the value is nil, there is no short cut, and indent-region actually works 
  17583. line by line. 
  17584.  
  17585.  A short cut function is useful in modes such as C mode and Lisp mode, where 
  17586. the indent-line-function must scan from the beginning of the function: applying 
  17587. it to each line would be quadratic in time.  The short cut can update the scan 
  17588. information as it moves through the lines indenting them; this takes linear 
  17589. time.  If indenting a line individually is fast, there is no need for a short 
  17590. cut. 
  17591.  
  17592.  indent-region with a non-nil argument has a different definition and does not 
  17593. use this variable. 
  17594.  
  17595. -- Command: indent-rigidly start end count 
  17596.  This command indents all lines starting between start (inclusive) and end 
  17597. (exclusive) sideways by count columns. This ``preserves the shape'' of the 
  17598. affected region, moving it as a rigid unit.  Consequently, this command is 
  17599. useful not only for indenting regions of unindented text, but also for 
  17600. indenting regions of formatted code. 
  17601.  
  17602.  For example, if count is 3, this command adds 3 columns of indentation to each 
  17603. of the lines beginning in the region specified. 
  17604.  
  17605.  In Mail mode, C-c C-y (mail-yank-original) uses indent-rigidly to indent the 
  17606. text copied from the message being replied to. 
  17607.  
  17608.  
  17609. ΓòÉΓòÉΓòÉ 31.12.4. Indentation Relative to Previous Lines ΓòÉΓòÉΓòÉ
  17610.  
  17611.  This section describes two commands which indent the current line based on the 
  17612. contents of previous lines. 
  17613.  
  17614. -- Command: indent-relative &optional unindented-ok 
  17615.  This function inserts whitespace at point, extending to the same column as the 
  17616. next indent point of the previous nonblank line.  An indent point is a 
  17617. non-whitespace character following whitespace.  The next indent point is the 
  17618. first one at a column greater than the current column of point.  For example, 
  17619. if point is underneath and to the left of the first non-blank character of a 
  17620. line of text, it moves to that column by inserting whitespace. 
  17621.  
  17622.  If the previous nonblank line has no next indent point (i.e., none at a great 
  17623. enough column position), this function either does nothing (if unindented-ok is 
  17624. non-nil) or calls tab-to-tab-stop. Thus, if point is underneath and to the 
  17625. right of the last column of a short line of text, this function moves point to 
  17626. the next tab stop by inserting whitespace. 
  17627.  
  17628.  This command returns an unpredictable value. 
  17629.  
  17630.  In the following example, point is at the beginning of the second line: 
  17631.  
  17632.             This line is indented twelve spaces.
  17633. -!-The quick brown fox jumped over the lazy dog.
  17634.  
  17635. Evaluation of the expression (indent-relative nil) produces the following: 
  17636.  
  17637.             This line is indented twelve spaces.
  17638.             -!-The quick brown fox jumped over the lazy dog.
  17639.  
  17640.  In this example, point is between the `m' and `p' of `jumped': 
  17641.  
  17642.             This line is indented twelve spaces.
  17643. The quick brown fox jum-!-ped over the lazy dog.
  17644.  
  17645. Evaluation of the expression (indent-relative nil) produces the following: 
  17646.  
  17647.             This line is indented twelve spaces.
  17648. The quick brown fox jum  -!-ped over the lazy dog.
  17649.  
  17650. -- Command: indent-relative-maybe 
  17651.  This command indents the current line like the previous nonblank line. The 
  17652. function consists of a call to indent-relative with a non-nil value passed to 
  17653. the unindented-ok optional argument.  The value is unpredictable. 
  17654.  
  17655.  If the previous line has no indentation, the current line is given no 
  17656. indentation (any existing indentation is deleted); if the previous nonblank 
  17657. line has no indent points beyond the column at which point starts, nothing is 
  17658. changed. 
  17659.  
  17660.  
  17661. ΓòÉΓòÉΓòÉ 31.12.5. Adjustable ``Tab Stops'' ΓòÉΓòÉΓòÉ
  17662.  
  17663.  This section explains the mechanism for user-specified ``tab stops'' and the 
  17664. mechanisms which use and set them.  The name ``tab stops'' is used because the 
  17665. feature is similar to that of the tab stops on a typewriter.  The feature works 
  17666. by inserting an appropriate number of spaces and tab characters to reach the 
  17667. designated position, like the other indentation functions; it does not affect 
  17668. the display of tab characters in the buffer (see Control Char Display).  Note 
  17669. that the TAB character as input uses this tab stop feature only in a few major 
  17670. modes, such as Text mode. 
  17671.  
  17672. -- Function: tab-to-tab-stop 
  17673.  This function inserts spaces or tabs up to the next tab stop column defined by 
  17674. tab-stop-list.  It searches the list for an element greater than the current 
  17675. column number, and uses that element as the column to indent to.  If no such 
  17676. element is found, then nothing is done. 
  17677.  
  17678. -- User Option: tab-stop-list 
  17679.  This variable is the list of tab stop columns used by tab-to-tab-stops.  The 
  17680. elements should be integers in increasing order.  The tab stop columns need not 
  17681. be evenly spaced. 
  17682.  
  17683.  Use M-x edit-tab-stops to edit the location of tab stops interactively. 
  17684.  
  17685.  
  17686. ΓòÉΓòÉΓòÉ 31.12.6. Indentation-Based Motion Commands ΓòÉΓòÉΓòÉ
  17687.  
  17688.  These commands, primarily for interactive use, act based on the indentation in 
  17689. the text. 
  17690.  
  17691. -- Command: back-to-indentation 
  17692.  This command moves point to the first non-whitespace character in the current 
  17693. line (which is the line in which point is located).  It returns nil. 
  17694.  
  17695. -- Command: backward-to-indentation arg 
  17696.  This command moves point backward arg lines and then to the first nonblank 
  17697. character on that line.  It returns nil. 
  17698.  
  17699. -- Command: forward-to-indentation arg 
  17700.  This command moves point forward arg lines and then to the first nonblank 
  17701. character on that line.  It returns nil. 
  17702.  
  17703.  
  17704. ΓòÉΓòÉΓòÉ 31.13. Counting Columns ΓòÉΓòÉΓòÉ
  17705.  
  17706.  The column functions convert between a character position (counting characters 
  17707. from the beginning of the buffer) and a column position (counting screen 
  17708. characters from the beginning of a line). 
  17709.  
  17710.  Column number computations ignore the width of the window and the amount of 
  17711. horizontal scrolling.  Consequently, a column value can be arbitrarily high. 
  17712. The first (or leftmost) column is numbered 0. 
  17713.  
  17714.  A character counts according to the number of columns it occupies on the 
  17715. screen.  This means control characters count as occupying 2 or 4 columns, 
  17716. depending upon the value of ctl-arrow, and tabs count as occupying a number of 
  17717. columns that depends on the value of tab-width and on the column where the tab 
  17718. begins. See Control Char Display. 
  17719.  
  17720. -- Function: current-column 
  17721.  This function returns the horizontal position of point, measured in columns, 
  17722. counting from 0 at the left margin.  The column count is calculated by adding 
  17723. together the widths of all the displayed representations of the characters 
  17724. between the start of the current line and point. 
  17725.  
  17726.  For a more complicated example of the use of current-column, see the 
  17727. description of count-lines in Text Lines. 
  17728.  
  17729. -- Function: move-to-column column 
  17730.  This function moves point to column in the current line.  The calculation of 
  17731. column takes into account the widths of all the displayed representations of 
  17732. the characters between the start of the line and point. 
  17733.  
  17734.  If the argument column is greater than the column position of the end of the 
  17735. line, point moves to the end of the line.  If column is negative, point moves 
  17736. to the beginning of the line.  An error is signaled if column is not an 
  17737. integer. 
  17738.  
  17739.  The return value is the column number actually moved to. 
  17740.  
  17741.  
  17742. ΓòÉΓòÉΓòÉ 31.14. Case Changes ΓòÉΓòÉΓòÉ
  17743.  
  17744.  The case change commands described here work on text in the current buffer. 
  17745. See Character Case, for case conversion commands that work on strings and 
  17746. characters. 
  17747.  
  17748. -- Command: capitalize-region start end 
  17749.  This function capitalizes all words in the region defined by start and end. 
  17750. To capitalize means to convert each word's first character to upper case and 
  17751. convert the rest of each word to lower case.  The function returns nil. 
  17752.  
  17753.  If one end of the region is in the middle of a word, the part of the word 
  17754. within the region is treated as an entire word. 
  17755.  
  17756.  When capitalize-region is called interactively, start and end are point and 
  17757. the mark, with the smallest first. 
  17758.  
  17759. ---------- Buffer: foo ----------
  17760. This is the contents of the 5th foo.
  17761. ---------- Buffer: foo ----------
  17762.  
  17763. (capitalize-region 1 44)
  17764. => nil
  17765.  
  17766. ---------- Buffer: foo ----------
  17767. This Is The Contents Of The 5th Foo.
  17768. ---------- Buffer: foo ----------
  17769.  
  17770. -- Command: downcase-region start end 
  17771.  This function converts all of the letters in the region defined by start and 
  17772. end to lower case.  The function returns nil. 
  17773.  
  17774.  When downcase-region is called interactively, start and end are point and the 
  17775. mark, with the smallest first. 
  17776.  
  17777. -- Command: upcase-region start end 
  17778.  This function converts all of the letters in the region defined by start and 
  17779. end to upper case.  The function returns nil. 
  17780.  
  17781.  When upcase-region is called interactively, start and end are point and the 
  17782. mark, with the smallest first. 
  17783.  
  17784. -- Command: capitalize-word count 
  17785.  This function capitalizes count words after point, moving point over as it 
  17786. does.  To capitalize means to convert each word's first character to upper case 
  17787. and convert the rest of each word to lower case. If count is negative, the 
  17788. function capitalizes the -count previous words but does not move point.  The 
  17789. value is nil. 
  17790.  
  17791.  If point is in the middle of a word, the part of word the before point (if 
  17792. moving forward) or after point (if operating backward) is ignored. The rest is 
  17793. treated as an entire word. 
  17794.  
  17795.  When capitalize-word is called interactively, count is set to the numeric 
  17796. prefix argument. 
  17797.  
  17798. -- Command: downcase-word count 
  17799.  This function converts the count words after point to all lower case, moving 
  17800. point over as it does.  If count is negative, it converts the -count previous 
  17801. words but does not move point. The value is nil. 
  17802.  
  17803.  When downcase-word is called interactively, count is set to the numeric prefix 
  17804. argument. 
  17805.  
  17806. -- Command: upcase-word count 
  17807.  This function converts the count words after point to all upper case, moving 
  17808. point over as it does.  If count is negative, it converts the -count previous 
  17809. words but does not move point. The value is nil. 
  17810.  
  17811.  When upcase-word is called interactively, count is set to the numeric prefix 
  17812. argument. 
  17813.  
  17814.  
  17815. ΓòÉΓòÉΓòÉ 31.15. Substituting for a Character Code ΓòÉΓòÉΓòÉ
  17816.  
  17817.  The following function replaces characters within a specified region based on 
  17818. their character code. 
  17819.  
  17820. -- Function: subst-char-in-region start end old-char new-char &optional noundo 
  17821.  This function replaces all occurrences of the character old-char with the 
  17822. character new-char in the region of the current buffer defined by start and 
  17823. end. 
  17824.  
  17825.  If noundo is non-nil, then subst-char-in-region does not record the change for 
  17826. undo and does not mark the buffer as modified.  This feature is useful for 
  17827. changes which are not considered significant, such as when Outline mode changes 
  17828. visible lines to invisible lines and vice versa. 
  17829.  
  17830.  subst-char-in-region does not move point and returns nil. 
  17831.  
  17832. ---------- Buffer: foo ----------
  17833. This is the contents of the buffer before.
  17834. ---------- Buffer: foo ----------
  17835.  
  17836. (subst-char-in-region 1 20 ?i ?X)
  17837.      => nil
  17838.  
  17839. ---------- Buffer: foo ----------
  17840. ThXs Xs the contents of the buffer before.
  17841. ---------- Buffer: foo ----------
  17842.  
  17843.  
  17844. ΓòÉΓòÉΓòÉ 31.16. Underlining ΓòÉΓòÉΓòÉ
  17845.  
  17846.  The underlining commands are somewhat obsolete.  The underline-region function 
  17847. actually inserts `_^H' before each appropriate character in the region.  This 
  17848. command provides a minimal text formatting feature that might work on your 
  17849. printer; however, we recommend instead that you use more powerful text 
  17850. formatting facilities, such as Texinfo. 
  17851.  
  17852. -- Command: underline-region start end 
  17853.  This function underlines all nonblank characters in the region defined by 
  17854. start and end.  That is, an underscore character and a backspace character are 
  17855. inserted just before each non-whitespace character in the region.  The 
  17856. backspace characters are intended to cause overstriking, but in Emacs they 
  17857. display as either `\010' or `^H', depending on the setting of ctl-arrow.  There 
  17858. is no way to see the effect of the overstriking within Emacs.  The value is 
  17859. nil. 
  17860.  
  17861. -- Command: ununderline-region start end 
  17862.  This function removes all underlining (overstruck underscores) in the region 
  17863. defined by start and end.  The value is nil. 
  17864.  
  17865.  
  17866. ΓòÉΓòÉΓòÉ 31.17. Registers ΓòÉΓòÉΓòÉ
  17867.  
  17868.  A register is a sort of variable used in Emacs editing that can hold a marker, 
  17869. a string, or a rectangle.  Each register is named by a single character.  All 
  17870. characters, including control and meta characters (but with the exception of 
  17871. C-g), can be used to name registers.  Thus, there are 255 possible registers. 
  17872. A register is designated in Emacs Lisp by a character which is its name. 
  17873.  
  17874.  The functions in this section return unpredictable values unless otherwise 
  17875. stated. 
  17876.  
  17877. -- Variable: register-alist 
  17878.  This variable is an alist of elements of the form (name . contents). 
  17879. Normally, there is one element for each Emacs register that has been used. 
  17880.  
  17881.  The object name is a character (an integer) identifying the register.  The 
  17882. object contents is a string, marker, or list representing the register 
  17883. contents.  A string represents text stored in the register.  A marker 
  17884. represents a position.  A list represents a rectangle; its elements are 
  17885. strings, one per line of the rectangle. 
  17886.  
  17887. -- Command: view-register reg 
  17888.  This command displays what is contained in register reg. 
  17889.  
  17890. -- Function: get-register reg 
  17891.  This function returns the contents of the register reg, or nil if it has no 
  17892. contents. 
  17893.  
  17894. -- Function: set-register reg value 
  17895.  This function sets the contents of register reg to value. A register can be 
  17896. set to any value, but the other register functions expect only strings, 
  17897. markers, and lists. 
  17898.  
  17899. -- Command: point-to-register reg 
  17900.  This command stores both the current location of point and the current buffer 
  17901. in register reg as a marker. 
  17902.  
  17903. -- Command: register-to-point reg 
  17904.  This command moves point to the position stored in register reg. Since both 
  17905. the buffer and the location within the buffer are stored by the 
  17906. point-to-register function, this command can switch you to another buffer. 
  17907.  
  17908.  If the register does not contain a saved position (a marker), then an error is 
  17909. signaled. 
  17910.  
  17911. -- Command: insert-register reg &optional beforep 
  17912.  This command inserts contents of register reg into the current buffer. 
  17913.  
  17914.  Normally, this command puts point before the inserted text, and the mark after 
  17915. it.  However, if the optional second argument beforep is non-nil, it puts the 
  17916. mark before and point after. You can pass a non-nil second argument beforep to 
  17917. this function interactively by supplying any prefix argument. 
  17918.  
  17919.  If the register contains a rectangle, then the rectangle is inserted with its 
  17920. upper left corner at point.  This means that text is inserted in the current 
  17921. line and underneath it on successive lines. 
  17922.  
  17923.  If the register contains something other than saved text (a string) or a 
  17924. rectangle (a list), currently useless things happen.  This may be changed in 
  17925. the future. 
  17926.  
  17927. -- Command: copy-to-register reg start end &optional delete-flag 
  17928.  This command copies the region from start to end into register reg.  If 
  17929. delete-flag is non-nil, it deletes the region from the buffer after copying it 
  17930. into the register. 
  17931.  
  17932. -- Command: prepend-to-register reg start end &optional delete-flag 
  17933.  This command prepends the region from start to end into register reg.  If 
  17934. delete-flag is non-nil, it deletes the region from the buffer after copying it 
  17935. to the register. 
  17936.  
  17937. -- Command: append-to-register reg start end &optional delete-flag 
  17938.  This command appends the region from start to end to the text already in 
  17939. register reg.  If delete-flag is non-nil, it deletes the region from the buffer 
  17940. after copying it to the register. 
  17941.  
  17942. -- Command: copy-rectangle-to-register reg start end &optional delete-flag 
  17943.  This command copies a rectangular region from start to end into register reg. 
  17944. If delete-flag is non-nil, it deletes the region from the buffer after copying 
  17945. it to the register. 
  17946.  
  17947.  
  17948. ΓòÉΓòÉΓòÉ 32. Searching and Matching ΓòÉΓòÉΓòÉ
  17949.  
  17950.  GNU Emacs provides two ways to search through a buffer for specified text: 
  17951. exact string searches and regular expression searches.  After a regular 
  17952. expression search, you can identify the text matched by parts of the regular 
  17953. expression by examining the match data. 
  17954.  
  17955.  
  17956. ΓòÉΓòÉΓòÉ 32.1. Searching for Strings ΓòÉΓòÉΓòÉ
  17957.  
  17958.  These are the primitive functions for searching through the text in a buffer. 
  17959. They are meant for use in programs, but you may call them interactively.  If 
  17960. you do so, they prompt for the search string; limit and noerror are set to nil, 
  17961. and repeat is set to 1. 
  17962.  
  17963. -- Command: search-forward string &optional limit noerror repeat 
  17964.  This function searches forward from point for an exact match for string.  It 
  17965. sets point to the end of the occurrence found, and returns t.  If no match is 
  17966. found, the value and side effects depend on noerror. 
  17967.  
  17968.  In the following example, point is positioned at the beginning of the line. 
  17969. Then (search-forward "fox") is evaluated in the minibuffer and point is left 
  17970. after the last letter of `fox': 
  17971.  
  17972. ---------- Buffer: foo ----------
  17973. -!-The quick brown fox jumped over the lazy dog.
  17974. ---------- Buffer: foo ----------
  17975.  
  17976. (search-forward "fox")
  17977.      => t
  17978.  
  17979. ---------- Buffer: foo ----------
  17980. The quick brown fox-!- jumped over the lazy dog.
  17981. ---------- Buffer: foo ----------
  17982.  
  17983.  If limit is non-nil, then it is the upper bound to the search.  (It must be a 
  17984. position in the current buffer.)  No match extending after that position is 
  17985. accepted. 
  17986.  
  17987.  What happens when the search fails depends on the value of noerror.  If 
  17988. noerror is nil, a search-failed error is signaled.  If noerror is t, 
  17989. search-forward returns nil and doesn't signal an error.  If noerror is neither 
  17990. nil nor t, then search-forward moves point to limit and returns nil. 
  17991.  
  17992.  If repeat is non-nil, then the search is repeated that many times.  Point is 
  17993. positioned at the end of the last match. 
  17994.  
  17995. -- Command: search-backward string &optional limit noerror repeat 
  17996.  This function searches backward from point for string.  It is just like 
  17997. search-forward except that it searches backwards and leaves point at the 
  17998. beginning of the match. 
  17999.  
  18000. -- Command: word-search-forward string &optional limit noerror repeat 
  18001.  This function searches forward from point for a ``word'' match for string.  It 
  18002. sets point to the end of the occurrence found, and returns t. 
  18003.  
  18004.  A word search differs from a simple string search in that a word search 
  18005. *requires* that the words it searches for are present as entire words 
  18006. (searching for the word `ball' will not match the word `balls'), and 
  18007. punctuation and spacing are ignored (searching for `ball boy' will match `ball. 
  18008. Boy!'). 
  18009.  
  18010.  In this example, point is first placed at the beginning of the buffer; the 
  18011. search leaves it between the y and the !. 
  18012.  
  18013. ---------- Buffer: foo ----------
  18014. -!-He said "Please!  Find
  18015. the ball boy!"
  18016. ---------- Buffer: foo ----------
  18017.  
  18018. (word-search-forward "Please find the ball, boy.")
  18019.      => t
  18020.  
  18021. ---------- Buffer: foo ----------
  18022. He said "Please!  Find
  18023. the ball boy-!-!"
  18024. ---------- Buffer: foo ----------
  18025.  
  18026.  If limit is non-nil (it must be a position in the current buffer), then it is 
  18027. the upper bound to the search.  The match found must not extend after that 
  18028. position. 
  18029.  
  18030.  If noerror is t, then word-search-forward returns nil when a search fails, 
  18031. instead of signaling an error.  If noerror is neither nil nor t, then 
  18032. word-search-forward moves point to limit and returns nil. 
  18033.  
  18034.  If repeat is non-nil, then the search is repeated that many times.  Point is 
  18035. positioned at the end of the last match. 
  18036.  
  18037. -- Command: word-search-backward string &optional limit noerror repeat 
  18038.  This function searches backward from point for a word match to string.  This 
  18039. function is just like word-search-forward except that it searches backward and 
  18040. normally leaves point at the beginning of the match. 
  18041.  
  18042.  
  18043. ΓòÉΓòÉΓòÉ 32.2. Regular Expressions ΓòÉΓòÉΓòÉ
  18044.  
  18045.  A regular expression (regexp, for short) is a pattern that denotes a (possibly 
  18046. infinite) set of strings.  Searching for matches for a regexp is a very 
  18047. powerful operation.  This section explains how to write regexps; the following 
  18048. section says how to search for them. 
  18049.  
  18050.  
  18051. ΓòÉΓòÉΓòÉ 32.2.1. Syntax of Regular Expressions ΓòÉΓòÉΓòÉ
  18052.  
  18053.  Regular expressions have a syntax in which a few characters are special 
  18054. constructs and the rest are ordinary.  An ordinary character is a simple 
  18055. regular expression which matches that character and nothing else. The special 
  18056. characters are `$', `^', `.', `*', `+', `?', `[', `]' and `\'; no new special 
  18057. characters will be defined in the future.  Any other character appearing in a 
  18058. regular expression is ordinary, unless a `\' precedes it. 
  18059.  
  18060. For example, `f' is not a special character, so it is ordinary, and therefore 
  18061. `f' is a regular expression that matches the string `f' and no other string. 
  18062. (It does not match the string `ff'.)  Likewise, `o' is a regular expression 
  18063. that matches only `o'. 
  18064.  
  18065. Any two regular expressions a and b can be concatenated.  The result is a 
  18066. regular expression which matches a string if a matches some amount of the 
  18067. beginning of that string and b matches the rest of the string. 
  18068.  
  18069. As a simple example, we can concatenate the regular expressions `f' and `o' to 
  18070. get the regular expression `fo', which matches only the string `fo'.  Still 
  18071. trivial.  To do something more powerful, you need to use one of the special 
  18072. characters.  Here is a list of them: 
  18073.  
  18074. . (Period) 
  18075.           is a special character that matches any single character except a 
  18076.           newline. Using concatenation, we can make regular expressions like 
  18077.           `a.b' which matches any three-character string which begins with `a' 
  18078.           and ends with `b'. 
  18079.  
  18080.           is not a construct by itself; it is a suffix that means the preceding 
  18081.           regular expression is to be repeated as many times as possible.  In 
  18082.           `fo*', the `*' applies to the `o', so `fo*' matches one `f' followed 
  18083.           by any number of `o's.  The case of zero `o's is allowed: `fo*' does 
  18084.           match `f'. 
  18085.  
  18086.           `*' always applies to the smallest possible preceding expression. 
  18087.           Thus, `fo*' has a repeating `o', not a repeating `fo'. 
  18088.  
  18089.           The matcher processes a `*' construct by matching, immediately, as 
  18090.           many repetitions as can be found.  Then it continues with the rest of 
  18091.           the pattern.  If that fails, backtracking occurs, discarding some of 
  18092.           the matches of the `*'-modified construct in case that makes it 
  18093.           possible to match the rest of the pattern.  For example, matching 
  18094.           `ca*ar' against the string `caaar', the `a*' first tries to match all 
  18095.           three `a's; but the rest of the pattern is `ar' and there is only `r' 
  18096.           left to match, so this try fails. The next alternative is for `a*' to 
  18097.           match only two `a's. With this choice, the rest of the regexp matches 
  18098.           successfully. 
  18099.  
  18100.           is a suffix character similar to `*' except that it must match the 
  18101.           preceding expression at least once.  So, for example, `ca+r' will 
  18102.           match the strings `car' and `caaaar' but not the string `cr', whereas 
  18103.           `ca*r' would match all three strings. 
  18104.  
  18105.           is a suffix character similar to `*' except that it can match the 
  18106.           preceding expression either once or not at all.  For example, `ca?r' 
  18107.           will match `car' or `cr'; nothing else. 
  18108.  
  18109. [ ... ] 
  18110.           `[' begins a character set, which is terminated by a `]'.  In the 
  18111.           simplest case, the characters between the two form the set.  Thus, 
  18112.           `[ad]' matches either one `a' or one `d', and `[ad]*' matches any 
  18113.           string composed of just `a's and `d's (including the empty string), 
  18114.           from which it follows that `c[ad]*r' matches `cr', `car', `cdr', 
  18115.           `caddaar', etc. 
  18116.  
  18117.           Character ranges can also be included in a character set, by writing 
  18118.           two characters with a `-' between them.  Thus, `[a-z]' matches any 
  18119.           lower case letter.  Ranges may be intermixed freely with individual 
  18120.           characters, as in `[a-z$%.]', which matches any lower case letter or 
  18121.           `$', `%' or a period. 
  18122.  
  18123.           Note that the usual special characters are not special any more 
  18124.           inside a character set.  A completely different set of special 
  18125.           characters exists inside character sets: `]', `-' and `^'. 
  18126.  
  18127.           To include a `]' in a character set, make it the first character. For 
  18128.           example, `[]a]' matches `]' or `a'.  To include a `-', write `---', 
  18129.           which is a range containing only `-', or write `-' as the first 
  18130.           character in the range. 
  18131.  
  18132.           To include `^', make it other than the first character in the set. 
  18133.  
  18134. [^ ... ] 
  18135.           `[^' begins a complement character set, which matches any character 
  18136.           except the ones specified.  Thus, `[^a-z0-9A-Z]' matches all 
  18137.           characters except letters and digits. 
  18138.  
  18139.           `^' is not special in a character set unless it is the first 
  18140.           character.  The character following the `^' is treated as if it were 
  18141.           first (thus, `-' and `]' are not special there). 
  18142.  
  18143.           Note that a complement character set can match a newline, unless 
  18144.           newline is mentioned as one of the characters not to match. 
  18145.  
  18146.           is a special character that matches the empty string, but only at the 
  18147.           beginning of a line in the text being matched.  Otherwise it fails to 
  18148.           match anything.  Thus, `^foo' matches a `foo' which occurs at the 
  18149.           beginning of a line. 
  18150.  
  18151.           When matching a string, `^' matches at the beginning of the string or 
  18152.           after a newline character `\n'. 
  18153.  
  18154.           is similar to `^' but matches only at the end of a line.  Thus, `x+$' 
  18155.           matches a string of one `x' or more at the end of a line. 
  18156.  
  18157.           When matching a string, `$' matches at the end of the string or 
  18158.           before a newline character `\n'. 
  18159.  
  18160.           has two functions: it quotes the special characters (including `\'), 
  18161.           and it introduces additional special constructs. 
  18162.  
  18163.           Because `\' quotes special characters, `\$' is a regular expression 
  18164.           which matches only `$', and `\[' is a regular expression which 
  18165.           matches only `[', and so on. 
  18166.  
  18167.           Note that `\' also has special meaning in the read syntax of Lisp 
  18168.           strings (see String Type), and must be quoted with `\'.  For example, 
  18169.           the regular expression that matches the `\' character is `\\'.  To 
  18170.           write a Lisp string that contains `\\', Lisp syntax requires you to 
  18171.           quote each `\' with another `\'.  Therefore, the read syntax for this 
  18172.           string is "\\\\". 
  18173.  
  18174. *Note:* for historical compatibility, special characters are treated as 
  18175. ordinary ones if they are in contexts where their special meanings make no 
  18176. sense.  For example, `*foo' treats `*' as ordinary since there is no preceding 
  18177. expression on which the `*' can act.  It is poor practice to depend on this 
  18178. behavior; better to quote the special character anyway, regardless of where it 
  18179. appears. 
  18180.  
  18181. For the most part, `\' followed by any character matches only that character. 
  18182. However, there are several exceptions: characters which, when preceded by `\', 
  18183. are special constructs.  Such characters are always ordinary when encountered 
  18184. on their own.  Here is a table of `\' constructs: 
  18185.  
  18186. \| 
  18187.           specifies an alternative. Two regular expressions a and b with `\|' 
  18188.           in between form an expression that matches anything that either a or 
  18189.           b matches. 
  18190.  
  18191.           Thus, `foo\|bar' matches either `foo' or `bar' but no other string. 
  18192.  
  18193.           `\|' applies to the largest possible surrounding expressions.  Only a 
  18194.           surrounding `\( ... \)' grouping can limit the grouping power of 
  18195.           `\|'. 
  18196.  
  18197.           Full backtracking capability exists to handle multiple uses of `\|'. 
  18198.  
  18199. \( ... \) 
  18200.           is a grouping construct that serves three purposes: 
  18201.  
  18202.     1. To enclose a set of `\|' alternatives for other operations. Thus, 
  18203.        `\(foo\|bar\)x' matches either `foox' or `barx'. 
  18204.  
  18205.     2. To enclose a complicated expression for a suffix character such as `*' 
  18206.        to operate on.  Thus, `ba\(na\)*' matches `bananana', etc., with any 
  18207.        (zero or more) number of `na' strings. 
  18208.  
  18209.     3. To record a matched substring for future reference. 
  18210.  
  18211.           This last application is not a consequence of the idea of a 
  18212.           parenthetical grouping; it is a separate feature which happens to be 
  18213.           assigned as a second meaning to the same `\( ... \)' construct 
  18214.           because there is no conflict in practice between the two meanings. 
  18215.           Here is an explanation of this feature: 
  18216.  
  18217. \digit 
  18218.           after the end of a `\( ... \)' construct, the matcher remembers the 
  18219.           beginning and end of the text matched by that construct.  Then, later 
  18220.           on in the regular expression, you can use `\' followed by digit to 
  18221.           mean ``match the same text matched the digitth time by the `\( ... 
  18222.           \)' construct.'' 
  18223.  
  18224.           The strings matching the first nine `\( ... \)' constructs appearing 
  18225.           in a regular expression are assigned numbers 1 through 9 in the order 
  18226.           that the open parentheses appear in the regular expression. `\1' 
  18227.           through `\9' can be used to refer to the text matched by the 
  18228.           corresponding `\( ... \)' construct. 
  18229.  
  18230.           For example, `\(.*\)\1' matches any newline-free string that is 
  18231.           composed of two identical halves.  The `\(.*\)' matches the first 
  18232.           half, which may be anything, but the `\1' that follows must match the 
  18233.           same exact text. 
  18234.  
  18235. \` 
  18236.           matches the empty string, provided it is at the beginning of the 
  18237.           buffer. 
  18238.  
  18239. \' 
  18240.           matches the empty string, provided it is at the end of the buffer. 
  18241.  
  18242. \b 
  18243.           matches the empty string, provided it is at the beginning or end of a 
  18244.           word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a separate 
  18245.           word.  `\bballs?\b' matches `ball' or `balls' as a separate word. 
  18246.  
  18247. \B 
  18248.           matches the empty string, provided it is not at the beginning or end 
  18249.           of a word. 
  18250.  
  18251. \< 
  18252.           matches the empty string, provided it is at the beginning of a word. 
  18253.  
  18254. \> 
  18255.           matches the empty string, provided it is at the end of a word. 
  18256.  
  18257. \w 
  18258.           matches any word-constituent character.  The editor syntax table 
  18259.           determines which characters these are.  See Syntax Tables. 
  18260.  
  18261. \W 
  18262.           matches any character that is not a word-constituent. 
  18263.  
  18264. \scode 
  18265.           matches any character whose syntax is code.  Here code is a character 
  18266.           which represents a syntax code: thus, `w' for word constituent, `-' 
  18267.           for whitespace, `(' for open parenthesis, etc.  See Syntax Tables, 
  18268.           for a list of the codes. 
  18269.  
  18270. \Scode 
  18271.           matches any character whose syntax is not code. 
  18272.  
  18273.  Not every string is a valid regular expression.  For example, any string with 
  18274. unbalanced square brackets is invalid, and so is a string that ends with a 
  18275. single `\'.  If an invalid regular expression is passed to any of the search 
  18276. functions, an invalid-regexp error is signaled. 
  18277.  
  18278. -- Function: regexp-quote string 
  18279.  This function returns a regular expression string which matches exactly string 
  18280. and nothing else.  This allows you to request an exact string match when 
  18281. calling a function that wants a regular expression. 
  18282.  
  18283. (regexp-quote "^The cat$")
  18284.      => "\\^The cat\\$"
  18285.  
  18286. One use of regexp-quote is to combine an exact string match with context 
  18287. described as a regular expression.  For example, this searches for the string 
  18288. which is the value of string, surrounded by whitespace: 
  18289.  
  18290. (re-search-forward (concat "\\s " (regexp-quote string) "\\s "))
  18291.  
  18292.  
  18293. ΓòÉΓòÉΓòÉ 32.2.2. Complex Regexp Example ΓòÉΓòÉΓòÉ
  18294.  
  18295.  Here is a complicated regexp, used by Emacs to recognize the end of a sentence 
  18296. together with any whitespace that follows.  It is the value of the variable 
  18297. sentence-end. 
  18298.  
  18299.  First, we show the regexp as a string in Lisp syntax to enable you to 
  18300. distinguish the spaces from the tab characters.  The string constant begins and 
  18301. ends with a double-quote.  `\"' stands for a double-quote as part of the 
  18302. string, `\\' for a backslash as part of the string, `\t' for a tab and `\n' for 
  18303. a newline. 
  18304.  
  18305. "[.?!][]\"')}]*\\($\\|\t\\|  \\)[ \t\n]*"
  18306.  
  18307.  In contrast, if you evaluate the variable sentence-end, you will see the 
  18308. following: 
  18309.  
  18310. sentence-end
  18311. =>
  18312. "[.?!][]\"')}]*\\($\\|  \\|  \\)[
  18313. ]*"
  18314.  
  18315. In this case, the tab and carriage return are the actual characters. 
  18316.  
  18317.  This regular expression contains four parts in succession and can be 
  18318. deciphered as follows: 
  18319.  
  18320. [.?!] 
  18321.           The first part of the pattern consists of three characters, a period, 
  18322.           a question mark and an exclamation mark, within square brackets.  The 
  18323.           match must begin with one of these three characters. 
  18324.  
  18325. []\"')}]* 
  18326.           The second part of the pattern matches any closing braces and 
  18327.           quotation marks, zero or more of them, that may follow the period, 
  18328.           question mark or exclamation mark.  The \" is Lisp syntax for a 
  18329.           double-quote in a string.  The `*' at the end indicates that the 
  18330.           immediately preceding regular expression (a character set, in this 
  18331.           case) may be repeated zero or more times. 
  18332.  
  18333. \\($\\|\t\\|@ @ \\) 
  18334.           The third part of the pattern matches the whitespace that follows the 
  18335.           end of a sentence: the end of a line, or a tab, or two spaces.  The 
  18336.           double backslashes are needed to prevent Emacs from reading the 
  18337.           parentheses and vertical bars as part of the search pattern; the 
  18338.           parentheses are used to mark the group and the vertical bars are used 
  18339.           to indicated that the patterns to either side of them are 
  18340.           alternatives. The dollar sign is used to match the end of a line. 
  18341.           The tab character is written using `\t' and the two spaces are 
  18342.           written as themselves. 
  18343.  
  18344. [ \t\n]* 
  18345.           Finally, the last part of the pattern indicates that the end of the 
  18346.           line or the whitespace following the period, question mark or 
  18347.           exclamation mark may, but need not, be followed by additional 
  18348.           whitespace. 
  18349.  
  18350.  
  18351. ΓòÉΓòÉΓòÉ 32.3. Regular Expression Searching ΓòÉΓòÉΓòÉ
  18352.  
  18353.  In GNU Emacs, you can search for the next match for a regexp either 
  18354. incrementally or not.  Incremental search commands are described in the The GNU 
  18355. Emacs Manual. See Regular Expression Search.  Here we describe only the search 
  18356. functions useful in programs.  The principal is re-search-forward. 
  18357.  
  18358. -- Command: re-search-forward regexp &optional limit noerror repeat 
  18359.  This function searches forward in the current buffer for a string of text that 
  18360. is matched by the regular expression regexp.  The function skips over any 
  18361. amount of text that is not matched by regexp, and leaves point at the end of 
  18362. the first string found that does match. 
  18363.  
  18364.  If the search is successful (i.e., if text matching regexp is found), then 
  18365. point is left at the end of that text, and the function returns t. 
  18366.  
  18367.  What happens when the search fails depends on the value of noerror.  If 
  18368. noerror is nil, a search-failed error is signaled.  If noerror is t, 
  18369. re-search-forward returns nil and doesn't signal an error. If noerror is 
  18370. neither nil nor t, then search-forward moves point to limit and returns nil. 
  18371.  
  18372.  If limit is non-nil (it must be a position in the current buffer), then it is 
  18373. the upper bound to the search.  No match extending after that position is 
  18374. accepted. 
  18375.  
  18376. If repeat is supplied (it must be a positive number), then the search is 
  18377. repeated that many times (each time starting at the end of the previous time's 
  18378. match).  The call succeeds if all these searches succeeded, and point is left 
  18379. at the end of the match found by the last search.  Otherwise the search fails. 
  18380.  
  18381.  In the following example, point is initially located directly before the `T'. 
  18382. After evaluating the form, point is located at the end of that line (between 
  18383. the `t' of `hat' and before the newline). 
  18384.  
  18385. ---------- Buffer: foo ----------
  18386. I read "-!-The cat in the hat
  18387. comes back" twice.
  18388. ---------- Buffer: foo ----------
  18389.  
  18390. (re-search-forward "[a-z]+" nil t 5)
  18391.      => t
  18392.  
  18393. ---------- Buffer: foo ----------
  18394. I read "The cat in the hat-!-
  18395. comes back" twice.
  18396. ---------- Buffer: foo ----------
  18397.  
  18398. -- Command: re-search-backward regexp &optional limit noerror repeat 
  18399.  This function searches backward in the current buffer for a string of text 
  18400. that is matched by the regular expression regexp, leaving point at the 
  18401. beginning of the first text found. 
  18402.  
  18403.  This function is analogous to re-search-forward, but they are not simple 
  18404. mirror images.  re-search-forward finds the match whose beginning is as close 
  18405. as possible.  If re-search-backward were a perfect mirror image, it would find 
  18406. the match whose end is as close as possible.  However, in fact it finds the 
  18407. match whose beginning is as close as possible.  The reason is that matching a 
  18408. regular expression at a given spot always works from beginning to end, and is 
  18409. done at a specified beginning position.  Thus, true mirror-image behavior would 
  18410. require a special feature for matching regexps from end to beginning. 
  18411.  
  18412. -- Function: string-match regexp string &optional start 
  18413.  This function returns the index of the start of the first match for the 
  18414. regular expression regexp in string, or nil if there is no match.  If start is 
  18415. non-nil, the search starts at that index in string. 
  18416.  
  18417.  For example, 
  18418.  
  18419. (string-match "quick" "The quick brown fox jumped quickly.")
  18420.      => 4
  18421. (string-match "quick" "The quick brown fox jumped quickly." 8)
  18422.      => 27
  18423.  
  18424. The index of the first character of the string is 0, the index of the second 
  18425. character is 1, and so on. 
  18426.  
  18427.  After this function returns, the index of the first character beyond the match 
  18428. is available as (match-end 0).  See Match Data. 
  18429.  
  18430. (string-match "quick" "The quick brown fox jumped quickly." 8)
  18431.      => 27
  18432.  
  18433. (match-end 0)
  18434.      => 32
  18435.  
  18436.  The match-end function is described along with match-beginning; see Match 
  18437. Data. 
  18438.  
  18439. -- Function: looking-at regexp 
  18440.  This function determines whether the text in the current buffer directly 
  18441. following point matches the regular expression regexp.  ``Directly following'' 
  18442. means precisely that: the search is ``anchored'' and it must succeed starting 
  18443. with the first character following point.  The result is t if so, nil 
  18444. otherwise. 
  18445.  
  18446.  Point is not moved, but the match data is updated and can be used with 
  18447. match-beginning or match-end.  See Match Data. 
  18448.  
  18449.  In this example, point is located directly before the `T'.  If it were 
  18450. anywhere else, the result would be nil. 
  18451.  
  18452. ---------- Buffer: foo ----------
  18453. I read "-!-The cat in the hat
  18454. comes back" twice.
  18455. ---------- Buffer: foo ----------
  18456. (looking-at "The cat in the hat$")
  18457.      => t
  18458.  
  18459.  
  18460. ΓòÉΓòÉΓòÉ 32.4. The Match Data ΓòÉΓòÉΓòÉ
  18461.  
  18462.  Emacs keeps track of the positions of the start and end of segments of text 
  18463. found during a regular expression search.  This means, for example, that you 
  18464. can search for a complex pattern, such as a date in an Rmail message, and 
  18465. extract parts of it. 
  18466.  
  18467. -- Function: match-beginning count 
  18468. This function returns the position of the start of text matched by the last 
  18469. regular expression searched for.  count, a number, specifies a subexpression 
  18470. whose start position is the value.  If count is zero, then the value is the 
  18471. position of the text matched by the whole regexp.  If count is greater than 
  18472. zero, then the value is the position of the beginning of the text matched by 
  18473. the countth subexpression, regardless of whether it was used in the final 
  18474. match. 
  18475.  
  18476. Subexpressions of a regular expression are those expressions grouped inside of 
  18477. parentheses, `\(...\)'.  The countth subexpression is found by counting 
  18478. occurrences of `\(' from the beginning of the whole regular expression.  The 
  18479. first subexpression is numbered 1, the second 2, and so on. 
  18480.  
  18481. The match-end function is similar to the match-beginning function except that 
  18482. it returns the position of the end of the matched text. 
  18483.  
  18484. Here is an example, with a comment showing the numbers of the positions in the 
  18485. text: 
  18486.  
  18487. (string-match "\\(qu\\)\\(ick\\)" "The quick fox jumped quickly.")
  18488.      => 4                         ;^^^^^^^^^^
  18489.                                   ;0123456789
  18490.  
  18491. (match-beginning 1)               ; The beginning of the match
  18492.      => 4                         ; with `qu' is at index 4.
  18493.  
  18494. (match-beginning 2)               ; The beginning of the match
  18495.      => 6                         ; with `ick' is at index 6.
  18496.  
  18497. (match-end 1)                     ; The end of the match
  18498.      => 6                         ; with `qu' is at index 6.
  18499.  
  18500. (match-end 2)                     ; The end of the match
  18501.      => 9                         ; with `ick' is at index 9.
  18502.  
  18503. Here is another example.  Before the form is evaluated, point is located at the 
  18504. beginning of the line.  After evaluating the search form, point is located on 
  18505. the line between the space and the word `in'.  The beginning of the entire 
  18506. match is at the 9th character of the buffer (`T'), and the beginning of the 
  18507. match for the first subexpression is at the 13th character (`c'). 
  18508.  
  18509. (list
  18510.   (re-search-forward "The \\(cat \\)")
  18511.   (match-beginning 0)
  18512.   (match-beginning 1))
  18513. => (t 9 13)
  18514.  
  18515. ---------- Buffer: foo ----------
  18516. I read "The cat -!-in the hat comes back" twice.
  18517.         ^   ^
  18518.         9  13
  18519. ---------- Buffer: foo ----------
  18520.  
  18521. (Note that in this case, the index returned is a buffer position; the first 
  18522. character of the buffer counts as 1.) 
  18523.  
  18524.  It is essential that match-beginning be called after the search desired, but 
  18525. before any other searches are performed. match-beginning may not give the 
  18526. desired results if any other Lisp programs are executed between the search and 
  18527. it, since they may do other searches.  This example shows misuse of 
  18528. match-beginning. 
  18529.  
  18530. (re-search-forward "The \\(cat \\)")
  18531.      => t
  18532. (foo)                   ; Perhaps foo does more regexp searching.
  18533. (match-beginning 0)
  18534.      => 61              ; Unexpected result!
  18535.  
  18536.  See the discussion of store-match-data for an example of how to save and 
  18537. restore the match data around a search. 
  18538.  
  18539. -- Function: match-end count 
  18540.  This function returns the position of the end of text matched by the last 
  18541. regular expression searched for.  This function is otherwise similar to 
  18542. match-beginning. 
  18543.  
  18544. -- Function: replace-match replacement &optional fixedcase literal 
  18545.  This function replaces the text matched by the last search with replacement. 
  18546.  
  18547.  If fixedcase is non-nil, then the case of the replacement text is not changed; 
  18548. otherwise, the replacement text is converted to a different case depending upon 
  18549. the capitalization of the text to be replaced.  If the original text is all 
  18550. upper case, the replacement text is converted to upper case, except when all of 
  18551. the words in the original text are only one character long.  In that event, the 
  18552. replacement text is capitalized.  If all of the words in the original text are 
  18553. capitalized, then all of the words in the replacement text are capitalized. 
  18554.  
  18555.  If literal is non-nil, then replacement is inserted exactly as it is, the only 
  18556. alterations being case changes as needed. If it is nil (the default), then the 
  18557. character `\' is treated specially.  If a `\' appears in replacement, then it 
  18558. must be part of one of the following sequences: 
  18559.  
  18560. `\&' 
  18561.           `\&' stands for the entire text being replaced. 
  18562.  
  18563. `\n' 
  18564.           `\n' stands for the nth subexpression in the original regexp. 
  18565.           Subexpressions are those expressions grouped inside of `\(...\)'.  n 
  18566.           is a digit. 
  18567.  
  18568. `\\' 
  18569.           `\\' stands for a single `\' in the replacement text. 
  18570.  
  18571. replace-match leaves point at the end of the replacement text, and returns t. 
  18572.  
  18573.  
  18574. ΓòÉΓòÉΓòÉ 32.5. Saving and Restoring the Match Data ΓòÉΓòÉΓòÉ
  18575.  
  18576. -- Function: match-data 
  18577.  This function returns a new list containing all the information on what text 
  18578. the last search matched.  Element zero is the position of the beginning of the 
  18579. match for the whole expression; element one is the position of the end of the 
  18580. match for the expression.  The next two elements are the positions of the 
  18581. beginning and end of the match for the first subexpression.  In general, 
  18582. element number 2n corresponds to (match-beginning n); and element number 2n + 1 
  18583. corresponds to (match-end n). 
  18584.  
  18585. All the elements are markers, or the integer 0 for a match at the beginning of 
  18586. a string (with string-match), or nil if there was no match for that 
  18587. subexpression.  As with other functions that get information about a search, 
  18588. there must be no possibility of intervening searches between the call to a 
  18589. search function and the call to match-data that is intended to save the 
  18590. match-data for that search. 
  18591.  
  18592. (match-data)
  18593.      =>  (#<marker at 9 in foo> #<marker at 17 in foo>
  18594.           #<marker at 13 in foo> #<marker at 17 in foo>)
  18595.  
  18596. In version 19, all elements will be markers or nil if matching was done on a 
  18597. buffer, and all will be integers or nil if matching was done on a string with 
  18598. string-match. 
  18599.  
  18600. -- Function: store-match-data match-list 
  18601. This function sets the match data within Emacs Lisp from the elements of 
  18602. match-list, which should be a list created by a previous call to match-data. 
  18603.  
  18604. store-match-data may be used together with match-data to perform a search 
  18605. without changing the match-data.  This is useful when such searches occur in 
  18606. subroutines whose callers may not expect searches to go on.  Here is how: 
  18607.  
  18608. (let ((data (match-data)))
  18609.   (unwind-protect
  18610.       ... ; May change the original match data.
  18611.     (store-match-data data)))
  18612.  
  18613.  All asynchronous process functions (filters and sentinels) and some modes that 
  18614. use recursive-edit should save and restore the match data if they do a search 
  18615. or if they let the user type arbitrary commands. 
  18616.  
  18617.  Here is a function which will restore the match data if the buffer associated 
  18618. with it still exists. 
  18619.  
  18620. (defun restore-match-data (data)
  18621.   "Restore the match data DATA unless the buffer is missing."
  18622.   (catch 'foo
  18623.     (let ((d data))
  18624.       (while d
  18625.         (and (car d)
  18626.              (null (marker-buffer (car d)))
  18627.              ;; match-data buffer is deleted.
  18628.              (throw 'foo nil))
  18629.         (setq d (cdr d)))
  18630.       (store-match-data data))))
  18631.  
  18632.  
  18633. ΓòÉΓòÉΓòÉ 32.6. Standard Regular Expressions Used in Editing ΓòÉΓòÉΓòÉ
  18634.  
  18635. -- Variable: page-delimiter 
  18636. This is the regexp describing line-beginnings that separate pages.  The default 
  18637. value is "^\014" (i.e., "^^L" or "^\C-l"). 
  18638.  
  18639. -- Variable: paragraph-separate 
  18640. This is the regular expression for recognizing the beginning of a line that 
  18641. separates paragraphs.  (If you change this, you may have to change 
  18642. paragraph-start also.)  The default value is "^[ \t\f]*$", which is a line that 
  18643. consists entirely of spaces, tabs, and form feeds. 
  18644.  
  18645. -- Variable: paragraph-start 
  18646. This is the regular expression for recognizing the beginning of a line that 
  18647. starts or separates paragraphs.  The default value is "^[ \t\n\f]", which 
  18648. matches a line starting with a space, tab, newline, or form feed. 
  18649.  
  18650. -- Variable: sentence-end 
  18651. This is the regular expression describing the end of a sentence.  (All 
  18652. paragraph boundaries also end sentences, regardless.)  The default value is: 
  18653.  
  18654. "[.?!][]\"')}]*\\($\\|\t\\| \\)[ \t\n]*"
  18655.  
  18656. This means a period, question mark or exclamation mark, followed by a closing 
  18657. brace, followed by tabs, spaces or new lines. 
  18658.  
  18659. For a detailed explanation of this regular expression, see Regexp Example. 
  18660.  
  18661.  
  18662. ΓòÉΓòÉΓòÉ 32.7. Searching and Case ΓòÉΓòÉΓòÉ
  18663.  
  18664.  By default, searches in Emacs ignore the case of the text they are searching 
  18665. through; if you specify searching for `FOO', then `Foo' or `foo' is also 
  18666. considered a match.  Regexps, and in particular character sets, are included: 
  18667. thus, `[aB]' would match `a' or `A' or `b' or `B'. 
  18668.  
  18669.  If you do not want this feature, set the variable case-fold-search to nil. 
  18670. Then all letters must match exactly, including case.  This is a 
  18671. per-buffer-local variable; altering the variable affects only the current 
  18672. buffer.  ( See Intro to Buffer-Local.)  Alternatively, you may change the value 
  18673. of default-case-fold-search, which is the default value of case-fold-search for 
  18674. buffers that do not override it. 
  18675.  
  18676. -- User Option: case-replace 
  18677.  This variable determines whether query-replace should preserve case in 
  18678. replacements.  If the variable is nil, then case need not be preserved. 
  18679.  
  18680. -- User Option: case-fold-search 
  18681.  This buffer-local variable determines whether searches should ignore case.  If 
  18682. the variable is nil they do not ignore case; otherwise they do ignore case. 
  18683.  
  18684. -- Variable: default-case-fold-search 
  18685.  The value of this variable is the default value for case-fold-search in 
  18686. buffers that do not override it.  This is the same as (default-value 
  18687. 'case-fold-search). 
  18688.  
  18689.  
  18690. ΓòÉΓòÉΓòÉ 33. Syntax Tables ΓòÉΓòÉΓòÉ
  18691.  
  18692.  A syntax table provides Emacs with the information that determines the 
  18693. syntactic use of each character in a buffer.  This information is used by the 
  18694. parsing commands, the complex movement commands, and others to determine where 
  18695. words, symbols, and other syntactic constructs begin and end. 
  18696.  
  18697.  A syntax table is a vector of 256 elements; it contains one entry for each of 
  18698. the 256 ASCII characters of an 8-bit byte.  Each element is an integer that 
  18699. encodes the syntax of the character in question. 
  18700.  
  18701.  Syntax tables are used only for moving across text, not for the GNU Emacs Lisp 
  18702. reader.  GNU Emacs Lisp uses built-in syntactic rules when reading Lisp 
  18703. expressions, and these rules cannot be changed. 
  18704.  
  18705.  Each buffer has its own major mode, and each major mode has its own idea of 
  18706. the syntactic class of various characters.  For example, in Lisp mode, the 
  18707. character `;' begins a comment, but in C mode, it terminates a statement.  To 
  18708. support these variations, Emacs makes the choice of syntax table local to the 
  18709. each buffer.  Typically, each major mode has its own syntax table and installs 
  18710. that table in each buffer which uses that mode.  Changing this table alters the 
  18711. syntax in all those buffers as well as in any buffers subsequently put in that 
  18712. mode. Occasionally several similar modes share one syntax table. See Example 
  18713. Major Modes, for an example of how to set up a syntax table. 
  18714.  
  18715. -- Function: syntax-table-p object 
  18716.  This function returns t if object is a vector of length 256 elements.  This 
  18717. means that the vector may be a syntax table. However, according to this test, 
  18718. any vector of length 256 is considered to be a syntax table, no matter what its 
  18719. contents. 
  18720.  
  18721.  
  18722. ΓòÉΓòÉΓòÉ 33.1. Syntax Descriptors ΓòÉΓòÉΓòÉ
  18723.  
  18724.  This section describes the syntax classes and flags that denote the syntax of 
  18725. a character, and how they are represented as a syntax descriptor, which is a 
  18726. Lisp string that you pass to modify-syntax-entry to specify the desired syntax. 
  18727.  
  18728.  Emacs defines twelve syntax classes.  Each syntax table contains a mapping 
  18729. that puts each character into one class.  There is no necessary relationship 
  18730. between the class of a character in one syntax table and its class in any other 
  18731. table. 
  18732.  
  18733.  Each class is designated by a mnemonic character which serves as the name of 
  18734. the class when you need to specify a class.  Usually the designator character 
  18735. is one which is frequently put in that class; however, its meaning as a 
  18736. designator is unvarying and independent of how it is actually classified. 
  18737.  
  18738.  A syntax descriptor is a Lisp string which specifies a syntax class, a 
  18739. matching character (unused except for parenthesis classes) and flags. The first 
  18740. character is the designator for a syntax class.  The second character is the 
  18741. character to match; if it is unused, put a space there. Then come the 
  18742. characters for any desired flags.  If no matching character or flags are 
  18743. needed, one character is sufficient. 
  18744.  
  18745.  Thus, the descriptor for the character `*' in C mode is `. 23' (i.e., 
  18746. punctuation, matching character slot unused, second character of a 
  18747. comment-starter, first character of an comment-ender), and the entry for `/' is 
  18748. `. 14' (i.e., punctuation, matching character slot unused, first character of a 
  18749. comment-starter, second character of a comment-ender). 
  18750.  
  18751.  
  18752. ΓòÉΓòÉΓòÉ 33.1.1. Table of Syntax Classes ΓòÉΓòÉΓòÉ
  18753.  
  18754.  Here is a summary of the classes, the characters that stand for them, their 
  18755. meanings, and examples of their use. 
  18756.  
  18757. -- Syntax class: whitespace character 
  18758. Whitespace characters (designated with `@ ' or `-') separate symbols and words 
  18759. from each other.  Typically, whitespace characters have no other syntactic use, 
  18760. and multiple whitespace characters are syntactically equivalent to one.  Space, 
  18761. tab, newline and formfeed are almost always considered whitespace. 
  18762.  
  18763. -- Syntax class: word constituent 
  18764. Word constituents (designated with `w') are parts of normal English words and 
  18765. are typically used in variable and command names in programs.  All upper and 
  18766. lower case letters and the digits are typically word constituents. 
  18767.  
  18768. -- Syntax class: symbol constituent 
  18769. Symbol constituents (designated with `_') are the extra characters that are 
  18770. used in variable and command names along with word constituents.  For example, 
  18771. the symbol constituents class is used in Lisp mode to indicate that certain 
  18772. characters may be part of symbol names even though they are not part of English 
  18773. words.  These characters are `$&*+-_<>'.  In standard C, the only 
  18774. non-word-constituent character that is valid in symbols is underscore (`_'). 
  18775.  
  18776. -- Syntax class: punctuation character 
  18777. Punctuation characters (`.') are those characters that are used as punctuation 
  18778. in English, or are used in some way in a programming language to separate 
  18779. symbols from one another.  Most programming language modes, including Emacs 
  18780. Lisp mode, have no characters in this class since the few characters that are 
  18781. not symbol or word constituents all have other uses. 
  18782.  
  18783. -- Syntax class: open parenthesis character 
  18784. -- Syntax class: close parenthesis character 
  18785. Open and close parenthesis characters are characters used in dissimilar pairs 
  18786. to surround sentences or expressions.  Such a grouping is begun with an open 
  18787. parenthesis character and terminated with a close. Each open parenthesis 
  18788. character matches a particular close parenthesis character, and vice versa. 
  18789. Normally, Emacs indicates momentarily the matching open parenthesis when you 
  18790. insert a close parenthesis. See Blinking. 
  18791.  
  18792. The class of open parentheses is designated with `(', and that of close 
  18793. parentheses with `)'. 
  18794.  
  18795. In English text, and in C code, the parenthesis pairs are `()', `[]', and `{}'. 
  18796. In Emacs Lisp, the delimiters for lists and vectors (`()' and `[]') are 
  18797. classified as parenthesis characters. 
  18798.  
  18799. -- Syntax class: string quote 
  18800. String quote characters (designated with `"') is used to delimit string 
  18801. constants in many languages, including Lisp and C.  The same string quote 
  18802. character appears at the beginning and the end of a string.  Such quoted 
  18803. strings do not nest. 
  18804.  
  18805. The parsing facilities of Emacs consider a string as a single token. The usual 
  18806. syntactic meanings of the characters in the string are suppressed. 
  18807.  
  18808. The Lisp modes have two string quote characters: double-quote (`"') and 
  18809. vertical bar (`|').  `|' is not used in Emacs Lisp, but it is used in Common 
  18810. Lisp.  C also has two string quote characters: double-quote for strings, and 
  18811. single-quote (`'') for character constants. 
  18812.  
  18813. English text has no string quote characters because English is not a 
  18814. programming language.  Although quotation marks are used in English, we do not 
  18815. want them to turn off the usual syntactic properties of other characters in the 
  18816. quotation. 
  18817.  
  18818. -- Syntax class: escape 
  18819. An escape character (designated with `\') starts an escape sequence such as is 
  18820. used in C string and character constants.  The character `\' belongs to this 
  18821. class in both C and Lisp.  (In C, it is used thus only inside strings, but it 
  18822. turns out to cause no trouble to treat it this way throughout C code.) 
  18823.  
  18824. -- Syntax class: character quote 
  18825. A character quote character (designated with `/') quotes the following 
  18826. character so that it loses its normal syntactic meaning.  This differs from an 
  18827. escape character in that only the character immediately following is ever 
  18828. affected. 
  18829.  
  18830. This class is not currently used in any standard Emacs modes. 
  18831.  
  18832. -- Syntax class: paired delimiter 
  18833. Paired delimiter characters (designated with `$') are like string quote 
  18834. characters except that the syntactic properties of the characters between the 
  18835. delimiters are not suppressed.  Only TeX mode uses a paired identical delimiter 
  18836. presently---the `$' that begins and ends math mode. 
  18837.  
  18838. -- Syntax class: expression prefix 
  18839. An expression prefix operator (designated with `'') is used for syntactic 
  18840. operators that are part of an expression if they appear next to one but are not 
  18841. part of an adjoining symbol.  These characters in Lisp include the apostrophe, 
  18842. `'' (used for quoting), and the comma, `,' (used in macros). 
  18843.  
  18844. -- Syntax class: comment starter 
  18845. -- Syntax class: comment ender 
  18846. The comment starter and comment ender characters are used in different 
  18847. languages to delimit comments.  These classes are designated with `<' and `>', 
  18848. respectively. 
  18849.  
  18850. English text has no comment characters.  In Lisp, the semi-colon (`;') starts a 
  18851. comment and a newline or formfeed ends one. 
  18852.  
  18853.  
  18854. ΓòÉΓòÉΓòÉ 33.1.2. Syntax Flags ΓòÉΓòÉΓòÉ
  18855.  
  18856.  In addition to the classes, entries for characters in a syntax table can 
  18857. include flags.  There are four possible flags, represented by the characters 
  18858. `1', `2', `3', and `4'.  All are used to describe multi-character comment 
  18859. delimiters.  A flag indicates that the character for which the entry is being 
  18860. made can also be part of a comment sequence, in addition to the syntactic 
  18861. properties associated with its character class.  The flags are independent of 
  18862. the class and each other for the sake of characters such as `*' in C mode, 
  18863. which is a punctuation character, and the second character of a 
  18864. start-of-comment sequence (`/*'), and the first character of an end-of-comment 
  18865. sequence (`*/'). 
  18866.  
  18867. The flags for a character c are: 
  18868.  
  18869. o `1' means c is the start of a two-character comment start sequence. 
  18870.  
  18871. o `2' means c is the second character of such a sequence. 
  18872.  
  18873. o `3' means c is the start of a two-character comment end sequence. 
  18874.  
  18875. o `4' means c is the second character of such a sequence. 
  18876.  
  18877.  
  18878. ΓòÉΓòÉΓòÉ 33.2. Syntax Table Functions ΓòÉΓòÉΓòÉ
  18879.  
  18880.  In this section we describe functions for creating, accessing and altering 
  18881. syntax tables. 
  18882.  
  18883. -- Function: make-syntax-table  &optional table 
  18884. This function constructs a copy of table and returns it.  If table is not 
  18885. supplied (or is nil), it returns a copy of the current syntax table. 
  18886. Otherwise, an error is signaled if table is not a syntax table. 
  18887.  
  18888. -- Function: copy-syntax-table &optional table 
  18889. This function is identical to make-syntax-table. 
  18890.  
  18891. -- Command: modify-syntax-entry char syntax-descriptor  &optional table 
  18892. This function sets the syntax entry for char according to syntax-descriptor. 
  18893. The syntax is changed only for table, which defaults to the current buffer's 
  18894. syntax table, and not in any other syntax table.  The argument 
  18895. syntax-descriptor specifies the desired syntax; this is a string beginning with 
  18896. a class designator character, and optionally containing a matching character 
  18897. and flags as well.  See Syntax Descriptors. 
  18898.  
  18899. This function always returns nil.  The old syntax information in the table for 
  18900. this character is discarded. 
  18901.  
  18902. An error is signaled if the first character of the syntax descriptor is not one 
  18903. of the twelve syntax class designator characters.  An error is also signaled if 
  18904. char is not a character. 
  18905.  
  18906. Examples: 
  18907.  
  18908. ;; Put the space character in class whitespace.
  18909. (modify-syntax-entry ?\  " ")
  18910.      => nil
  18911.  
  18912. ;; Make `$' an open parenthesis character,
  18913. ;; with `^' as its matching close.
  18914. (modify-syntax-entry ?$ "(^")
  18915.      => nil
  18916. ;; Make `^' a close parenthesis character,
  18917. ;; with `$' as its matching open.
  18918. (modify-syntax-entry ?^ ")$")
  18919.      => nil
  18920.  
  18921. ;; Make `/' a punctuation character,
  18922. ;; the first character of a start-comment sequence,
  18923. ;; and the second character of an end-comment sequence.
  18924. ;; This is used in C mode.
  18925. (modify-syntax-entry ?/ ".13")
  18926.      => nil
  18927.  
  18928. -- Function: char-syntax character 
  18929. This function returns the syntax class of character, represented by its 
  18930. mnemonic designator character.  This only returns the class, not any matching 
  18931. parenthesis or flags. 
  18932.  
  18933. An error is signaled if char is not a character. 
  18934.  
  18935. The first example shows that the syntax class of space is whitespace 
  18936. (represented by a space).  The second example shows that the syntax of `/' is 
  18937. punctuation in C-mode.  This does not show the fact that it is also a comment 
  18938. sequence character.  The third example shows that open parenthesis is in the 
  18939. class of open parentheses.  This does not show the fact that it has a matching 
  18940. character, `)'. 
  18941.  
  18942. (char-to-string (char-syntax ?\ ))
  18943.      => " "
  18944.  
  18945. (char-to-string (char-syntax ?/))
  18946.      => "."
  18947.  
  18948. (char-to-string (char-syntax ?\())
  18949.      => "("
  18950.  
  18951. -- Function: set-syntax-table table 
  18952. This function makes table the syntax table for the current buffer. It returns 
  18953. table. 
  18954.  
  18955. -- Function: syntax-table 
  18956. This function returns the current syntax table, which is the table for the 
  18957. current buffer. 
  18958.  
  18959. -- command: describe-syntax 
  18960. This function describes the syntax specifications of the current syntax table. 
  18961. It makes a listing in the `*Help*' buffer, and then pops up a window to display 
  18962. it.  It returns nil. 
  18963.  
  18964. A portion of a description is shown here: 
  18965.  
  18966. (describe-syntax)
  18967.      => nil
  18968.  
  18969. ---------- Buffer: *Help* ----------
  18970. C-q             \       which means: escape
  18971. C-r .. C-_              which means: whitespace
  18972. !               .       which means: punctuation
  18973. (               ()      which means: open, matches )
  18974. )               )(      which means: close, matches (
  18975. * .. +          _       which means: symbol
  18976. ,               .       which means: punctuation
  18977. -               _       which means: symbol
  18978. .               .       which means: punctuation
  18979. /               . 13    which means: punctuation,
  18980.           is the first character of a comment-start sequence,
  18981.           is the first character of a comment-end sequence
  18982. 0 .. 9          w       which means: word
  18983. ---------- Buffer: *Help* ----------
  18984.  
  18985.  
  18986. ΓòÉΓòÉΓòÉ 33.3. Parsing and Moving Over Balanced Expressions ΓòÉΓòÉΓòÉ
  18987.  
  18988.  Here are several functions for parsing and scanning balanced expressions.  The 
  18989. syntax table controls the interpretation of characters, so these functions can 
  18990. be used for Lisp expressions when in Lisp mode and for C expressions when in C 
  18991. mode.  See List Motion, for convenient higher-level functions for moving over 
  18992. balanced expressions. 
  18993.  
  18994. -- Function: parse-partial-sexp start limit &optional target-depth stop-before 
  18995. state 
  18996.  This function parses an expression in the current buffer starting at start, 
  18997. not scanning past limit.  Parsing stops at limit or when certain criteria 
  18998. described below are met; point is set to the location where parsing stops.  The 
  18999. value returned is a description of the status of the parse at the point where 
  19000. it stops. 
  19001.  
  19002.  Normally, start is assumed to be the top level of an expression to be parsed, 
  19003. such as the beginning of a function definition. Alternatively, you might wish 
  19004. to resume parsing in the middle of an expression.  To do this, you must provide 
  19005. a state argument that describes the initial status of parsing.  If state is 
  19006. omitted (or nil), parsing assumes that start is the beginning of a new parse at 
  19007. level 0. 
  19008.  
  19009.  If the third argument target-depth is non-nil, parsing stops if the depth in 
  19010. parentheses becomes equal to target-depth. The depth starts at 0, or at 
  19011. whatever is given in state. 
  19012.  
  19013.  If the fourth argument stop-before is non-nil, parsing stops when it comes to 
  19014. any character that starts a sexp. 
  19015.  
  19016.  The fifth argument state is a seven-element list of the same form as the value 
  19017. of this function, described below.  The return value of one call may be used to 
  19018. initialize the state of the parse on another call to parse-partial-sexp. 
  19019.  
  19020.  The result is a list of seven elements describing the final state of the 
  19021. parse: 
  19022.  
  19023.  1. The depth in parentheses, starting at 0. 
  19024.  
  19025.  2. The character position of the start of the innermost containing 
  19026.     parenthetical grouping; nil if none. 
  19027.  
  19028.  3. The character position of the start of the last complete subexpression 
  19029.     terminated; nil if none. 
  19030.  
  19031.  4. Non-nil if inside a string.  (It is the character that will terminate the 
  19032.     string.) 
  19033.  
  19034.  5. t if inside a comment. 
  19035.  
  19036.  6. t if point is just after a quote character. 
  19037.  
  19038.  7. The minimum parenthesis depth encountered during this scan. 
  19039.  
  19040. Elements 1, 4, 5, and 6 are significant in the argument state. 
  19041.  
  19042. This function is used to determine how to indent lines in programs written in 
  19043. languages that have nested parentheses. 
  19044.  
  19045. -- Function: scan-lists from count depth 
  19046.  This function scans forward count balanced parenthetical groupings from 
  19047. character number from.  It returns the character number of the position thus 
  19048. found. 
  19049.  
  19050.  If depth is nonzero, parenthesis depth counting begins from that value.  The 
  19051. only candidates for stopping are places where the depth in parentheses becomes 
  19052. zero; scan-lists counts count such places and then stops.  Thus, a positive 
  19053. value for depth means go out levels of parenthesis. 
  19054.  
  19055.  Comments are ignored if parse-sexp-ignore-comments is non-nil. 
  19056.  
  19057.  If the beginning or end of the buffer (or its accessible portion) is reached 
  19058. and the depth is not zero, an end-of-file error is signaled.  If the depth is 
  19059. zero but the count is not used up, nil is returned. 
  19060.  
  19061. -- Function: scan-sexps from count 
  19062.  Scan from character number from by count balanced expressions.  It returns the 
  19063. character number of the position thus found. 
  19064.  
  19065.  Comments are ignored if parse-sexp-ignore-comments is non-nil. 
  19066.  
  19067.  If the beginning or end of (the accessible part of) the buffer is reached in 
  19068. the middle of a parenthetical grouping, an end-of-file error is signaled.  If 
  19069. the beginning or end is reached between groupings but before count is used up, 
  19070. nil is returned. 
  19071.  
  19072. -- Function: backward-prefix-chars 
  19073. This function moves point backward over any number of chars with expression 
  19074. prefix syntax. 
  19075.  
  19076. -- Variable: parse-sexp-ignore-comments 
  19077.  If the value is non-nil, then comments are treated as whitespace by the 
  19078. functions in this section and by forward-sexp. 
  19079.  
  19080.  This works only when the comment terminator is something like `*/', and 
  19081. appears only to end a comment.  If comments are terminated by newlines, you 
  19082. must make this variable nil, since not every newline is the end of a comment. 
  19083. (In version 19, this limitation is removed.) 
  19084.  
  19085.  
  19086. ΓòÉΓòÉΓòÉ 33.4. Some Standard Syntax Tables ΓòÉΓòÉΓòÉ
  19087.  
  19088.  Each of the major modes in Emacs has its own syntax table.  Here are several 
  19089. of them: 
  19090.  
  19091. -- Function: standard-syntax-table 
  19092. This function returns the standard syntax table, which is the syntax table used 
  19093. in Fundamental mode. 
  19094.  
  19095. -- Variable: text-mode-syntax-table 
  19096. The value of this variable is the syntax table used in Text mode. 
  19097.  
  19098. -- Variable: c-mode-syntax-table 
  19099. The value of this variable is the syntax table in use in C-mode buffers. 
  19100.  
  19101. -- Variable: emacs-lisp-mode-syntax-table 
  19102. The value of this variable is the syntax table used in Emacs Lisp mode by 
  19103. editing commands.  (It has no effect on the Lisp read function.) 
  19104.  
  19105.  
  19106. ΓòÉΓòÉΓòÉ 33.5. Syntax Table Internals ΓòÉΓòÉΓòÉ
  19107.  
  19108.  Each element of a syntax table is an integer that translates into the full 
  19109. meaning of the entry: class, possible matching character, and flags.  However, 
  19110. it is not common for a programmer to work with the entries directly in this 
  19111. form since the Lisp-level syntax table functions usually work with syntax 
  19112. descriptors (see Syntax Descriptors). 
  19113.  
  19114.   The low 8 bits of each element of a syntax table indicates the syntax class. 
  19115.  
  19116. Integer 
  19117.           Class 
  19118.  
  19119.           whitespace 
  19120.  
  19121.           punctuation 
  19122.  
  19123.           word 
  19124.  
  19125.           symbol 
  19126.  
  19127.           open parenthesis 
  19128.  
  19129.           close parenthesis 
  19130.  
  19131.           expression prefix 
  19132.  
  19133.           string quote 
  19134.  
  19135.           paired delimiter 
  19136.  
  19137.           escape 
  19138.  
  19139. 10 
  19140.           character quote 
  19141.  
  19142. 11 
  19143.           comment-start 
  19144.  
  19145. 12 
  19146.           comment-end 
  19147.  
  19148.  The next 8 bits are the matching opposite parenthesis (if the character has 
  19149. parenthesis syntax); otherwise, they are not meaningful. The next 4 bits are 
  19150. the flags. 
  19151.  
  19152.  
  19153. ΓòÉΓòÉΓòÉ 34. Abbrevs And Abbrev Expansion ΓòÉΓòÉΓòÉ
  19154.  
  19155.  An abbreviation or abbrev is a string of characters that may be expanded to a 
  19156. longer string.  The user can insert the abbrev string and find it replaced 
  19157. automatically with the expansion of the abbrev.  This saves typing. 
  19158.  
  19159.  The set of abbrevs currently in effect is recorded in an abbrev table.  Each 
  19160. buffer has a local abbrev table, but normally all buffers in the same major 
  19161. mode share one abbrev table.  There is also a global abbrev table.  Normally 
  19162. both are used. 
  19163.  
  19164.  An abbrev table is represented as an obarray containing a symbol for each 
  19165. abbreviation.  The symbol's name is the abbreviation.  Its value is the 
  19166. expansion; its function definition is the hook; its property list cell contains 
  19167. the use count, the number of times the abbreviation has been expanded.  Because 
  19168. these symbols are not inturned in the usual obarray, they will never appear as 
  19169. the result of reading a Lisp expression; in fact, they will never be used 
  19170. except by the code that handles abbrevs.  Therefore, it is safe to use them in 
  19171. an extremely nonstandard way.  See Creating Symbols. 
  19172.  
  19173.  For the user-level commands for abbrevs, see Abbrev Mode. 
  19174.  
  19175.  
  19176. ΓòÉΓòÉΓòÉ 34.1. Setting Up Abbrev Mode ΓòÉΓòÉΓòÉ
  19177.  
  19178.  Abbrev mode is a minor mode controlled by the value of the variable 
  19179. abbrev-mode. 
  19180.  
  19181. -- Variable: abbrev-mode 
  19182. A non-nil value of this variable turns on the automatic expansion of abbrevs 
  19183. when their abbreviations are inserted into a buffer. If the value is nil, 
  19184. abbrevs may be defined, but they are not expanded automatically. 
  19185.  
  19186. This variable automatically becomes local when set in any fashion. 
  19187.  
  19188. -- Variable: default-abbrev-mode 
  19189. This is the value abbrev-mode for buffers that do not override it. This is the 
  19190. same as (default-value 'abbrev-mode). 
  19191.  
  19192.  
  19193. ΓòÉΓòÉΓòÉ 34.2. Abbrev Tables ΓòÉΓòÉΓòÉ
  19194.  
  19195.  This section describes how to create and manipulate abbrev tables. 
  19196.  
  19197. -- Function: make-abbrev-table 
  19198. This function creates and returns a new, empty abbrev table---an obarray 
  19199. containing no symbols.  It is a vector filled with nils. 
  19200.  
  19201. -- Function: clear-abbrev-table table 
  19202. This function undefines all the abbrevs in abbrev table table, leaving it 
  19203. empty.  The function returns nil. 
  19204.  
  19205. -- Function: define-abbrev-table tabname definitions 
  19206. This function defines tabname (a symbol) as an abbrev table name, i.e., as a 
  19207. variable whose value is an abbrev table.  It defines abbrevs in the table 
  19208. according to definitions, a list of elements of the form (abbrevname expansion 
  19209. hook usecount).  The value is always nil. 
  19210.  
  19211. -- Variable: abbrev-table-name-list 
  19212. This is a list of symbols whose values are abbrev tables. define-abbrev-table 
  19213. adds the new abbrev table name to this list. 
  19214.  
  19215. -- Function: insert-abbrev-table-description name human 
  19216. This function inserts before point a description of the abbrev table named 
  19217. name.  The argument name is a symbol whose value is an abbrev table.  The value 
  19218. is always nil. 
  19219.  
  19220. If human is non-nil, a human-oriented description is inserted.  Otherwise the 
  19221. description is a Lisp expression---a call to define-abbrev-table which would 
  19222. define name exactly as it is currently defined. 
  19223.  
  19224.  
  19225. ΓòÉΓòÉΓòÉ 34.3. Defining Abbrevs ΓòÉΓòÉΓòÉ
  19226.  
  19227.  These functions define an abbrev in a specified abbrev table. define-abbrev is 
  19228. the low-level basic function, while add-abbrev is used by commands that ask for 
  19229. information from the user. 
  19230.  
  19231. -- Function: add-abbrev table type arg 
  19232. This function adds an abbreviation to abbrev table table.  The argument type is 
  19233. a string describing in English the kind of abbrev this will be (typically, 
  19234. "global" or "mode-specific"); this is used in prompting the user.  The argument 
  19235. arg is the number of words in the expansion. 
  19236.  
  19237. The return value is the symbol which internally represents the new abbrev, or 
  19238. nil if the user declines to redefine an existing abbrev. 
  19239.  
  19240. -- Function: define-abbrev table name expansion hook 
  19241. This function defines an abbrev in table named name, to expand to expansion, 
  19242. and call hook.  The return value is an uninterned symbol which represents the 
  19243. abbrev inside Emacs; its name is name. 
  19244.  
  19245. The argument name should be a string.  The argument expansion should be a 
  19246. string, or nil, to undefine the abbrev. 
  19247.  
  19248. The argument hook is a function or nil.  If hook is non-nil, then it is called 
  19249. with no arguments after the abbrev is replaced with expansion; point is located 
  19250. at the end of expansion. 
  19251.  
  19252. The use count of the abbrev is initialized to zero. 
  19253.  
  19254. -- User Option: only-global-abbrevs 
  19255. If this variable is non-nil, it means that the user plans to use global abbrevs 
  19256. only.  This tells the commands that define mode-specific abbrevs to define 
  19257. global ones instead.  This variable does not alter the functioning of the 
  19258. functions in this section; it is examined by their callers. 
  19259.  
  19260.  
  19261. ΓòÉΓòÉΓòÉ 34.4. Saving Abbrevs in Files ΓòÉΓòÉΓòÉ
  19262.  
  19263.  A file of saved abbrev definitions is actually a file of Lisp code. The 
  19264. abbrevs are saved in the form of a Lisp program to define the same abbrev 
  19265. tables with the same contents.  Therefore, you can load the file with load (see 
  19266. How Programs Do Loading).  However, the function quietly-read-abbrev-file is 
  19267. provided as a more convenient interface. 
  19268.  
  19269.  User-level facilities such as save-some-buffers can save abbrevs in a file 
  19270. automatically, under the control of variables described here. 
  19271.  
  19272. -- User Option: abbrev-file-name 
  19273. This is the default file name for reading and saving abbrevs. 
  19274.  
  19275. -- Function: quietly-read-abbrev-file filename 
  19276. This function reads abbrev definitions from a file named filename, previously 
  19277. written with write-abbrev-file.  If filename is nil, the file specified in 
  19278. abbrev-file-name is used. save-abbrevs is set to t so that changes will be 
  19279. saved. 
  19280.  
  19281. This function does not display any messages.  It returns nil. 
  19282.  
  19283. -- User Option: save-abbrevs 
  19284. A non-nil value for save-abbrev means that Emacs should save abbrevs when files 
  19285. are saved.  abbrev-file-name specifies the file to save the abbrevs in. 
  19286.  
  19287. -- Variable: abbrevs-changed 
  19288. This variable is set non-nil by defining or altering any abbrevs.  This serves 
  19289. as a flag for various Emacs commands to offer to save your abbrevs. 
  19290.  
  19291. -- Command: write-abbrev-file filename 
  19292. Save all abbrev definitions, in all abbrev tables, in the file filename as a 
  19293. Lisp program which will define the same abbrevs when loaded.  This function 
  19294. returns nil. 
  19295.  
  19296.  
  19297. ΓòÉΓòÉΓòÉ 34.5. Looking Up and Expanding Abbreviations ΓòÉΓòÉΓòÉ
  19298.  
  19299.  Abbrevs are usually expanded by commands for interactive use, or automatically 
  19300. by self-insert.  This section describes the subroutines used in writing such 
  19301. functions, as well as the variables they use for communication. 
  19302.  
  19303. -- Function: abbrev-symbol abbrev table 
  19304. This function returns the symbol representing the abbrev named abbrev.  The 
  19305. value returned is nil if that abbrev is not defined.  The optional second 
  19306. argument table is the abbrev table to look it up in.  By default, this function 
  19307. tries first the current buffer's local abbrev table, and second the global 
  19308. abbrev table. 
  19309.  
  19310. -- User Option: abbrev-all-caps 
  19311. When this is set non-nil, an abbrev entered entirely in upper case is expanded 
  19312. using all upper case.  Otherwise, an abbrev entered entirely in upper case is 
  19313. expanded by capitalizing each word of the expansion. 
  19314.  
  19315. -- Function: abbrev-expansion abbrev &optional table 
  19316. This function returns the string that abbrev would expand into (as defined by 
  19317. the abbrev tables used for the current buffer).  The optional argument table 
  19318. specifies the abbrev table to use; if it is specified, the abbrev is looked up 
  19319. in that table only. 
  19320.  
  19321. -- Variable: abbrev-start-location 
  19322. This is the buffer position for expand-abbrev to use as the start of the next 
  19323. abbrev to be expanded.  nil means use the word before point as the abbrev. 
  19324. abbrev-start-location is set to nil each time expand-abbrev is called.  This 
  19325. variable is set by abbrev-prefix-mark. 
  19326.  
  19327. -- Variable: abbrev-start-location-buffer 
  19328. The value of this variable is the buffer for which abbrev-start-location has 
  19329. been set.  Trying to expand an abbrev in any other buffer clears 
  19330. abbrev-start-location.  This variable is set by abbrev-prefix-mark. 
  19331.  
  19332. -- Variable: last-abbrev 
  19333. This is the abbrev-symbol of the last abbrev expanded.  This information is 
  19334. left by expand-abbrev for the sake of the unexpand-abbrev command. 
  19335.  
  19336. -- Variable: last-abbrev-location 
  19337. This is the location of the last abbrev expanded.  This contains information 
  19338. left by expand-abbrev for the sake of the unexpand-abbrev command. 
  19339.  
  19340. -- Variable: last-abbrev-text 
  19341. This is the exact expansion  text of the last abbrev expanded, as results from 
  19342. case conversion.  Its value is nil if the abbrev has already been unexpanded. 
  19343. This contains information left by expand-abbrev for the sake of the 
  19344. unexpand-abbrev command. 
  19345.  
  19346.  
  19347. ΓòÉΓòÉΓòÉ 34.6. Standard Abbrev Tables ΓòÉΓòÉΓòÉ
  19348.  
  19349.  Here we list the variables that hold the abbrev tables for the preloaded major 
  19350. modes of Emacs. 
  19351.  
  19352. -- Variable: global-abbrev-table 
  19353. This is the abbrev table for mode-independent abbrevs.  The abbrevs defined in 
  19354. it apply to all buffers.  Each buffer may also have a local abbrev table, whose 
  19355. abbrev definitions take precedence over those in the global table. 
  19356.  
  19357. -- Variable: local-abbrev-table 
  19358. The value of this buffer-local variable is the (mode-specific) abbreviation 
  19359. table of the current buffer. 
  19360.  
  19361. -- Variable: fundamental-mode-abbrev-table 
  19362. This is the local abbrev table used in Fundamental mode.  It is the local 
  19363. abbrev table in all buffers in Fundamental mode. 
  19364.  
  19365. -- Variable: text-mode-abbrev-table 
  19366. This is the local abbrev table used in Text mode. 
  19367.  
  19368. -- Variable: c-mode-abbrev-table 
  19369. This is the local abbrev table used in C mode. 
  19370.  
  19371. -- Variable: lisp-mode-abbrev-table 
  19372. This is the local abbrev table used in Lisp mode and Emacs Lisp mode. 
  19373.  
  19374.  
  19375. ΓòÉΓòÉΓòÉ 35. Processes ΓòÉΓòÉΓòÉ
  19376.  
  19377.  In the terminology of operating systems, a process is a space in which a 
  19378. program can execute.  Emacs runs in a process.  Emacs Lisp programs can invoke 
  19379. other programs in processes of their own.  These are called subprocesses or 
  19380. child processes of the Emacs process, which is their parent process. 
  19381.  
  19382.  A subprocess of Emacs may be synchronous or asynchronous. depending on how it 
  19383. is created.  When you create a synchronous subprocess, the Lisp program waits 
  19384. for the subprocess to terminate before continuing execution.  When you create 
  19385. an asynchronous subprocess, it can run in parallel with the Lisp program.  This 
  19386. kind of subprocess is represented within Emacs by a Lisp object which is also 
  19387. called a ``process''.  Lisp programs can use this object to communicate with 
  19388. the subprocess or to control it.  For example, you can send signals, obtain 
  19389. status information, receive output from the process, or send input to it. 
  19390.  
  19391. -- Function: processp object 
  19392. This function returns t if object is a process, nil otherwise. 
  19393.  
  19394.  
  19395. ΓòÉΓòÉΓòÉ 35.1. Functions that Create Subprocesses ΓòÉΓòÉΓòÉ
  19396.  
  19397.  There are three functions that create a new Unix subprocess in which to run a 
  19398. program.  One of them, start-process, creates an asynchronous process and 
  19399. returns a process object ( see Asynchronous Processes).  The other two, 
  19400. call-process and call-process-region, create a synchronous process and do not 
  19401. return a process object (see Synchronous Processes). 
  19402.  
  19403.  Synchronous and asynchronous processes are explained in following sections. 
  19404. Since the three functions are all called in a similar fashion, their common 
  19405. arguments are described here. 
  19406.  
  19407.  In all cases, the program to be run is specified with the function's program 
  19408. argument.  An error is signaled if the file is not found or cannot be executed. 
  19409. The actual file containing the program is found by following normal Unix rules: 
  19410. if an absolute file name is given, then the program must be found in the 
  19411. specified file; if a relative file name is given, then the directories in 
  19412. exec-path are searched sequentially for a suitable file.  The variable 
  19413. exec-path is initialized when Emacs is started, based on the value of the 
  19414. environment variable PATH.  The standard Unix abbreviations, `~', `.', and 
  19415. `..', are interpreted as usual, but environment variable substitutions 
  19416. (`$HOME', etc.) are not recognized; use substitute-in-file-name to perform them 
  19417. ( see File Name Expansion). 
  19418.  
  19419.  Each of the subprocess-creating functions has a buffer-or-name argument which 
  19420. specifies where the standard output from the program will go.  If 
  19421. buffer-or-name is nil, then the output will be discarded (by directing it to 
  19422. `/dev/null') unless a filter function is specified to handle it.  (See Filter 
  19423. Functions, and Streams.)  Normally, you should avoid having multiple processes 
  19424. send output to the same buffer because the outputs will be intermixed randomly. 
  19425.  
  19426.  All three of the subprocess-creating functions have a &rest argument, args. 
  19427. The args must all be strings, and they are supplied to program as separate 
  19428. command line arguments.  Wildcard characters and other shell constructs are not 
  19429. allowed in these strings, since they are passed directly to the specified 
  19430. program.  *Note:* the argument program contains only the name of the program; 
  19431. it may not contain any command-line arguments.  Such arguments must be provided 
  19432. via args. 
  19433.  
  19434.  The subprocess gets its current directory from the value of default-directory 
  19435. (see File Name Expansion). 
  19436.  
  19437.  The subprocess inherits its environment from Emacs; but you can specify 
  19438. overrides for it with process-environment. 
  19439.  
  19440. -- Variable: process-environment 
  19441. This variable is a list of strings to append to the environment of processes as 
  19442. they are created.  Each string assigns a value to a shell environment variable. 
  19443. (This applies both to asynchronous and synchronous processes.) 
  19444.  
  19445. process-environment
  19446. => ("l=/usr/stanford/lib/gnuemacs/lisp"
  19447.     "PATH=.:/user/lewis/bin:/usr/class:/nfsusr/local/bin"
  19448.     "USER=lewis"
  19449.     "TERM=ibmapa16"
  19450.     "SHELL=/bin/csh"
  19451.     "HOME=/user/lewis")
  19452.  
  19453. -- Variable: exec-directory 
  19454. The value of this variable is the name of a directory (a string) that contains 
  19455. programs that come with GNU Emacs, that are intended for Emacs to invoke.  The 
  19456. program loadst is an example of such a program; it is used by the display-time 
  19457. command to print the current time (and certain other information) once per 
  19458. minute. 
  19459.  
  19460. The default value is the name of a directory whose name ends in `etc'.  We call 
  19461. the directory `emacs/etc', since its name usually ends that way.  We sometimes 
  19462. refer to ``the directory `emacs/etc','' when strictly speaking we ought to say, 
  19463. ``the directory named by the variable exec-directory.''  Most of the time, 
  19464. there is no difference. 
  19465.  
  19466. -- User Option: exec-path 
  19467. The value of this variable is a list of directories to search for programs to 
  19468. run in subprocesses.  Each element is either the name of a directory (i.e., a 
  19469. string), or nil, which stands for the default directory (which is the value of 
  19470. default-directory). 
  19471.  
  19472. The value of exec-path is used by call-process and start-process when the 
  19473. program argument is not an absolute file name. 
  19474.  
  19475.  
  19476. ΓòÉΓòÉΓòÉ 35.2. Creating a Synchronous Process ΓòÉΓòÉΓòÉ
  19477.  
  19478.  After a synchronous process is created, Emacs waits for the process to 
  19479. terminate before continuing.  Starting Dired is an example of this: it runs ls 
  19480. in a synchronous process, then modifies the output slightly.  Because the 
  19481. process is synchronous, the entire directory listing arrives in the buffer 
  19482. before Emacs tries to do anything with it. 
  19483.  
  19484.  While Emacs waits for the synchronous subprocess to terminate, the user can 
  19485. quit by typing C-g, and the process is killed by sending it a SIGKILL signal. 
  19486. See Quitting. 
  19487.  
  19488.  The synchronous subprocess functions return nil in version 18. In version 19, 
  19489. they will return an indication of how the process terminated. 
  19490.  
  19491. -- Function: call-process program &optional infile buffer-or-name display &rest 
  19492. args 
  19493. This function calls program in a separate process and waits for it to finish. 
  19494.  
  19495. The standard input for the process comes from file infile if infile is not nil 
  19496. and from `/dev/null' otherwise.  The process output gets inserted in buffer 
  19497. buffer-or-name before point, if that argument names a buffer.  If 
  19498. buffer-or-name is t, output is sent to the current buffer; if buffer-or-name is 
  19499. nil, output is discarded. 
  19500.  
  19501. If buffer-or-name is the integer 0, the output is discarded and call-process 
  19502. returns immediately.  In this case, the process is not truly synchronous, since 
  19503. it can run in parallel with Emacs; but you can think of it as synchronous in 
  19504. that Emacs is essentially finished with the subprocess as soon as this function 
  19505. returns. 
  19506.  
  19507. If display is non-nil, then call-process redisplays the buffer as output is 
  19508. inserted.  Otherwise the function does no redisplay, and the results become 
  19509. visible on the screen only when Emacs redisplays that buffer in the normal 
  19510. course of events. 
  19511.  
  19512. The remaining arguments, args, are strings that are supplied as the command 
  19513. line arguments for the program. 
  19514.  
  19515. The examples below are both run with the buffer `foo' current. 
  19516.  
  19517. (call-process "pwd" nil t)
  19518.      => nil
  19519.  
  19520. ---------- Buffer: foo ----------
  19521. /usr/user/lewis/manual
  19522. ---------- Buffer: foo ----------
  19523.  
  19524. (call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
  19525.      => nil
  19526.  
  19527. ---------- Buffer: bar ----------
  19528. lewis:5LTsHm66CSWKg:398:21:Bil Lewis:/user/lewis:/bin/csh
  19529.  
  19530. ---------- Buffer: bar ----------
  19531.  
  19532. The dired-readin function contains a good example of the use of call-process: 
  19533.  
  19534. (call-process "ls" nil buffer nil dired-listing-switches dirname)
  19535.  
  19536. -- Function: call-process-region start end program &optional delete 
  19537. buffer-or-name display &rest args 
  19538. This function sends the text between start to end as standard input to a 
  19539. process running program.  It deletes the text sent if delete is non-nil, which 
  19540. may be useful when the output is going to be inserted back in the current 
  19541. buffer. 
  19542.  
  19543. If buffer-or-name names a buffer, the output is inserted in that buffer at 
  19544. point.  If buffer-or-name is t, the output is sent to the current buffer.  If 
  19545. buffer-or-name is nil, the output is discarded.  If buffer-or-name is the 
  19546. integer 0, the output is discarded and call-process returns immediately, as in 
  19547. call-process. 
  19548.  
  19549. If display is non-nil, then call-process-region redisplays the buffer as output 
  19550. is inserted.  Otherwise the function does no redisplay, and the results become 
  19551. visible on the screen only when Emacs redisplays that buffer in the normal 
  19552. course of events. 
  19553.  
  19554. The remaining arguments, args, are strings that are supplied as the command 
  19555. line arguments for the program. 
  19556.  
  19557. In the following example, we use call-process-region to run the cat utility, 
  19558. with standard input being the first five characters in buffer `foo' (the word 
  19559. `input').  cat copies its standard input into its standard output.  Since the 
  19560. argument buffer-or-name is t, this output is inserted in the current buffer. 
  19561.  
  19562. ---------- Buffer: foo ----------
  19563. input-!-
  19564. ---------- Buffer: foo ----------
  19565.  
  19566. (call-process-region 1 6 "cat" nil t)
  19567.      => nil
  19568.  
  19569. ---------- Buffer: foo ----------
  19570. inputinput-!-
  19571. ---------- Buffer: foo ----------
  19572.  
  19573.  The shell-command-on-region command uses call-process-region like this: 
  19574.  
  19575. (call-process-region start end
  19576.                      shell-file-name    ; Name of program.
  19577.                      nil                ; Do not delete region.
  19578.                      buffer             ; Send output to buffer.
  19579.                      nil                ; No redisplay during output.
  19580.                      "-c" command)      ; Arguments for the shell.
  19581.  
  19582.  
  19583. ΓòÉΓòÉΓòÉ 35.3. Creating an Asynchronous Process ΓòÉΓòÉΓòÉ
  19584.  
  19585.  After an asynchronous process is created, Emacs and the Lisp program can 
  19586. continue running immediately.  The process may thereafter run in parallel with 
  19587. Emacs, and the two may communicate with each other using the functions 
  19588. described in following sections.  Here we describe how to create an 
  19589. asynchronous process, with start-process. 
  19590.  
  19591. -- Function: start-process name buffer-or-name program &rest args 
  19592. This function creates a new asynchronous subprocess and starts the program 
  19593. program running in it.  It returns a process object that stands for the new 
  19594. subprocess for Emacs Lisp programs.  The argument name specifies the name for 
  19595. the process object; if a process with this name already exists, then name is 
  19596. modified (by adding `<1>', etc.) to be unique.  The buffer buffer-or-name is 
  19597. the buffer to associate with the process. 
  19598.  
  19599. The remaining arguments, args, are strings that are supplied as the command 
  19600. line arguments for the program. 
  19601.  
  19602. In the example below, the first process is started and runs (rather, sleeps) 
  19603. for 100 seconds.  Meanwhile, the second process is started, given the name 
  19604. `my-process<1>' for the sake of uniqueness.  It inserts the directory listing 
  19605. at the end of the buffer `foo', before the first process finishes.  Then it 
  19606. finishes, and a message to that effect is inserted in the buffer.  Much later, 
  19607. the first process finishes, and another message is inserted in the buffer for 
  19608. it. 
  19609.  
  19610. (start-process "my-process" "foo" "sleep" "100")
  19611.      => #<process my-process>
  19612.  
  19613. (start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
  19614.      => #<process my-process<1>>
  19615.  
  19616. ---------- Buffer: foo ----------
  19617. total 2
  19618. lrwxrwxrwx  1 lewis          14 Jul 22 10:12 gnuemacs --> /emacs
  19619. -rwxrwxrwx  1 lewis          19 Jul 30 21:02 lemon
  19620.  
  19621. Process my-process<1> finished
  19622.  
  19623. Process my-process finished
  19624. ---------- Buffer: foo ----------
  19625.  
  19626. -- Variable: process-connection-type 
  19627. This variable controls the type of device used to communicate with asynchronous 
  19628. subprocesses.  If it is nil, then pipes are used. If it is t, then ptys are 
  19629. used (or pipes if ptys not supported). 
  19630.  
  19631. ptys are usually preferable for processes visible to the user, as in Shell 
  19632. mode, because they allow job control (C-c, C-z, etc.) to work between the 
  19633. process and its children whereas pipes do not. For subprocesses used for 
  19634. internal purposes by programs, it is often better to use a pipe, because they 
  19635. are more efficient.  In addition, the total number of ptys is limited on many 
  19636. systems and it is good not to waste them. 
  19637.  
  19638. The value process-connection-type is used when start-process is called, so in 
  19639. order to change it for just one call of start-process, temporarily rebind it 
  19640. with let. 
  19641.  
  19642. (let ((process-connection-type nil))  ; Use a pipe.
  19643.   (start-process ...))
  19644.  
  19645.  
  19646. ΓòÉΓòÉΓòÉ 35.4. Deleting Processes ΓòÉΓòÉΓòÉ
  19647.  
  19648.  Deleting a process disconnects Emacs immediately from the subprocess, and 
  19649. removes it from the list of active processes.  It sends a signal to the 
  19650. subprocess to make the subprocess terminate, but this is not guaranteed to 
  19651. happen immediately.  (The process object itself continues to exist as long as 
  19652. other Lisp objects point to it.) 
  19653.  
  19654.  You can delete a process explicitly at any time.  Processes are deleted 
  19655. automatically after they terminate, but not necessarily right away.  If you 
  19656. delete a terminated process explicitly before it is deleted automatically, no 
  19657. harm results. 
  19658.  
  19659. -- Variable: delete-exited-processes 
  19660. This variable controls automatic deletion of processes that have terminated 
  19661. (due to calling exit or to a signal).  If it is nil, then they continue to 
  19662. exist until the user runs list-processes.  Otherwise, they are deleted 
  19663. immediately after they exit. 
  19664.  
  19665. -- Function: delete-process name 
  19666. This function deletes the process associated with name.  The argument name may 
  19667. be a process, the name of a process, a buffer, or the name of a buffer.  The 
  19668. subprocess is killed with a SIGHUP signal. 
  19669.  
  19670. (delete-process "*shell*")
  19671.      => nil
  19672.  
  19673. -- Function: process-kill-without-query process 
  19674.  This function declares that Emacs need not query the user if process is still 
  19675. running when Emacs is exited.  The process will be deleted silently.  The value 
  19676. is t. 
  19677.  
  19678. (process-kill-without-query (get-process "shell"))
  19679.      => t
  19680.  
  19681.  
  19682. ΓòÉΓòÉΓòÉ 35.5. Process Information ΓòÉΓòÉΓòÉ
  19683.  
  19684.  Several functions return information about processes. list-processes is 
  19685. provided for interactive use. 
  19686.  
  19687. -- Command: list-processes 
  19688. This command displays a listing of all living processes.  (Any processes listed 
  19689. as `Exited' or `Signaled' are actually eliminated after the listing is made.) 
  19690. This function returns nil. 
  19691.  
  19692. -- Function: process-list 
  19693. This function returns a list of all processes that have not been deleted. 
  19694.  
  19695. (process-list)
  19696.      => (#<process display-time> #<process shell>)
  19697.  
  19698. -- Function: get-process name 
  19699. This function returns the process named name, or nil if there is none.  An 
  19700. error is signaled if name is not a string. 
  19701.  
  19702. (get-process "shell")
  19703.      => #<process shell>
  19704.  
  19705. -- Function: process-command process 
  19706. This function returns the command that was executed to start process.  This is 
  19707. a list of strings, the first string being the program executed and the rest of 
  19708. the strings being the arguments that were given to the program. 
  19709.  
  19710. (process-command (get-process "shell"))
  19711.      => ("/bin/csh" "-i")
  19712.  
  19713. -- Function: process-exit-status process 
  19714. This function returns the exit status of process or the signal number that 
  19715. killed it.  If process has not yet terminated, the value is 0. 
  19716.  
  19717. -- Function: process-id process 
  19718.  This function returns the pid of process.  This is an integer which 
  19719. distinguishes the process process from all other processes running on the same 
  19720. computer at the current time.  The pid of a process is chosen by the operating 
  19721. system kernel when the process is started and remains constant as long as the 
  19722. process exists. 
  19723.  
  19724. -- Function: process-name process 
  19725. This function returns the name of process. 
  19726.  
  19727. -- Function: process-status process-name 
  19728.  This function returns the status of process-name as a symbol. The argument 
  19729. process-name must be either a process or a string. If it is a string, it need 
  19730. not name an actual process. 
  19731.  
  19732. The possible values for an actual subprocess are: 
  19733.  
  19734. run 
  19735.            for a process that is running. 
  19736.  
  19737. stop 
  19738.            for a process that is stopped but continuable. 
  19739.  
  19740. exit 
  19741.            for a process that has exited. 
  19742.  
  19743. signal 
  19744.            for a process that has received a fatal signal. 
  19745.  
  19746. nil 
  19747.            if process-name is not the name of an existing process. 
  19748.  
  19749. (process-status "shell")
  19750.      => run
  19751. (process-status "never-existed")
  19752.      => nil
  19753. x
  19754.      => #<process xx<1>>
  19755. (process-status x)
  19756.      => exit
  19757.  
  19758. For a network stream, process-status returns one of the symbols open or closed. 
  19759. The latter means that the other side closed the connection, or Emacs did 
  19760. delete-process. 
  19761.  
  19762.  
  19763. ΓòÉΓòÉΓòÉ 35.6. Sending Input to Processes ΓòÉΓòÉΓòÉ
  19764.  
  19765.  Asynchronous subprocesses receive input when it is sent to them by Emacs, 
  19766. which is done with the functions in this section.  You must specify the process 
  19767. to send input to, and the input data to send.  The data appears on the 
  19768. ``standard input'' of the subprocess. 
  19769.  
  19770.  Some operating systems have limited space for buffered input in a pty.  On 
  19771. these systems, the subprocess will cease to read input correctly if you send an 
  19772. input line longer than the system can handle. You cannot avoid the problem by 
  19773. breaking the input into pieces and sending them separately, for the operating 
  19774. system will still have to put all the pieces together in the input buffer 
  19775. before it lets the subprocess read the line.  The only solution is to put the 
  19776. input in a temporary file, and send the process a brief command to read that 
  19777. file. 
  19778.  
  19779. -- Function: process-send-string process-name string 
  19780.  This function sends process-name the contents of string as standard input. 
  19781. The argument process-name must be a process or the name of a process. 
  19782.  
  19783.  The function returns nil. 
  19784.  
  19785. (process-send-string "shell<1>" "ls\n")
  19786.      => nil
  19787.  
  19788. ---------- Buffer: *shell* ----------
  19789. ...
  19790. introduction.texi               syntax-tables.texi~
  19791. introduction.texi~              text.texi
  19792. introduction.txt                text.texi~
  19793. ...
  19794. ---------- Buffer: *shell* ----------
  19795.  
  19796. -- Command: process-send-region process-name start end 
  19797.  This function sends the text in the region defined by start and end as 
  19798. standard input to process-name, which is a process or a process name. 
  19799.  
  19800.  An error is signaled unless both start and end are integers or markers that 
  19801. indicate positions in the current buffer.  (It is unimportant which number is 
  19802. larger.) 
  19803.  
  19804. -- Function: process-send-eof &optional process-name 
  19805.  This function makes process-name see an end-of-file in its input.  The eof 
  19806. comes after any text already sent to it. 
  19807.  
  19808.  If process-name is not supplied, or if it is nil, then this function sends the 
  19809. eof to the current buffer's process.  An error is signaled if the current 
  19810. buffer has no process. 
  19811.  
  19812.  The function returns process-name. 
  19813.  
  19814. (process-send-eof "shell")
  19815.      => "shell"
  19816.  
  19817.  
  19818. ΓòÉΓòÉΓòÉ 35.7. Sending Signals to Processes ΓòÉΓòÉΓòÉ
  19819.  
  19820.  Sending a signal to a subprocess is a way of interrupting its activities. 
  19821. There are several different signals, each with its own meaning.  For example, 
  19822. the signal SIGINT means that the user has typed C-c, or that some analogous 
  19823. thing has happened. 
  19824.  
  19825.  Each signal has a standard effect on the subprocess.  Most signals kill the 
  19826. subprocess, but some stop or resume execution instead.  Most signals can 
  19827. optionally be handled by programs; if the program handles the signal, then we 
  19828. can say nothing in general about its effects. 
  19829.  
  19830.  The set of signals and their names is defined by the operating system; Emacs 
  19831. has facilities for sending only a few of the signals that are defined.  Emacs 
  19832. can send signals only to its own subprocesses. 
  19833.  
  19834.  You can send signals explicitly by calling the function in this section. 
  19835. Emacs also sends signals automatically at certain times: killing a buffer sends 
  19836. a SIGHUP signal to all its associated processes; killing Emacs sends a SIGHUP 
  19837. signal to all remaining processes.  (SIGHUP is a signal that usually indicates 
  19838. that the user hung up the phone.) 
  19839.  
  19840.  Each of the signal-sending functions takes two optional arguments: 
  19841. process-name and current-group. 
  19842.  
  19843.  The argument process-name must be either a process, the name of one, or nil. 
  19844. If it is nil, the process defaults to the process associated with the current 
  19845. buffer.  An error is signaled if process-name does not identify a process. 
  19846.  
  19847.  The argument current-group is a flag that makes a difference when you are 
  19848. running a job-control shell as an Emacs subprocess.  If it is non-nil, then the 
  19849. signal is sent to the current process-group of the terminal which Emacs uses to 
  19850. communicate with the subprocess.  If the process is a job-control shell, this 
  19851. means the shell's current subjob.  If it is nil, the signal is sent to the 
  19852. process group of the immediate subprocess of Emacs.  If the subprocess is a 
  19853. job-control shell, this is the shell itself. 
  19854.  
  19855.  The flag current-group has no effect when a pipe is used to communicate with 
  19856. the subprocess, because the operating system does not support the distinction 
  19857. in the case of pipes.  For the same reason, job-control shells won't work when 
  19858. a pipe is used.  See process-connection-type in Asynchronous Processes. 
  19859.  
  19860. -- Function: interrupt-process &optional process-name current-group 
  19861. This function interrupts the process process-name by sending the Unix signal 
  19862. SIGINT.  Outside of Emacs, typing the ``interrupt character'' (usually C-c on 
  19863. Berkeley Unix) sends this signal. When the argument current-group is non-nil, 
  19864. you can think of this function as ``typing C-c'' on the terminal by which Emacs 
  19865. talks to the subprocess. 
  19866.  
  19867. -- Function: kill-process &optional process-name current-group 
  19868. This function kills the process process-name by sending the Unix signal 
  19869. SIGKILL.  This signal kills the subprocess immediately, and cannot be handled 
  19870. by the subprocess. 
  19871.  
  19872. -- Function: quit-process &optional process-name current-group 
  19873. This function sends the Unix signal SIGQUIT to the process process-name.  This 
  19874. signal is the one sent by the ``quit character'' (usually C-b or C-\) when you 
  19875. are not inside Emacs. 
  19876.  
  19877. -- Function: stop-process &optional process-name current-group 
  19878. This function stops the process process-name by sending the Unix signal 
  19879. SIGTSTP.  Use continue-process to resume its execution. 
  19880.  
  19881. On systems with job control, the ``stop character'' (usually C-z) sends this 
  19882. signal (outside of Emacs).  When current-group is non-nil, you can think of 
  19883. this function as ``typing C-z'' on the terminal Emacs uses to communicate with 
  19884. the subprocess. 
  19885.  
  19886. -- Function: continue-process &optional process-name current-group 
  19887. This function resumes execution of the process process by sending it the Unix 
  19888. signal SIGCONT.  This presumes that process-name was stopped previously. 
  19889.  
  19890.  
  19891. ΓòÉΓòÉΓòÉ 35.8. Receiving Output from Processes ΓòÉΓòÉΓòÉ
  19892.  
  19893.  There are two ways to receive the output that a subprocess writes to its 
  19894. standard output stream.  The output can be inserted in a buffer, which is 
  19895. called the associated buffer of the process, or a function called the filter 
  19896. function can be called to act on the output. 
  19897.  
  19898.  
  19899. ΓòÉΓòÉΓòÉ 35.8.1. Process Buffers ΓòÉΓòÉΓòÉ
  19900.  
  19901.  A process can (and usually does) have an associated buffer, which is an 
  19902. ordinary Emacs buffer that is used for two purposes: storing the output from 
  19903. the process, and deciding when to kill the process.  You can also use the 
  19904. buffer to identify a process to operate on, since in normal practice only one 
  19905. process is associated with any given buffer. Many applications of processes 
  19906. also use the buffer for editing input to be sent to the process, but this is 
  19907. not built into Emacs Lisp. 
  19908.  
  19909.  Unless the process has a filter function (see Filter Functions), its output is 
  19910. inserted in the associated buffer.  The position to insert the output is 
  19911. determined by the process-mark ( see Process Information), which is then 
  19912. updated to point to the end of the text just inserted.  Usually, but not 
  19913. always, the process-mark is at the end of the buffer.  If the process has no 
  19914. buffer and no filter function, its output is discarded. 
  19915.  
  19916. -- Function: process-buffer process 
  19917. This function returns the associated buffer of the process process. 
  19918.  
  19919. (process-buffer (get-process "shell"))
  19920.      => #<buffer *shell*>
  19921.  
  19922. -- Function: process-mark process 
  19923. This function returns the marker which controls where additional output from 
  19924. the process will be inserted in the process buffer ( see Process Buffers). 
  19925. When output is inserted, the marker is updated to point at the end of the 
  19926. output.  This causes successive batches of output to be inserted consecutively. 
  19927.  
  19928. If process does not insert its output into a buffer, then process-mark returns 
  19929. a marker that points nowhere. 
  19930.  
  19931. Filter functions normally should use this marker in the same fashion as is done 
  19932. by direct insertion of output in the buffer.  A good example of a filter 
  19933. function that uses process-mark is found at the end of the following section. 
  19934.  
  19935. When the user is expected to enter input in the process buffer for transmission 
  19936. to the process, the process marker is useful for distinguishing the new input 
  19937. from previous output. 
  19938.  
  19939. -- Function: set-process-buffer process buffer 
  19940. This function sets the buffer associated with process to buffer.  If buffer is 
  19941. nil, the process will not be associated with any buffer. 
  19942.  
  19943. -- Function: get-buffer-process buffer-or-name 
  19944. This function returns the process associated with buffer-or-name. If there are 
  19945. several processes associated with it, then one is chosen. (Presently, the one 
  19946. chosen is the one most recently created.)  It is usually a bad idea to have 
  19947. more than one process associated with the same buffer. 
  19948.  
  19949. (get-buffer-process "*shell*")
  19950.      => #<process shell>
  19951.  
  19952. If the process's buffer is killed, the actual child process is killed with a 
  19953. SIGHUP signal (see Signals to Processes). 
  19954.  
  19955.  
  19956. ΓòÉΓòÉΓòÉ 35.8.2. Process Filter Functions ΓòÉΓòÉΓòÉ
  19957.  
  19958.  A process filter function is a function that receives the standard output from 
  19959. the associated process.  If a process has a filter, then all standard output 
  19960. from that process is passed to the filter rather than be inserted into a buffer 
  19961. or discarded.  The process buffer is used for output from the process only when 
  19962. there is no filter. 
  19963.  
  19964.  A filter function must accept two arguments: the associated process and a 
  19965. string, which is the output.  The function is then free to do whatever it 
  19966. chooses with the output. 
  19967.  
  19968.  A filter function runs only while Emacs is waiting (e.g., for terminal input, 
  19969. or for time to elapse, or for process output).  This avoids the timing errors 
  19970. that could result from running filters at random places in the middle of other 
  19971. Lisp programs.  You may explicitly cause Emacs to wait, so that filter 
  19972. functions will run, by calling sit-for, sleep-for or accept-process-output ( 
  19973. see Accepting Output).  Emacs is also waiting when the command loop is reading 
  19974. input. 
  19975.  
  19976.  Quitting is normally inhibited within a filter function---otherwise, the 
  19977. effect of typing C-g at command level or to quit a user command would be 
  19978. unpredictable.  If you want to permit quitting inside a filter function, bind 
  19979. inhibit-quit to nil. See Quitting. 
  19980.  
  19981.  Many filter functions sometimes or always insert the text in the process's 
  19982. buffer, mimicking the actions of Emacs when there is no filter.  Such filter 
  19983. functions need to use set-buffer in order to be sure to insert in that buffer. 
  19984. To avoid setting the current buffer semipermanently, these filter functions 
  19985. must use unwind-protect to make sure to restore the previous current buffer. 
  19986. They should also update the process marker, and in some cases update the value 
  19987. of point. Here is how to do these things: 
  19988.  
  19989. (defun ordinary-insertion-filter (proc string)
  19990.   (let ((old-buffer (current-buffer)))
  19991.     (unwind-protect
  19992.         (let (moving)
  19993.           (set-buffer (process-buffer proc))
  19994.           (setq moving (= (point) (process-mark proc)))
  19995.           (save-excursion
  19996.             ;; Insert the text, moving the process-marker.
  19997.             (goto-char (process-mark proc))
  19998.             (insert string)
  19999.             (set-marker (process-mark proc) (point)))
  20000.           (if moving (goto-char (process-mark proc))))
  20001.       (set-buffer old-buffer))))
  20002.  
  20003. The reason to use an explicit unwind-protect rather than letting save-excursion 
  20004. restore the current buffer is so as to preserve the change in point made by 
  20005. goto-char. 
  20006.  
  20007.  To make the filter force the process buffer to be visible whenever new text 
  20008. arrives, insert the following line just before the unwind-protect: 
  20009.  
  20010. (display-buffer (process-buffer proc))
  20011.  
  20012.  To force point to move to the end of the new output no matter where it was 
  20013. previously, eliminate the variable moving and call goto-char unconditionally. 
  20014.  
  20015.  All filter functions that do regexp searching or matching should save and 
  20016. restore the match data.  Otherwise, a filter function that runs during a call 
  20017. to sit-for might clobber the match data of the program that called sit-for. 
  20018. See Match Data. 
  20019.  
  20020.  The output to the function may come in chunks of any size.  A program that 
  20021. produces the same output twice in a row may send it as one batch of 200 
  20022. characters one time, and five batches of 40 characters the next. 
  20023.  
  20024. -- Function: set-process-filter process filter 
  20025. This function gives process the filter function filter.  If filter is nil, then 
  20026. the process will have no filter. 
  20027.  
  20028. -- Function: process-filter process 
  20029. This function returns the filter function of process, or nil if it has none. 
  20030.  
  20031.  Here is an example of use of a filter function: 
  20032.  
  20033. (defun keep-output (process output)
  20034.    (setq kept (cons output kept)))
  20035.      => keep-output
  20036. (setq kept nil)
  20037.      => nil
  20038. (set-process-filter (get-process "shell") 'keep-output)
  20039.      => keep-output
  20040. (process-send-string "shell" "ls ~/other\n")
  20041.      => nil
  20042. kept
  20043.      => ("lewis@slug[8] % "
  20044. "FINAL-W87-SHORT.MSS    backup.otl              kolstad.mss~
  20045. address.txt             backup.psf              kolstad.psf
  20046. backup.bib~             david.mss               resume-Dec-86.mss~
  20047. backup.err              david.psf               resume-Dec.psf
  20048. backup.mss              dland                   syllabus.mss
  20049. "
  20050. "#backups.mss#          backup.mss~             kolstad.mss
  20051. ")
  20052.  
  20053. Here is another, more realistic example, which demonstrates how to use the 
  20054. process mark to do insertion in the same fashion as is done when there is no 
  20055. filter function: 
  20056.  
  20057. ;; Insert input in the buffer specified by my-shell-buffer
  20058. ;; and make sure that buffer is shown in some window.
  20059. (defun my-process-filter (proc str)
  20060.     (let ((cur (selected-window))
  20061.           (pop-up-windows t))
  20062.       (pop-to-buffer my-shell-buffer)
  20063.       (goto-char (point-max))
  20064.       (insert str)
  20065.       (set-marker (process-mark proc) (point-max))
  20066.       (select-window cur)))
  20067.  
  20068.  
  20069. ΓòÉΓòÉΓòÉ 35.8.3. Accepting Output from Processes ΓòÉΓòÉΓòÉ
  20070.  
  20071.  Output from asynchronous subprocesses normally arrives only while Emacs is 
  20072. waiting for some sort of external event, such as elapsed time or terminal 
  20073. input.  Occasionally it is useful in a Lisp program to explicitly permit output 
  20074. to arrive at a specific point, or even to wait until output arrives from a 
  20075. process. 
  20076.  
  20077. -- Function: accept-process-output &optional process 
  20078. This function allows Emacs to read pending output from processes.  The output 
  20079. is inserted in the associated buffers or given to their filter functions.  If 
  20080. process is non-nil then this function does not return until some output has 
  20081. been received from process. 
  20082.  
  20083.  
  20084. ΓòÉΓòÉΓòÉ 35.8.4. Sentinels: Detecting Process Status Changes ΓòÉΓòÉΓòÉ
  20085.  
  20086.  A process sentinel is a function that is called whenever the associated 
  20087. process changes status for any reason, including signals (whether sent by Emacs 
  20088. or caused by the process's own actions) that terminate, stop, or continue the 
  20089. process.  The process sentinel is also called if the process exits.  The 
  20090. sentinel receives two arguments: the process for which the event occurred, and 
  20091. a string describing the type of event. 
  20092.  
  20093.  The string describing the event looks like one of the following: 
  20094.  
  20095. o "finished\n". 
  20096.  
  20097. o "exited abnormally with code exitcode\n". 
  20098.  
  20099. o "name-of-signal\n". 
  20100.  
  20101. o "name-of-signal (core dumped)\n". 
  20102.  
  20103.  A sentinel runs only while Emacs is waiting (e.g., for terminal input, or for 
  20104. time to elapse, or for process output).  This avoids the timing errors that 
  20105. could result from running them at random places in the middle of other Lisp 
  20106. programs.  You may explicitly cause Emacs to wait, so that sentinels will run, 
  20107. by calling sit-for, sleep-for or accept-process-output (see Accepting Output). 
  20108. Emacs is also waiting when the command loop is reading input. 
  20109.  
  20110.  Quitting is normally inhibited within a sentinel---otherwise, the effect of 
  20111. typing C-g at command level or to quit a user command would be unpredictable. 
  20112. If you want to permit quitting inside a sentinel, bind inhibit-quit to nil. 
  20113. See Quitting. 
  20114.  
  20115.  All sentinels that do regexp searching or matching should save and restore the 
  20116. match data.  Otherwise, a sentinel that runs during a call to sit-for might 
  20117. clobber the match data of the program that called sit-for.  See Match Data. 
  20118.  
  20119. -- Function: set-process-sentinel process sentinel 
  20120. This function associates sentinel with process.  If sentinel is nil, then the 
  20121. process will have no sentinel. The default behavior when there is no sentinel 
  20122. is to insert a message in the process's buffer when the process status changes. 
  20123.  
  20124. (defun msg-me (process event)
  20125.    (princ
  20126.      (format "Process: %s had the event `%s'" process event)))
  20127. (set-process-sentinel (get-process "shell") 'msg-me)
  20128.      => msg-me
  20129. (kill-process (get-process "shell"))
  20130.      -| Process: #<process shell> had the event `killed'
  20131.      => #<process shell>
  20132.  
  20133. -- Function: process-sentinel process 
  20134. This function returns the sentinel of process, or nil if it has none. 
  20135.  
  20136. -- Function: waiting-for-user-input-p 
  20137. While a sentinel or filter function is running, this function returns non-nil 
  20138. if Emacs was waiting for keyboard input from the user at the time the sentinel 
  20139. or filter function was called, nil if it was not. 
  20140.  
  20141.  
  20142. ΓòÉΓòÉΓòÉ 35.9. Subprocess Functions for VMS ΓòÉΓòÉΓòÉ
  20143.  
  20144. The ordinary subprocess functions do not work on VMS in version 18. Instead, 
  20145. these functions are available. 
  20146.  
  20147. -- Function: default-subprocess-input-handler 
  20148. This function is the default input handler for input from spawned subprocesses. 
  20149.  
  20150. -- Function: spawn-subprocess integer &optional filter sentinel 
  20151. This function spawns an asynchronous VMS subprocess for command processing. 
  20152. The arguments are integer, an integer to identify the subprocess in future 
  20153. operations; filter, a function to be called when output arrives from the 
  20154. subprocess; and sentinel, a function to be called when the subprocess 
  20155. terminates. 
  20156.  
  20157. If filter is nil, output is inserted in the current buffer.  If sentinel is 
  20158. nil, nothing special is done when the subprocess terminates. 
  20159.  
  20160. When the filter is called, it receives two arguments; integer to identify the 
  20161. process, and a string containing the output. 
  20162.  
  20163. When the sentinel is called, it receives just one argument, integer. 
  20164.  
  20165. -- Function: send-command-to-subprocess integer command 
  20166. This function sends the string command to a VMS subprocess numbered integer. 
  20167.  
  20168. -- Function: stop-subprocess integer 
  20169. This function terminates the VMS subprocess numbered integer. 
  20170.  
  20171.  In version 19, these functions have been eliminated, and the ordinary 
  20172. subprocess functions are implemented on VMS. 
  20173.  
  20174.  
  20175. ΓòÉΓòÉΓòÉ 35.10. TCP ΓòÉΓòÉΓòÉ
  20176.  
  20177.  Emacs Lisp programs can open TCP connections to other processes on the same 
  20178. machine or other machines.  A network connection is handled by Lisp much like a 
  20179. subprocess, and is represented by a process object. However, the process you 
  20180. are communicating with is not a child of the Emacs process, so you can't kill 
  20181. it or send it signals.  All you can do is send and receive data. 
  20182. delete-process closes the connection, but does not kill the process at the 
  20183. other end of it. 
  20184.  
  20185.  You can distinguish process objects representing network connections from 
  20186. those representing subprocesses with the process-status function. 
  20187.  
  20188. -- Function: open-network-stream name buffer-or-name host service 
  20189. This function opens a TCP connection for a service to a host.  It returns a 
  20190. process object to represent the connection. 
  20191.  
  20192. The name argument specifies the name for the process object.  It is modified as 
  20193. necessary to make it unique. 
  20194.  
  20195. The buffer-or-name argument is the buffer to associate with the connection. 
  20196. Output from the connection is inserted in the buffer, unless you specify a 
  20197. filter function to handle the output.  If buffer-or-name is nil, it means that 
  20198. the connection is not associated with any buffer. 
  20199.  
  20200. The arguments host and service specify where to connect to; host is the host 
  20201. name (a string), and service is the name of the service desired (a string) or 
  20202. an integer specifying a port number to connect to. 
  20203.  
  20204.  
  20205. ΓòÉΓòÉΓòÉ 36. Operating System Interface ΓòÉΓòÉΓòÉ
  20206.  
  20207.  This chapter is about starting and getting out of Emacs, access to values in 
  20208. the operating system environment, and terminal input, output and flow control. 
  20209.  
  20210.  See Building Emacs, for related information.  See also Emacs Display, for 
  20211. additional operating system status information which pertain to the terminal 
  20212. and the screen. 
  20213.  
  20214.  
  20215. ΓòÉΓòÉΓòÉ 36.1. Starting Up Emacs ΓòÉΓòÉΓòÉ
  20216.  
  20217.  This section describes what Emacs does when it is started, and how you can 
  20218. customize these actions. 
  20219.  
  20220.  
  20221. ΓòÉΓòÉΓòÉ 36.1.1. Summary: Sequence of Actions at Start Up ΓòÉΓòÉΓòÉ
  20222.  
  20223.   The order of operations performed (in `startup.el') by Emacs when it is 
  20224. started up is as follows: 
  20225.  
  20226.  1. It loads `.emacs' unless `-q' was specified on command line. (This is not 
  20227.     done in `-batch' mode.)  `.emacs' is found in the user's home directory; 
  20228.     the `-u' option can specify the user name whose home directory should be 
  20229.     used. 
  20230.  
  20231.  2. It loads `default.el' unless inhibit-default-init is non-nil.  (This is not 
  20232.     done in `-batch' mode or if `-q' was specified on command line.) 
  20233.  
  20234.  3. It loads the terminal-specific Lisp file, if any, except when in batch 
  20235.     mode. 
  20236.  
  20237.  4. It runs term-setup-hook. 
  20238.  
  20239.  5. It runs window-setup-hook. 
  20240.  
  20241.  6. It displays copyleft and nonwarranty, plus basic use information, unless 
  20242.     the value of inhibit-startup-message is non-nil. 
  20243.  
  20244.     This display is also inhibited in batch mode, and if the current buffer is 
  20245.     not `*scratch*'. 
  20246.  
  20247.  7. It processes any remaining command line arguments. 
  20248.  
  20249. -- User Option: inhibit-startup-message 
  20250.  This variable inhibits the initial startup messages (the nonwarranty, etc.). 
  20251. If it is non-nil, then the messages are not printed. 
  20252.  
  20253.  This variable exists so you can set it in your personal init file, once you 
  20254. are familiar with the contents of the startup message.  Do not set this 
  20255. variable in the init file of a new user, or in a way that affects more than one 
  20256. user, because that would prevent new users from receiving the information they 
  20257. are supposed to see. 
  20258.  
  20259.  
  20260. ΓòÉΓòÉΓòÉ 36.1.2. The Init File: .emacs ΓòÉΓòÉΓòÉ
  20261.  
  20262.  When you start Emacs, it normally attempts to load the file `.emacs' from your 
  20263. home directory.  This file, if it exists, must contain Lisp code.  It is called 
  20264. your init file.  The command line switches `-q' and `-u' can be used to control 
  20265. the use of the init file; `-q' says not to load an init file, and `-u' says to 
  20266. load a specified user's init file instead of yours. See Entering Emacs. 
  20267.  
  20268.  Emacs may also have a default init file, which is the library named 
  20269. `default.el'.  Emacs finds the `default.el' file through the standard search 
  20270. path for libraries ( see How Programs Do Loading).  The Emacs distribution does 
  20271. not have any such file; you may create one at your site for local 
  20272. customizations.  If the default init file exists, it is loaded whenever you 
  20273. start Emacs, except in batch mode or if `-q' is specified.  But your own 
  20274. personal init file, if any, is loaded first; if it sets inhibit-default-init to 
  20275. a non-nil value, then Emacs will not load the `default.el' file. 
  20276.  
  20277.  If there is a great deal of code in your `.emacs' file, you should move it 
  20278. into another file named `something.el', byte-compile it (see Byte Compilation), 
  20279. and make your `.emacs' file load the other file using load (see Loading). 
  20280.  
  20281.  See Init File Examples, for examples of how to make various commonly desired 
  20282. customizations in your `.emacs' file. 
  20283.  
  20284. -- User Option: inhibit-default-init 
  20285.  This variable prevents Emacs from loading the default initialization library 
  20286. file for your session of Emacs.  If its value is non-nil, then the default 
  20287. library is not loaded.  The default value is nil. 
  20288.  
  20289.  
  20290. ΓòÉΓòÉΓòÉ 36.1.3. Terminal-Specific Initialization ΓòÉΓòÉΓòÉ
  20291.  
  20292.  Each terminal type can have its own Lisp library that Emacs will load when run 
  20293. on that type of terminal.  For a terminal type named termtype, the library is 
  20294. called `term/termtype'.  Emacs finds the file by searching the load-path 
  20295. directories as it does for other files, and trying the `.elc' and `.el' 
  20296. suffixes. Normally, terminal-specific Lisp library is located in 
  20297. `emacs/lisp/term', a subdirectory of the `emacs/lisp' directory in which most 
  20298. Emacs Lisp libraries are kept. 
  20299.  
  20300.  The library's name is constructed by concatenating the value of the variable 
  20301. term-file-prefix and the terminal type.  Normally, term-file-prefix has the 
  20302. value "term/"; changing this is not recommended. 
  20303.  
  20304.  The usual purpose of a terminal-specific library is to define the escape 
  20305. sequences used by a terminal's function keys.  See the file `term/vt100.el' for 
  20306. an example of a terminal-specific library. 
  20307.  
  20308.  Function keys are handled by a two-level procedure.  The first level is 
  20309. dependent on the specific type of terminal and maps Emacs's input sequences to 
  20310. the function keys that they represent.  The second level is independent of 
  20311. terminal type and is customized by users; function keys are mapped into 
  20312. meanings at this level.  The terminal-specific library handles the first level 
  20313. of the process and the library `keypad.el' handles the second level of mapping. 
  20314.  
  20315.  When the name of the terminal type contains a hyphen, only the part of the 
  20316. name before the first hyphen is significant in choosing the library name. 
  20317. Thus, terminal types `aaa-48' and `aaa-30-rv' both use the `term/aaa' library. 
  20318. If necessary, the library can evaluate (getenv "TERM") to find the full name of 
  20319. the terminal type. 
  20320.  
  20321.  Your `.emacs' file can prevent the loading of the terminal-specific library by 
  20322. setting term-file-prefix to nil.  This feature is very useful when 
  20323. experimenting with your own peculiar customizations. 
  20324.  
  20325.  You can also arrange to override some of the actions of the terminal-specific 
  20326. library by setting the variable term-setup-hook.  If it is not nil, Emacs calls 
  20327. the value of the variable term-setup-hook as a function of no arguments at the 
  20328. end of Emacs initialization, after Emacs has already loaded both your `.emacs' 
  20329. file and any terminal-specific libraries.  You can use this variable to define 
  20330. initializations for terminals that do not have their own libraries. 
  20331.  
  20332. -- Variable: term-file-prefix 
  20333.  If the term-file-prefix variable is non-nil, Emacs loads a terminal-specific 
  20334. initialization file as follows: 
  20335.  
  20336. (load (concat term-file-prefix (getenv "TERM")))
  20337.  
  20338. You may set the term-file-prefix variable to nil in your `.emacs' file if you 
  20339. do not wish to load the terminal-initialization file.  To do this, put the 
  20340. following in your `.emacs' file: (setq term-file-prefix nil). 
  20341.  
  20342. -- Variable: term-setup-hook 
  20343.  The value of this variable is either nil or a function to be called by Emacs 
  20344. after loading your `.emacs' file, the default initialization file (if any) and 
  20345. after loading terminal-specific Lisp code.  The function is called with no 
  20346. arguments. 
  20347.  
  20348.  You can use term-setup-hook to override the definitions made by a 
  20349. terminal-specific file. 
  20350.  
  20351.  See also window-setup-hook in Window Systems. 
  20352.  
  20353.  
  20354. ΓòÉΓòÉΓòÉ 36.1.4. Command Line Arguments ΓòÉΓòÉΓòÉ
  20355.  
  20356.  You can use command line arguments to request various actions when you start 
  20357. Emacs.  Since you do not need to start Emacs more than once per day, and will 
  20358. often leave your Emacs session running longer than that, command line arguments 
  20359. are hardly ever used.  As a practical matter, it is best to avoid making the 
  20360. habit of using them, since this habit would encourage you to kill and restart 
  20361. Emacs unnecessarily often.  These options exist for two reasons: to be 
  20362. compatible with other editors (for invocation by other programs) and to enable 
  20363. shell scripts to run specific Lisp programs. 
  20364.  
  20365. -- Function: command-line 
  20366.  This function parses the command line which Emacs was called with, processes 
  20367. it, loads the user's `.emacs' file and displays the initial nonwarranty 
  20368. information, etc. 
  20369.  
  20370. -- Variable: command-line-processed 
  20371.  The value of this variable is t once the command line has been processed. 
  20372.  
  20373. If you redump Emacs by calling dump-emacs, you must set this variable to nil 
  20374. first in order to cause the new dumped Emacs to process its new command line 
  20375. arguments. 
  20376.  
  20377. -- Variable: command-switch-alist 
  20378. The value of this variable is an alist of user-defined command-line options and 
  20379. associated handler functions.  This variable exists so you can add elements to 
  20380. it. 
  20381.  
  20382. A command line option is an argument on the command line of the form: 
  20383.  
  20384. -option
  20385.  
  20386. The elements of the command-switch-alist look like this: 
  20387.  
  20388. (option . handler-function)
  20389.  
  20390. For each element, the handler-function receives the switch name as its sole 
  20391. argument. 
  20392.  
  20393. In some cases, the option is followed in the command line by an argument.  In 
  20394. these cases, the handler-function can find all the remaining command-line 
  20395. arguments in the variable command-line-args-left.  (The entire list of 
  20396. command-line arguments is in command-line-args.) 
  20397.  
  20398. The command line arguments are parsed by the command-line-1 function in the 
  20399. `startup.el' file.  See also Command Line Switches and Arguments. 
  20400.  
  20401. -- Variable: command-line-args 
  20402. The value of this variable is the arguments passed by the shell to Emacs, as a 
  20403. list of strings. 
  20404.  
  20405.  
  20406. ΓòÉΓòÉΓòÉ 36.2. Getting out of Emacs ΓòÉΓòÉΓòÉ
  20407.  
  20408.  There are two ways to get out of Emacs: you can kill the Emacs job, which 
  20409. exits permanently, or you can suspend it, which permits you to reenter the 
  20410. Emacs process later.  As a practical matter, you seldom kill Emacs---only when 
  20411. you are about to log out.  Suspending is much more common. 
  20412.  
  20413.  
  20414. ΓòÉΓòÉΓòÉ 36.2.1. Killing Emacs ΓòÉΓòÉΓòÉ
  20415.  
  20416.  Killing Emacs means ending the execution of the Emacs process. It will return 
  20417. to its superior process. 
  20418.  
  20419.  All the information in the Emacs process, aside from files that have been 
  20420. saved, is lost when the Emacs is killed.  Because killing Emacs inadvertently 
  20421. can lose a lot of work, Emacs will query for confirmation before actually 
  20422. terminating if you have buffers that need saving or subprocesses that are 
  20423. running. 
  20424.  
  20425. -- Function: kill-emacs &optional no-query 
  20426.  This function exits the Emacs process and kills it. 
  20427.  
  20428.  Normally, if there are modified files or if there are running processes, 
  20429. kill-emacs asks the user for confirmation before exiting.  However, if no-query 
  20430. is supplied and non-nil, then Emacs exits without confirmation. 
  20431.  
  20432.  If no-query is an integer, then it is used as the exit status of the Emacs 
  20433. process.  (This is useful primarily in batch operation; see Batch Mode.) 
  20434.  
  20435.  If no-query is a string, its contents are stuffed into the terminal input 
  20436. buffer so that the shell (or whatever program next reads input) can read them. 
  20437.  
  20438. -- Variable: kill-emacs-hook 
  20439.  The value of the kill-emacs-hook variable is either nil or is that of a 
  20440. function to be called by kill-emacs.  The hook is called before anything else 
  20441. is done by kill-emacs. 
  20442.  
  20443.  
  20444. ΓòÉΓòÉΓòÉ 36.2.2. Suspending Emacs ΓòÉΓòÉΓòÉ
  20445.  
  20446.  Suspending Emacs means stopping Emacs temporarily and returning control to its 
  20447. superior process, which is usually the shell.  This allows you to resume 
  20448. editing later in the same Emacs process, with the same buffers, the same kill 
  20449. ring, the same undo history, and so on.  To resume Emacs, use the appropriate 
  20450. command in the parent shell---most likely fg. 
  20451.  
  20452.  Some operating systems do not support suspension of jobs; on these systems, 
  20453. ``suspension'' actually creates a new shell temporarily as a subprocess of 
  20454. Emacs.  Then you would exit the shell to return to Emacs. 
  20455.  
  20456.  Suspension is not useful with window systems such as X Windows, because the 
  20457. Emacs job may not have a parent that can resume it again, and in any case you 
  20458. can give input to some other job such as a shell merely by moving to a 
  20459. different window.  Therefore, suspending is not allowed under X Windows. 
  20460.  
  20461. -- Function: suspend-emacs string 
  20462.  This function stops Emacs and returns to the superior process.  It returns 
  20463. nil. 
  20464.  
  20465.  If string is non-nil, its characters are sent to be read as terminal input by 
  20466. Emacs's superior shell.  The characters in string will not be echoed by the 
  20467. superior shell; just the results will appear. 
  20468.  
  20469.  Before suspending, Emacs examines the symbol suspend-hook.  If it is bound, 
  20470. and its value is non-nil, then the value is called as a function of no 
  20471. arguments.  If the function returns non-nil, then suspend-emacs returns 
  20472. immediately and suspension does not occur. 
  20473.  
  20474.  After Emacs resumes, the symbol suspend-resume-hook is examined.  If it is 
  20475. bound and non-nil, then the value is called as a function of no arguments. 
  20476.  
  20477.  The next redisplay after resumption will redraw the entire screen, unless 
  20478. no-redraw-on-reenter is set (see Screen Attributes). 
  20479.  
  20480.  In the following example, note that `pwd' is not echoed after Emacs is 
  20481. suspended.  But it is read and executed by the shell. 
  20482.  
  20483. (suspend-emacs)
  20484.      => nil
  20485.  
  20486. (setq suspend-hook
  20487.     (function (lambda ()
  20488.               (not (y-or-n-p "Really suspend? ")))))
  20489.      => (lambda nil (not (y-or-n-p "Really suspend? ")))
  20490. (setq suspend-resume-hook
  20491.     (function (lambda () (message "Resumed!"))))
  20492.      => (lambda nil (message "Resumed!"))
  20493. (suspend-emacs "pwd")
  20494.      => nil
  20495. ---------- Buffer: Minibuffer ----------
  20496. Really suspend? y
  20497.  
  20498. ---------- Parent Shell ----------
  20499. lewis@slug[23] % /user/lewis/manual
  20500. lewis@slug[24] % fg
  20501.  
  20502. ---------- Echo Area ----------
  20503. Resumed!
  20504.  
  20505. -- Variable: suspend-hook 
  20506.  The value of the suspend-hook variable, if not nil, is called as a function 
  20507. with no arguments by suspend-emacs before Emacs is actually suspended.  If the 
  20508. function returns non-nil, then suspension does not take place. 
  20509.  
  20510. -- Variable: suspend-resume-hook 
  20511.  The value of the suspend-resume-hook variable, if not nil, is called as a 
  20512. function with no arguments after resumption of an Emacs session that was 
  20513. suspended with suspend-emacs. 
  20514.  
  20515.  
  20516. ΓòÉΓòÉΓòÉ 36.3. Operating System Environment ΓòÉΓòÉΓòÉ
  20517.  
  20518.  Emacs provides access to variables in the operating system environment through 
  20519. various functions.  These variables include the name of the system, the user's 
  20520. uid, and so on. 
  20521.  
  20522. -- Variable: system-type 
  20523.  The value of this variable is a symbol indicating the type of operating system 
  20524. Emacs is operating on.  Here is a table of the symbols for the operating 
  20525. systems that Emacs can run on up to version 18.51. 
  20526.  
  20527. berkeley-unix 
  20528.           Berkeley BSD 4.1, 4.2, or 4.3. 
  20529.  
  20530. hpux 
  20531.           Hewlett-Packard operating system, version 5, 6, or 7. 
  20532.  
  20533. silicon-graphics-unix 
  20534.           Silicon Graphics Iris 3.5 or 3.6. 
  20535.  
  20536. rtu 
  20537.           RTU 3.0, UCB universe. 
  20538.  
  20539. unisoft-unix 
  20540.           UniSoft's UniPlus 5.0 or 5.2. 
  20541.  
  20542. usg-unix-v 
  20543.           AT&T's System V.0, System V Release 2.0, 2.2, or 3. 
  20544.  
  20545. vax-vms 
  20546.           VMS VMS version 4 or 5. 
  20547.  
  20548. xenix 
  20549.           SCO Xenix 386 Release 2.2. 
  20550.  
  20551. We do not wish to add new symbols to make finer distinctions unless it is 
  20552. absolutely necessary!  In fact, it would be nice to eliminate a couple of 
  20553. possibilities in the future. 
  20554.  
  20555. -- Function: getenv var 
  20556.  This function returns the value of the environment variable var, as a string. 
  20557.  
  20558. (getenv "USER")
  20559.      => "lewis"
  20560.  
  20561. lewis@slug[10] % printenv
  20562. PATH=.:/user/lewis/bin:/usr/bin:/usr/local/bin
  20563. USER=lewis
  20564. TERM=ibmapa16
  20565. SHELL=/bin/csh
  20566. HOME=/user/lewis
  20567.  
  20568. -- Function: user-login-name 
  20569.  This function returns the name under which the user is logged in. This is 
  20570. based on the effective uid, not the real uid. 
  20571.  
  20572. (user-login-name)
  20573.      => "lewis"
  20574.  
  20575. -- Function: user-real-login-name 
  20576.  This function returns the name under which the user logged in. This is based 
  20577. on the real uid, not the effective uid.  This differs from user-login-name only 
  20578. when running with the setuid bit. 
  20579.  
  20580. -- Function: user-full-name 
  20581. This function returns the full name of the user. 
  20582.  
  20583. (user-full-name)
  20584.      => "Bil Lewis"
  20585.  
  20586. -- Function: user-real-uid 
  20587.  This function returns the real uid of the user. 
  20588.  
  20589. (user-real-uid)
  20590.      => 19
  20591.  
  20592. -- Function: user-uid 
  20593.   This function returns the effective uid of the user. 
  20594.  
  20595. -- Function: system-name 
  20596.   This function returns the name of the machine you are running on. 
  20597.  
  20598. (system-name)
  20599.      => "prep.ai.mit.edu"
  20600.  
  20601. -- Function: current-time-string 
  20602.   This function returns the current time and date as a humanly-readable string. 
  20603. The format of the string is unvarying; the number of characters used for each 
  20604. part is always the same, so you can reliably use substring to extract pieces of 
  20605. it.  However, it would be wise to count the characters from the beginning of 
  20606. the string rather than from the end, as additional information describing the 
  20607. time zone may be added in version 19. 
  20608.  
  20609. (current-time-string)
  20610.      => "Wed Oct 14 22:21:05 1987"
  20611.  
  20612. -- Function: load-average 
  20613.   This function returns the current 1 minute, 5 minute and 15 minute load 
  20614. averages in a list.  The values are integers that are 100 times the system load 
  20615. averages.  (The load averages indicate the number of processes trying to run.) 
  20616.  
  20617. (load-average)
  20618.      => (169 48 36)
  20619.  
  20620. lewis@rocky[5] % uptime
  20621.  11:55am  up 1 day, 19:37,  3 users,  load average: 1.69, 0.48, 0.36
  20622.  
  20623. -- Function: setprv privilege-name &optional setp getprv 
  20624.  This function sets or resets a VMS privilege.  (It does not exist on Unix.) 
  20625. The first arg is the privilege name, as a string.  The second argument, setp, 
  20626. is t or nil, indicating whether the privilege is to be turned on or off.  Its 
  20627. default is nil.  The function returns t if success, nil if not. 
  20628.  
  20629.  If the third argument, getprv, is non-nil, setprv does not change the 
  20630. privilege, but returns t or nil indicating whether the privilege is currently 
  20631. enabled. 
  20632.  
  20633.  
  20634. ΓòÉΓòÉΓòÉ 36.4. Terminal Input ΓòÉΓòÉΓòÉ
  20635.  
  20636.  The terminal input functions and variables keep track of or manipulate 
  20637. terminal input. 
  20638.  
  20639.  See Emacs Display, for related functions. 
  20640.  
  20641. -- Function: recent-keys 
  20642.  This function returns a string comprising the last 100 characters read from 
  20643. the terminal.  These are the last 100 characters read by Emacs, no exceptions. 
  20644.  
  20645. (recent-keys)
  20646. => "erminal.  These are the last 100 characters read by Emacs, no
  20647. exceptions.
  20648.  
  20649. @example
  20650. (recent-keys)^U^X^E"
  20651.  
  20652. Here the string `@example' is a Texinfo command that was inserted in the source 
  20653. file for the manual, and `^U^X^E' are the characters that were typed to 
  20654. evaluate the expression (recent-keys). 
  20655.  
  20656. -- Command: open-dribble-file  filename 
  20657.  This function opens a dribble file named filename.  When a dribble file is 
  20658. open, Emacs copies all keyboard input characters to that file.  (The contents 
  20659. of keyboard macros are not typed on the keyboard so they are not copied to the 
  20660. dribble file.) 
  20661.  
  20662.  You close the dribble file by calling this function with an argument of "". 
  20663. The function always returns nil. 
  20664.  
  20665.  This function is normally used to record the input necessary to trigger an 
  20666. Emacs bug, for the sake of a bug report. 
  20667.  
  20668. (open-dribble-file "$j/dribble")
  20669.      => nil
  20670.  
  20671.  See also the open-termscript function (see Terminal Output). 
  20672.  
  20673. -- Function: set-input-mode interrupt flow quit-char 
  20674.  This function sets the mode for reading keyboard input.  If interrupt is 
  20675. non-null, then Emacs uses input interrupts.  If it is nil, then it uses cbreak 
  20676. mode. 
  20677.  
  20678.  If flow is non-nil, then Emacs uses xon/xoff (C-q, C-s) flow control for 
  20679. output to terminal.  This has no effect except in cbreak mode.  See Flow 
  20680. Control. 
  20681.  
  20682.  The normal setting is system dependent.  Some systems always use cbreak mode 
  20683. regardless of what is specified. 
  20684.  
  20685.  If quit-char is non-nil, it specifies the character to use for quitting. 
  20686. Normally this is 7, the code for C-g. See Quitting. 
  20687.  
  20688. -- Variable: meta-flag 
  20689.  This variable tells Emacs whether to treat the 0200 bit in keyboard input as 
  20690. the Meta bit.  nil means no, and anything else means yes.  In version 19, 
  20691. meta-flag will be a function instead of a variable. 
  20692.  
  20693. -- Variable: keyboard-translate-table 
  20694.  This variable defines the translate table for keyboard input.  This allows the 
  20695. user to redefine the keys on the keyboard without changing any command 
  20696. bindings.  Its value must be a string or nil. 
  20697.  
  20698.  If keyboard-translate-table is a string, then each character read from the 
  20699. keyboard is looked up in this string and the character in the string is used 
  20700. instead.  If the string is of length n, character codes n and up are 
  20701. untranslated. 
  20702.  
  20703.  In the example below, keyboard-translate-table is set to a string of 128 
  20704. characters.  Then the characters C-s and C-\ are swapped and the characters C-q 
  20705. and C-^ are swapped. After executing this function, typing C-\ has all the 
  20706. usual effects of typing C-s, and vice versa.  (See Flow Control for more 
  20707. information on this subject.) 
  20708.  
  20709. (defun evade-flow-control ()
  20710.   "Replace C-s with C-\ and C-q with C-^."
  20711.   (interactive)
  20712.   (let ((the-table (make-string 128 0)))
  20713.     (let ((i 0))
  20714.       (while (< i 128)
  20715.         (aset the-table i i)
  20716.         (setq i (1+ i))))
  20717.  
  20718.     ;; Swap C-s and C-\.
  20719.     (aset the-table ?\034 ?\^s)
  20720.     (aset the-table ?\^s ?\034)
  20721.     ;; Swap C-q and C-^.
  20722.     (aset the-table ?\036 ?\^q)
  20723.     (aset the-table ?\^q ?\036)
  20724.  
  20725.     (setq keyboard-translate-table the-table)))
  20726.  
  20727. Note that this translation is the first thing that happens after a character is 
  20728. read from the terminal.  As a result, record-keeping features such as 
  20729. recent-keys and open-dribble-file record the translated characters. 
  20730.  
  20731.  
  20732. ΓòÉΓòÉΓòÉ 36.5. Terminal Output ΓòÉΓòÉΓòÉ
  20733.  
  20734.  The terminal output functions send or keep track of output sent from the 
  20735. computer to the terminal.  The baud-rate function tells you what Emacs thinks 
  20736. is the output baud rate of the terminal. 
  20737.  
  20738. -- Function: baud-rate 
  20739.  This function returns the output baud rate of the terminal. 
  20740.  
  20741. (baud-rate)
  20742.      => 9600
  20743.  
  20744.  If you are running across a network, and different parts of the network work 
  20745. at different baud rates, the value returned by Emacs may be different from the 
  20746. value used by your local terminal.  Some network protocols communicate the 
  20747. local terminal speed to the remote machine, so that Emacs and other programs 
  20748. can get the proper value, but others do not.  If the machine where Emacs is 
  20749. running has the wrong speed setting, you can specify the right speed using the 
  20750. stty program.  However, you will have to start Emacs afresh to make this take 
  20751. effect. 
  20752.  
  20753. *Note:* In version 19, baud-rate is a variable so that you can change it 
  20754. conveniently within Emacs. 
  20755.  
  20756. -- Function: send-string-to-terminal string 
  20757.  This function sends string to the terminal without alteration. Control 
  20758. characters in string will have terminal-dependent effects. 
  20759.  
  20760.  One use of this function is to define function keys on terminals that have 
  20761. downloadable function key definitions.  For example, this is how on certain 
  20762. terminals to define function key 4 to move forward four characters (by 
  20763. transmitting the characters C-u C-f to the computer): 
  20764.  
  20765. (send-string-to-terminal "\eF4\^U\^F")
  20766.      => nil
  20767.  
  20768. -- Command: open-termscript filename 
  20769.  This function is used to open a termscript file that will record all the 
  20770. characters sent by Emacs to the terminal.  It returns nil.  Termscript files 
  20771. are useful for investigating problems where Emacs garbles the screen, problems 
  20772. which are due to incorrect termcap entries or to undesirable settings of 
  20773. terminal options more often than actual Emacs bugs.  Once you are certain which 
  20774. characters were actually output, you can determine reliably whether they 
  20775. correspond to the termcap specifications in use. 
  20776.  
  20777.  See also open-dribble-file in Terminal Input. 
  20778.  
  20779. (open-termscript "../junk/termscript")
  20780.      => nil
  20781.  
  20782.  
  20783. ΓòÉΓòÉΓòÉ 36.6. Flow Control ΓòÉΓòÉΓòÉ
  20784.  
  20785.  This section attempts to answer the question ``Why does Emacs choose to use 
  20786. flow-control characters in its command character set?''  For a second view on 
  20787. this issue, read the comments on flow control in the `emacs/INSTALL' file from 
  20788. the distribution; for help with termcaps and DEC terminal concentrators, see 
  20789. `emacs/etc/TERMS'. 
  20790.  
  20791.  At one time, most terminals did not need flow control.  This meant that the 
  20792. choice of C-s and C-q as command characters was reasonable.  Emacs, for economy 
  20793. of keystrokes and portability, chose to use the control characters in the ASCII 
  20794. character set, and tried to make the assignments mnemonic (thus, C-s for search 
  20795. and C-q for quote). 
  20796.  
  20797.  Later, some terminals were introduced which used these characters for flow 
  20798. control.  They were not very good terminals, so Emacs maintainers did not pay 
  20799. attention.  In later years, the practice became widespread among terminals, but 
  20800. by this time it was usually an option.  And the majority of users, who can turn 
  20801. flow control off, were unwilling to switch to less mnemonic key bindings for 
  20802. the sake of flow control. 
  20803.  
  20804.  So which usage is ``right'', Emacs's or that of some terminal and concentrator 
  20805. manufacturers?  This is a rhetorical (or religious) question; it has no simple 
  20806. answer. 
  20807.  
  20808.  One reason why we are reluctant to cater to the problems caused by C-s and C-q 
  20809. is that they are gratuitous.  There are other techniques (albeit less common in 
  20810. practice) for flow control that preserve transparency of the character stream. 
  20811. Note also that their use for flow control is not an official standard. 
  20812. Interestingly, on the model 33 teletype with a paper tape punch (which is very 
  20813. old), C-s and C-q were sent by the computer to turn the punch on and off! 
  20814.  
  20815.  GNU Emacs (version 18.48 and later) provides several options for coping with 
  20816. terminals or front-ends that insist on using flow control characters.  Listed 
  20817. in estimated order of preference, these options are as follows: 
  20818.  
  20819.  1. Have Emacs run in cbreak mode with the kernel handling flow control.  Issue 
  20820.     (set-input-mode nil t) from `.emacs'.  After doing this, it is necessary to 
  20821.     find other keys to bind to the commands isearch-forward and quoted-insert. 
  20822.     The usual nominees are C-^ and C-\.  There are two ways to get this effect: 
  20823.  
  20824.     a. Use the keyboard-translate-table to cause C-^ and C-\ to be received by 
  20825.        Emacs as though C-s and C-q were typed.  Emacs (except at its very 
  20826.        lowest level) never knows that the characters typed were anything but 
  20827.        C-s and C-q, so the use of these keys inside isearch-forward still 
  20828.        works---typing C-^ while incremental searching will move the cursor to 
  20829.        the next match, etc.  For example: 
  20830.  
  20831.               (setq keyboard-translate-table (make-string 128 0))
  20832.               (let ((i 0))
  20833.                 (while (< i 128)
  20834.                   (aset keyboard-translate-table i i)
  20835.                   (setq i (1+ i))))
  20836.  
  20837.                 ;; Swap C-s and C-\.
  20838.                 (aset the-table ?\034 ?\^s)
  20839.                 (aset the-table ?\^s ?\034)
  20840.                 ;; Swap C-q and C-^.
  20841.                 (aset the-table ?\036 ?\^q)
  20842.                 (aset the-table ?\^q ?\036)))
  20843.  
  20844.     b. Simply rebind the keys C-^ and C-\ to isearch-forward and quoted-insert. 
  20845.        To use the new keys to repeat searches, it is necessary to set 
  20846.        search-repeat-char to C-^ as well. 
  20847.  
  20848.  2. Don't use cbreak mode, but cause C-s and C-q to be bound to a null command. 
  20849.     The problem with this solution is that the flow control characters were 
  20850.     probably sent because whatever sent them is falling behind on the 
  20851.     characters being sent to it.  The characters that find their way to the 
  20852.     terminal screen will not in general be those that are intended.  Also, it 
  20853.     will be be necessary to find other keys to bind to isearch-forward and 
  20854.     quoted-insert; see the previous alternative. 
  20855.  
  20856.     Here is a suitable null command: 
  20857.  
  20858.         (defun noop ()
  20859.           "Do nothing; return nil."
  20860.           (interactive))
  20861.  
  20862.  3. Don't use cbreak mode, and unset the C-s and C-q keys with the 
  20863.     global-unset-key function.  This is similar to the previous alternative, 
  20864.     except that the flow control characters will probably cause beeps or 
  20865.     visible bells. 
  20866.  
  20867.     Note that if the terminal is the source of the flow control characters and 
  20868.     kernel flow control handling is enabled, you probably will not have to send 
  20869.     padding characters as specified in a termcap or terminfo entry. In this 
  20870.     case, it may be possible to customize a termcap entry to provide better 
  20871.     Emacs performance on the assumption that flow control is in use. This 
  20872.     effect can also be simulated by announcing (with stty or its equivalent) 
  20873.     that the terminal is running at a very slow speed, provided you are 
  20874.     communicating across a network so that stty does not actually try to change 
  20875.     the line speed. 
  20876.  
  20877.  
  20878. ΓòÉΓòÉΓòÉ 36.7. Batch Mode ΓòÉΓòÉΓòÉ
  20879.  
  20880.  The command line option `-batch' causes Emacs to run noninteractively.  In 
  20881. this mode, Emacs does not read commands from the terminal, it does not alter 
  20882. the terminal modes, and it does not expect to be outputting to an erasable 
  20883. screen.  The idea is that you will specify Lisp programs to run; when they are 
  20884. finished, Emacs should exit. The way to specify the programs to run is with `-l 
  20885. file', which causes the library named file to be loaded, and `-f function', 
  20886. which causes function to be called with no arguments. 
  20887.  
  20888.  Any Lisp program output that would normally go to the echo area, either using 
  20889. message or using prin1, etc., with t as the stream, will actually go to Emacs's 
  20890. standard output descriptor when in batch mode.  Thus, Emacs behaves much like a 
  20891. noninteractive application program.  (The echo area output that Emacs itself 
  20892. normally generates, such as command echoing, is suppressed entirely.) 
  20893.  
  20894. -- Variable: noninteractive 
  20895. This variable is non-nil when Emacs is running in batch mode. 
  20896.  
  20897.  
  20898. ΓòÉΓòÉΓòÉ 37. Emacs Display ΓòÉΓòÉΓòÉ
  20899.  
  20900.  This chapter describes a number of features related to the display that Emacs 
  20901. presents to the user. 
  20902.  
  20903.  
  20904. ΓòÉΓòÉΓòÉ 37.1. Refreshing the Screen ΓòÉΓòÉΓòÉ
  20905.  
  20906. -- Command: redraw-display 
  20907.  This function clears the screen and redraws what is supposed to appear on it. 
  20908.  
  20909.  
  20910. ΓòÉΓòÉΓòÉ 37.2. Screen Attributes ΓòÉΓòÉΓòÉ
  20911.  
  20912.  The screen attribute functions describe and define the characteristics of the 
  20913. terminal. 
  20914.  
  20915. -- Function: screen-height 
  20916.  This function returns the number of lines on the screen that are available for 
  20917. display. 
  20918.  
  20919. (screen-height)
  20920.      => 50
  20921.  
  20922. -- Function: screen-width 
  20923.  This function returns the number of columns on the screen that are available 
  20924. for display. 
  20925.  
  20926. (screen-width)
  20927.      => 80
  20928.  
  20929. -- Function: set-screen-height lines &optional not-actual-size 
  20930.  This function declares that the terminal can display lines lines. The sizes of 
  20931. existing windows will be altered proportionally to fit. 
  20932.  
  20933.  If not-actual-size is non-nil, then Emacs will display lines lines of output, 
  20934. but will not change its value for the actual height of the screen.  Knowing the 
  20935. correct actual size may be necessary for correct cursor positioning. 
  20936.  
  20937.  If lines is different from what it was previously, then the entire screen is 
  20938. cleared and redisplayed using the new size. 
  20939.  
  20940.  This function returns nil. 
  20941.  
  20942. -- Function: set-screen-width columns &optional not-actual-size 
  20943.  This function declares that the terminal can display columns columns.  The 
  20944. details are as in set-screen-height. 
  20945.  
  20946. -- Variable: no-redraw-on-reenter 
  20947.  This variable controls whether Emacs redraws the entire screen after it has 
  20948. been suspended and resumed.  Non-nil means yes, nil means no.  On most 
  20949. terminals, it is necessary to redraw.  Not redrawing is useful if the terminal 
  20950. can remember and restore the Emacs screen contents. 
  20951.  
  20952. -- Variable: inverse-video 
  20953.  This variable controls whether Emacs uses inverse video for all text on the 
  20954. screen.  Non-nil means yes, nil means no.  The default is nil. 
  20955.  
  20956. -- User Option: mode-line-inverse-video 
  20957.  This variable controls the use of inverse video for mode lines.  If it is 
  20958. non-nil, then mode lines are displayed in inverse video (or another suitable 
  20959. display mode).  Otherwise, mode lines are displayed normal, just like the rest 
  20960. of the screen.  The default is t. 
  20961.  
  20962.  
  20963. ΓòÉΓòÉΓòÉ 37.3. Truncation ΓòÉΓòÉΓòÉ
  20964.  
  20965.  When a line of text extends beyond the right edge of a window, the line can 
  20966. either be truncated or continued on the next line.  When a line is truncated, 
  20967. this is shown with a `$' in the rightmost column of the window.  When a line is 
  20968. continued or ``wrapped'' onto the next line, this is shown with a `\' on the 
  20969. rightmost column of the window. The additional screen lines used to display a 
  20970. long text line are called continuation lines.  (Note that wrapped lines are not 
  20971. filled; filling has nothing to do with truncation and continuation. See 
  20972. Filling.) 
  20973.  
  20974. -- User Option: truncate-lines 
  20975.   This buffer-local variable controls how Emacs displays lines that extend 
  20976. beyond the right edge of the window.  If it is non-nil, then Emacs does not 
  20977. display continuation lines; but rather each line of text will take exactly one 
  20978. screen line, and a dollar sign will be shown at the edge of any line that 
  20979. extends to or beyond the edge of the window.  The default is nil. 
  20980.  
  20981.  If the variable truncate-partial-width-windows is non-nil, then truncation is 
  20982. used for windows that are not the full width of the screen, regardless of the 
  20983. value of truncate-lines. 
  20984.  
  20985. -- Variable: default-truncate-lines 
  20986.  This variable is the default value for truncate-lines in buffers that do not 
  20987. override it. 
  20988.  
  20989. -- User Option: truncate-partial-width-windows 
  20990.  This variable determines how lines that are too wide to fit on the screen are 
  20991. displayed in side-by-side windows ( see Splitting Windows).  If it is non-nil, 
  20992. then wide lines are truncated (with a `$' at the end of the line); otherwise 
  20993. they are wrapped (with a `\' at the end of the line). 
  20994.  
  20995.  
  20996. ΓòÉΓòÉΓòÉ 37.4. The Echo Area ΓòÉΓòÉΓòÉ
  20997.  
  20998.  The echo area is used for displaying messages made with the message primitive, 
  20999. and for echoing keystrokes.  It is not the same as the minibuffer, despite the 
  21000. fact that the minibuffer appears (when active) in the same place on the screen 
  21001. as the echo area.  The GNU Emacs Manual specifies the rules for resolving 
  21002. conflicts between the echo area and the minibuffer for use of that screen space 
  21003. (see The Minibuffer). 
  21004.  
  21005. You can write output in the echo area by using the Lisp printing funtions with 
  21006. t as the stream (see Output Functions), or as follows: 
  21007.  
  21008. -- Function: message string &rest arguments 
  21009.  This function prints a one-line message in the echo area.  The argument string 
  21010. is similar to a C language printf control string.  See format in String 
  21011. Conversion, for the details on the conversion specifications.  message returns 
  21012. the constructed string. 
  21013.  
  21014. (message "Minibuffer depth is %d." (minibuffer-depth))
  21015. => "Minibuffer depth is 0."
  21016.  
  21017. ---------- Echo Area ----------
  21018. Minibuffer depth is 0.
  21019. ---------- Echo Area ----------
  21020.  
  21021. -- Variable: cursor-in-echo-area 
  21022.  This variable controls where the cursor is positioned when a message is 
  21023. displayed in the echo area.  If it is non-nil, then the cursor appears at the 
  21024. end of the message.  Otherwise, the cursor appears at point---not in the echo 
  21025. area at all. 
  21026.  
  21027.  The value is normally nil except when bound to t for brief periods of time. 
  21028.  
  21029.  
  21030. ΓòÉΓòÉΓòÉ 37.5. Selective Display ΓòÉΓòÉΓòÉ
  21031.  
  21032.  Selective display is a class of minor modes in which specially marked lines do 
  21033. not appear on the screen, or in which highly indented lines do not appear. 
  21034.  
  21035.  The first variant, explicit selective display, is designed for use in a Lisp 
  21036. program.  The program controls which lines are hidden by altering the text. 
  21037. Outline mode uses this variant.  In the second variant, the choice of lines to 
  21038. hide is made automatically based on indentation. This variant is designed as a 
  21039. user-level feature. 
  21040.  
  21041.  The way you control explicit selective display is by replacing a newline 
  21042. (control-j) with a control-m.  The text which was formerly a line following 
  21043. that newline is now invisible.  Strictly speaking, it is no longer a separate 
  21044. line, since only newlines can separate lines; it is now part of the previous 
  21045. line. 
  21046.  
  21047.  On its own, selective display does not affect editing commands.  For example, 
  21048. C-f (forward-char) moves point unhesitatingly into invisible space.  However, 
  21049. the replacement of newline characters with carriage return characters affects 
  21050. some editing commands.  For example, next-line skips invisible lines, since it 
  21051. searches only for newlines.  Modes that use selective display can also define 
  21052. commands that take account of the newlines, or which make parts of the text 
  21053. visible or invisible. 
  21054.  
  21055.  When you write a selectively displayed buffer into a file, all the control-m's 
  21056. are replaced by their original newlines.  This means that when you next read in 
  21057. the file, it looks OK, with nothing invisible. Selective display is an effect 
  21058. that is seen only in Emacs. 
  21059.  
  21060. -- Variable: selective-display 
  21061.  This buffer-local variable enables selective display.  This means that lines, 
  21062. or portions of lines, may be made invisible. 
  21063.  
  21064. o If the value of selective-display is t, then any portion of a line that 
  21065.   follows a control-m will not be displayed. 
  21066.  
  21067. o If the value of selective-display is a positive integer, then lines that 
  21068.   start with more than selective-display columns of indentation will not be 
  21069.   displayed. 
  21070.  
  21071.  When some portion of a buffer is invisible, the vertical movement commands 
  21072. operate as if that portion did not exist, allowing a single next-line command 
  21073. to skip any number of invisible lines. However, character movement commands 
  21074. (such as forward-char) will not skip the invisible portion, and it is possible 
  21075. (if tricky) to insert or delete parts of an invisible portion. 
  21076.  
  21077.  In the examples below, what is shown is the display of the buffer foo, which 
  21078. changes with the value of selective-display.  The contents of the buffer do not 
  21079. change. 
  21080.  
  21081. (setq selective-display nil)
  21082.      => nil
  21083.  
  21084. ---------- Buffer: foo ----------
  21085. 1 on this column
  21086.  2on this column
  21087.   3n this column
  21088.   3n this column
  21089.  2on this column
  21090. 1 on this column
  21091. ---------- Buffer: foo ----------
  21092.  
  21093. (setq selective-display 2)
  21094.      => 2
  21095.  
  21096. ---------- Buffer: foo ----------
  21097. 1 on this column
  21098.  2on this column
  21099.  2on this column
  21100. 1 on this column
  21101. ---------- Buffer: foo ----------
  21102.  
  21103. -- Variable: selective-display-ellipses 
  21104. If this buffer-local variable is non-nil, then Emacs displays `...' at the end 
  21105. of a line that is followed by invisible text. This example is a continuation of 
  21106. the previous one. 
  21107.  
  21108. (setq selective-display-ellipses t)
  21109.      => t
  21110.  
  21111. ---------- Buffer: foo ----------
  21112. 1 on this column
  21113.  2on this column ...
  21114.  2on this column
  21115. 1 on this column
  21116. ---------- Buffer: foo ----------
  21117.  
  21118.  
  21119. ΓòÉΓòÉΓòÉ 37.6. Overlay Arrow ΓòÉΓòÉΓòÉ
  21120.  
  21121.  The overlay arrow is useful for directing the user's attention to a particular 
  21122. line in a buffer.  For example, in the modes used for interface to debuggers, 
  21123. the overlay arrow indicates the current line of code about to be executed. 
  21124.  
  21125. -- Variable: overlay-arrow-string 
  21126. This variable holds the string to display as an arrow, or nil if the arrow 
  21127. feature is not in use. 
  21128.  
  21129. -- Variable: overlay-arrow-position 
  21130. This variable holds a marker which indicates where to display the arrow. It 
  21131. should point at the beginning of a line.  The arrow text will be displayed at 
  21132. the beginning of that line, overlaying any text that would otherwise appear. 
  21133. Since the arrow is usually short, and the line usually begins with indentation, 
  21134. normally nothing significant is overwritten. 
  21135.  
  21136. The overlay string is displayed only in the buffer which this marker points 
  21137. into.  Thus, only one buffer can have an overlay arrow at any given time. 
  21138.  
  21139.  
  21140. ΓòÉΓòÉΓòÉ 37.7. Temporary Displays ΓòÉΓòÉΓòÉ
  21141.  
  21142.  Temporary displays are used by commands to put output into a buffer and then 
  21143. present it to the user for perusal rather than for editing. Many of the help 
  21144. commands use this feature. 
  21145.  
  21146. -- Special Form: with-output-to-temp-buffer buffer-name forms... 
  21147.  This function executes forms while arranging to insert any output they print 
  21148. into the buffer named buffer-name.  The buffer is then shown in some window for 
  21149. viewing, displayed but not selected. 
  21150.  
  21151.  The buffer is named by the string buffer-name, and it need not already exist. 
  21152. The argument buffer-name must be a string, not a buffer.  The buffer is erased 
  21153. initially (with no questions asked), and it is marked as unmodified after 
  21154. with-output-to-temp-buffer exits. 
  21155.  
  21156.  with-output-to-temp-buffer first binds standard-output to the buffer, then it 
  21157. evaluates the forms in forms.  With standard-output rebound, any output 
  21158. directed there will naturally be inserted into that buffer.  Only Lisp output 
  21159. directed to the stream standard-output is affected; screen display and messages 
  21160. in the echo area, although output in the general sense of the word, are not 
  21161. affected.  See Output Functions. 
  21162.  
  21163.  The value of the last form in forms is returned. 
  21164.  
  21165. ---------- Buffer: foo ----------
  21166.  This is the contents of foo.
  21167. ---------- Buffer: foo ----------
  21168.  
  21169. (with-output-to-temp-buffer "foo"
  21170.     (print 20)
  21171.     (print standard-output))
  21172. => #<buffer foo>
  21173.  
  21174. ---------- Buffer: foo ----------
  21175. 20
  21176.  
  21177. #<buffer foo>
  21178.  
  21179. ---------- Buffer: foo ----------
  21180.  
  21181. -- Variable: temp-buffer-show-hook 
  21182.  The value of the temp-buffer-show-hook variable is either nil or is called as 
  21183. a function to display a help buffer.  This variable is used by 
  21184. with-output-to-temp-buffer. 
  21185.  
  21186. -- Function: momentary-string-display string position &optional char message 
  21187.  This function momentarily displays string in the current buffer at position 
  21188. (which is a character offset from the beginning of the buffer).  The display 
  21189. remains until the next character is typed. 
  21190.  
  21191.  If the next character the user types is char, Emacs ignores it. Otherwise, 
  21192. that character remains buffered for subsequent use as input. Thus, typing char 
  21193. will simply remove the string from the display, while typing (say) C-f will 
  21194. remove the string from the display and later (presumably) move point forward. 
  21195. The argument char is a space by default. 
  21196.  
  21197.  The result of momentary-string-display is not useful. 
  21198.  
  21199.  If message is non-nil, it is displayed in the echo area.  If it is nil, then 
  21200. instructions to type char are displayed there, e.g., `Type RET to continue 
  21201. editing'. 
  21202.  
  21203.  In this example, point is initially located at the beginning of the second 
  21204. line: 
  21205.  
  21206. ---------- Buffer: foo ----------
  21207. This is the contents of foo.
  21208. -!-This is the contents of foo.
  21209. ---------- Buffer: foo ----------
  21210.  
  21211. (momentary-string-display
  21212.    "******* Important Message! *******" (point) ?\r
  21213.    "Type RET when done reading")
  21214. => t
  21215.  
  21216. ---------- Buffer: foo ----------
  21217. This is the contents of foo.
  21218. ******* Important Message! *******This is the contents of foo.
  21219. ---------- Buffer: foo ----------
  21220.  
  21221. ---------- Echo Area ----------
  21222. Type RET when done reading
  21223.  
  21224.  This function works by actually changing the text in the buffer.  As a result, 
  21225. if you later undo in this buffer, you will see the message come and go. 
  21226.  
  21227.  
  21228. ΓòÉΓòÉΓòÉ 37.8. Waiting for Elapsed Time or Input ΓòÉΓòÉΓòÉ
  21229.  
  21230.  The waiting commands are designed to make Emacs wait for a certain amount of 
  21231. time to pass or until there is input.  For example, you may wish to pause in 
  21232. the middle of a computation to allow the user time to view the display. 
  21233. sit-for performs a pause with an update of screen, while sleep-for performs a 
  21234. pause without updating the screen. 
  21235.  
  21236. -- Function: sit-for seconds 
  21237. This function performs redisplay (provided there is no pending input from the 
  21238. user), then waits seconds seconds, or until input is available.  The result is 
  21239. t if sit-for waited the full time with no input arriving (see input-pending-p 
  21240. in Keyboard Input).  Otherwise, nil is returned. 
  21241.  
  21242. Redisplay is always preempted if input arrives, and does not happen at all if 
  21243. input is available before it starts.  Thus, there is no way to force screen 
  21244. updating if there is pending input; however, if there is no input pending, you 
  21245. can force an update with no delay by using (sit-for 0). 
  21246.  
  21247. The purpose of sit-for to give the user time to read text that you display. 
  21248.  
  21249. -- Function: sleep-for seconds 
  21250. This function simply pauses for seconds seconds without updating the display. 
  21251. It pays no attention to available input.  It returns nil. 
  21252.  
  21253. Use sleep-for when you wish to guarantee a delay. 
  21254.  
  21255.  
  21256. ΓòÉΓòÉΓòÉ 37.9. Blinking ΓòÉΓòÉΓòÉ
  21257.  
  21258.  This section describes the mechanism by which Emacs shows a matching open 
  21259. parenthesis when the user inserts a close parenthesis. 
  21260.  
  21261. -- Variable: blink-paren-hook 
  21262.  The value of this variable should be a function (of no arguments) to be called 
  21263. whenever a char with close parenthesis syntax is inserted. The value of 
  21264. blink-paren-hook may be nil, in which case nothing is done. 
  21265.  
  21266. *Note:* in version 18, this function is named blink-paren-hook, but since it is 
  21267. not called with the standard convention for hooks, it is being renamed to 
  21268. blink-paren-function in version 19. 
  21269.  
  21270. -- Variable: blink-matching-paren 
  21271. If this variable is nil, then blink-matching-open does nothing. 
  21272.  
  21273. -- Variable: blink-matching-paren-distance 
  21274. This variable specifies the maximum distance to scan for a matching parenthesis 
  21275. before giving up. 
  21276.  
  21277. -- Function: blink-matching-open 
  21278. This function is the default value of blink-paren-hook.  It assumes that point 
  21279. follows a character with close parenthesis syntax and moves the cursor 
  21280. momentarily to the matching opening character.  If that character is not 
  21281. already on the screen, then its context is shown by displaying it in the echo 
  21282. area.  To avoid long delays, this function does not search farther than 
  21283. blink-matching-paren-distance characters. 
  21284.  
  21285. Here is an example of calling this function explicitly. 
  21286.  
  21287. (defun interactive-blink-matching-open ()
  21288.   "Indicate momentarily the start of sexp before point."
  21289.   (interactive)
  21290.   (let ((blink-matching-paren-distance (buffer-size))
  21291.         (blink-matching-paren t))
  21292.     (blink-matching-open)))
  21293.  
  21294.  
  21295. ΓòÉΓòÉΓòÉ 37.10. Display of Control Characters ΓòÉΓòÉΓòÉ
  21296.  
  21297.  These variables affect the way certain characters are displayed on the screen. 
  21298. Since they change the number of columns the characters occupy, they also affect 
  21299. the indentation functions. 
  21300.  
  21301. -- User Option: ctl-arrow 
  21302.  This buffer-local variable controls how control characters are displayed.  If 
  21303. it is non-nil, they are displayed as an uparrow followed by the character: 
  21304. `^A'.  If it is nil, they are displayed as a backslash followed by three octal 
  21305. digits: `\001'. 
  21306.  
  21307. -- Variable: default-ctl-arrow 
  21308.  The value of this variable is the default value for ctl-arrow in buffers that 
  21309. do not override it.  This is the same as (default-value 'ctl-arrow) (see 
  21310. Default Value). 
  21311.  
  21312. -- User Option: tab-width 
  21313.  The value of this variable is the spacing between tab stops used for 
  21314. displaying tab characters in Emacs buffers.  The default is 8.  Note that this 
  21315. feature is completely independent from the user-settable tab stops used by the 
  21316. command tab-to-tab-stop.  See Indent Tabs. 
  21317.  
  21318.  
  21319. ΓòÉΓòÉΓòÉ 37.11. Beeping ΓòÉΓòÉΓòÉ
  21320.  
  21321.  You can make Emacs ring a bell (or blink the screen) to attract the user's 
  21322. attention.  Be conservative about how often you do this; frequent bells can 
  21323. become irritating.  Also be careful not to use beeping alone when signaling an 
  21324. error is appropriate.  (See Errors.) 
  21325.  
  21326. -- Function: ding &optional dont-terminate 
  21327.  This function beeps, or flashes the screen (see visible-bell below). It also 
  21328. terminates any keyboard macro currently executing unless dont-terminate is 
  21329. non-nil. 
  21330.  
  21331. -- Function: beep &optional dont-terminate 
  21332. This is a synonym for ding. 
  21333.  
  21334. -- Variable: visible-bell 
  21335.  This variable determines whether Emacs will try to flash the screen to 
  21336. represent a bell.  Non-nil means yes, nil means no.  This is effective only if 
  21337. the termcap entry for the terminal in use has the visible bell flag (`vb') set. 
  21338.  
  21339.  
  21340. ΓòÉΓòÉΓòÉ 37.12. Window Systems ΓòÉΓòÉΓòÉ
  21341.  
  21342.  Emacs works with several window systems, most notably X Windows.  Note that 
  21343. both Emacs and the X Window System use the term ``window'', but use it 
  21344. differently.  The entire Emacs screen is a single window as far as X Windows is 
  21345. concerned; the individual Emacs windows are not known to X Windows at all. 
  21346.  
  21347. -- Variable: window-system 
  21348.  This variable tells Lisp programs what window system Emacs is running under. 
  21349. Its value should be a symbol such as x (if Emacs is running under X Windows) or 
  21350. nil (if Emacs is running on an ordinary terminal). 
  21351.  
  21352. -- Variable: window-system-version 
  21353.  This variable distinguishes between different versions of the X Window System. 
  21354. Its value is 10 or 11 when using X Windows; nil otherwise. 
  21355.  
  21356. -- Variable: window-setup-hook 
  21357.  The value of the window-setup-hook variable is either nil or a function for 
  21358. Emacs to call after loading your `.emacs' file and the default initialization 
  21359. file (if any), after loading terminal-specific Lisp code, and after calling 
  21360. term-setup-hook.  window-setup-hook is called with no arguments. 
  21361.  
  21362.  This hook is used for internal purposes: setting up communication with the 
  21363. window system, and creating the initial window.  Users should not interfere 
  21364. with it. 
  21365.  
  21366.  
  21367. ΓòÉΓòÉΓòÉ 38. Tips and Standards ΓòÉΓòÉΓòÉ
  21368.  
  21369.  This chapter describes no additional features of Emacs Lisp. Instead it gives 
  21370. advice on making effective use of the features described in the previous 
  21371. chapters. 
  21372.  
  21373.  
  21374. ΓòÉΓòÉΓòÉ 38.1. Writing Clean Lisp Programs ΓòÉΓòÉΓòÉ
  21375.  
  21376.  Here are some tips for avoiding common errors in writing Lisp code intended 
  21377. for widespread use: 
  21378.  
  21379. o Since all global variables share the same name space, and all functions share 
  21380.   another name space, you should choose a short word to distinguish your 
  21381.   program from other Lisp programs.  Then take care to begin the names of all 
  21382.   global variables, constants, and functions with the chosen prefix.  This 
  21383.   helps avoid name conflicts. 
  21384.  
  21385.   This recommendation applies even to names for traditional Lisp primitives 
  21386.   that are not primitives in Emacs Lisp---even to cadr. Believe it or not, 
  21387.   there is more than one plausible way to define cadr.  Play it safe; append 
  21388.   your name prefix to produce a name like foo-cadr or mylib-cadr instead. 
  21389.  
  21390.   If one prefix is insufficient, your package may use two or three alternative 
  21391.   common prefixes, so long as they make sense. 
  21392.  
  21393. o It is often useful to put a call to provide in each separate library program, 
  21394.   at least if there is more than one entry point to the program. 
  21395.  
  21396. o If one file foo uses a macro defined in another file bar, foo should contain 
  21397.   (require 'bar) before the first use of the macro.  (And bar should contain 
  21398.   (provide 'bar), to make the require work.)  This will cause bar to be loaded 
  21399.   when you byte-compile foo.  Otherwise, you risk compiling foo without the 
  21400.   necessary macro loaded, and that would produce compiled code that won't work 
  21401.   right. See Compiling Macros. 
  21402.  
  21403. o If you define a major mode, make sure to run a hook variable using run-hooks, 
  21404.   just as the existing major modes do.  See Hooks. 
  21405.  
  21406. o Please do not define C-c letter as a key.  These sequences are reserved for 
  21407.   users; they are the *only* sequences reserved for users, so we cannot do 
  21408.   without them. 
  21409.  
  21410.   Everything in Emacs that used to define such sequences has been changed, 
  21411.   which was a lot of work.  Abandoning this convention would waste that work 
  21412.   and inconvenience the users. 
  21413.  
  21414. o It is a bad idea to define aliases for the Emacs primitives. Use the standard 
  21415.   names instead. 
  21416.  
  21417. o Redefining an Emacs primitive is an even worse idea. It may do the right 
  21418.   thing for a particular program, but there is no telling what other programs 
  21419.   might break as a result. 
  21420.  
  21421. o If a file does replace any of the functions or library programs of standard 
  21422.   Emacs, prominent comments at the beginning of the file should say which 
  21423.   functions are replaced, and how the behavior of the replacements differs from 
  21424.   that of the originals. 
  21425.  
  21426. o If a file requires certain standard library programs to be loaded beforehand, 
  21427.   then the comments at the beginning of the file should say so. 
  21428.  
  21429. o Don't use next-line or previous-line in programs; nearly always, forward-line 
  21430.   is more convenient as well as more predictable and robust.  See Text Lines. 
  21431.  
  21432. o Don't use functions that set the mark in your Lisp code (unless you are 
  21433.   writing a command to set the mark).  The mark is a user-level feature, so it 
  21434.   is incorrect to change the mark except to supply a value for the user's 
  21435.   benefit.  See The Mark. 
  21436.  
  21437.   In particular, don't use these functions: 
  21438.  
  21439.    - beginning-of-buffer, end-of-buffer 
  21440.  
  21441.    - replace-string, replace-regexp 
  21442.  
  21443.   If you just want to move point, or replace a certain string, without any of 
  21444.   the other features intended for interactive users, you can replace these 
  21445.   functions with one or two lines of simple Lisp code. 
  21446.  
  21447. o The recommended way to print a message in the echo area is with the message 
  21448.   function, not princ.  See The Echo Area. 
  21449.  
  21450. o When you encounter an error condition, call the function error (or signal). 
  21451.   The function error does not return. See Signaling Errors. 
  21452.  
  21453.   Do not use message, throw, sleep-for, or beep to report errors. 
  21454.  
  21455. o Avoid using recursive edits.  Instead, do what the Rmail w command does: use 
  21456.   a new local keymap that contains one command defined to switch back to the 
  21457.   old local keymap.  Or do what the edit-options command does: switch to 
  21458.   another buffer and let the user switch back at will.  See Recursive Editing. 
  21459.  
  21460. o In some other systems there is a convention of choosing variable names that 
  21461.   begin and end with `*'.  We don't use that convention in Emacs Lisp, so 
  21462.   please don't use it in your library.  The users will find Emacs more coherent 
  21463.   if all libraries use the same conventions. 
  21464.  
  21465. o Indent each function with C-M-q (indent-sexp) using the default indentation 
  21466.   parameters. 
  21467.  
  21468. o Don't make a habit of putting close-parentheses on lines by themselves; Lisp 
  21469.   programmers find this disconcerting.  Once in a while, when there is a 
  21470.   sequence of many consecutive close-parentheses, it may make sense to split 
  21471.   them in one or two significant places. 
  21472.  
  21473. o Please put a copyright notice on the file if you give copies to anyone. Use 
  21474.   the same lines that appear at the top of the Lisp files in Emacs itself.  If 
  21475.   you have not signed papers to assign the copyright to the Foundation, then 
  21476.   place your name in the copyright notice in place of the Foundation's name. 
  21477.  
  21478.  
  21479. ΓòÉΓòÉΓòÉ 38.2. Tips for Making Compiled Code Fast ΓòÉΓòÉΓòÉ
  21480.  
  21481.  Here are ways of improving the execution speed of byte-compiled lisp programs. 
  21482.  
  21483. o Use iteration rather than recursion whenever possible. Function calls are 
  21484.   slow in Emacs Lisp even when a compiled function is calling another compiled 
  21485.   function. 
  21486.  
  21487. o Using the primitive list-searching functions memq, assq or assoc is even 
  21488.   faster than explicit iteration.  It may be worth rearranging a data structure 
  21489.   so that one of these primitive search functions can be used. 
  21490.  
  21491.   For example, if you want to search a list of strings for a string equal to a 
  21492.   given one, you can use an explicit loop: 
  21493.  
  21494.     (let ((tail list))
  21495.       (while (and tail (not (string= string (car tail))))
  21496.         (setq tail (cdr tail))))
  21497.  
  21498.   However, if you use a list of elements of the form (string), such as (("foo") 
  21499.   ("#&") ("bar")), then you can search it with assoc: 
  21500.  
  21501.     (assoc string list)
  21502.  
  21503.   The latter runs entirely in C code, so it is much faster. 
  21504.  
  21505. o Certain built-in functions are handled specially by the byte compiler 
  21506.   avoiding the need for an ordinary function call.  It is a good idea to use 
  21507.   these functions rather than alternatives.  To see whether a function is 
  21508.   handled specially by the compiler, examine its byte-compile property.  If the 
  21509.   property is non-nil, then the function is handled specially. 
  21510.  
  21511.   For example, the following input will show you that aref is compiled 
  21512.   specially (see Array Functions) while elt is not (see Sequence Functions): 
  21513.  
  21514.     (get 'aref 'byte-compile)
  21515.          => byte-compile-two-args
  21516.  
  21517.     (get 'elt 'byte-compile)
  21518.          => nil
  21519.  
  21520. o Often macros result in faster execution than functions.  For example, the 
  21521.   following macro and the following function have the same effect when called, 
  21522.   but code using the macro runs faster because it avoids an extra call to a 
  21523.   user-defined function: 
  21524.  
  21525.     (defmacro fast-cadr (x) (list 'car (list 'cdr x)))
  21526.  
  21527.     (defun slow-cadr (x) (car (cdr x)))
  21528.  
  21529.  
  21530. ΓòÉΓòÉΓòÉ 38.3. Tips for Documentation Strings ΓòÉΓòÉΓòÉ
  21531.  
  21532.  Here are some tips for the writing of documentation strings. 
  21533.  
  21534. o Every command, function or variable intended for users to know about should 
  21535.   have a documentation string. 
  21536.  
  21537. o An internal subroutine of a Lisp program need not have a documentation 
  21538.   string, and you can save space by using a comment instead. 
  21539.  
  21540. o The first line of the documentation string should consist of one or two 
  21541.   complete sentences which stand on their own as a summary.  In particular, 
  21542.   start the line with a capital letter and end with a period. 
  21543.  
  21544.   The documentation string can have additional lines which expand on the 
  21545.   details of how to use the function or variable.  The additional lines should 
  21546.   be made up of complete sentences also, but they may be filled if that looks 
  21547.   good. 
  21548.  
  21549. o Do not start or end a documentation string with whitespace. 
  21550.  
  21551. o Format the documentation string so that it fits in an Emacs window on an 80 
  21552.   column screen.  It is a good idea for most lines to be no wider than 60 
  21553.   characters.  The first line can be wider if necessary to fit the information 
  21554.   that ought to be there. 
  21555.  
  21556.   However, rather than simply filling the entire documentation string, you can 
  21557.   make it much more readable by choosing line breaks with care. Use blank lines 
  21558.   between topics if the documentation string is long. 
  21559.  
  21560. o *Do not* indent subsequent lines of a documentation string so that the text 
  21561.   is lined up in the source code with the text of the first line.  This looks 
  21562.   nice in the source code, but looks bizarre when users view the documentation. 
  21563.   Remember that the indentation before the starting double-quote is not part of 
  21564.   the string! 
  21565.  
  21566. o A variable's documentation string should start with `*' if the variable is 
  21567.   one that users would want to set interactively often.  If the value is a long 
  21568.   list, or a function, or if the variable would only be set in init files, then 
  21569.   don't start the documentation string with `*'.  See Defining Variables. 
  21570.  
  21571. o The documentation string for a variable that is a yes-or-no flag should start 
  21572.   with words such as ``Non-nil means...'', to make it clear both that the 
  21573.   variable only has two meaningfully distinct values and which value means 
  21574.   ``yes''. 
  21575.  
  21576. o When a function's documentation string mentions the value of an argument of 
  21577.   the function, use the argument name in capital letters as if it were a name 
  21578.   for that value.  Thus, the documentation string of the function / refers to 
  21579.   its second argument as `DIVISOR'. 
  21580.  
  21581.   Also use all caps for meta-syntactic variables, such as when you show the 
  21582.   decomposition of a list or vector into subunits, some of which may be 
  21583.   variable. 
  21584.  
  21585. o When a documentation string refers to a Lisp symbol, write it as it would be 
  21586.   printed (which usually means in lower case), with single-quotes around it. 
  21587.   For example: ``lambda''.  There are two exceptions: write t and nil without 
  21588.   single-quotes. 
  21589.  
  21590. o Don't write key sequences directly in documentation strings.  Instead, use 
  21591.   the `\\[...]' construct to stand for them.  For example, instead of writing 
  21592.   `C-f', write `\\[forward-char]'.  When the documentation string is printed, 
  21593.   Emacs will substitute whatever key is currently bound to forward-char.  This 
  21594.   will usually be `C-f', but if the user has moved key bindings, it will be the 
  21595.   correct key for that user.  See Keys in Documentation. 
  21596.  
  21597. o In documentation strings for a major mode, you will want to refer to the key 
  21598.   bindings of that mode's local map, rather than global ones. Therefore, use 
  21599.   the construct `\\<...>' once in the documentation string to specify which key 
  21600.   map to use.  Do this before the first use of `\\[...]'.  The text inside the 
  21601.   `\\<...>' should be the name of the variable containing the local keymap for 
  21602.   the major mode. 
  21603.  
  21604.  
  21605. ΓòÉΓòÉΓòÉ 39. GNU Emacs Internals ΓòÉΓòÉΓòÉ
  21606.  
  21607. This chapter describes how the runnable Emacs executable is dumped with the 
  21608. preloaded Lisp libraries in it, how storage is allocated, and some internal 
  21609. aspects of GNU Emacs that may be of interest to C programmers. 
  21610.  
  21611.  
  21612. ΓòÉΓòÉΓòÉ 39.1. Building Emacs ΓòÉΓòÉΓòÉ
  21613.  
  21614.  The first step in building Emacs is to compile the C sources.  This produces a 
  21615. program called temacs, also called a bare impure Emacs.  It contains the Emacs 
  21616. Lisp interpreter and I/O routines, but not the editing commands. 
  21617.  
  21618.  Then, to create a working Emacs editor, issue the command `temacs -l loadup'. 
  21619. This directs temacs to evaluate the Lisp files specified in the file 
  21620. `loadup.el'.  These files set up the normal Emacs editing environment, 
  21621. resulting in an Emacs which is still impure but no longer bare. 
  21622.  
  21623.  It takes long time to load the standard Lisp files.  Luckily, you don't have 
  21624. to do this each time you run Emacs; temacs can dump out an executable program 
  21625. called xemacs which has these files preloaded.  xemacs starts more quickly 
  21626. because it does not need to load the files.  It is xemacs that is normally 
  21627. installed under the name emacs for users to run. 
  21628.  
  21629.  To create xemacs, use the command `temacs -batch -l loadup dump'.  The purpose 
  21630. of `-batch' here is to prevent temacs from trying to initialize any of its data 
  21631. on the terminal; this ensures that the tables of terminal information are empty 
  21632. in the dumped Emacs. 
  21633.  
  21634.  When the xemacs executable is started, it will automatically load the user's 
  21635. `.emacs' file, or the default initialization file `default.el' if the user has 
  21636. none.  With the `.emacs' file, you can produce a version of Emacs that suits 
  21637. you and is not the same as the version other people use.  With `default.el', 
  21638. you can customize Emacs for all the users at your site who don't choose to 
  21639. customize it for themselves.  (For further reflection: why is this different 
  21640. from the case of the barber who shaves every man who doesn't shave himself?) 
  21641.  
  21642.  On some systems, dumping does not work.  Then, you must start Emacs with the 
  21643. `temacs -l loadup' command each time you use it.  This takes a long time, but 
  21644. since you need to start Emacs once a day at most---and once a week or less 
  21645. frequently if you never log out---the extra time is not too severe a problem. 
  21646.  
  21647.  Before xemacs is dumped, the documentation strings for primitive and preloaded 
  21648. functions (and variables) need to be found in the file where they are stored. 
  21649. This is done by calling Snarf-documentation (see Accessing Documentation). 
  21650. These strings are omitted from temacs to save space. See Documentation Basics. 
  21651.  
  21652. -- Function: dump-emacs to-file from-file 
  21653.  This function dumps the current state of Emacs into an executable file 
  21654. to-file.  It takes symbols from from-file (this is normally the executable file 
  21655. `temacs'). 
  21656.  
  21657. If you use this function in an Emacs that was already dumped, you must set 
  21658. command-line-processed to nil first for good results. See Command Line 
  21659. Arguments. 
  21660.  
  21661. -- Command: emacs-version 
  21662.  This function returns a string describing the version of Emacs that is 
  21663. running.  It is useful to include this string in bug reports. 
  21664.  
  21665. (emacs-version)
  21666.   => "GNU Emacs 18.36.1 of Fri Feb 27 1987 on slug (berkeley-unix)"
  21667.  
  21668. Called interactively, the function prints the same information in the echo 
  21669. area. 
  21670.  
  21671. -- Variable: emacs-build-time 
  21672.  The value of this variable is the time at which Emacs was built at the local 
  21673. site. 
  21674.  
  21675. emacs-build-time
  21676.      => "Fri Feb 27 14:55:57 1987"
  21677.  
  21678. -- Variable: emacs-version 
  21679.  The value of this variable is the version of Emacs being run.  It is a string, 
  21680. e.g. "18.36.1". 
  21681.  
  21682.  
  21683. ΓòÉΓòÉΓòÉ 39.2. Pure Storage ΓòÉΓòÉΓòÉ
  21684.  
  21685.  There are two types of storage in GNU Emacs Lisp for user-created Lisp 
  21686. objects: normal storage and pure storage.  Normal storage is where all the new 
  21687. data which is created during an Emacs session is kept; see the following 
  21688. section for information on normal storage.  Pure storage is used for certain 
  21689. data in the preloaded standard Lisp files: data that should never change during 
  21690. actual use of Emacs. 
  21691.  
  21692.  Pure storage is allocated only while temacs is loading the standard preloaded 
  21693. Lisp libraries.  In the file xemacs, it is marked as read-only (on operating 
  21694. systems which permit this), so that the memory space can be shared by all the 
  21695. Emacs jobs running on the machine at once.  Pure storage is not expandable; a 
  21696. fixed amount is allocated when Emacs is compiled, and if that is not sufficient 
  21697. for the preloaded libraries, temacs crashes.  If that happens, you will have to 
  21698. increase the compilation parameter PURESIZE in the file `config.h'.  This 
  21699. normally won't happen unless you try to preload additional libraries or add 
  21700. features to the standard ones. 
  21701.  
  21702. -- Function: purecopy object 
  21703.  This function makes a copy of object in pure storage and returns it.  It 
  21704. copies strings by simply making a new string with the same characters in pure 
  21705. storage.  It recursively copies the contents of vectors and cons cells.  It 
  21706. does not make copies of symbols, or any other objects, but just returns them 
  21707. unchanged.  It signals an error if asked to copy markers. 
  21708.  
  21709. This function is used only while Emacs is being built and dumped, and is called 
  21710. only in the file `emacs/lisp/loaddefs.el'. 
  21711.  
  21712. -- Variable: pure-bytes-used 
  21713.  The value of this variable is the number of bytes of pure storage allocated so 
  21714. far.  Typically, in a dumped Emacs, this number is very close to the total 
  21715. amount of pure storage available---if it were not, we would preallocate less. 
  21716.  
  21717. -- Variable: purify-flag 
  21718.  This variable determines whether defun should make a copy of the function 
  21719. definition in pure storage.  If it is non-nil, then the function definition is 
  21720. copied into pure storage. 
  21721.  
  21722.  This flag is t while loading all of the basic functions for building Emacs 
  21723. initially (allowing those functions to be sharable and non-collectible).  It is 
  21724. set to nil when Emacs is saved out as xemacs.  The flag is set and reset in the 
  21725. C sources. 
  21726.  
  21727.  You should not change this flag in a running Emacs. 
  21728.  
  21729.  
  21730. ΓòÉΓòÉΓòÉ 39.3. Garbage Collection ΓòÉΓòÉΓòÉ
  21731.  
  21732.  When a program creates a list or the user defines a new function (such as by 
  21733. loading a library), then that data is placed in normal storage. If normal 
  21734. storage runs low, then Emacs asks the operating system to allocate more memory 
  21735. in blocks of 1k bytes.  Each block is used for one type of Lisp object, so 
  21736. symbols, cons cells, markers, etc. are segregated in distinct blocks in memory. 
  21737. (Vectors, buffers and certain other editing types, which are fairly large, are 
  21738. allocated in individual blocks, one per object, while strings are packed into 
  21739. blocks of 8k bytes.) 
  21740.  
  21741.  It is quite common to use some storage for a while, then release it by, for 
  21742. example, killing a buffer or deleting the last pointer to an object.  Emacs 
  21743. provides a garbage collector to reclaim this abandoned storage.  (This name is 
  21744. traditional, but ``garbage recycler'' might be a more intuitive metaphor for 
  21745. this facility.) 
  21746.  
  21747.  The garbage collector operates by scanning all the objects that have been 
  21748. allocated and marking those that are still accessible to Lisp programs.  To 
  21749. begin with, all the symbols, their values and associated function definitions, 
  21750. and any data presently on the stack, are accessible.  Any objects which can be 
  21751. reached indirectly through other accessible objects are also accessible. 
  21752.  
  21753.  When this is finished, all inaccessible objects are garbage.  No matter what 
  21754. the Lisp program or the user does, it is impossible to refer to them, since 
  21755. there is no longer a way to reach them.  Their space might as well be reused, 
  21756. since no one will notice.  That is what the garbage collector arranges to do. 
  21757.  
  21758.  Unused cons cells are chained together onto a free list for future allocation; 
  21759. likewise for symbols and markers.  The accessible strings are compacted so they 
  21760. are contiguous in memory; then the rest of the space formerly occupied by 
  21761. strings is made available to the string creation functions.  Vectors, buffers, 
  21762. windows and other large objects are individually allocated and freed using 
  21763. malloc. 
  21764.  
  21765. Common Lisp note: unlike other Lisps, GNU Emacs Lisp does not call the garbage 
  21766. collector when the free list is empty.  Instead, it simply requests the 
  21767. operating system to allocate more storage, and processing continues until 
  21768. gc-cons-threshold bytes have been used. 
  21769.  
  21770. This means that you can make sure that the garbage collector will not run 
  21771. during a certain portion of a Lisp program by calling the garbage collector 
  21772. explicitly just before it (provided that portion of the program does not use so 
  21773. much space as to force a second garbage collection). 
  21774.  
  21775. -- Command: garbage-collect 
  21776.  This command runs a garbage collection, and returns information on the amount 
  21777. of space in use.  (Garbage collection can also occur spontaneously if you use 
  21778. more than gc-cons-threshold bytes of Lisp data since the previous garbage 
  21779. collection.) 
  21780.  
  21781.  garbage-collect returns a list containing the following information: 
  21782.  
  21783. ((used-conses . free-conses)
  21784.  (used-syms . free-syms)
  21785.  (used-markers . free-markers)
  21786.  used-string-chars
  21787.  used-vector-slots)
  21788.  
  21789. (garbage-collect)
  21790.      => ((3435 . 2332) (1688 . 0) (57 . 417) 24510 3839)
  21791.  
  21792. Here is a table explaining each element: 
  21793.  
  21794. used-conses 
  21795.           The number of cons cells in use. 
  21796.  
  21797. free-conses 
  21798.           The number of cons cells for which space has been obtained from the 
  21799.           operating system, but that are not currently being used. 
  21800.  
  21801. used-syms 
  21802.           The number of symbols in use. 
  21803.  
  21804. free-syms 
  21805.           The number of symbols for which space has been obtained from the 
  21806.           operating system, but that are not currently being used. 
  21807.  
  21808. used-markers 
  21809.           The number of markers in use. 
  21810.  
  21811. free-markers 
  21812.           The number of markers for which space has been obtained from the 
  21813.           operating system, but that are not currently being used. 
  21814.  
  21815. used-string-chars 
  21816.           The total size of all strings, in characters. 
  21817.  
  21818. used-vector-slots 
  21819.           The total number of elements of existing vectors. 
  21820.  
  21821. -- User Option: gc-cons-threshold 
  21822.  The value of this variable is the number of bytes of storage that must be 
  21823. allocated for Lisp objects after one garbage collection in order to request 
  21824. another garbage collection.  A cons cell counts as eight bytes, a string as one 
  21825. byte per character plus a few bytes of overhead, and so on.  (Space allocated 
  21826. to the contents of buffers does not count.)  Note that the new garbage 
  21827. collection does not happen immediately when the threshold is exhausted, but 
  21828. only the next time the Lisp evaluator is called. 
  21829.  
  21830.  The initial threshold value is 100,000.  If you specify a larger value, 
  21831. garbage collection will happen less often.  This reduces the amount of time 
  21832. spent garbage collecting, but increases total memory use. You may want to do 
  21833. this when running a program which creates lots of Lisp data. 
  21834.  
  21835.  You can make collections more frequent by specifying a smaller value, down to 
  21836. 10,000.  A value less than 10,000 will remain in effect only until the 
  21837. subsequent garbage collection, at which time garbage-collect will set the 
  21838. threshold back to 100,000. 
  21839.  
  21840.  
  21841. ΓòÉΓòÉΓòÉ 39.4. Writing Emacs Primitives ΓòÉΓòÉΓòÉ
  21842.  
  21843.  Lisp primitives are Lisp functions implemented in C.  The details of 
  21844. interfacing the C function so that Lisp can call it are handled by a few C 
  21845. macros.  The only way to really understand how to write new C code is to read 
  21846. the source, but we can explain some things here. 
  21847.  
  21848.  An example of a special form is the definition of or, from `eval.c'.  (An 
  21849. ordinary function would have the same general appearance.) 
  21850.  
  21851. DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
  21852.   "Eval args until one of them yields non-NIL, then return that value.\n\
  21853. The remaining args are not evalled at all.\n\
  21854. If all args return NIL, return NIL.")
  21855.   (args)
  21856.      Lisp_Object args;
  21857. {
  21858.   register Lisp_Object val;
  21859.   Lisp_Object args_left;
  21860.   struct gcpro gcpro1;
  21861.  
  21862.   if (NULL(args))
  21863.     return Qnil;
  21864.  
  21865.   args_left = args;
  21866.   GCPRO1 (args_left);
  21867.  
  21868.   do
  21869.     {
  21870.       val = Feval (Fcar (args_left));
  21871.       if (!NULL (val))
  21872.         break;
  21873.       args_left = Fcdr (args_left);
  21874.     }
  21875.   while (!NULL(args_left));
  21876.  
  21877.   UNGCPRO;
  21878.   return val;
  21879. }
  21880.  
  21881.  Let's start with a precise explanation of the arguments to the DEFUN macro: 
  21882.  
  21883.  1. The first argument is the name of the Lisp symbol to define with this 
  21884.     function; it is or. 
  21885.  
  21886.  2. The second argument is the C function name for this function.  This is the 
  21887.     name that is used in C code for calling the function.  The name is, by 
  21888.     convention, `F' prepended to the Lisp name, with all dashes (`-') in the 
  21889.     Lisp name changed to underscores.  Thus, to call this function from C code, 
  21890.     call For.  Remember that the arguments must be of type Lisp_Object; various 
  21891.     macros and functions for creating values of type Lisp_Object are declared 
  21892.     in the file `lisp.h'. 
  21893.  
  21894.  3. The third argument is a C variable name to use for a structure that holds 
  21895.     the data for the subr object that represents the function in Lisp. This 
  21896.     structure conveys the Lisp symbol name to the initialization routine that 
  21897.     will create the symbol and store the subr object as its definition.  By 
  21898.     convention, this name is the C function name with `F' replaced with `S'. 
  21899.  
  21900.  4. The fourth argument is the minimum number of arguments that the function 
  21901.     requires.  In this case, no arguments are required. 
  21902.  
  21903.  5. The fifth argument is the maximum number of arguments that the function 
  21904.     accepts.  Alternatively, it can be UNEVALLED, indicating a special form 
  21905.     that receives unevaluated arguments.  A function with the equivalent of an 
  21906.     &rest argument would have MANY in this position.  Both UNEVALLED and MANY 
  21907.     are macros.  This argument must be one of these macros or a number at least 
  21908.     as large as the fourth argument. 
  21909.  
  21910.  6. The sixth argument is an interactive specification, a string such as might 
  21911.     be used as the argument of interactive in a Lisp function. In this case it 
  21912.     is 0 (a null pointer), indicating that this function cannot be called 
  21913.     interactively.  A value of "" indicates an interactive function not taking 
  21914.     arguments. 
  21915.  
  21916.  7. The last argument is the documentation string.  It is written just like a 
  21917.     documentation string for a function defined in Lisp, except you must write 
  21918.     `\n\' at the end of each line.  In particular, the first line should be a 
  21919.     single sentence. 
  21920.  
  21921.  After the call to the DEFUN macro, you must write the list of argument names 
  21922. that every C function must have, followed by ordinary C declarations for them. 
  21923. Normally, all the arguments must be declared as Lisp_Object.  If the function 
  21924. has no upper limit on the number of arguments in Lisp, then in C it receives 
  21925. two arguments: the number of Lisp arguments, and the address of a block 
  21926. containing their values.  These have types int and Lisp_Object *. 
  21927.  
  21928.  Within the function For itself, note the use of the macros GCPRO1 and UNGCPRO. 
  21929. GCPRO1 is used to ``protect'' a variable from garbage collection---to inform 
  21930. the garbage collector that it must look in that variable and regard its 
  21931. contents as an accessible object.  This is necessary whenever you call Feval or 
  21932. anything that can directly or indirectly call Feval.  At such a time, any Lisp 
  21933. object that you intend to refer to again must be protected somehow. UNGCPRO 
  21934. cancels the protection of the variables that are protected in the current 
  21935. function.  It is necessary to do this explicitly. 
  21936.  
  21937.  For most data types, it suffices to know that one pointer to the object is 
  21938. protected; as long as the object is not recycled, all pointers to it remain 
  21939. valid.  This is not so for strings, because the garbage collector can move 
  21940. them.  When a string is moved, any pointers to it that the garbage collector 
  21941. does not know about will not be properly relocated.  Therefore, all pointers to 
  21942. strings must be protected across any point where garbage collection may be 
  21943. possible. 
  21944.  
  21945.  The macro GCPRO1 protects just one local variable.  If you want to protect 
  21946. two, use GCPRO2 instead; repeating GCPRO1 will not work.  There are also GCPRO3 
  21947. and GCPRO4. 
  21948.  
  21949.  In addition to using these macros, you must declare the local variables such 
  21950. as gcpro1 which they implicitly use.  If you protect two variables, with 
  21951. GCPRO2, you must declare gcpro1 and gcpro2, as it uses them both.  Alas, we 
  21952. can't explain all the tricky details here. 
  21953.  
  21954.  Defining the C function is not enough; you must also create the Lisp symbol 
  21955. for the primitive and store a suitable subr object in its function cell.  This 
  21956. is done by adding code to an initialization routine.  The code looks like this: 
  21957.  
  21958. defsubr (&subr-structure-name);
  21959.  
  21960. subr-structure-name is the name you used as the third argument to DEFUN. 
  21961.  
  21962.  If you are adding a primitive to a file that already has Lisp primitives 
  21963. defined in it, find the function (near the end of the file) named 
  21964. syms_of_something, and add that function call to it. If the file doesn't have 
  21965. this function, or if you create a new file, add to it a syms_of_filename (e.g., 
  21966. syms_of_myfile). Then find the spot in `emacs.c' where all of these functions 
  21967. are called, and add a call to syms_of_filename there. 
  21968.  
  21969.  This function syms_of_filename is also the place to define any C variables 
  21970. which are to be visible as Lisp variables. DEFVAR_LISP is used to make a C 
  21971. variable of type Lisp_Object visible in Lisp.  DEFVAR_INT is used to make a C 
  21972. variable of type int visible in Lisp with a value that is an integer. 
  21973.  
  21974.  Here is another function, with more complicated arguments.  This comes from 
  21975. the code for the X Window System, and it demonstrates the use of macros and 
  21976. functions to manipulate Lisp objects. 
  21977.  
  21978. DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
  21979.   Scoordinates_in_window_p, 2, 2,
  21980.   "xSpecify coordinate pair: \nXExpression which evals to window: ",
  21981.   "Return non-nil if POSITIONS (a list, (SCREEN-X SCREEN-Y)) is in WINDOW.\n\
  21982.   Returned value is list of positions expressed\n\
  21983.   relative to window upper left corner.")
  21984.   (coordinate, window)
  21985.      register Lisp_Object coordinate, window;
  21986. {
  21987.   register Lisp_Object xcoord, ycoord;
  21988.  
  21989.   if (!CONSP (coordinate)) wrong_type_argument (Qlistp, coordinate);
  21990.   CHECK_WINDOW (window, 2);
  21991.   xcoord = Fcar (coordinate);
  21992.   ycoord = Fcar (Fcdr (coordinate));
  21993.   CHECK_NUMBER (xcoord, 0);
  21994.   CHECK_NUMBER (ycoord, 1);
  21995.   if ((XINT (xcoord) < XINT (XWINDOW (window)->left))
  21996.       || (XINT (xcoord) >= (XINT (XWINDOW (window)->left)
  21997.                             + XINT (XWINDOW (window)->width))))
  21998.     {
  21999.       return Qnil;
  22000.     }
  22001.   XFASTINT (xcoord) -= XFASTINT (XWINDOW (window)->left);
  22002.   if (XINT (ycoord) == (screen_height - 1))
  22003.     return Qnil;
  22004.   if ((XINT (ycoord) < XINT (XWINDOW (window)->top))
  22005.       || (XINT (ycoord) >= (XINT (XWINDOW (window)->top)
  22006.                             + XINT (XWINDOW (window)->height)) - 1))
  22007.     {
  22008.       return Qnil;
  22009.     }
  22010.   XFASTINT (ycoord) -= XFASTINT (XWINDOW (window)->top);
  22011.   return (Fcons (xcoord, Fcons (ycoord, Qnil)));
  22012. }
  22013.  
  22014.  Note that you cannot directly call functions defined in Lisp as, for example, 
  22015. the primitive function Fcons is called above.  You must create the appropriate 
  22016. Lisp form, protect everything from garbage collection, and Feval the form, as 
  22017. was done in For above. 
  22018.  
  22019.  `eval.c' is a very good file to look through for examples; `lisp.h' contains 
  22020. the definitions for some important macros and functions. 
  22021.  
  22022.  
  22023. ΓòÉΓòÉΓòÉ 39.5. Object Internals ΓòÉΓòÉΓòÉ
  22024.  
  22025.  GNU Emacs Lisp manipulates many different types of data.  The actual data are 
  22026. stored in a heap and the only access that programs have to it is through 
  22027. pointers.  Pointers are thirty-two bits wide in most implementations. 
  22028. Depending on the operating system and type of machine for which you compile 
  22029. Emacs, twenty-four to twenty-six bits are used to address the object, and the 
  22030. remaining six to eight bits are used for a tag that identifies the object's 
  22031. type. 
  22032.  
  22033.  Because all access to data is through tagged pointers, it is always possible 
  22034. to determine the type of any object.  This allows variables to be untyped, and 
  22035. the values assigned to them to be changed without regard to type.  Function 
  22036. arguments also can be of any type; if you want a function to accept only a 
  22037. certain type of argument, you must check the type explicitly using a suitable 
  22038. predicate (see Type Predicates). 
  22039.  
  22040.  
  22041. ΓòÉΓòÉΓòÉ 39.5.1. Buffer Internals ΓòÉΓòÉΓòÉ
  22042.  
  22043.  Buffers contain fields not directly accessible by the Lisp programmer. We 
  22044. describe them here, naming them by the names used in the C code. Many are 
  22045. accessible indirectly in Lisp programs via Lisp primitives. 
  22046.  
  22047. name 
  22048.           The buffer name is a string which names the buffer.  It is guaranteed 
  22049.           to be unique.  See Buffer Names. 
  22050.  
  22051. save_modified 
  22052.           This field contains the time when the buffer was last saved, as an 
  22053.           integer. See Buffer Modification. 
  22054.  
  22055. modtime 
  22056.           This field contains the modification time of the visited file.  It is 
  22057.           set when the file is written or read.  Every time the buffer is 
  22058.           written to the file, this field is compared to the modification time 
  22059.           of the file.  See Buffer Modification. 
  22060.  
  22061. auto_save_modified 
  22062.           This field contains the time when the buffer was last auto-saved. 
  22063.  
  22064. last_window_start 
  22065.           This field contains the window-start position in the buffer as of the 
  22066.           last time the buffer was displayed in a window. 
  22067.  
  22068. undodata 
  22069.           This field points to the buffer's undo stack.  See Undo. 
  22070.  
  22071. syntax_table_v 
  22072.           This field contains the syntax table for the buffer.  See Syntax 
  22073.           Tables. 
  22074.  
  22075. markers 
  22076.           This field contains the chain of all markers that point into the 
  22077.           buffer.  At each deletion or motion of the buffer gap, all of these 
  22078.           markers must be checked and perhaps updated.  See Markers. 
  22079.  
  22080. backed_up 
  22081.           This field is a flag which tells whether a backup file has been made 
  22082.           for the visited file of this buffer. 
  22083.  
  22084. mark 
  22085.           This field contains the mark for the buffer.  The mark is a marker, 
  22086.           hence it is also included on the list markers.  See The Mark. 
  22087.  
  22088. local_var_alist 
  22089.           This field contains the association list containing all of the 
  22090.           variables local in this buffer, and their values.  A copy of this 
  22091.           list is returned by the function buffer-local-variables. See 
  22092.           Buffer-Local Variables. 
  22093.  
  22094. mode_line_format 
  22095.           This field contains a Lisp object which controls how to display the 
  22096.           mode line for this buffer.  See Mode Line Format. 
  22097.  
  22098.  
  22099. ΓòÉΓòÉΓòÉ 39.5.2. Window Internals ΓòÉΓòÉΓòÉ
  22100.  
  22101.  Windows have the following accessible fields: 
  22102.  
  22103. height 
  22104.            The height of the window, measured in lines. 
  22105.  
  22106. width 
  22107.            The width of the window, measured in columns. 
  22108.  
  22109. buffer 
  22110.            The buffer which the window is displaying.  This may change often 
  22111.           during the life of the window. 
  22112.  
  22113. start 
  22114.            The position in the buffer which is the first character to be 
  22115.           displayed in the window. 
  22116.  
  22117. pointm 
  22118.            This is the value of point in the current buffer when this window is 
  22119.           selected; when it is not selected, it retains its previous value. 
  22120.  
  22121. left 
  22122.            This is the left-hand edge of the window, measured in columns.  (The 
  22123.           leftmost column on the screen is column 0.) 
  22124.  
  22125. top 
  22126.            This is the top edge of the window, measured in lines.  (The top 
  22127.           line on the screen is line 0.) 
  22128.  
  22129. next 
  22130.            This is the window that is the next in the chain of siblings. 
  22131.  
  22132. prev 
  22133.            This is the window that is the previous in the chain of siblings. 
  22134.  
  22135. force_start 
  22136.            This is a flag which, if non-nil, says that the window has been 
  22137.           scrolled explicitly by the Lisp program.  At the next redisplay, if 
  22138.           point is off the screen, instead of scrolling the window to show the 
  22139.           text around point, point will be moved to a location that is on the 
  22140.           screen. 
  22141.  
  22142. hscroll 
  22143.            This is the number of columns that the display in the window is 
  22144.           scrolled horizontally to the left.  Normally, this is 0. 
  22145.  
  22146. use_time 
  22147.            This is the last time that the window was selected.  This field is 
  22148.           used by get-lru-window. 
  22149.  
  22150.  
  22151. ΓòÉΓòÉΓòÉ 39.5.3. Process Internals ΓòÉΓòÉΓòÉ
  22152.  
  22153.  The fields of a process are: 
  22154.  
  22155. name 
  22156.           A string, the name of the process. 
  22157.  
  22158. command 
  22159.           A list containing the command arguments that were used to start this 
  22160.           process. 
  22161.  
  22162. filter 
  22163.           A function used to accept output from the process instead of a 
  22164.           buffer, or nil. 
  22165.  
  22166. sentinel 
  22167.           A function called whenever the process receives a signal, or nil. 
  22168.  
  22169. buffer 
  22170.           The associated buffer of the process. 
  22171.  
  22172. pid 
  22173.           An integer, the Unix process id. 
  22174.  
  22175. childp 
  22176.           A flag, non-nil if this is really a child process. It is nil for a 
  22177.           network connection. 
  22178.  
  22179. flags 
  22180.           A symbol indicating the state of the process.  Possible values 
  22181.           include run, stop, closed, etc. 
  22182.  
  22183. reason 
  22184.           An integer, the Unix signal number that the process received that 
  22185.           caused the process to terminate or stop.  If the process has exited, 
  22186.           then this is the exit code it specified. 
  22187.  
  22188. mark 
  22189.           A marker indicating the position of end of last output from this 
  22190.           process inserted into the buffer.  This is usually the end of the 
  22191.           buffer. 
  22192.  
  22193. kill_without_query 
  22194.           A flag, non-nil meaning this process should not cause confirmation to 
  22195.           be needed if Emacs is killed. 
  22196.  
  22197.  
  22198. ΓòÉΓòÉΓòÉ 40. Standard Errors ΓòÉΓòÉΓòÉ
  22199.  
  22200.  Here is the complete list of the error symbols in standard Emacs, grouped by 
  22201. concept.  The list includes each symbol's message (on the error-message 
  22202. property of the symbol), and a cross reference to a description of how the 
  22203. error can occur. 
  22204.  
  22205.  Each error symbol has an error-conditions property which is a list of symbols. 
  22206. Normally, this list includes the error symbol itself, and the symbol error. 
  22207. Occasionally it includes additional symbols, which are intermediate 
  22208. classifications, narrower than error but broader than a single error symbol. 
  22209. For example, all the errors in accessing files have the condition file-error. 
  22210.  
  22211.  As a special exception, the error symbol quit does not have the condition 
  22212. error, because quitting is not considered an error. 
  22213.  
  22214.  See Errors, for an explanation of how errors are generated and handled. 
  22215.  
  22216. symbol 
  22217.           string; reference. 
  22218.  
  22219. error 
  22220.           "error"; see error in Errors. 
  22221.  
  22222. quit 
  22223.           "Quit"; see Quitting. 
  22224.  
  22225. args-out-of-range 
  22226.           "Args out of range"; see Sequences Arrays Vectors. 
  22227.  
  22228. arith-error 
  22229.           "Arithmetic error"; see / and % in Numbers. 
  22230.  
  22231. beginning-of-buffer 
  22232.           "Beginning of buffer"; see Motion. 
  22233.  
  22234. buffer-read-only 
  22235.           "Buffer is read-only"; see Read Only Buffers. 
  22236.  
  22237. end-of-buffer 
  22238.           "End of buffer"; see Motion. 
  22239.  
  22240. end-of-file 
  22241.           "End of file during parsing"; see Input Functions. This is not a 
  22242.           file-error. 
  22243.  
  22244. file-error 
  22245.           See Files.  This error, and its subcategories, do not have 
  22246.           error-strings, because the error message is constructed from the data 
  22247.           items alone when the error condition file-error is present. 
  22248.  
  22249. file-locked 
  22250.           See File Locks.  This is a file-error. 
  22251.  
  22252. file-already-exists 
  22253.           See Writing to Files.  This is a file-error. 
  22254.  
  22255. file-supersession 
  22256.           See Buffer Modification.  This is a file-error. 
  22257.  
  22258. invalid-function 
  22259.           "Invalid function"; see Classifying Lists. 
  22260.  
  22261. invalid-read-syntax 
  22262.           "Invalid read syntax"; see Input Functions. 
  22263.  
  22264. invalid-regexp 
  22265.           "Invalid regexp"; see Regular Expressions. 
  22266.  
  22267. no-catch 
  22268.           "No catch for tag"; see Catch and Throw. 
  22269.  
  22270. search-failed 
  22271.           "Search failed"; see Searching and Matching. 
  22272.  
  22273. setting-constant 
  22274.           "Attempt to set a constant symbol"; the values of the symbols nil and 
  22275.           t may not be changed. 
  22276.  
  22277. void-function 
  22278.           "Symbol's function definition is void"; 
  22279.           see Function Cells. 
  22280.  
  22281. void-variable 
  22282.           "Symbol's value as variable is void"; 
  22283.           see Accessing Variables. 
  22284.  
  22285. wrong-number-of-arguments 
  22286.           "Wrong number of arguments"; see Classifying Lists. 
  22287.  
  22288. wrong-type-argument 
  22289.           "Wrong type argument"; see Type Predicates. 
  22290.  
  22291.  
  22292. ΓòÉΓòÉΓòÉ 41. Standard Buffer-Local Variables ΓòÉΓòÉΓòÉ
  22293.  
  22294.  The table below shows all of the variables that are automatically local (when 
  22295. set) in each buffer in Emacs Version 18 with the common packages loaded. 
  22296.  
  22297. abbrev-mode 
  22298.           See Abbrevs. 
  22299.  
  22300. auto-fill-hook 
  22301.           See Auto Filling. 
  22302.  
  22303. buffer-auto-save-file-name 
  22304.           See Auto-Saving. 
  22305.  
  22306. buffer-backed-up 
  22307.           See Backup Files. 
  22308.  
  22309. buffer-file-name 
  22310.           See Buffer File Name. 
  22311.  
  22312. buffer-read-only 
  22313.           See Read Only Buffers. 
  22314.  
  22315. buffer-saved-size 
  22316.           See Point. 
  22317.  
  22318. case-fold-search 
  22319.           See Searching and Case. 
  22320.  
  22321. ctl-arrow 
  22322.           See Control Char Display. 
  22323.  
  22324. default-directory 
  22325.           See System Environment. 
  22326.  
  22327. fill-column 
  22328.           See Auto Filling. 
  22329.  
  22330. left-margin 
  22331.           See Indentation. 
  22332.  
  22333. local-abbrev-table 
  22334.           See Abbrevs. 
  22335.  
  22336. major-mode 
  22337.           See Mode Help. 
  22338.  
  22339. mark-ring 
  22340.           See The Mark. 
  22341.  
  22342. minor-modes 
  22343.           See Minor Modes. 
  22344.  
  22345. mode-name 
  22346.           See Mode Line Variables. 
  22347.  
  22348. overwrite-mode 
  22349.           See Insertion. 
  22350.  
  22351. paragraph-separate 
  22352.           See Standard Regexps. 
  22353.  
  22354. paragraph-start 
  22355.           See Standard Regexps. 
  22356.  
  22357. require-final-newline 
  22358.           See Insertion. 
  22359.  
  22360. selective-display 
  22361.           See Selective Display. 
  22362.  
  22363. selective-display-ellipses 
  22364.           See Selective Display. 
  22365.  
  22366. tab-width 
  22367.           See Control Char Display. 
  22368.  
  22369. truncate-lines 
  22370.           See Truncation. 
  22371.  
  22372.  
  22373. ΓòÉΓòÉΓòÉ 42. Standard Keymaps ΓòÉΓòÉΓòÉ
  22374.  
  22375. The following symbols are used as the names for various keymaps. Some of these 
  22376. exist when Emacs is first started, others are only loaded when their respective 
  22377. mode is used.  This is not an exhaustive list. 
  22378.  
  22379. Almost all of these maps are used as local maps.  Indeed, of the modes that 
  22380. presently exist, only Vip mode and Terminal mode ever change the global keymap. 
  22381.  
  22382. Buffer-menu-mode-map 
  22383.           A full keymap used by Buffer Menu mode. 
  22384.  
  22385. c-mode-map 
  22386.           A sparse keymap used in C mode as a local map. 
  22387.  
  22388. command-history-map 
  22389.           A full keymap used by Command History mode. 
  22390.  
  22391. ctl-x-4-map 
  22392.           A sparse keymap for subcommands of the prefix C-x 4. 
  22393.  
  22394. ctl-x-map 
  22395.           A full keymap for C-x commands. 
  22396.  
  22397. debugger-mode-map 
  22398.           A full keymap used by Debugger mode. 
  22399.  
  22400. dired-mode-map 
  22401.           A full keymap for dired-mode buffers. 
  22402.  
  22403. doctor-mode-map 
  22404.           A sparse keymap used by Doctor mode. 
  22405.  
  22406. edit-abbrevs-map 
  22407.           A sparse keymap used in edit-abbrevs. 
  22408.  
  22409. edit-tab-stops-map 
  22410.           A sparse keymap used in edit-tab-stops. 
  22411.  
  22412. electric-buffer-menu-mode-map 
  22413.           A full keymap used by Electric Buffer Menu mode. 
  22414.  
  22415. electric-history-map 
  22416.           A full keymap used by Electric Command History mode. 
  22417.  
  22418. emacs-lisp-mode-map 
  22419.           A sparse keymap used in Emacs Lisp mode. 
  22420.  
  22421. function-keymap 
  22422.           The keymap for the definitions of keypad and function keys. 
  22423.           If there are none, then it contains an empty sparse keymap. 
  22424.  
  22425. fundamental-mode-map 
  22426.           The local keymap for Fundamental mode. 
  22427.           It is empty and should not be changed. 
  22428.  
  22429. Helper-help-map 
  22430.           A full keymap used by the help utility package. 
  22431.           It has the same keymap in its value cell and in its function cell. 
  22432.  
  22433. Info-edit-map 
  22434.           A sparse keymap used by the e command of Info. 
  22435.  
  22436. Info-mode-map 
  22437.           A sparse keymap containing Info commands. 
  22438.  
  22439. lisp-interaction-mode-map 
  22440.           A sparse keymap used in Lisp mode. 
  22441.  
  22442. lisp-mode-map 
  22443.           A sparse keymap used in Lisp mode. 
  22444.  
  22445. mode-specific-map 
  22446.           The keymap for characters following C-c.  Note, this is in the global 
  22447.           map.  This map is not actually mode specific: its name was chosen to 
  22448.           be informative for the user in C-h b (display-bindings), where it 
  22449.           describes the main use of the C-c prefix key. 
  22450.  
  22451. mouse-map 
  22452.           A sparse keymap for mouse commands from the X Window System. 
  22453.  
  22454. occur-mode-map 
  22455.           A local keymap used in Occur mode. 
  22456.  
  22457. text-mode-map 
  22458.           A sparse keymap used by Text mode. 
  22459.  
  22460. view-mode-map 
  22461.           A full keymap used by View mode. 
  22462.  
  22463.  
  22464. ΓòÉΓòÉΓòÉ 43. Standard Hooks ΓòÉΓòÉΓòÉ
  22465.  
  22466. The following is a list of hooks available with the distributed 18.52 version 
  22467. of GNU Emacs.  Some of these hooks are called with run-hooks and can be a list 
  22468. of functions.  Others are not called with run-hooks and may or may not allow a 
  22469. list of functions.  For example, the suspend-hook can only reference a single 
  22470. function. See Hooks, for more information about using hooks. 
  22471.  
  22472. *Note:* in version 19, blink-paren-hook and auto-fill-hook are renamed to 
  22473. blink-paren-function and auto-fill-function respectively, since they are not 
  22474. called by the run-hooks function. 
  22475.  
  22476. auto-fill-hook 
  22477.  
  22478. blink-paren-hook 
  22479.  
  22480. c-mode-hook 
  22481.  
  22482. command-history-hook 
  22483.  
  22484. comment-indent-hook 
  22485.  
  22486. define-hooked-global-abbrev 
  22487.  
  22488. define-hooked-local-abbrev 
  22489.  
  22490. dired-mode-hook 
  22491.  
  22492. disabled-command-hook 
  22493.  
  22494. edit-picture-hook 
  22495.  
  22496. electric-buffer-menu-mode-hook 
  22497.  
  22498. electric-command-history-hook 
  22499.  
  22500. electric-help-mode-hook 
  22501.  
  22502. emacs-lisp-mode-hook 
  22503.  
  22504. find-file-hooks 
  22505.  
  22506. find-file-not-found-hooks 
  22507.  
  22508. fortran-comment-hook 
  22509.  
  22510. fortran-mode-hook 
  22511.  
  22512. ftp-setup-write-file-hooks 
  22513.  
  22514. ftp-write-file-hook 
  22515.  
  22516. indent-mim-hook 
  22517.  
  22518. LaTeX-mode-hook 
  22519.  
  22520. ledit-mode-hook 
  22521.  
  22522. lisp-indent-hook 
  22523.  
  22524. lisp-interaction-mode-hook 
  22525.  
  22526. lisp-mode-hook 
  22527.  
  22528. m2-mode-hook 
  22529.  
  22530. mail-mode-hook 
  22531.  
  22532. mail-setup-hook 
  22533.  
  22534. medit-mode-hook 
  22535.  
  22536. mh-compose-letter-hook 
  22537.  
  22538. mh-folder-mode-hook 
  22539.  
  22540. mh-letter-mode-hook 
  22541.  
  22542. mim-mode-hook 
  22543.  
  22544. news-mode-hook 
  22545.  
  22546. news-reply-mode-hook 
  22547.  
  22548. news-setup-hook 
  22549.  
  22550. nroff-mode-hook 
  22551.  
  22552. outline-mode-hook 
  22553.  
  22554. plain-TeX-mode-hook 
  22555.  
  22556. prolog-mode-hook 
  22557.  
  22558. protect-innocence-hook 
  22559.  
  22560. rmail-edit-mode-hook 
  22561.  
  22562. rmail-mode-hook 
  22563.  
  22564. rmail-summary-mode-hook 
  22565.  
  22566. scheme-indent-hook 
  22567.  
  22568. scheme-mode-hook 
  22569.  
  22570. scribe-mode-hook 
  22571.  
  22572. shell-mode-hook 
  22573.  
  22574. shell-set-directory-error-hook 
  22575.  
  22576. suspend-hook 
  22577.  
  22578. suspend-resume-hook 
  22579.  
  22580. temp-buffer-show-hook 
  22581.  
  22582. term-setup-hook 
  22583.  
  22584. terminal-mode-hook 
  22585.  
  22586. terminal-mode-break-hook 
  22587.  
  22588. TeX-mode-hook 
  22589.  
  22590. text-mode-hook 
  22591.  
  22592. vi-mode-hook 
  22593.  
  22594. view-hook 
  22595.  
  22596. write-file-hooks 
  22597.  
  22598. x-process-mouse-hook 
  22599.  
  22600.  
  22601. ΓòÉΓòÉΓòÉ 44. Index ΓòÉΓòÉΓòÉ
  22602.  
  22603. Sorry, no fn index 
  22604.  
  22605.  These words prevent "local variables" above from confusing Emacs.