Mercurial > emacs
annotate info/eintr-1 @ 73590:dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
`Introduction to Programming in Emacs Lisp'
author | Robert J. Chassell <bob@rattlesnake.com> |
---|---|
date | Tue, 31 Oct 2006 17:00:13 +0000 |
parents | |
children | a9d44a0da97d |
rev | line source |
---|---|
73590
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1 This is ../info/eintr, produced by makeinfo version 4.8 from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2 emacs-lisp-intro.texi. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4 INFO-DIR-SECTION Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5 START-INFO-DIR-ENTRY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6 * Emacs Lisp Intro: (eintr). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7 A simple introduction to Emacs Lisp programming. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
8 END-INFO-DIR-ENTRY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
9 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
10 This is an `Introduction to Programming in Emacs Lisp', for people who |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
11 are not programmers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
12 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
13 Edition 3.00, 2006 Oct 31 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
14 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
15 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1997, 2001, 2002, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
16 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
17 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
18 Published by the: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
19 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
20 GNU Press, Website: http://www.gnupress.org |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
21 a division of the General: press@gnu.org |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
22 Free Software Foundation, Inc. Orders: sales@gnu.org |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
23 51 Franklin Street, Fifth Floor Tel: +1 (617) 542-5942 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
24 Boston, MA 02110-1301 USA Fax: +1 (617) 542-2652 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
25 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
26 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
27 ISBN 1-882114-43-4 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
28 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
29 Permission is granted to copy, distribute and/or modify this document |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
30 under the terms of the GNU Free Documentation License, Version 1.2 or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
31 any later version published by the Free Software Foundation; there |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
32 being no Invariant Section, with the Front-Cover Texts being "A GNU |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
33 Manual", and with the Back-Cover Texts as in (a) below. A copy of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
34 license is included in the section entitled "GNU Free Documentation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
35 License". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
36 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
37 (a) The FSF's Back-Cover Text is: "You have freedom to copy and modify |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
38 this GNU Manual, like GNU software. Copies published by the Free |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
39 Software Foundation raise funds for GNU development." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
40 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
41 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
42 File: eintr, Node: Top, Next: Preface, Prev: (dir), Up: (dir) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
43 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
44 An Introduction to Programming in Emacs Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
45 ******************************************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
46 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
47 This is an `Introduction to Programming in Emacs Lisp', for people who |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
48 are not programmers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
49 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
50 Edition 3.00, 2006 Oct 31 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
51 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
52 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1997, 2001, 2002, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
53 2003, 2004, 2005, 2006 Free Software Foundation, Inc. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
54 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
55 Published by the: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
56 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
57 GNU Press, Website: http://www.gnupress.org |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
58 a division of the General: press@gnu.org |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
59 Free Software Foundation, Inc. Orders: sales@gnu.org |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
60 51 Franklin Street, Fifth Floor Tel: +1 (617) 542-5942 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
61 Boston, MA 02110-1301 USA Fax: +1 (617) 542-2652 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
62 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
63 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
64 ISBN 1-882114-43-4 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
65 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
66 Permission is granted to copy, distribute and/or modify this document |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
67 under the terms of the GNU Free Documentation License, Version 1.2 or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
68 any later version published by the Free Software Foundation; there |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
69 being no Invariant Section, with the Front-Cover Texts being "A GNU |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
70 Manual", and with the Back-Cover Texts as in (a) below. A copy of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
71 license is included in the section entitled "GNU Free Documentation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
72 License". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
73 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
74 (a) The FSF's Back-Cover Text is: "You have freedom to copy and modify |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
75 this GNU Manual, like GNU software. Copies published by the Free |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
76 Software Foundation raise funds for GNU development." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
77 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
78 This master menu first lists each chapter and index; then it lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
79 every node in every chapter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
80 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
81 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
82 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
83 * Preface:: What to look for. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
84 * List Processing:: What is Lisp? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
85 * Practicing Evaluation:: Running several programs. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
86 * Writing Defuns:: How to write function definitions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
87 * Buffer Walk Through:: Exploring a few buffer-related functions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
88 * More Complex:: A few, even more complex functions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
89 * Narrowing & Widening:: Restricting your and Emacs attention to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
90 a region. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
91 * car cdr & cons:: Fundamental functions in Lisp. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
92 * Cutting & Storing Text:: Removing text and saving it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
93 * List Implementation:: How lists are implemented in the computer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
94 * Yanking:: Pasting stored text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
95 * Loops & Recursion:: How to repeat a process. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
96 * Regexp Search:: Regular expression searches. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
97 * Counting Words:: A review of repetition and regexps. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
98 * Words in a defun:: Counting words in a `defun'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
99 * Readying a Graph:: A prototype graph printing function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
100 * Emacs Initialization:: How to write a `.emacs' file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
101 * Debugging:: How to run the Emacs Lisp debuggers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
102 * Conclusion:: Now you have the basics. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
103 * the-the:: An appendix: how to find reduplicated words. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
104 * Kill Ring:: An appendix: how the kill ring works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
105 * Full Graph:: How to create a graph with labelled axes. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
106 * Free Software and Free Manuals:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
107 * GNU Free Documentation License:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
108 * Index:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
109 * About the Author:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
110 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
111 --- The Detailed Node Listing --- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
112 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
113 Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
114 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
115 * Why:: Why learn Emacs Lisp? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
116 * On Reading this Text:: Read, gain familiarity, pick up habits.... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
117 * Who You Are:: For whom this is written. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
118 * Lisp History:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
119 * Note for Novices:: You can read this as a novice. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
120 * Thank You:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
121 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
122 List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
123 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
124 * Lisp Lists:: What are lists? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
125 * Run a Program:: Any list in Lisp is a program ready to run. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
126 * Making Errors:: Generating an error message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
127 * Names & Definitions:: Names of symbols and function definitions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
128 * Lisp Interpreter:: What the Lisp interpreter does. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
129 * Evaluation:: Running a program. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
130 * Variables:: Returning a value from a variable. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
131 * Arguments:: Passing information to a function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
132 * set & setq:: Setting the value of a variable. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
133 * Summary:: The major points. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
134 * Error Message Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
135 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
136 Lisp Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
137 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
138 * Numbers Lists:: List have numbers, other lists, in them. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
139 * Lisp Atoms:: Elemental entities. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
140 * Whitespace in Lists:: Formatting lists to be readable. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
141 * Typing Lists:: How GNU Emacs helps you type lists. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
142 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
143 The Lisp Interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
144 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
145 * Complications:: Variables, Special forms, Lists within. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
146 * Byte Compiling:: Specially processing code for speed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
147 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
148 Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
149 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
150 * Evaluating Inner Lists:: Lists within lists... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
151 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
152 Variables |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
153 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
154 * fill-column Example:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
155 * Void Function:: The error message for a symbol |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
156 without a function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
157 * Void Variable:: The error message for a symbol without a value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
158 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
159 Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
160 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
161 * Data types:: Types of data passed to a function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
162 * Args as Variable or List:: An argument can be the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
163 of a variable or list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
164 * Variable Number of Arguments:: Some functions may take a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
165 variable number of arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
166 * Wrong Type of Argument:: Passing an argument of the wrong type |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
167 to a function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
168 * message:: A useful function for sending messages. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
169 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
170 Setting the Value of a Variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
171 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
172 * Using set:: Setting values. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
173 * Using setq:: Setting a quoted value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
174 * Counting:: Using `setq' to count. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
175 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
176 Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
177 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
178 * How to Evaluate:: Typing editing commands or C-x C-e |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
179 causes evaluation. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
180 * Buffer Names:: Buffers and files are different. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
181 * Getting Buffers:: Getting a buffer itself, not merely its name. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
182 * Switching Buffers:: How to change to another buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
183 * Buffer Size & Locations:: Where point is located and the size of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
184 the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
185 * Evaluation Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
186 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
187 How To Write Function Definitions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
188 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
189 * Primitive Functions:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
190 * defun:: The `defun' special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
191 * Install:: Install a function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
192 * Interactive:: Making a function interactive. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
193 * Interactive Options:: Different options for `interactive'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
194 * Permanent Installation:: Installing code permanently. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
195 * let:: Creating and initializing local variables. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
196 * if:: What if? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
197 * else:: If--then--else expressions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
198 * Truth & Falsehood:: What Lisp considers false and true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
199 * save-excursion:: Keeping track of point, mark, and buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
200 * Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
201 * defun Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
202 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
203 Install a Function Definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
204 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
205 * Effect of installation:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
206 * Change a defun:: How to change a function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
207 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
208 Make a Function Interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
209 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
210 * Interactive multiply-by-seven:: An overview. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
211 * multiply-by-seven in detail:: The interactive version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
212 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
213 `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
214 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
215 * Prevent confusion:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
216 * Parts of let Expression:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
217 * Sample let Expression:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
218 * Uninitialized let Variables:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
219 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
220 The `if' Special Form |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
221 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
222 * if in more detail:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
223 * type-of-animal in detail:: An example of an `if' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
224 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
225 Truth and Falsehood in Emacs Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
226 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
227 * nil explained:: `nil' has two meanings. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
228 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
229 `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
230 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
231 * Point and mark:: A review of various locations. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
232 * Template for save-excursion:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
233 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
234 A Few Buffer--Related Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
235 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
236 * Finding More:: How to find more information. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
237 * simplified-beginning-of-buffer:: Shows `goto-char', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
238 `point-min', and `push-mark'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
239 * mark-whole-buffer:: Almost the same as `beginning-of-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
240 * append-to-buffer:: Uses `save-excursion' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
241 `insert-buffer-substring'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
242 * Buffer Related Review:: Review. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
243 * Buffer Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
244 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
245 The Definition of `mark-whole-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
246 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
247 * mark-whole-buffer overview:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
248 * Body of mark-whole-buffer:: Only three lines of code. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
249 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
250 The Definition of `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
251 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
252 * append-to-buffer overview:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
253 * append interactive:: A two part interactive expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
254 * append-to-buffer body:: Incorporates a `let' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
255 * append save-excursion:: How the `save-excursion' works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
256 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
257 A Few More Complex Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
258 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
259 * copy-to-buffer:: With `set-buffer', `get-buffer-create'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
260 * insert-buffer:: Read-only, and with `or'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
261 * beginning-of-buffer:: Shows `goto-char', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
262 `point-min', and `push-mark'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
263 * Second Buffer Related Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
264 * optional Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
265 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
266 The Definition of `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
267 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
268 * insert-buffer code:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
269 * insert-buffer interactive:: When you can read, but not write. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
270 * insert-buffer body:: The body has an `or' and a `let'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
271 * if & or:: Using an `if' instead of an `or'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
272 * Insert or:: How the `or' expression works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
273 * Insert let:: Two `save-excursion' expressions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
274 * New insert-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
275 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
276 The Interactive Expression in `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
277 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
278 * Read-only buffer:: When a buffer cannot be modified. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
279 * b for interactive:: An existing buffer or else its name. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
280 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
281 Complete Definition of `beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
282 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
283 * Optional Arguments:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
284 * beginning-of-buffer opt arg:: Example with optional argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
285 * beginning-of-buffer complete:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
286 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
287 `beginning-of-buffer' with an Argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
288 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
289 * Disentangle beginning-of-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
290 * Large buffer case:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
291 * Small buffer case:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
292 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
293 Narrowing and Widening |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
294 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
295 * Narrowing advantages:: The advantages of narrowing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
296 * save-restriction:: The `save-restriction' special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
297 * what-line:: The number of the line that point is on. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
298 * narrow Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
299 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
300 `car', `cdr', `cons': Fundamental Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
301 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
302 * Strange Names:: An historical aside: why the strange names? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
303 * car & cdr:: Functions for extracting part of a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
304 * cons:: Constructing a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
305 * nthcdr:: Calling `cdr' repeatedly. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
306 * nth:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
307 * setcar:: Changing the first element of a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
308 * setcdr:: Changing the rest of a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
309 * cons Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
310 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
311 `cons' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
312 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
313 * Build a list:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
314 * length:: How to find the length of a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
315 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
316 Cutting and Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
317 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
318 * Storing Text:: Text is stored in a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
319 * zap-to-char:: Cutting out text up to a character. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
320 * kill-region:: Cutting text out of a region. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
321 * copy-region-as-kill:: A definition for copying text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
322 * Digression into C:: Minor note on C programming language macros. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
323 * defvar:: How to give a variable an initial value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
324 * cons & search-fwd Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
325 * search Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
326 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
327 `zap-to-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
328 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
329 * Complete zap-to-char:: The complete implementation. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
330 * zap-to-char interactive:: A three part interactive expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
331 * zap-to-char body:: A short overview. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
332 * search-forward:: How to search for a string. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
333 * progn:: The `progn' special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
334 * Summing up zap-to-char:: Using `point' and `search-forward'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
335 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
336 `kill-region' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
337 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
338 * Complete kill-region:: The function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
339 * condition-case:: Dealing with a problem. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
340 * Lisp macro:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
341 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
342 `copy-region-as-kill' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
343 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
344 * Complete copy-region-as-kill:: The complete function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
345 * copy-region-as-kill body:: The body of `copy-region-as-kill'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
346 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
347 The Body of `copy-region-as-kill' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
348 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
349 * last-command & this-command:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
350 * kill-append function:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
351 * kill-new function:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
352 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
353 Initializing a Variable with `defvar' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
354 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
355 * See variable current value:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
356 * defvar and asterisk:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
357 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
358 How Lists are Implemented |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
359 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
360 * Lists diagrammed:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
361 * Symbols as Chest:: Exploring a powerful metaphor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
362 * List Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
363 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
364 Yanking Text Back |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
365 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
366 * Kill Ring Overview:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
367 * kill-ring-yank-pointer:: The kill ring is a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
368 * yank nthcdr Exercises:: The `kill-ring-yank-pointer' variable. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
369 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
370 Loops and Recursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
371 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
372 * while:: Causing a stretch of code to repeat. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
373 * dolist dotimes:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
374 * Recursion:: Causing a function to call itself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
375 * Looping exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
376 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
377 `while' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
378 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
379 * Looping with while:: Repeat so long as test returns true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
380 * Loop Example:: A `while' loop that uses a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
381 * print-elements-of-list:: Uses `while', `car', `cdr'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
382 * Incrementing Loop:: A loop with an incrementing counter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
383 * Decrementing Loop:: A loop with a decrementing counter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
384 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
385 A Loop with an Incrementing Counter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
386 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
387 * Incrementing Example:: Counting pebbles in a triangle. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
388 * Inc Example parts:: The parts of the function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
389 * Inc Example altogether:: Putting the function definition together. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
390 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
391 Loop with a Decrementing Counter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
392 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
393 * Decrementing Example:: More pebbles on the beach. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
394 * Dec Example parts:: The parts of the function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
395 * Dec Example altogether:: Putting the function definition together. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
396 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
397 Save your time: `dolist' and `dotimes' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
398 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
399 * dolist:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
400 * dotimes:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
401 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
402 Recursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
403 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
404 * Building Robots:: Same model, different serial number ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
405 * Recursive Definition Parts:: Walk until you stop ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
406 * Recursion with list:: Using a list as the test whether to recurse. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
407 * Recursive triangle function:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
408 * Recursion with cond:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
409 * Recursive Patterns:: Often used templates. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
410 * No Deferment:: Don't store up work ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
411 * No deferment solution:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
412 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
413 Recursion in Place of a Counter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
414 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
415 * Recursive Example arg of 1 or 2:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
416 * Recursive Example arg of 3 or 4:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
417 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
418 Recursive Patterns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
419 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
420 * Every:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
421 * Accumulate:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
422 * Keep:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
423 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
424 Regular Expression Searches |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
425 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
426 * sentence-end:: The regular expression for `sentence-end'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
427 * re-search-forward:: Very similar to `search-forward'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
428 * forward-sentence:: A straightforward example of regexp search. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
429 * forward-paragraph:: A somewhat complex example. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
430 * etags:: How to create your own `TAGS' table. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
431 * Regexp Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
432 * re-search Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
433 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
434 `forward-sentence' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
435 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
436 * Complete forward-sentence:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
437 * fwd-sentence while loops:: Two `while' loops. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
438 * fwd-sentence re-search:: A regular expression search. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
439 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
440 `forward-paragraph': a Goldmine of Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
441 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
442 * forward-paragraph in brief:: Key parts of the function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
443 * fwd-para let:: The `let*' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
444 * fwd-para while:: The forward motion `while' loop. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
445 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
446 Counting: Repetition and Regexps |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
447 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
448 * Why Count Words:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
449 * count-words-region:: Use a regexp, but find a problem. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
450 * recursive-count-words:: Start with case of no words in region. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
451 * Counting Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
452 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
453 The `count-words-region' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
454 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
455 * Design count-words-region:: The definition using a `while' loop. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
456 * Whitespace Bug:: The Whitespace Bug in `count-words-region'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
457 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
458 Counting Words in a `defun' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
459 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
460 * Divide and Conquer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
461 * Words and Symbols:: What to count? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
462 * Syntax:: What constitutes a word or symbol? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
463 * count-words-in-defun:: Very like `count-words'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
464 * Several defuns:: Counting several defuns in a file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
465 * Find a File:: Do you want to look at a file? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
466 * lengths-list-file:: A list of the lengths of many definitions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
467 * Several files:: Counting in definitions in different files. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
468 * Several files recursively:: Recursively counting in different files. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
469 * Prepare the data:: Prepare the data for display in a graph. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
470 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
471 Count Words in `defuns' in Different Files |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
472 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
473 * lengths-list-many-files:: Return a list of the lengths of defuns. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
474 * append:: Attach one list to another. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
475 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
476 Prepare the Data for Display in a Graph |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
477 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
478 * Sorting:: Sorting lists. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
479 * Files List:: Making a list of files. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
480 * Counting function definitions:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
481 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
482 Readying a Graph |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
483 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
484 * Columns of a graph:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
485 * graph-body-print:: How to print the body of a graph. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
486 * recursive-graph-body-print:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
487 * Printed Axes:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
488 * Line Graph Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
489 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
490 Your `.emacs' File |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
491 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
492 * Default Configuration:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
493 * Site-wide Init:: You can write site-wide init files. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
494 * defcustom:: Emacs will write code for you. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
495 * Beginning a .emacs File:: How to write a `.emacs file'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
496 * Text and Auto-fill:: Automatically wrap lines. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
497 * Mail Aliases:: Use abbreviations for email addresses. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
498 * Indent Tabs Mode:: Don't use tabs with TeX |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
499 * Keybindings:: Create some personal keybindings. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
500 * Keymaps:: More about key binding. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
501 * Loading Files:: Load (i.e., evaluate) files automatically. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
502 * Autoload:: Make functions available. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
503 * Simple Extension:: Define a function; bind it to a key. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
504 * X11 Colors:: Colors in version 19 in X. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
505 * Miscellaneous:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
506 * Mode Line:: How to customize your mode line. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
507 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
508 Debugging |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
509 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
510 * debug:: How to use the built-in debugger. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
511 * debug-on-entry:: Start debugging when you call a function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
512 * debug-on-quit:: Start debugging when you quit with C-g. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
513 * edebug:: How to use Edebug, a source level debugger. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
514 * Debugging Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
515 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
516 Handling the Kill Ring |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
517 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
518 * current-kill:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
519 * yank:: Paste a copy of a clipped element. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
520 * yank-pop:: Insert element pointed to. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
521 * ring file:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
522 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
523 The `current-kill' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
524 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
525 * Understanding current-kill:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
526 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
527 `current-kill' in Outline |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
528 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
529 * Digression concerning error:: How to mislead humans, but not computers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
530 * Determining the Element:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
531 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
532 A Graph with Labelled Axes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
533 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
534 * Labelled Example:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
535 * print-graph Varlist:: `let' expression in `print-graph'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
536 * print-Y-axis:: Print a label for the vertical axis. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
537 * print-X-axis:: Print a horizontal label. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
538 * Print Whole Graph:: The function to print a complete graph. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
539 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
540 The `print-Y-axis' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
541 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
542 * Height of label:: What height for the Y axis? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
543 * Compute a Remainder:: How to compute the remainder of a division. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
544 * Y Axis Element:: Construct a line for the Y axis. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
545 * Y-axis-column:: Generate a list of Y axis labels. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
546 * print-Y-axis Penultimate:: A not quite final version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
547 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
548 The `print-X-axis' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
549 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
550 * Similarities differences:: Much like `print-Y-axis', but not exactly. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
551 * X Axis Tic Marks:: Create tic marks for the horizontal axis. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
552 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
553 Printing the Whole Graph |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
554 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
555 * The final version:: A few changes. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
556 * Test print-graph:: Run a short test. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
557 * Graphing words in defuns:: Executing the final code. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
558 * lambda:: How to write an anonymous function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
559 * mapcar:: Apply a function to elements of a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
560 * Another Bug:: Yet another bug ... most insidious. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
561 * Final printed graph:: The graph itself! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
562 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
563 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
564 File: eintr, Node: Preface, Next: List Processing, Prev: Top, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
565 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
566 Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
567 ******* |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
568 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
569 Most of the GNU Emacs integrated environment is written in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
570 programming language called Emacs Lisp. The code written in this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
571 programming language is the software--the sets of instructions--that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
572 tell the computer what to do when you give it commands. Emacs is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
573 designed so that you can write new code in Emacs Lisp and easily |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
574 install it as an extension to the editor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
575 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
576 (GNU Emacs is sometimes called an "extensible editor", but it does much |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
577 more than provide editing capabilities. It is better to refer to Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
578 as an "extensible computing environment". However, that phrase is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
579 quite a mouthful. It is easier to refer to Emacs simply as an editor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
580 Moreover, everything you do in Emacs--find the Mayan date and phases of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
581 the moon, simplify polynomials, debug code, manage files, read letters, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
582 write books--all these activities are kinds of editing in the most |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
583 general sense of the word.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
584 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
585 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
586 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
587 * Why:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
588 * On Reading this Text:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
589 * Who You Are:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
590 * Lisp History:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
591 * Note for Novices:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
592 * Thank You:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
593 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
594 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
595 File: eintr, Node: Why, Next: On Reading this Text, Prev: Preface, Up: Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
596 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
597 Why Study Emacs Lisp? |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
598 ===================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
599 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
600 Although Emacs Lisp is usually thought of in association only with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
601 Emacs, it is a full computer programming language. You can use Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
602 Lisp as you would any other programming language. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
603 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
604 Perhaps you want to understand programming; perhaps you want to extend |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
605 Emacs; or perhaps you want to become a programmer. This introduction to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
606 Emacs Lisp is designed to get you started: to guide you in learning the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
607 fundamentals of programming, and more importantly, to show you how you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
608 can teach yourself to go further. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
609 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
610 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
611 File: eintr, Node: On Reading this Text, Next: Who You Are, Prev: Why, Up: Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
612 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
613 On Reading this Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
614 ==================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
615 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
616 All through this document, you will see little sample programs you can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
617 run inside of Emacs. If you read this document in Info inside of GNU |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
618 Emacs, you can run the programs as they appear. (This is easy to do and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
619 is explained when the examples are presented.) Alternatively, you can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
620 read this introduction as a printed book while sitting beside a computer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
621 running Emacs. (This is what I like to do; I like printed books.) If |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
622 you don't have a running Emacs beside you, you can still read this book, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
623 but in this case, it is best to treat it as a novel or as a travel guide |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
624 to a country not yet visited: interesting, but not the same as being |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
625 there. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
626 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
627 Much of this introduction is dedicated to walk-throughs or guided tours |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
628 of code used in GNU Emacs. These tours are designed for two purposes: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
629 first, to give you familiarity with real, working code (code you use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
630 every day); and, second, to give you familiarity with the way Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
631 works. It is interesting to see how a working environment is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
632 implemented. Also, I hope that you will pick up the habit of browsing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
633 through source code. You can learn from it and mine it for ideas. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
634 Having GNU Emacs is like having a dragon's cave of treasures. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
635 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
636 In addition to learning about Emacs as an editor and Emacs Lisp as a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
637 programming language, the examples and guided tours will give you an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
638 opportunity to get acquainted with Emacs as a Lisp programming |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
639 environment. GNU Emacs supports programming and provides tools that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
640 you will want to become comfortable using, such as `M-.' (the key which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
641 invokes the `find-tag' command). You will also learn about buffers and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
642 other objects that are part of the environment. Learning about these |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
643 features of Emacs is like learning new routes around your home town. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
644 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
645 Finally, I hope to convey some of the skills for using Emacs to learn |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
646 aspects of programming that you don't know. You can often use Emacs to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
647 help you understand what puzzles you or to find out how to do something |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
648 new. This self-reliance is not only a pleasure, but an advantage. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
649 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
650 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
651 File: eintr, Node: Who You Are, Next: Lisp History, Prev: On Reading this Text, Up: Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
652 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
653 For Whom This is Written |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
654 ======================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
655 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
656 This text is written as an elementary introduction for people who are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
657 not programmers. If you are a programmer, you may not be satisfied with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
658 this primer. The reason is that you may have become expert at reading |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
659 reference manuals and be put off by the way this text is organized. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
660 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
661 An expert programmer who reviewed this text said to me: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
662 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
663 I prefer to learn from reference manuals. I "dive into" each |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
664 paragraph, and "come up for air" between paragraphs. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
665 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
666 When I get to the end of a paragraph, I assume that that subject is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
667 done, finished, that I know everything I need (with the possible |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
668 exception of the case when the next paragraph starts talking about |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
669 it in more detail). I expect that a well written reference manual |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
670 will not have a lot of redundancy, and that it will have excellent |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
671 pointers to the (one) place where the information I want is. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
672 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
673 This introduction is not written for this person! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
674 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
675 Firstly, I try to say everything at least three times: first, to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
676 introduce it; second, to show it in context; and third, to show it in a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
677 different context, or to review it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
678 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
679 Secondly, I hardly ever put all the information about a subject in one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
680 place, much less in one paragraph. To my way of thinking, that imposes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
681 too heavy a burden on the reader. Instead I try to explain only what |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
682 you need to know at the time. (Sometimes I include a little extra |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
683 information so you won't be surprised later when the additional |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
684 information is formally introduced.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
685 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
686 When you read this text, you are not expected to learn everything the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
687 first time. Frequently, you need only make, as it were, a `nodding |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
688 acquaintance' with some of the items mentioned. My hope is that I have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
689 structured the text and given you enough hints that you will be alert to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
690 what is important, and concentrate on it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
691 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
692 You will need to "dive into" some paragraphs; there is no other way to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
693 read them. But I have tried to keep down the number of such |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
694 paragraphs. This book is intended as an approachable hill, rather than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
695 as a daunting mountain. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
696 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
697 This introduction to `Programming in Emacs Lisp' has a companion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
698 document, *Note The GNU Emacs Lisp Reference Manual: (elisp)Top. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
699 reference manual has more detail than this introduction. In the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
700 reference manual, all the information about one topic is concentrated |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
701 in one place. You should turn to it if you are like the programmer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
702 quoted above. And, of course, after you have read this `Introduction', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
703 you will find the `Reference Manual' useful when you are writing your |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
704 own programs. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
705 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
706 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
707 File: eintr, Node: Lisp History, Next: Note for Novices, Prev: Who You Are, Up: Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
708 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
709 Lisp History |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
710 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
711 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
712 Lisp was first developed in the late 1950s at the Massachusetts |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
713 Institute of Technology for research in artificial intelligence. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
714 great power of the Lisp language makes it superior for other purposes as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
715 well, such as writing editor commands and integrated environments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
716 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
717 GNU Emacs Lisp is largely inspired by Maclisp, which was written at MIT |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
718 in the 1960s. It is somewhat inspired by Common Lisp, which became a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
719 standard in the 1980s. However, Emacs Lisp is much simpler than Common |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
720 Lisp. (The standard Emacs distribution contains an optional extensions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
721 file, `cl.el', that adds many Common Lisp features to Emacs Lisp.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
722 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
723 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
724 File: eintr, Node: Note for Novices, Next: Thank You, Prev: Lisp History, Up: Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
725 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
726 A Note for Novices |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
727 ================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
728 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
729 If you don't know GNU Emacs, you can still read this document |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
730 profitably. However, I recommend you learn Emacs, if only to learn to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
731 move around your computer screen. You can teach yourself how to use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
732 Emacs with the on-line tutorial. To use it, type `C-h t'. (This means |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
733 you press and release the <CTRL> key and the `h' at the same time, and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
734 then press and release `t'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
735 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
736 Also, I often refer to one of Emacs' standard commands by listing the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
737 keys which you press to invoke the command and then giving the name of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
738 the command in parentheses, like this: `M-C-\' (`indent-region'). What |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
739 this means is that the `indent-region' command is customarily invoked |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
740 by typing `M-C-\'. (You can, if you wish, change the keys that are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
741 typed to invoke the command; this is called "rebinding". *Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
742 Keymaps: Keymaps.) The abbreviation `M-C-\' means that you type your |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
743 <META> key, <CTRL> key and <\> key all at the same time. (On many |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
744 modern keyboards the <META> key is labelled <ALT>.) Sometimes a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
745 combination like this is called a keychord, since it is similar to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
746 way you play a chord on a piano. If your keyboard does not have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
747 <META> key, the <ESC> key prefix is used in place of it. In this case, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
748 `M-C-\' means that you press and release your <ESC> key and then type |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
749 the <CTRL> key and the <\> key at the same time. But usually `M-C-\' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
750 means press the <CTRL> key along with the key that is labelled <ALT> |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
751 and, at the same time, press the <\> key. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
752 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
753 In addition to typing a lone keychord, you can prefix what you type |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
754 with `C-u', which is called the `universal argument'. The `C-u' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
755 keychord passes an argument to the subsequent command. Thus, to indent |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
756 a region of plain text by 6 spaces, mark the region, and then type |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
757 `C-u 6 M-C-\'. (If you do not specify a number, Emacs either passes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
758 the number 4 to the command or otherwise runs the command differently |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
759 than it would otherwise.) *Note Numeric Arguments: (emacs)Arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
760 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
761 If you are reading this in Info using GNU Emacs, you can read through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
762 this whole document just by pressing the space bar, <SPC>. (To learn |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
763 about Info, type `C-h i' and then select Info.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
764 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
765 A note on terminology: when I use the word Lisp alone, I often am |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
766 referring to the various dialects of Lisp in general, but when I speak |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
767 of Emacs Lisp, I am referring to GNU Emacs Lisp in particular. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
768 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
769 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
770 File: eintr, Node: Thank You, Prev: Note for Novices, Up: Preface |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
771 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
772 Thank You |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
773 ========= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
774 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
775 My thanks to all who helped me with this book. My especial thanks to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
776 Jim Blandy, Noah Friedman, Jim Kingdon, Roland McGrath, Frank Ritter, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
777 Randy Smith, Richard M. Stallman, and Melissa Weisshaus. My thanks |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
778 also go to both Philip Johnson and David Stampe for their patient |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
779 encouragement. My mistakes are my own. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
780 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
781 Robert J. Chassell |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
782 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
783 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
784 File: eintr, Node: List Processing, Next: Practicing Evaluation, Prev: Preface, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
785 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
786 1 List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
787 ***************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
788 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
789 To the untutored eye, Lisp is a strange programming language. In Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
790 code there are parentheses everywhere. Some people even claim that the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
791 name stands for `Lots of Isolated Silly Parentheses'. But the claim is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
792 unwarranted. Lisp stands for LISt Processing, and the programming |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
793 language handles _lists_ (and lists of lists) by putting them between |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
794 parentheses. The parentheses mark the boundaries of the list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
795 Sometimes a list is preceded by a single apostrophe or quotation mark, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
796 `''(1) Lists are the basis of Lisp. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
797 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
798 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
799 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
800 * Lisp Lists:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
801 * Run a Program:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
802 * Making Errors:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
803 * Names & Definitions:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
804 * Lisp Interpreter:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
805 * Evaluation:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
806 * Variables:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
807 * Arguments:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
808 * set & setq:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
809 * Summary:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
810 * Error Message Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
811 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
812 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
813 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
814 (1) The single apostrophe or quotation mark is an abbreviation for the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
815 function `quote'; you need not think about functions now; functions are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
816 defined in *Note Generate an Error Message: Making Errors. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
817 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
818 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
819 File: eintr, Node: Lisp Lists, Next: Run a Program, Prev: List Processing, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
820 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
821 1.1 Lisp Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
822 ============== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
823 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
824 In Lisp, a list looks like this: `'(rose violet daisy buttercup)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
825 This list is preceded by a single apostrophe. It could just as well be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
826 written as follows, which looks more like the kind of list you are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
827 likely to be familiar with: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
828 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
829 '(rose |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
830 violet |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
831 daisy |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
832 buttercup) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
833 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
834 The elements of this list are the names of the four different flowers, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
835 separated from each other by whitespace and surrounded by parentheses, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
836 like flowers in a field with a stone wall around them. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
837 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
838 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
839 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
840 * Numbers Lists:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
841 * Lisp Atoms:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
842 * Whitespace in Lists:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
843 * Typing Lists:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
844 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
845 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
846 File: eintr, Node: Numbers Lists, Next: Lisp Atoms, Prev: Lisp Lists, Up: Lisp Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
847 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
848 Numbers, Lists inside of Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
849 ------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
850 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
851 Lists can also have numbers in them, as in this list: `(+ 2 2)'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
852 list has a plus-sign, `+', followed by two `2's, each separated by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
853 whitespace. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
854 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
855 In Lisp, both data and programs are represented the same way; that is, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
856 they are both lists of words, numbers, or other lists, separated by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
857 whitespace and surrounded by parentheses. (Since a program looks like |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
858 data, one program may easily serve as data for another; this is a very |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
859 powerful feature of Lisp.) (Incidentally, these two parenthetical |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
860 remarks are _not_ Lisp lists, because they contain `;' and `.' as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
861 punctuation marks.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
862 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
863 Here is another list, this time with a list inside of it: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
864 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
865 '(this list has (a list inside of it)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
866 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
867 The components of this list are the words `this', `list', `has', and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
868 the list `(a list inside of it)'. The interior list is made up of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
869 words `a', `list', `inside', `of', `it'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
870 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
871 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
872 File: eintr, Node: Lisp Atoms, Next: Whitespace in Lists, Prev: Numbers Lists, Up: Lisp Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
873 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
874 1.1.1 Lisp Atoms |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
875 ---------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
876 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
877 In Lisp, what we have been calling words are called "atoms". This term |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
878 comes from the historical meaning of the word atom, which means |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
879 `indivisible'. As far as Lisp is concerned, the words we have been |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
880 using in the lists cannot be divided into any smaller parts and still |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
881 mean the same thing as part of a program; likewise with numbers and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
882 single character symbols like `+'. On the other hand, unlike an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
883 ancient atom, a list can be split into parts. (*Note `car' `cdr' & |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
884 `cons' Fundamental Functions: car cdr & cons.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
885 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
886 In a list, atoms are separated from each other by whitespace. They can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
887 be right next to a parenthesis. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
888 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
889 Technically speaking, a list in Lisp consists of parentheses surrounding |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
890 atoms separated by whitespace or surrounding other lists or surrounding |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
891 both atoms and other lists. A list can have just one atom in it or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
892 have nothing in it at all. A list with nothing in it looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
893 `()', and is called the "empty list". Unlike anything else, an empty |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
894 list is considered both an atom and a list at the same time. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
895 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
896 The printed representation of both atoms and lists are called "symbolic |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
897 expressions" or, more concisely, "s-expressions". The word |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
898 "expression" by itself can refer to either the printed representation, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
899 or to the atom or list as it is held internally in the computer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
900 Often, people use the term "expression" indiscriminately. (Also, in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
901 many texts, the word "form" is used as a synonym for expression.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
902 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
903 Incidentally, the atoms that make up our universe were named such when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
904 they were thought to be indivisible; but it has been found that physical |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
905 atoms are not indivisible. Parts can split off an atom or it can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
906 fission into two parts of roughly equal size. Physical atoms were named |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
907 prematurely, before their truer nature was found. In Lisp, certain |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
908 kinds of atom, such as an array, can be separated into parts; but the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
909 mechanism for doing this is different from the mechanism for splitting a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
910 list. As far as list operations are concerned, the atoms of a list are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
911 unsplittable. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
912 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
913 As in English, the meanings of the component letters of a Lisp atom are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
914 different from the meaning the letters make as a word. For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
915 the word for the South American sloth, the `ai', is completely |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
916 different from the two words, `a', and `i'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
917 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
918 There are many kinds of atom in nature but only a few in Lisp: for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
919 example, "numbers", such as 37, 511, or 1729, and "symbols", such as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
920 `+', `foo', or `forward-line'. The words we have listed in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
921 examples above are all symbols. In everyday Lisp conversation, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
922 word "atom" is not often used, because programmers usually try to be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
923 more specific about what kind of atom they are dealing with. Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
924 programming is mostly about symbols (and sometimes numbers) within |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
925 lists. (Incidentally, the preceding three word parenthetical remark is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
926 a proper list in Lisp, since it consists of atoms, which in this case |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
927 are symbols, separated by whitespace and enclosed by parentheses, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
928 without any non-Lisp punctuation.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
929 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
930 In addition, text between double quotation marks--even sentences or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
931 paragraphs--is an atom. Here is an example: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
932 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
933 '(this list includes "text between quotation marks.") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
934 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
935 In Lisp, all of the quoted text including the punctuation mark and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
936 blank spaces is a single atom. This kind of atom is called a "string" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
937 (for `string of characters') and is the sort of thing that is used for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
938 messages that a computer can print for a human to read. Strings are a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
939 different kind of atom than numbers or symbols and are used differently. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
940 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
941 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
942 File: eintr, Node: Whitespace in Lists, Next: Typing Lists, Prev: Lisp Atoms, Up: Lisp Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
943 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
944 1.1.2 Whitespace in Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
945 ------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
946 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
947 The amount of whitespace in a list does not matter. From the point of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
948 view of the Lisp language, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
949 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
950 '(this list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
951 looks like this) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
952 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
953 is exactly the same as this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
954 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
955 '(this list looks like this) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
956 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
957 Both examples show what to Lisp is the same list, the list made up of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
958 the symbols `this', `list', `looks', `like', and `this' in that order. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
959 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
960 Extra whitespace and newlines are designed to make a list more readable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
961 by humans. When Lisp reads the expression, it gets rid of all the extra |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
962 whitespace (but it needs to have at least one space between atoms in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
963 order to tell them apart.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
964 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
965 Odd as it seems, the examples we have seen cover almost all of what Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
966 lists look like! Every other list in Lisp looks more or less like one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
967 of these examples, except that the list may be longer and more complex. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
968 In brief, a list is between parentheses, a string is between quotation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
969 marks, a symbol looks like a word, and a number looks like a number. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
970 (For certain situations, square brackets, dots and a few other special |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
971 characters may be used; however, we will go quite far without them.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
972 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
973 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
974 File: eintr, Node: Typing Lists, Prev: Whitespace in Lists, Up: Lisp Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
975 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
976 1.1.3 GNU Emacs Helps You Type Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
977 ------------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
978 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
979 When you type a Lisp expression in GNU Emacs using either Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
980 Interaction mode or Emacs Lisp mode, you have available to you several |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
981 commands to format the Lisp expression so it is easy to read. For |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
982 example, pressing the <TAB> key automatically indents the line the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
983 cursor is on by the right amount. A command to properly indent the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
984 code in a region is customarily bound to `M-C-\'. Indentation is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
985 designed so that you can see which elements of a list belong to which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
986 list--elements of a sub-list are indented more than the elements of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
987 enclosing list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
988 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
989 In addition, when you type a closing parenthesis, Emacs momentarily |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
990 jumps the cursor back to the matching opening parenthesis, so you can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
991 see which one it is. This is very useful, since every list you type in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
992 Lisp must have its closing parenthesis match its opening parenthesis. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
993 (*Note Major Modes: (emacs)Major Modes, for more information about |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
994 Emacs' modes.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
995 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
996 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
997 File: eintr, Node: Run a Program, Next: Making Errors, Prev: Lisp Lists, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
998 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
999 1.2 Run a Program |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1000 ================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1001 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1002 A list in Lisp--any list--is a program ready to run. If you run it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1003 (for which the Lisp jargon is "evaluate"), the computer will do one of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1004 three things: do nothing except return to you the list itself; send you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1005 an error message; or, treat the first symbol in the list as a command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1006 to do something. (Usually, of course, it is the last of these three |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1007 things that you really want!) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1008 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1009 The single apostrophe, `'', that I put in front of some of the example |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1010 lists in preceding sections is called a "quote"; when it precedes a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1011 list, it tells Lisp to do nothing with the list, other than take it as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1012 it is written. But if there is no quote preceding a list, the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1013 item of the list is special: it is a command for the computer to obey. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1014 (In Lisp, these commands are called _functions_.) The list `(+ 2 2)' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1015 shown above did not have a quote in front of it, so Lisp understands |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1016 that the `+' is an instruction to do something with the rest of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1017 list: add the numbers that follow. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1018 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1019 If you are reading this inside of GNU Emacs in Info, here is how you can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1020 evaluate such a list: place your cursor immediately after the right |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1021 hand parenthesis of the following list and then type `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1022 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1023 (+ 2 2) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1024 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1025 You will see the number `4' appear in the echo area. (In the jargon, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1026 what you have just done is "evaluate the list." The echo area is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1027 line at the bottom of the screen that displays or "echoes" text.) Now |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1028 try the same thing with a quoted list: place the cursor right after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1029 the following list and type `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1030 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1031 '(this is a quoted list) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1032 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1033 You will see `(this is a quoted list)' appear in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1034 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1035 In both cases, what you are doing is giving a command to the program |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1036 inside of GNU Emacs called the "Lisp interpreter"--giving the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1037 interpreter a command to evaluate the expression. The name of the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1038 interpreter comes from the word for the task done by a human who comes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1039 up with the meaning of an expression--who "interprets" it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1040 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1041 You can also evaluate an atom that is not part of a list--one that is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1042 not surrounded by parentheses; again, the Lisp interpreter translates |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1043 from the humanly readable expression to the language of the computer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1044 But before discussing this (*note Variables::), we will discuss what the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1045 Lisp interpreter does when you make an error. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1046 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1047 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1048 File: eintr, Node: Making Errors, Next: Names & Definitions, Prev: Run a Program, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1049 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1050 1.3 Generate an Error Message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1051 ============================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1052 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1053 Partly so you won't worry if you do it accidentally, we will now give a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1054 command to the Lisp interpreter that generates an error message. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1055 is a harmless activity; and indeed, we will often try to generate error |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1056 messages intentionally. Once you understand the jargon, error messages |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1057 can be informative. Instead of being called "error" messages, they |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1058 should be called "help" messages. They are like signposts to a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1059 traveller in a strange country; deciphering them can be hard, but once |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1060 understood, they can point the way. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1061 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1062 The error message is generated by a built-in GNU Emacs debugger. We |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1063 will `enter the debugger'. You get out of the debugger by typing `q'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1064 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1065 What we will do is evaluate a list that is not quoted and does not have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1066 a meaningful command as its first element. Here is a list almost |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1067 exactly the same as the one we just used, but without the single-quote |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1068 in front of it. Position the cursor right after it and type `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1069 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1070 (this is an unquoted list) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1071 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1072 What you see depends on which version of Emacs you are running. GNU |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1073 Emacs version 22 provides more information than version 20 and before. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1074 First, the more recent result of generating an error; then the earlier, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1075 version 20 result. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1076 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1077 In GNU Emacs version 22, a `*Backtrace*' window will open up and you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1078 will see the following in it: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1079 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1080 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1081 Debugger entered--Lisp error: (void-function this) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1082 (this is an unquoted list) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1083 eval((this is an unquoted list)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1084 eval-last-sexp-1(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1085 eval-last-sexp(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1086 call-interactively(eval-last-sexp) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1087 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1088 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1089 Your cursor will be in this window (you may have to wait a few seconds |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1090 before it becomes visible). To quit the debugger and make the debugger |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1091 window go away, type: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1092 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1093 q |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1094 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1095 Please type `q' right now, so you become confident that you can get out |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1096 of the debugger. Then, type `C-x C-e' again to re-enter it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1097 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1098 Based on what we already know, we can almost read this error message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1099 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1100 You read the `*Backtrace*' buffer from the bottom up; it tells you what |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1101 Emacs did. When you typed `C-x C-e', you made an interactive call to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1102 the command `eval-last-sexp'. `eval' is an abbreviation for `evaluate' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1103 and `sexp' is an abbreviation for `symbolic expression'. The command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1104 means `evaluate last symbolic expression', which is the expression just |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1105 before your cursor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1106 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1107 Each line above tells you what the Lisp interpreter evaluated next. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1108 The most recent action is at the top. The buffer is called the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1109 `*Backtrace*' buffer because it enables you to track Emacs backwards. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1110 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1111 At the top of the `*Backtrace*' buffer, you see the line: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1112 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1113 Debugger entered--Lisp error: (void-function this) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1114 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1115 The Lisp interpreter tried to evaluate the first atom of the list, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1116 word `this'. It is this action that generated the error message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1117 `void-function this'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1118 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1119 The message contains the words `void-function' and `this'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1120 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1121 The word `function' was mentioned once before. It is a very important |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1122 word. For our purposes, we can define it by saying that a "function" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1123 is a set of instructions to the computer that tell the computer to do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1124 something. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1125 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1126 Now we can begin to understand the error message: `void-function this'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1127 The function (that is, the word `this') does not have a definition of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1128 any set of instructions for the computer to carry out. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1129 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1130 The slightly odd word, `void-function', is designed to cover the way |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1131 Emacs Lisp is implemented, which is that when a symbol does not have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1132 function definition attached to it, the place that should contain the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1133 instructions is `void'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1134 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1135 On the other hand, since we were able to add 2 plus 2 successfully, by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1136 evaluating `(+ 2 2)', we can infer that the symbol `+' must have a set |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1137 of instructions for the computer to obey and those instructions must be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1138 to add the numbers that follow the `+'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1139 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1140 In GNU Emacs version 20, and in earlier versions, you will see only one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1141 line of error message; it will appear in the echo area and look like |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1142 this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1143 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1144 Symbol's function definition is void: this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1145 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1146 (Also, your terminal may beep at you--some do, some don't; and others |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1147 blink. This is just a device to get your attention.) The message goes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1148 away as soon as you type another key, even just to move the cursor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1149 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1150 We know the meaning of the word `Symbol'. It refers to the first atom |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1151 of the list, the word `this'. The word `function' refers to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1152 instructions that tell the computer what to do. (Technically, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1153 symbol tells the computer where to find the instructions, but this is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1154 complication we can ignore for the moment.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1155 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1156 The error message can be understood: `Symbol's function definition is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1157 void: this'. The symbol (that is, the word `this') lacks instructions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1158 for the computer to carry out. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1159 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1160 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1161 File: eintr, Node: Names & Definitions, Next: Lisp Interpreter, Prev: Making Errors, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1162 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1163 1.4 Symbol Names and Function Definitions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1164 ========================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1165 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1166 We can articulate another characteristic of Lisp based on what we have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1167 discussed so far--an important characteristic: a symbol, like `+', is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1168 not itself the set of instructions for the computer to carry out. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1169 Instead, the symbol is used, perhaps temporarily, as a way of locating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1170 the definition or set of instructions. What we see is the name through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1171 which the instructions can be found. Names of people work the same |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1172 way. I can be referred to as `Bob'; however, I am not the letters `B', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1173 `o', `b' but am, or was, the consciousness consistently associated with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1174 a particular life-form. The name is not me, but it can be used to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1175 refer to me. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1176 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1177 In Lisp, one set of instructions can be attached to several names. For |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1178 example, the computer instructions for adding numbers can be linked to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1179 the symbol `plus' as well as to the symbol `+' (and are in some |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1180 dialects of Lisp). Among humans, I can be referred to as `Robert' as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1181 well as `Bob' and by other words as well. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1182 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1183 On the other hand, a symbol can have only one function definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1184 attached to it at a time. Otherwise, the computer would be confused as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1185 to which definition to use. If this were the case among people, only |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1186 one person in the world could be named `Bob'. However, the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1187 definition to which the name refers can be changed readily. (*Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1188 Install a Function Definition: Install.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1189 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1190 Since Emacs Lisp is large, it is customary to name symbols in a way |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1191 that identifies the part of Emacs to which the function belongs. Thus, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1192 all the names for functions that deal with Texinfo start with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1193 `texinfo-' and those for functions that deal with reading mail start |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1194 with `rmail-'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1195 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1196 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1197 File: eintr, Node: Lisp Interpreter, Next: Evaluation, Prev: Names & Definitions, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1198 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1199 1.5 The Lisp Interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1200 ======================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1201 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1202 Based on what we have seen, we can now start to figure out what the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1203 Lisp interpreter does when we command it to evaluate a list. First, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1204 looks to see whether there is a quote before the list; if there is, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1205 interpreter just gives us the list. On the other hand, if there is no |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1206 quote, the interpreter looks at the first element in the list and sees |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1207 whether it has a function definition. If it does, the interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1208 carries out the instructions in the function definition. Otherwise, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1209 the interpreter prints an error message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1210 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1211 This is how Lisp works. Simple. There are added complications which we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1212 will get to in a minute, but these are the fundamentals. Of course, to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1213 write Lisp programs, you need to know how to write function definitions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1214 and attach them to names, and how to do this without confusing either |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1215 yourself or the computer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1216 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1217 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1218 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1219 * Complications:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1220 * Byte Compiling:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1221 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1222 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1223 File: eintr, Node: Complications, Next: Byte Compiling, Prev: Lisp Interpreter, Up: Lisp Interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1224 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1225 Complications |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1226 ------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1227 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1228 Now, for the first complication. In addition to lists, the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1229 interpreter can evaluate a symbol that is not quoted and does not have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1230 parentheses around it. The Lisp interpreter will attempt to determine |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1231 the symbol's value as a "variable". This situation is described in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1232 section on variables. (*Note Variables::.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1233 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1234 The second complication occurs because some functions are unusual and do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1235 not work in the usual manner. Those that don't are called "special |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1236 forms". They are used for special jobs, like defining a function, and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1237 there are not many of them. In the next few chapters, you will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1238 introduced to several of the more important special forms. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1239 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1240 The third and final complication is this: if the function that the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1241 interpreter is looking at is not a special form, and if it is part of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1242 list, the Lisp interpreter looks to see whether the list has a list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1243 inside of it. If there is an inner list, the Lisp interpreter first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1244 figures out what it should do with the inside list, and then it works on |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1245 the outside list. If there is yet another list embedded inside the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1246 inner list, it works on that one first, and so on. It always works on |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1247 the innermost list first. The interpreter works on the innermost list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1248 first, to evaluate the result of that list. The result may be used by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1249 the enclosing expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1250 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1251 Otherwise, the interpreter works left to right, from one expression to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1252 the next. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1253 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1254 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1255 File: eintr, Node: Byte Compiling, Prev: Complications, Up: Lisp Interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1256 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1257 1.5.1 Byte Compiling |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1258 -------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1259 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1260 One other aspect of interpreting: the Lisp interpreter is able to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1261 interpret two kinds of entity: humanly readable code, on which we will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1262 focus exclusively, and specially processed code, called "byte compiled" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1263 code, which is not humanly readable. Byte compiled code runs faster |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1264 than humanly readable code. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1265 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1266 You can transform humanly readable code into byte compiled code by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1267 running one of the compile commands such as `byte-compile-file'. Byte |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1268 compiled code is usually stored in a file that ends with a `.elc' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1269 extension rather than a `.el' extension. You will see both kinds of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1270 file in the `emacs/lisp' directory; the files to read are those with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1271 `.el' extensions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1272 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1273 As a practical matter, for most things you might do to customize or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1274 extend Emacs, you do not need to byte compile; and I will not discuss |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1275 the topic here. *Note Byte Compilation: (elisp)Byte Compilation, for a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1276 full description of byte compilation. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1277 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1278 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1279 File: eintr, Node: Evaluation, Next: Variables, Prev: Lisp Interpreter, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1280 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1281 1.6 Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1282 ============== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1283 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1284 When the Lisp interpreter works on an expression, the term for the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1285 activity is called "evaluation". We say that the interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1286 `evaluates the expression'. I've used this term several times before. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1287 The word comes from its use in everyday language, `to ascertain the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1288 value or amount of; to appraise', according to `Webster's New |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1289 Collegiate Dictionary'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1290 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1291 After evaluating an expression, the Lisp interpreter will most likely |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1292 "return" the value that the computer produces by carrying out the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1293 instructions it found in the function definition, or perhaps it will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1294 give up on that function and produce an error message. (The interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1295 may also find itself tossed, so to speak, to a different function or it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1296 may attempt to repeat continually what it is doing for ever and ever in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1297 what is called an `infinite loop'. These actions are less common; and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1298 we can ignore them.) Most frequently, the interpreter returns a value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1299 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1300 At the same time the interpreter returns a value, it may do something |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1301 else as well, such as move a cursor or copy a file; this other kind of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1302 action is called a "side effect". Actions that we humans think are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1303 important, such as printing results, are often "side effects" to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1304 Lisp interpreter. The jargon can sound peculiar, but it turns out that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1305 it is fairly easy to learn to use side effects. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1306 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1307 In summary, evaluating a symbolic expression most commonly causes the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1308 Lisp interpreter to return a value and perhaps carry out a side effect; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1309 or else produce an error. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1310 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1311 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1312 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1313 * Evaluating Inner Lists:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1314 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1315 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1316 File: eintr, Node: Evaluating Inner Lists, Prev: Evaluation, Up: Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1317 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1318 1.6.1 Evaluating Inner Lists |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1319 ---------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1320 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1321 If evaluation applies to a list that is inside another list, the outer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1322 list may use the value returned by the first evaluation as information |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1323 when the outer list is evaluated. This explains why inner expressions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1324 are evaluated first: the values they return are used by the outer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1325 expressions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1326 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1327 We can investigate this process by evaluating another addition example. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1328 Place your cursor after the following expression and type `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1329 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1330 (+ 2 (+ 3 3)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1331 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1332 The number 8 will appear in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1333 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1334 What happens is that the Lisp interpreter first evaluates the inner |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1335 expression, `(+ 3 3)', for which the value 6 is returned; then it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1336 evaluates the outer expression as if it were written `(+ 2 6)', which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1337 returns the value 8. Since there are no more enclosing expressions to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1338 evaluate, the interpreter prints that value in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1339 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1340 Now it is easy to understand the name of the command invoked by the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1341 keystrokes `C-x C-e': the name is `eval-last-sexp'. The letters `sexp' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1342 are an abbreviation for `symbolic expression', and `eval' is an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1343 abbreviation for `evaluate'. The command means `evaluate last symbolic |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1344 expression'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1345 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1346 As an experiment, you can try evaluating the expression by putting the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1347 cursor at the beginning of the next line immediately following the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1348 expression, or inside the expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1349 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1350 Here is another copy of the expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1351 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1352 (+ 2 (+ 3 3)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1353 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1354 If you place the cursor at the beginning of the blank line that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1355 immediately follows the expression and type `C-x C-e', you will still |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1356 get the value 8 printed in the echo area. Now try putting the cursor |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1357 inside the expression. If you put it right after the next to last |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1358 parenthesis (so it appears to sit on top of the last parenthesis), you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1359 will get a 6 printed in the echo area! This is because the command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1360 evaluates the expression `(+ 3 3)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1361 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1362 Now put the cursor immediately after a number. Type `C-x C-e' and you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1363 will get the number itself. In Lisp, if you evaluate a number, you get |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1364 the number itself--this is how numbers differ from symbols. If you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1365 evaluate a list starting with a symbol like `+', you will get a value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1366 returned that is the result of the computer carrying out the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1367 instructions in the function definition attached to that name. If a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1368 symbol by itself is evaluated, something different happens, as we will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1369 see in the next section. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1370 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1371 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1372 File: eintr, Node: Variables, Next: Arguments, Prev: Evaluation, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1373 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1374 1.7 Variables |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1375 ============= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1376 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1377 In Emacs Lisp, a symbol can have a value attached to it just as it can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1378 have a function definition attached to it. The two are different. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1379 function definition is a set of instructions that a computer will obey. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1380 A value, on the other hand, is something, such as number or a name, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1381 that can vary (which is why such a symbol is called a variable). The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1382 value of a symbol can be any expression in Lisp, such as a symbol, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1383 number, list, or string. A symbol that has a value is often called a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1384 "variable". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1385 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1386 A symbol can have both a function definition and a value attached to it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1387 at the same time. Or it can have just one or the other. The two are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1388 separate. This is somewhat similar to the way the name Cambridge can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1389 refer to the city in Massachusetts and have some information attached |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1390 to the name as well, such as "great programming center". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1391 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1392 Another way to think about this is to imagine a symbol as being a chest |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1393 of drawers. The function definition is put in one drawer, the value in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1394 another, and so on. What is put in the drawer holding the value can be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1395 changed without affecting the contents of the drawer holding the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1396 function definition, and vice-verse. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1397 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1398 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1399 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1400 * fill-column Example:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1401 * Void Function:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1402 * Void Variable:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1403 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1404 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1405 File: eintr, Node: fill-column Example, Next: Void Function, Prev: Variables, Up: Variables |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1406 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1407 `fill-column', an Example Variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1408 ---------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1409 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1410 The variable `fill-column' illustrates a symbol with a value attached |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1411 to it: in every GNU Emacs buffer, this symbol is set to some value, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1412 usually 72 or 70, but sometimes to some other value. To find the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1413 of this symbol, evaluate it by itself. If you are reading this in Info |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1414 inside of GNU Emacs, you can do this by putting the cursor after the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1415 symbol and typing `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1416 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1417 fill-column |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1418 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1419 After I typed `C-x C-e', Emacs printed the number 72 in my echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1420 This is the value for which `fill-column' is set for me as I write |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1421 this. It may be different for you in your Info buffer. Notice that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1422 the value returned as a variable is printed in exactly the same way as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1423 the value returned by a function carrying out its instructions. From |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1424 the point of view of the Lisp interpreter, a value returned is a value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1425 returned. What kind of expression it came from ceases to matter once |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1426 the value is known. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1427 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1428 A symbol can have any value attached to it or, to use the jargon, we can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1429 "bind" the variable to a value: to a number, such as 72; to a string, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1430 `"such as this"'; to a list, such as `(spruce pine oak)'; we can even |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1431 bind a variable to a function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1432 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1433 A symbol can be bound to a value in several ways. *Note Setting the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1434 Value of a Variable: set & setq, for information about one way to do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1435 this. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1436 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1437 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1438 File: eintr, Node: Void Function, Next: Void Variable, Prev: fill-column Example, Up: Variables |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1439 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1440 1.7.1 Error Message for a Symbol Without a Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1441 --------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1442 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1443 When we evaluated `fill-column' to find its value as a variable, we did |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1444 not place parentheses around the word. This is because we did not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1445 intend to use it as a function name. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1446 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1447 If `fill-column' were the first or only element of a list, the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1448 interpreter would attempt to find the function definition attached to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1449 it. But `fill-column' has no function definition. Try evaluating this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1450 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1451 (fill-column) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1452 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1453 In GNU Emacs version 22, you will create a `*Backtrace*' buffer that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1454 says: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1455 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1456 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1457 Debugger entered--Lisp error: (void-function fill-column) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1458 (fill-column) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1459 eval((fill-column)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1460 eval-last-sexp-1(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1461 eval-last-sexp(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1462 call-interactively(eval-last-sexp) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1463 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1464 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1465 (Remember, to quit the debugger and make the debugger window go away, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1466 type `q' in the `*Backtrace*' buffer.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1467 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1468 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1469 File: eintr, Node: Void Variable, Prev: Void Function, Up: Variables |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1470 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1471 1.7.2 Error Message for a Symbol Without a Value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1472 ------------------------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1473 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1474 If you attempt to evaluate a symbol that does not have a value bound to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1475 it, you will receive an error message. You can see this by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1476 experimenting with our 2 plus 2 addition. In the following expression, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1477 put your cursor right after the `+', before the first number 2, type |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1478 `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1479 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1480 (+ 2 2) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1481 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1482 In GNU Emacs 22, you will create a `*Backtrace*' buffer that says: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1483 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1484 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1485 Debugger entered--Lisp error: (void-variable +) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1486 eval(+) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1487 eval-last-sexp-1(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1488 eval-last-sexp(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1489 call-interactively(eval-last-sexp) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1490 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1491 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1492 (As with the other times we entered the debugger, you can quit by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1493 typing `q' in the `*Backtrace*' buffer.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1494 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1495 This backtrace is different from the very first error message we saw, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1496 which said, `Debugger entered--Lisp error: (void-function this)'. In |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1497 this case, the function does not have a value as a variable; while in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1498 the other error message, the function (the word `this') did not have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1499 definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1500 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1501 In this experiment with the `+', what we did was cause the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1502 interpreter to evaluate the `+' and look for the value of the variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1503 instead of the function definition. We did this by placing the cursor |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1504 right after the symbol rather than after the parenthesis of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1505 enclosing list as we did before. As a consequence, the Lisp interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1506 evaluated the preceding s-expression, which in this case was the `+' by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1507 itself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1508 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1509 Since `+' does not have a value bound to it, just the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1510 definition, the error message reported that the symbol's value as a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1511 variable was void. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1512 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1513 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1514 File: eintr, Node: Arguments, Next: set & setq, Prev: Variables, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1515 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1516 1.8 Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1517 ============= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1518 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1519 To see how information is passed to functions, let's look again at our |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1520 old standby, the addition of two plus two. In Lisp, this is written as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1521 follows: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1522 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1523 (+ 2 2) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1524 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1525 If you evaluate this expression, the number 4 will appear in your echo |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1526 area. What the Lisp interpreter does is add the numbers that follow |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1527 the `+'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1528 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1529 The numbers added by `+' are called the "arguments" of the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1530 `+'. These numbers are the information that is given to or "passed" to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1531 the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1532 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1533 The word `argument' comes from the way it is used in mathematics and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1534 does not refer to a disputation between two people; instead it refers to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1535 the information presented to the function, in this case, to the `+'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1536 In Lisp, the arguments to a function are the atoms or lists that follow |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1537 the function. The values returned by the evaluation of these atoms or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1538 lists are passed to the function. Different functions require |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1539 different numbers of arguments; some functions require none at all.(1) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1540 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1541 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1542 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1543 * Data types:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1544 * Args as Variable or List:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1545 * Variable Number of Arguments:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1546 * Wrong Type of Argument:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1547 * message:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1548 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1549 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1550 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1551 (1) It is curious to track the path by which the word `argument' came |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1552 to have two different meanings, one in mathematics and the other in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1553 everyday English. According to the `Oxford English Dictionary', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1554 word derives from the Latin for `to make clear, prove'; thus it came to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1555 mean, by one thread of derivation, `the evidence offered as proof', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1556 which is to say, `the information offered', which led to its meaning in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1557 Lisp. But in the other thread of derivation, it came to mean `to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1558 assert in a manner against which others may make counter assertions', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1559 which led to the meaning of the word as a disputation. (Note here that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1560 the English word has two different definitions attached to it at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1561 same time. By contrast, in Emacs Lisp, a symbol cannot have two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1562 different function definitions at the same time.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1563 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1564 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1565 File: eintr, Node: Data types, Next: Args as Variable or List, Prev: Arguments, Up: Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1566 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1567 1.8.1 Arguments' Data Types |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1568 --------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1569 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1570 The type of data that should be passed to a function depends on what |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1571 kind of information it uses. The arguments to a function such as `+' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1572 must have values that are numbers, since `+' adds numbers. Other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1573 functions use different kinds of data for their arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1574 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1575 For example, the `concat' function links together or unites two or more |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1576 strings of text to produce a string. The arguments are strings. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1577 Concatenating the two character strings `abc', `def' produces the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1578 single string `abcdef'. This can be seen by evaluating the following: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1579 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1580 (concat "abc" "def") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1581 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1582 The value produced by evaluating this expression is `"abcdef"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1583 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1584 A function such as `substring' uses both a string and numbers as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1585 arguments. The function returns a part of the string, a substring of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1586 the first argument. This function takes three arguments. Its first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1587 argument is the string of characters, the second and third arguments are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1588 numbers that indicate the beginning and end of the substring. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1589 numbers are a count of the number of characters (including spaces and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1590 punctuations) from the beginning of the string. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1591 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1592 For example, if you evaluate the following: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1593 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1594 (substring "The quick brown fox jumped." 16 19) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1595 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1596 you will see `"fox"' appear in the echo area. The arguments are the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1597 string and the two numbers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1598 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1599 Note that the string passed to `substring' is a single atom even though |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1600 it is made up of several words separated by spaces. Lisp counts |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1601 everything between the two quotation marks as part of the string, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1602 including the spaces. You can think of the `substring' function as a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1603 kind of `atom smasher' since it takes an otherwise indivisible atom and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1604 extracts a part. However, `substring' is only able to extract a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1605 substring from an argument that is a string, not from another type of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1606 atom such as a number or symbol. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1607 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1608 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1609 File: eintr, Node: Args as Variable or List, Next: Variable Number of Arguments, Prev: Data types, Up: Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1610 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1611 1.8.2 An Argument as the Value of a Variable or List |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1612 ---------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1613 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1614 An argument can be a symbol that returns a value when it is evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1615 For example, when the symbol `fill-column' by itself is evaluated, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1616 returns a number. This number can be used in an addition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1617 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1618 Position the cursor after the following expression and type `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1619 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1620 (+ 2 fill-column) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1621 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1622 The value will be a number two more than what you get by evaluating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1623 `fill-column' alone. For me, this is 74, because my value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1624 `fill-column' is 72. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1625 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1626 As we have just seen, an argument can be a symbol that returns a value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1627 when evaluated. In addition, an argument can be a list that returns a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1628 value when it is evaluated. For example, in the following expression, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1629 the arguments to the function `concat' are the strings `"The "' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1630 `" red foxes."' and the list `(number-to-string (+ 2 fill-column))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1631 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1632 (concat "The " (number-to-string (+ 2 fill-column)) " red foxes.") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1633 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1634 If you evaluate this expression--and if, as with my Emacs, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1635 `fill-column' evaluates to 72--`"The 74 red foxes."' will appear in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1636 echo area. (Note that you must put spaces after the word `The' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1637 before the word `red' so they will appear in the final string. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1638 function `number-to-string' converts the integer that the addition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1639 function returns to a string. `number-to-string' is also known as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1640 `int-to-string'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1641 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1642 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1643 File: eintr, Node: Variable Number of Arguments, Next: Wrong Type of Argument, Prev: Args as Variable or List, Up: Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1644 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1645 1.8.3 Variable Number of Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1646 ---------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1647 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1648 Some functions, such as `concat', `+' or `*', take any number of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1649 arguments. (The `*' is the symbol for multiplication.) This can be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1650 seen by evaluating each of the following expressions in the usual way. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1651 What you will see in the echo area is printed in this text after `=>', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1652 which you may read as `evaluates to'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1653 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1654 In the first set, the functions have no arguments: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1655 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1656 (+) => 0 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1657 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1658 (*) => 1 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1659 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1660 In this set, the functions have one argument each: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1661 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1662 (+ 3) => 3 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1663 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1664 (* 3) => 3 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1665 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1666 In this set, the functions have three arguments each: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1667 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1668 (+ 3 4 5) => 12 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1669 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1670 (* 3 4 5) => 60 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1671 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1672 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1673 File: eintr, Node: Wrong Type of Argument, Next: message, Prev: Variable Number of Arguments, Up: Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1674 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1675 1.8.4 Using the Wrong Type Object as an Argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1676 ------------------------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1677 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1678 When a function is passed an argument of the wrong type, the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1679 interpreter produces an error message. For example, the `+' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1680 expects the values of its arguments to be numbers. As an experiment we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1681 can pass it the quoted symbol `hello' instead of a number. Position |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1682 the cursor after the following expression and type `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1683 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1684 (+ 2 'hello) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1685 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1686 When you do this you will generate an error message. What has happened |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1687 is that `+' has tried to add the 2 to the value returned by `'hello', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1688 but the value returned by `'hello' is the symbol `hello', not a number. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1689 Only numbers can be added. So `+' could not carry out its addition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1690 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1691 In GNU Emacs version 22, you will create and enter a `*Backtrace*' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1692 buffer that says: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1693 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1694 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1695 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1696 Debugger entered--Lisp error: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1697 (wrong-type-argument number-or-marker-p hello) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1698 +(2 hello) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1699 eval((+ 2 (quote hello))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1700 eval-last-sexp-1(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1701 eval-last-sexp(nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1702 call-interactively(eval-last-sexp) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1703 ---------- Buffer: *Backtrace* ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1704 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1705 As usual, the error message tries to be helpful and makes sense after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1706 you learn how to read it.(1) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1707 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1708 The first part of the error message is straightforward; it says `wrong |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1709 type argument'. Next comes the mysterious jargon word |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1710 `number-or-marker-p'. This word is trying to tell you what kind of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1711 argument the `+' expected. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1712 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1713 The symbol `number-or-marker-p' says that the Lisp interpreter is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1714 trying to determine whether the information presented it (the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1715 the argument) is a number or a marker (a special object representing a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1716 buffer position). What it does is test to see whether the `+' is being |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1717 given numbers to add. It also tests to see whether the argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1718 something called a marker, which is a specific feature of Emacs Lisp. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1719 (In Emacs, locations in a buffer are recorded as markers. When the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1720 mark is set with the `C-@' or `C-<SPC>' command, its position is kept |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1721 as a marker. The mark can be considered a number--the number of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1722 characters the location is from the beginning of the buffer.) In Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1723 Lisp, `+' can be used to add the numeric value of marker positions as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1724 numbers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1725 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1726 The `p' of `number-or-marker-p' is the embodiment of a practice started |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1727 in the early days of Lisp programming. The `p' stands for `predicate'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1728 In the jargon used by the early Lisp researchers, a predicate refers |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1729 to a function to determine whether some property is true or false. So |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1730 the `p' tells us that `number-or-marker-p' is the name of a function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1731 that determines whether it is true or false that the argument supplied |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1732 is a number or a marker. Other Lisp symbols that end in `p' include |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1733 `zerop', a function that tests whether its argument has the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1734 zero, and `listp', a function that tests whether its argument is a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1735 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1736 Finally, the last part of the error message is the symbol `hello'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1737 This is the value of the argument that was passed to `+'. If the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1738 addition had been passed the correct type of object, the value passed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1739 would have been a number, such as 37, rather than a symbol like |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1740 `hello'. But then you would not have got the error message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1741 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1742 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1743 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1744 (1) `(quote hello)' is an expansion of the abbreviation `'hello'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1745 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1746 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1747 File: eintr, Node: message, Prev: Wrong Type of Argument, Up: Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1748 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1749 1.8.5 The `message' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1750 ---------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1751 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1752 Like `+', the `message' function takes a variable number of arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1753 It is used to send messages to the user and is so useful that we will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1754 describe it here. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1755 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1756 A message is printed in the echo area. For example, you can print a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1757 message in your echo area by evaluating the following list: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1758 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1759 (message "This message appears in the echo area!") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1760 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1761 The whole string between double quotation marks is a single argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1762 and is printed in toto. (Note that in this example, the message itself |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1763 will appear in the echo area within double quotes; that is because you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1764 see the value returned by the `message' function. In most uses of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1765 `message' in programs that you write, the text will be printed in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1766 echo area as a side-effect, without the quotes. *Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1767 `multiply-by-seven' in detail: multiply-by-seven in detail, for an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1768 example of this.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1769 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1770 However, if there is a `%s' in the quoted string of characters, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1771 `message' function does not print the `%s' as such, but looks to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1772 argument that follows the string. It evaluates the second argument and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1773 prints the value at the location in the string where the `%s' is. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1774 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1775 You can see this by positioning the cursor after the following |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1776 expression and typing `C-x C-e': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1777 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1778 (message "The name of this buffer is: %s." (buffer-name)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1779 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1780 In Info, `"The name of this buffer is: *info*."' will appear in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1781 echo area. The function `buffer-name' returns the name of the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1782 as a string, which the `message' function inserts in place of `%s'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1783 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1784 To print a value as an integer, use `%d' in the same way as `%s'. For |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1785 example, to print a message in the echo area that states the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1786 the `fill-column', evaluate the following: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1787 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1788 (message "The value of fill-column is %d." fill-column) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1789 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1790 On my system, when I evaluate this list, `"The value of fill-column is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1791 72."' appears in my echo area(1). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1792 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1793 If there is more than one `%s' in the quoted string, the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1794 first argument following the quoted string is printed at the location |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1795 of the first `%s' and the value of the second argument is printed at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1796 the location of the second `%s', and so on. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1797 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1798 For example, if you evaluate the following, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1799 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1800 (message "There are %d %s in the office!" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1801 (- fill-column 14) "pink elephants") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1802 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1803 a rather whimsical message will appear in your echo area. On my system |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1804 it says, `"There are 58 pink elephants in the office!"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1805 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1806 The expression `(- fill-column 14)' is evaluated and the resulting |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1807 number is inserted in place of the `%d'; and the string in double |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1808 quotes, `"pink elephants"', is treated as a single argument and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1809 inserted in place of the `%s'. (That is to say, a string between |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1810 double quotes evaluates to itself, like a number.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1811 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1812 Finally, here is a somewhat complex example that not only illustrates |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1813 the computation of a number, but also shows how you can use an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1814 expression within an expression to generate the text that is substituted |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1815 for `%s': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1816 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1817 (message "He saw %d %s" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1818 (- fill-column 32) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1819 (concat "red " |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1820 (substring |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1821 "The quick brown foxes jumped." 16 21) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1822 " leaping.")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1823 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1824 In this example, `message' has three arguments: the string, `"He saw %d |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1825 %s"', the expression, `(- fill-column 32)', and the expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1826 beginning with the function `concat'. The value resulting from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1827 evaluation of `(- fill-column 32)' is inserted in place of the `%d'; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1828 and the value returned by the expression beginning with `concat' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1829 inserted in place of the `%s'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1830 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1831 When your fill column is 70 and you evaluate the expression, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1832 message `"He saw 38 red foxes leaping."' appears in your echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1833 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1834 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1835 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1836 (1) Actually, you can use `%s' to print a number. It is non-specific. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1837 `%d' prints only the part of a number left of a decimal point, and not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1838 anything that is not a number. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1839 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1840 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1841 File: eintr, Node: set & setq, Next: Summary, Prev: Arguments, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1842 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1843 1.9 Setting the Value of a Variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1844 =================================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1845 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1846 There are several ways by which a variable can be given a value. One of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1847 the ways is to use either the function `set' or the function `setq'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1848 Another way is to use `let' (*note let::). (The jargon for this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1849 process is to "bind" a variable to a value.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1850 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1851 The following sections not only describe how `set' and `setq' work but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1852 also illustrate how arguments are passed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1853 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1854 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1855 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1856 * Using set:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1857 * Using setq:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1858 * Counting:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1859 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1860 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1861 File: eintr, Node: Using set, Next: Using setq, Prev: set & setq, Up: set & setq |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1862 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1863 1.9.1 Using `set' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1864 ----------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1865 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1866 To set the value of the symbol `flowers' to the list `'(rose violet |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1867 daisy buttercup)', evaluate the following expression by positioning the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1868 cursor after the expression and typing `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1869 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1870 (set 'flowers '(rose violet daisy buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1871 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1872 The list `(rose violet daisy buttercup)' will appear in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1873 This is what is _returned_ by the `set' function. As a side effect, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1874 the symbol `flowers' is bound to the list; that is, the symbol |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1875 `flowers', which can be viewed as a variable, is given the list as its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1876 value. (This process, by the way, illustrates how a side effect to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1877 Lisp interpreter, setting the value, can be the primary effect that we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1878 humans are interested in. This is because every Lisp function must |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1879 return a value if it does not get an error, but it will only have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1880 side effect if it is designed to have one.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1881 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1882 After evaluating the `set' expression, you can evaluate the symbol |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1883 `flowers' and it will return the value you just set. Here is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1884 symbol. Place your cursor after it and type `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1885 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1886 flowers |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1887 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1888 When you evaluate `flowers', the list `(rose violet daisy buttercup)' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1889 appears in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1890 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1891 Incidentally, if you evaluate `'flowers', the variable with a quote in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1892 front of it, what you will see in the echo area is the symbol itself, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1893 `flowers'. Here is the quoted symbol, so you can try this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1894 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1895 'flowers |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1896 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1897 Note also, that when you use `set', you need to quote both arguments to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1898 `set', unless you want them evaluated. Since we do not want either |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1899 argument evaluated, neither the variable `flowers' nor the list `(rose |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1900 violet daisy buttercup)', both are quoted. (When you use `set' without |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1901 quoting its first argument, the first argument is evaluated before |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1902 anything else is done. If you did this and `flowers' did not have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1903 value already, you would get an error message that the `Symbol's value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1904 as variable is void'; on the other hand, if `flowers' did return a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1905 value after it was evaluated, the `set' would attempt to set the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1906 that was returned. There are situations where this is the right thing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1907 for the function to do; but such situations are rare.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1908 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1909 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1910 File: eintr, Node: Using setq, Next: Counting, Prev: Using set, Up: set & setq |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1911 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1912 1.9.2 Using `setq' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1913 ------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1914 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1915 As a practical matter, you almost always quote the first argument to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1916 `set'. The combination of `set' and a quoted first argument is so |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1917 common that it has its own name: the special form `setq'. This special |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1918 form is just like `set' except that the first argument is quoted |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1919 automatically, so you don't need to type the quote mark yourself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1920 Also, as an added convenience, `setq' permits you to set several |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1921 different variables to different values, all in one expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1922 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1923 To set the value of the variable `carnivores' to the list `'(lion tiger |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1924 leopard)' using `setq', the following expression is used: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1925 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1926 (setq carnivores '(lion tiger leopard)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1927 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1928 This is exactly the same as using `set' except the first argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1929 automatically quoted by `setq'. (The `q' in `setq' means `quote'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1930 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1931 With `set', the expression would look like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1932 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1933 (set 'carnivores '(lion tiger leopard)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1934 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1935 Also, `setq' can be used to assign different values to different |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1936 variables. The first argument is bound to the value of the second |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1937 argument, the third argument is bound to the value of the fourth |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1938 argument, and so on. For example, you could use the following to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1939 assign a list of trees to the symbol `trees' and a list of herbivores |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1940 to the symbol `herbivores': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1941 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1942 (setq trees '(pine fir oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1943 herbivores '(gazelle antelope zebra)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1944 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1945 (The expression could just as well have been on one line, but it might |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1946 not have fit on a page; and humans find it easier to read nicely |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1947 formatted lists.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1948 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1949 Although I have been using the term `assign', there is another way of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1950 thinking about the workings of `set' and `setq'; and that is to say |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1951 that `set' and `setq' make the symbol _point_ to the list. This latter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1952 way of thinking is very common and in forthcoming chapters we shall |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1953 come upon at least one symbol that has `pointer' as part of its name. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1954 The name is chosen because the symbol has a value, specifically a list, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1955 attached to it; or, expressed another way, the symbol is set to "point" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1956 to the list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1957 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1958 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1959 File: eintr, Node: Counting, Prev: Using setq, Up: set & setq |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1960 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1961 1.9.3 Counting |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1962 -------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1963 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1964 Here is an example that shows how to use `setq' in a counter. You |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1965 might use this to count how many times a part of your program repeats |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1966 itself. First set a variable to zero; then add one to the number each |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1967 time the program repeats itself. To do this, you need a variable that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1968 serves as a counter, and two expressions: an initial `setq' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1969 that sets the counter variable to zero; and a second `setq' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1970 that increments the counter each time it is evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1971 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1972 (setq counter 0) ; Let's call this the initializer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1973 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1974 (setq counter (+ counter 1)) ; This is the incrementer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1975 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1976 counter ; This is the counter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1977 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1978 (The text following the `;' are comments. *Note Change a Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1979 Definition: Change a defun.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1980 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1981 If you evaluate the first of these expressions, the initializer, `(setq |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1982 counter 0)', and then evaluate the third expression, `counter', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1983 number `0' will appear in the echo area. If you then evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1984 second expression, the incrementer, `(setq counter (+ counter 1))', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1985 counter will get the value 1. So if you again evaluate `counter', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1986 number `1' will appear in the echo area. Each time you evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1987 second expression, the value of the counter will be incremented. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1988 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1989 When you evaluate the incrementer, `(setq counter (+ counter 1))', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1990 Lisp interpreter first evaluates the innermost list; this is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1991 addition. In order to evaluate this list, it must evaluate the variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1992 `counter' and the number `1'. When it evaluates the variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1993 `counter', it receives its current value. It passes this value and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1994 number `1' to the `+' which adds them together. The sum is then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1995 returned as the value of the inner list and passed to the `setq' which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1996 sets the variable `counter' to this new value. Thus, the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1997 variable, `counter', is changed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1998 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
1999 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2000 File: eintr, Node: Summary, Next: Error Message Exercises, Prev: set & setq, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2001 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2002 1.10 Summary |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2003 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2004 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2005 Learning Lisp is like climbing a hill in which the first part is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2006 steepest. You have now climbed the most difficult part; what remains |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2007 becomes easier as you progress onwards. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2008 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2009 In summary, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2010 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2011 * Lisp programs are made up of expressions, which are lists or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2012 single atoms. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2013 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2014 * Lists are made up of zero or more atoms or inner lists, separated |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2015 by whitespace and surrounded by parentheses. A list can be empty. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2016 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2017 * Atoms are multi-character symbols, like `forward-paragraph', single |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2018 character symbols like `+', strings of characters between double |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2019 quotation marks, or numbers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2020 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2021 * A number evaluates to itself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2022 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2023 * A string between double quotes also evaluates to itself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2024 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2025 * When you evaluate a symbol by itself, its value is returned. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2026 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2027 * When you evaluate a list, the Lisp interpreter looks at the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2028 symbol in the list and then at the function definition bound to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2029 that symbol. Then the instructions in the function definition are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2030 carried out. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2031 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2032 * A single quotation mark, ' , tells the Lisp interpreter that it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2033 should return the following expression as written, and not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2034 evaluate it as it would if the quote were not there. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2035 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2036 * Arguments are the information passed to a function. The arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2037 to a function are computed by evaluating the rest of the elements |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2038 of the list of which the function is the first element. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2039 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2040 * A function always returns a value when it is evaluated (unless it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2041 gets an error); in addition, it may also carry out some action |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2042 called a "side effect". In many cases, a function's primary |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2043 purpose is to create a side effect. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2044 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2045 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2046 File: eintr, Node: Error Message Exercises, Prev: Summary, Up: List Processing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2047 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2048 1.11 Exercises |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2049 ============== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2050 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2051 A few simple exercises: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2052 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2053 * Generate an error message by evaluating an appropriate symbol that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2054 is not within parentheses. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2055 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2056 * Generate an error message by evaluating an appropriate symbol that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2057 is between parentheses. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2058 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2059 * Create a counter that increments by two rather than one. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2060 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2061 * Write an expression that prints a message in the echo area when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2062 evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2063 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2064 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2065 File: eintr, Node: Practicing Evaluation, Next: Writing Defuns, Prev: List Processing, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2066 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2067 2 Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2068 *********************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2069 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2070 Before learning how to write a function definition in Emacs Lisp, it is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2071 useful to spend a little time evaluating various expressions that have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2072 already been written. These expressions will be lists with the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2073 functions as their first (and often only) element. Since some of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2074 functions associated with buffers are both simple and interesting, we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2075 will start with those. In this section, we will evaluate a few of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2076 these. In another section, we will study the code of several other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2077 buffer-related functions, to see how they were written. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2078 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2079 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2080 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2081 * How to Evaluate:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2082 * Buffer Names:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2083 * Getting Buffers:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2084 * Switching Buffers:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2085 * Buffer Size & Locations:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2086 * Evaluation Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2087 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2088 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2089 File: eintr, Node: How to Evaluate, Next: Buffer Names, Prev: Practicing Evaluation, Up: Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2090 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2091 How to Evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2092 =============== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2093 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2094 Whenever you give an editing command to Emacs Lisp, such as the command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2095 to move the cursor or to scroll the screen, you are evaluating an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2096 expression, the first element of which is a function. This is how |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2097 Emacs works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2098 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2099 When you type keys, you cause the Lisp interpreter to evaluate an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2100 expression and that is how you get your results. Even typing plain text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2101 involves evaluating an Emacs Lisp function, in this case, one that uses |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2102 `self-insert-command', which simply inserts the character you typed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2103 The functions you evaluate by typing keystrokes are called |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2104 "interactive" functions, or "commands"; how you make a function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2105 interactive will be illustrated in the chapter on how to write function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2106 definitions. *Note Making a Function Interactive: Interactive. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2107 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2108 In addition to typing keyboard commands, we have seen a second way to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2109 evaluate an expression: by positioning the cursor after a list and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2110 typing `C-x C-e'. This is what we will do in the rest of this section. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2111 There are other ways to evaluate an expression as well; these will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2112 described as we come to them. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2113 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2114 Besides being used for practicing evaluation, the functions shown in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2115 next few sections are important in their own right. A study of these |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2116 functions makes clear the distinction between buffers and files, how to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2117 switch to a buffer, and how to determine a location within it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2118 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2119 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2120 File: eintr, Node: Buffer Names, Next: Getting Buffers, Prev: How to Evaluate, Up: Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2121 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2122 2.1 Buffer Names |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2123 ================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2124 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2125 The two functions, `buffer-name' and `buffer-file-name', show the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2126 difference between a file and a buffer. When you evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2127 following expression, `(buffer-name)', the name of the buffer appears |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2128 in the echo area. When you evaluate `(buffer-file-name)', the name of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2129 the file to which the buffer refers appears in the echo area. Usually, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2130 the name returned by `(buffer-name)' is the same as the name of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2131 file to which it refers, and the name returned by `(buffer-file-name)' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2132 is the full path-name of the file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2133 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2134 A file and a buffer are two different entities. A file is information |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2135 recorded permanently in the computer (unless you delete it). A buffer, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2136 on the other hand, is information inside of Emacs that will vanish at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2137 the end of the editing session (or when you kill the buffer). Usually, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2138 a buffer contains information that you have copied from a file; we say |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2139 the buffer is "visiting" that file. This copy is what you work on and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2140 modify. Changes to the buffer do not change the file, until you save |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2141 the buffer. When you save the buffer, the buffer is copied to the file |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2142 and is thus saved permanently. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2143 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2144 If you are reading this in Info inside of GNU Emacs, you can evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2145 each of the following expressions by positioning the cursor after it and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2146 typing `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2147 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2148 (buffer-name) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2149 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2150 (buffer-file-name) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2151 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2152 When I do this in Info, the value returned by evaluating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2153 `(buffer-name)' is `"*info*"', and the value returned by evaluating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2154 `(buffer-file-name)' is `nil'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2155 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2156 On the other hand, while I am writing this Introduction, the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2157 returned by evaluating `(buffer-name)' is `"introduction.texinfo"', and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2158 the value returned by evaluating `(buffer-file-name)' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2159 `"/gnu/work/intro/introduction.texinfo"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2160 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2161 The former is the name of the buffer and the latter is the name of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2162 file. In Info, the buffer name is `"*info*"'. Info does not point to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2163 any file, so the result of evaluating `(buffer-file-name)' is `nil'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2164 The symbol `nil' is from the Latin word for `nothing'; in this case, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2165 means that the buffer is not associated with any file. (In Lisp, `nil' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2166 is also used to mean `false' and is a synonym for the empty list, `()'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2167 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2168 When I am writing, the name of my buffer is `"introduction.texinfo"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2169 The name of the file to which it points is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2170 `"/gnu/work/intro/introduction.texinfo"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2171 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2172 (In the expressions, the parentheses tell the Lisp interpreter to treat |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2173 `buffer-name' and `buffer-file-name' as functions; without the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2174 parentheses, the interpreter would attempt to evaluate the symbols as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2175 variables. *Note Variables::.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2176 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2177 In spite of the distinction between files and buffers, you will often |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2178 find that people refer to a file when they mean a buffer and vice-verse. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2179 Indeed, most people say, "I am editing a file," rather than saying, "I |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2180 am editing a buffer which I will soon save to a file." It is almost |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2181 always clear from context what people mean. When dealing with computer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2182 programs, however, it is important to keep the distinction in mind, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2183 since the computer is not as smart as a person. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2184 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2185 The word `buffer', by the way, comes from the meaning of the word as a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2186 cushion that deadens the force of a collision. In early computers, a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2187 buffer cushioned the interaction between files and the computer's |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2188 central processing unit. The drums or tapes that held a file and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2189 central processing unit were pieces of equipment that were very |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2190 different from each other, working at their own speeds, in spurts. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2191 buffer made it possible for them to work together effectively. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2192 Eventually, the buffer grew from being an intermediary, a temporary |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2193 holding place, to being the place where work is done. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2194 transformation is rather like that of a small seaport that grew into a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2195 great city: once it was merely the place where cargo was warehoused |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2196 temporarily before being loaded onto ships; then it became a business |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2197 and cultural center in its own right. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2198 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2199 Not all buffers are associated with files. For example, a `*scratch*' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2200 buffer does not visit any file. Similarly, a `*Help*' buffer is not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2201 associated with any file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2202 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2203 In the old days, when you lacked a `~/.emacs' file and started an Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2204 session by typing the command `emacs' alone, without naming any files, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2205 Emacs started with the `*scratch*' buffer visible. Nowadays, you will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2206 see a splash screen. You can follow one of the commands suggested on |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2207 the splash screen, visit a file, or press the spacebar to reach the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2208 `*scratch*' buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2209 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2210 If you switch to the `*scratch*' buffer, type `(buffer-name)', position |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2211 the cursor after it, and then type `C-x C-e' to evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2212 expression. The name `"*scratch*"' will be returned and will appear in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2213 the echo area. `"*scratch*"' is the name of the buffer. When you type |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2214 `(buffer-file-name)' in the `*scratch*' buffer and evaluate that, `nil' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2215 will appear in the echo area, just as it does when you evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2216 `(buffer-file-name)' in Info. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2217 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2218 Incidentally, if you are in the `*scratch*' buffer and want the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2219 returned by an expression to appear in the `*scratch*' buffer itself |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2220 rather than in the echo area, type `C-u C-x C-e' instead of `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2221 This causes the value returned to appear after the expression. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2222 buffer will look like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2223 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2224 (buffer-name)"*scratch*" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2225 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2226 You cannot do this in Info since Info is read-only and it will not allow |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2227 you to change the contents of the buffer. But you can do this in any |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2228 buffer you can edit; and when you write code or documentation (such as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2229 this book), this feature is very useful. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2230 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2231 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2232 File: eintr, Node: Getting Buffers, Next: Switching Buffers, Prev: Buffer Names, Up: Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2233 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2234 2.2 Getting Buffers |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2235 =================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2236 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2237 The `buffer-name' function returns the _name_ of the buffer; to get the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2238 buffer _itself_, a different function is needed: the `current-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2239 function. If you use this function in code, what you get is the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2240 itself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2241 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2242 A name and the object or entity to which the name refers are different |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2243 from each other. You are not your name. You are a person to whom |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2244 others refer by name. If you ask to speak to George and someone hands |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2245 you a card with the letters `G', `e', `o', `r', `g', and `e' written on |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2246 it, you might be amused, but you would not be satisfied. You do not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2247 want to speak to the name, but to the person to whom the name refers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2248 A buffer is similar: the name of the scratch buffer is `*scratch*', but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2249 the name is not the buffer. To get a buffer itself, you need to use a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2250 function such as `current-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2251 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2252 However, there is a slight complication: if you evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2253 `current-buffer' in an expression on its own, as we will do here, what |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2254 you see is a printed representation of the name of the buffer without |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2255 the contents of the buffer. Emacs works this way for two reasons: the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2256 buffer may be thousands of lines long--too long to be conveniently |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2257 displayed; and, another buffer may have the same contents but a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2258 different name, and it is important to distinguish between them. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2259 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2260 Here is an expression containing the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2261 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2262 (current-buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2263 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2264 If you evaluate this expression in Info in Emacs in the usual way, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2265 `#<buffer *info*>' will appear in the echo area. The special format |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2266 indicates that the buffer itself is being returned, rather than just |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2267 its name. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2268 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2269 Incidentally, while you can type a number or symbol into a program, you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2270 cannot do that with the printed representation of a buffer: the only way |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2271 to get a buffer itself is with a function such as `current-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2272 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2273 A related function is `other-buffer'. This returns the most recently |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2274 selected buffer other than the one you are in currently, not a printed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2275 representation of its name. If you have recently switched back and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2276 forth from the `*scratch*' buffer, `other-buffer' will return that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2277 buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2278 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2279 You can see this by evaluating the expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2280 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2281 (other-buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2282 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2283 You should see `#<buffer *scratch*>' appear in the echo area, or the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2284 name of whatever other buffer you switched back from most recently(1). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2285 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2286 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2287 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2288 (1) Actually, by default, if the buffer from which you just switched is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2289 visible to you in another window, `other-buffer' will choose the most |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2290 recent buffer that you cannot see; this is a subtlety that I often |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2291 forget. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2292 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2293 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2294 File: eintr, Node: Switching Buffers, Next: Buffer Size & Locations, Prev: Getting Buffers, Up: Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2295 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2296 2.3 Switching Buffers |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2297 ===================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2298 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2299 The `other-buffer' function actually provides a buffer when it is used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2300 as an argument to a function that requires one. We can see this by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2301 using `other-buffer' and `switch-to-buffer' to switch to a different |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2302 buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2303 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2304 But first, a brief introduction to the `switch-to-buffer' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2305 When you switched back and forth from Info to the `*scratch*' buffer to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2306 evaluate `(buffer-name)', you most likely typed `C-x b' and then typed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2307 `*scratch*'(1) when prompted in the minibuffer for the name of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2308 buffer to which you wanted to switch. The keystrokes, `C-x b', cause |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2309 the Lisp interpreter to evaluate the interactive function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2310 `switch-to-buffer'. As we said before, this is how Emacs works: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2311 different keystrokes call or run different functions. For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2312 `C-f' calls `forward-char', `M-e' calls `forward-sentence', and so on. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2313 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2314 By writing `switch-to-buffer' in an expression, and giving it a buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2315 to switch to, we can switch buffers just the way `C-x b' does. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2316 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2317 Here is the Lisp expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2318 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2319 (switch-to-buffer (other-buffer)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2320 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2321 The symbol `switch-to-buffer' is the first element of the list, so the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2322 Lisp interpreter will treat it as a function and carry out the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2323 instructions that are attached to it. But before doing that, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2324 interpreter will note that `other-buffer' is inside parentheses and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2325 work on that symbol first. `other-buffer' is the first (and in this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2326 case, the only) element of this list, so the Lisp interpreter calls or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2327 runs the function. It returns another buffer. Next, the interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2328 runs `switch-to-buffer', passing to it, as an argument, the other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2329 buffer, which is what Emacs will switch to. If you are reading this in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2330 Info, try this now. Evaluate the expression. (To get back, type `C-x |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2331 b <RET>'.)(2) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2332 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2333 In the programming examples in later sections of this document, you will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2334 see the function `set-buffer' more often than `switch-to-buffer'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2335 is because of a difference between computer programs and humans: humans |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2336 have eyes and expect to see the buffer on which they are working on |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2337 their computer terminals. This is so obvious, it almost goes without |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2338 saying. However, programs do not have eyes. When a computer program |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2339 works on a buffer, that buffer does not need to be visible on the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2340 screen. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2341 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2342 `switch-to-buffer' is designed for humans and does two different |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2343 things: it switches the buffer to which Emacs' attention is directed; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2344 and it switches the buffer displayed in the window to the new buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2345 `set-buffer', on the other hand, does only one thing: it switches the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2346 attention of the computer program to a different buffer. The buffer on |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2347 the screen remains unchanged (of course, normally nothing happens there |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2348 until the command finishes running). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2349 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2350 Also, we have just introduced another jargon term, the word "call". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2351 When you evaluate a list in which the first symbol is a function, you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2352 are calling that function. The use of the term comes from the notion of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2353 the function as an entity that can do something for you if you `call' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2354 it--just as a plumber is an entity who can fix a leak if you call him |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2355 or her. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2356 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2357 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2358 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2359 (1) Or rather, to save typing, you probably only typed `RET' if the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2360 default buffer was `*scratch*', or if it was different, then you typed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2361 just part of the name, such as `*sc', pressed your `TAB' key to cause |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2362 it to expand to the full name, and then typed your `RET' key. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2363 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2364 (2) Remember, this expression will move you to your most recent other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2365 buffer that you cannot see. If you really want to go to your most |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2366 recently selected buffer, even if you can still see it, you need to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2367 evaluate the following more complex expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2368 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2369 (switch-to-buffer (other-buffer (current-buffer) t)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2370 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2371 In this case, the first argument to `other-buffer' tells it which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2372 buffer to skip--the current one--and the second argument tells |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2373 `other-buffer' it is OK to switch to a visible buffer. In regular use, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2374 `switch-to-buffer' takes you to an invisible window since you would |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2375 most likely use `C-x o' (`other-window') to go to another visible |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2376 buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2377 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2378 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2379 File: eintr, Node: Buffer Size & Locations, Next: Evaluation Exercise, Prev: Switching Buffers, Up: Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2380 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2381 2.4 Buffer Size and the Location of Point |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2382 ========================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2383 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2384 Finally, let's look at several rather simple functions, `buffer-size', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2385 `point', `point-min', and `point-max'. These give information about |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2386 the size of a buffer and the location of point within it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2387 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2388 The function `buffer-size' tells you the size of the current buffer; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2389 that is, the function returns a count of the number of characters in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2390 the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2391 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2392 (buffer-size) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2393 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2394 You can evaluate this in the usual way, by positioning the cursor after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2395 the expression and typing `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2396 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2397 In Emacs, the current position of the cursor is called "point". The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2398 expression `(point)' returns a number that tells you where the cursor |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2399 is located as a count of the number of characters from the beginning of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2400 the buffer up to point. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2401 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2402 You can see the character count for point in this buffer by evaluating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2403 the following expression in the usual way: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2404 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2405 (point) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2406 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2407 As I write this, the value of `point' is 65724. The `point' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2408 is frequently used in some of the examples later in this book. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2409 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2410 The value of point depends, of course, on its location within the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2411 buffer. If you evaluate point in this spot, the number will be larger: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2412 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2413 (point) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2414 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2415 For me, the value of point in this location is 66043, which means that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2416 there are 319 characters (including spaces) between the two expressions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2417 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2418 The function `point-min' is somewhat similar to `point', but it returns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2419 the value of the minimum permissible value of point in the current |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2420 buffer. This is the number 1 unless "narrowing" is in effect. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2421 (Narrowing is a mechanism whereby you can restrict yourself, or a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2422 program, to operations on just a part of a buffer. *Note Narrowing and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2423 Widening: Narrowing & Widening.) Likewise, the function `point-max' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2424 returns the value of the maximum permissible value of point in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2425 current buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2426 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2427 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2428 File: eintr, Node: Evaluation Exercise, Prev: Buffer Size & Locations, Up: Practicing Evaluation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2429 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2430 2.5 Exercise |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2431 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2432 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2433 Find a file with which you are working and move towards its middle. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2434 Find its buffer name, file name, length, and your position in the file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2435 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2436 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2437 File: eintr, Node: Writing Defuns, Next: Buffer Walk Through, Prev: Practicing Evaluation, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2438 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2439 3 How To Write Function Definitions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2440 *********************************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2441 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2442 When the Lisp interpreter evaluates a list, it looks to see whether the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2443 first symbol on the list has a function definition attached to it; or, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2444 put another way, whether the symbol points to a function definition. If |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2445 it does, the computer carries out the instructions in the definition. A |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2446 symbol that has a function definition is called, simply, a function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2447 (although, properly speaking, the definition is the function and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2448 symbol refers to it.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2449 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2450 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2451 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2452 * Primitive Functions:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2453 * defun:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2454 * Install:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2455 * Interactive:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2456 * Interactive Options:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2457 * Permanent Installation:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2458 * let:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2459 * if:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2460 * else:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2461 * Truth & Falsehood:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2462 * save-excursion:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2463 * Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2464 * defun Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2465 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2466 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2467 File: eintr, Node: Primitive Functions, Next: defun, Prev: Writing Defuns, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2468 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2469 An Aside about Primitive Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2470 ================================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2471 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2472 All functions are defined in terms of other functions, except for a few |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2473 "primitive" functions that are written in the C programming language. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2474 When you write functions' definitions, you will write them in Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2475 Lisp and use other functions as your building blocks. Some of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2476 functions you will use will themselves be written in Emacs Lisp (perhaps |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2477 by you) and some will be primitives written in C. The primitive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2478 functions are used exactly like those written in Emacs Lisp and behave |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2479 like them. They are written in C so we can easily run GNU Emacs on any |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2480 computer that has sufficient power and can run C. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2481 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2482 Let me re-emphasize this: when you write code in Emacs Lisp, you do not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2483 distinguish between the use of functions written in C and the use of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2484 functions written in Emacs Lisp. The difference is irrelevant. I |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2485 mention the distinction only because it is interesting to know. Indeed, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2486 unless you investigate, you won't know whether an already-written |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2487 function is written in Emacs Lisp or C. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2488 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2489 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2490 File: eintr, Node: defun, Next: Install, Prev: Primitive Functions, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2491 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2492 3.1 The `defun' Special Form |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2493 ============================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2494 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2495 In Lisp, a symbol such as `mark-whole-buffer' has code attached to it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2496 that tells the computer what to do when the function is called. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2497 code is called the "function definition" and is created by evaluating a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2498 Lisp expression that starts with the symbol `defun' (which is an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2499 abbreviation for _define function_). Because `defun' does not evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2500 its arguments in the usual way, it is called a "special form". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2501 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2502 In subsequent sections, we will look at function definitions from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2503 Emacs source code, such as `mark-whole-buffer'. In this section, we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2504 will describe a simple function definition so you can see how it looks. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2505 This function definition uses arithmetic because it makes for a simple |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2506 example. Some people dislike examples using arithmetic; however, if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2507 you are such a person, do not despair. Hardly any of the code we will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2508 study in the remainder of this introduction involves arithmetic or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2509 mathematics. The examples mostly involve text in one way or another. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2510 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2511 A function definition has up to five parts following the word `defun': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2512 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2513 1. The name of the symbol to which the function definition should be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2514 attached. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2515 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2516 2. A list of the arguments that will be passed to the function. If no |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2517 arguments will be passed to the function, this is an empty list, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2518 `()'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2519 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2520 3. Documentation describing the function. (Technically optional, but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2521 strongly recommended.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2522 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2523 4. Optionally, an expression to make the function interactive so you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2524 can use it by typing `M-x' and then the name of the function; or by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2525 typing an appropriate key or keychord. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2526 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2527 5. The code that instructs the computer what to do: the "body" of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2528 function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2529 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2530 It is helpful to think of the five parts of a function definition as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2531 being organized in a template, with slots for each part: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2532 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2533 (defun FUNCTION-NAME (ARGUMENTS...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2534 "OPTIONAL-DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2535 (interactive ARGUMENT-PASSING-INFO) ; optional |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2536 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2537 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2538 As an example, here is the code for a function that multiplies its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2539 argument by 7. (This example is not interactive. *Note Making a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2540 Function Interactive: Interactive, for that information.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2541 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2542 (defun multiply-by-seven (number) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2543 "Multiply NUMBER by seven." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2544 (* 7 number)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2545 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2546 This definition begins with a parenthesis and the symbol `defun', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2547 followed by the name of the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2548 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2549 The name of the function is followed by a list that contains the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2550 arguments that will be passed to the function. This list is called the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2551 "argument list". In this example, the list has only one element, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2552 symbol, `number'. When the function is used, the symbol will be bound |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2553 to the value that is used as the argument to the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2554 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2555 Instead of choosing the word `number' for the name of the argument, I |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2556 could have picked any other name. For example, I could have chosen the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2557 word `multiplicand'. I picked the word `number' because it tells what |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2558 kind of value is intended for this slot; but I could just as well have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2559 chosen the word `multiplicand' to indicate the role that the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2560 placed in this slot will play in the workings of the function. I could |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2561 have called it `foogle', but that would have been a bad choice because |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2562 it would not tell humans what it means. The choice of name is up to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2563 the programmer and should be chosen to make the meaning of the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2564 clear. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2565 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2566 Indeed, you can choose any name you wish for a symbol in an argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2567 list, even the name of a symbol used in some other function: the name |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2568 you use in an argument list is private to that particular definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2569 In that definition, the name refers to a different entity than any use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2570 of the same name outside the function definition. Suppose you have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2571 nick-name `Shorty' in your family; when your family members refer to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2572 `Shorty', they mean you. But outside your family, in a movie, for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2573 example, the name `Shorty' refers to someone else. Because a name in an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2574 argument list is private to the function definition, you can change the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2575 value of such a symbol inside the body of a function without changing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2576 its value outside the function. The effect is similar to that produced |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2577 by a `let' expression. (*Note `let': let.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2578 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2579 The argument list is followed by the documentation string that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2580 describes the function. This is what you see when you type `C-h f' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2581 the name of a function. Incidentally, when you write a documentation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2582 string like this, you should make the first line a complete sentence |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2583 since some commands, such as `apropos', print only the first line of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2584 multi-line documentation string. Also, you should not indent the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2585 second line of a documentation string, if you have one, because that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2586 looks odd when you use `C-h f' (`describe-function'). The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2587 documentation string is optional, but it is so useful, it should be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2588 included in almost every function you write. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2589 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2590 The third line of the example consists of the body of the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2591 definition. (Most functions' definitions, of course, are longer than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2592 this.) In this function, the body is the list, `(* 7 number)', which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2593 says to multiply the value of NUMBER by 7. (In Emacs Lisp, `*' is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2594 function for multiplication, just as `+' is the function for addition.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2595 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2596 When you use the `multiply-by-seven' function, the argument `number' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2597 evaluates to the actual number you want used. Here is an example that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2598 shows how `multiply-by-seven' is used; but don't try to evaluate this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2599 yet! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2600 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2601 (multiply-by-seven 3) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2602 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2603 The symbol `number', specified in the function definition in the next |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2604 section, is given or "bound to" the value 3 in the actual use of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2605 function. Note that although `number' was inside parentheses in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2606 function definition, the argument passed to the `multiply-by-seven' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2607 function is not in parentheses. The parentheses are written in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2608 function definition so the computer can figure out where the argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2609 list ends and the rest of the function definition begins. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2610 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2611 If you evaluate this example, you are likely to get an error message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2612 (Go ahead, try it!) This is because we have written the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2613 definition, but not yet told the computer about the definition--we have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2614 not yet installed (or `loaded') the function definition in Emacs. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2615 Installing a function is the process that tells the Lisp interpreter the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2616 definition of the function. Installation is described in the next |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2617 section. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2618 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2619 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2620 File: eintr, Node: Install, Next: Interactive, Prev: defun, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2621 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2622 3.2 Install a Function Definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2623 ================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2624 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2625 If you are reading this inside of Info in Emacs, you can try out the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2626 `multiply-by-seven' function by first evaluating the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2627 definition and then evaluating `(multiply-by-seven 3)'. A copy of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2628 function definition follows. Place the cursor after the last |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2629 parenthesis of the function definition and type `C-x C-e'. When you do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2630 this, `multiply-by-seven' will appear in the echo area. (What this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2631 means is that when a function definition is evaluated, the value it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2632 returns is the name of the defined function.) At the same time, this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2633 action installs the function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2634 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2635 (defun multiply-by-seven (number) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2636 "Multiply NUMBER by seven." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2637 (* 7 number)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2638 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2639 By evaluating this `defun', you have just installed `multiply-by-seven' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2640 in Emacs. The function is now just as much a part of Emacs as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2641 `forward-word' or any other editing function you use. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2642 (`multiply-by-seven' will stay installed until you quit Emacs. To |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2643 reload code automatically whenever you start Emacs, see *Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2644 Installing Code Permanently: Permanent Installation.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2645 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2646 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2647 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2648 * Effect of installation:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2649 * Change a defun:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2650 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2651 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2652 File: eintr, Node: Effect of installation, Next: Change a defun, Prev: Install, Up: Install |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2653 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2654 The effect of installation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2655 -------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2656 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2657 You can see the effect of installing `multiply-by-seven' by evaluating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2658 the following sample. Place the cursor after the following expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2659 and type `C-x C-e'. The number 21 will appear in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2660 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2661 (multiply-by-seven 3) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2662 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2663 If you wish, you can read the documentation for the function by typing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2664 `C-h f' (`describe-function') and then the name of the function, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2665 `multiply-by-seven'. When you do this, a `*Help*' window will appear |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2666 on your screen that says: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2667 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2668 multiply-by-seven is a Lisp function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2669 (multiply-by-seven NUMBER) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2670 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2671 Multiply NUMBER by seven. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2672 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2673 (To return to a single window on your screen, type `C-x 1'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2674 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2675 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2676 File: eintr, Node: Change a defun, Prev: Effect of installation, Up: Install |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2677 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2678 3.2.1 Change a Function Definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2679 ---------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2680 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2681 If you want to change the code in `multiply-by-seven', just rewrite it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2682 To install the new version in place of the old one, evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2683 function definition again. This is how you modify code in Emacs. It is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2684 very simple. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2685 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2686 As an example, you can change the `multiply-by-seven' function to add |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2687 the number to itself seven times instead of multiplying the number by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2688 seven. It produces the same answer, but by a different path. At the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2689 same time, we will add a comment to the code; a comment is text that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2690 the Lisp interpreter ignores, but that a human reader may find useful |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2691 or enlightening. The comment is that this is the "second version". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2692 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2693 (defun multiply-by-seven (number) ; Second version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2694 "Multiply NUMBER by seven." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2695 (+ number number number number number number number)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2696 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2697 The comment follows a semicolon, `;'. In Lisp, everything on a line |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2698 that follows a semicolon is a comment. The end of the line is the end |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2699 of the comment. To stretch a comment over two or more lines, begin |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2700 each line with a semicolon. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2701 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2702 *Note Beginning a `.emacs' File: Beginning a .emacs File, and *Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2703 Comments: (elisp)Comments, for more about comments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2704 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2705 You can install this version of the `multiply-by-seven' function by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2706 evaluating it in the same way you evaluated the first function: place |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2707 the cursor after the last parenthesis and type `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2708 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2709 In summary, this is how you write code in Emacs Lisp: you write a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2710 function; install it; test it; and then make fixes or enhancements and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2711 install it again. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2712 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2713 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2714 File: eintr, Node: Interactive, Next: Interactive Options, Prev: Install, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2715 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2716 3.3 Make a Function Interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2717 =============================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2718 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2719 You make a function interactive by placing a list that begins with the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2720 special form `interactive' immediately after the documentation. A user |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2721 can invoke an interactive function by typing `M-x' and then the name of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2722 the function; or by typing the keys to which it is bound, for example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2723 by typing `C-n' for `next-line' or `C-x h' for `mark-whole-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2724 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2725 Interestingly, when you call an interactive function interactively, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2726 value returned is not automatically displayed in the echo area. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2727 is because you often call an interactive function for its side effects, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2728 such as moving forward by a word or line, and not for the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2729 returned. If the returned value were displayed in the echo area each |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2730 time you typed a key, it would be very distracting. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2731 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2732 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2733 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2734 * Interactive multiply-by-seven:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2735 * multiply-by-seven in detail:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2736 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2737 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2738 File: eintr, Node: Interactive multiply-by-seven, Next: multiply-by-seven in detail, Prev: Interactive, Up: Interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2739 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2740 An Interactive `multiply-by-seven', An Overview |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2741 ----------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2742 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2743 Both the use of the special form `interactive' and one way to display a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2744 value in the echo area can be illustrated by creating an interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2745 version of `multiply-by-seven'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2746 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2747 Here is the code: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2748 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2749 (defun multiply-by-seven (number) ; Interactive version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2750 "Multiply NUMBER by seven." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2751 (interactive "p") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2752 (message "The result is %d" (* 7 number))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2753 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2754 You can install this code by placing your cursor after it and typing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2755 `C-x C-e'. The name of the function will appear in your echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2756 Then, you can use this code by typing `C-u' and a number and then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2757 typing `M-x multiply-by-seven' and pressing <RET>. The phrase `The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2758 result is ...' followed by the product will appear in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2759 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2760 Speaking more generally, you invoke a function like this in either of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2761 two ways: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2762 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2763 1. By typing a prefix argument that contains the number to be passed, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2764 and then typing `M-x' and the name of the function, as with `C-u 3 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2765 M-x forward-sentence'; or, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2766 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2767 2. By typing whatever key or keychord the function is bound to, as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2768 with `C-u 3 M-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2769 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2770 Both the examples just mentioned work identically to move point forward |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2771 three sentences. (Since `multiply-by-seven' is not bound to a key, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2772 could not be used as an example of key binding.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2773 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2774 (*Note Some Keybindings: Keybindings, to learn how to bind a command to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2775 a key.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2776 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2777 A prefix argument is passed to an interactive function by typing the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2778 <META> key followed by a number, for example, `M-3 M-e', or by typing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2779 `C-u' and then a number, for example, `C-u 3 M-e' (if you type `C-u' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2780 without a number, it defaults to 4). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2781 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2782 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2783 File: eintr, Node: multiply-by-seven in detail, Prev: Interactive multiply-by-seven, Up: Interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2784 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2785 3.3.1 An Interactive `multiply-by-seven' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2786 ---------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2787 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2788 Let's look at the use of the special form `interactive' and then at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2789 function `message' in the interactive version of `multiply-by-seven'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2790 You will recall that the function definition looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2791 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2792 (defun multiply-by-seven (number) ; Interactive version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2793 "Multiply NUMBER by seven." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2794 (interactive "p") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2795 (message "The result is %d" (* 7 number))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2796 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2797 In this function, the expression, `(interactive "p")', is a list of two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2798 elements. The `"p"' tells Emacs to pass the prefix argument to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2799 function and use its value for the argument of the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2800 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2801 The argument will be a number. This means that the symbol `number' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2802 will be bound to a number in the line: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2803 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2804 (message "The result is %d" (* 7 number)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2805 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2806 For example, if your prefix argument is 5, the Lisp interpreter will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2807 evaluate the line as if it were: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2808 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2809 (message "The result is %d" (* 7 5)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2810 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2811 (If you are reading this in GNU Emacs, you can evaluate this expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2812 yourself.) First, the interpreter will evaluate the inner list, which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2813 is `(* 7 5)'. This returns a value of 35. Next, it will evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2814 outer list, passing the values of the second and subsequent elements of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2815 the list to the function `message'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2816 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2817 As we have seen, `message' is an Emacs Lisp function especially |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2818 designed for sending a one line message to a user. (*Note The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2819 `message' function: message.) In summary, the `message' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2820 prints its first argument in the echo area as is, except for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2821 occurrences of `%d' or `%s' (and various other %-sequences which we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2822 have not mentioned). When it sees a control sequence, the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2823 looks to the second or subsequent arguments and prints the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2824 argument in the location in the string where the control sequence is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2825 located. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2826 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2827 In the interactive `multiply-by-seven' function, the control string is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2828 `%d', which requires a number, and the value returned by evaluating `(* |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2829 7 5)' is the number 35. Consequently, the number 35 is printed in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2830 place of the `%d' and the message is `The result is 35'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2831 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2832 (Note that when you call the function `multiply-by-seven', the message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2833 is printed without quotes, but when you call `message', the text is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2834 printed in double quotes. This is because the value returned by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2835 `message' is what appears in the echo area when you evaluate an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2836 expression whose first element is `message'; but when embedded in a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2837 function, `message' prints the text as a side effect without quotes.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2838 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2839 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2840 File: eintr, Node: Interactive Options, Next: Permanent Installation, Prev: Interactive, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2841 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2842 3.4 Different Options for `interactive' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2843 ======================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2844 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2845 In the example, `multiply-by-seven' used `"p"' as the argument to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2846 `interactive'. This argument told Emacs to interpret your typing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2847 either `C-u' followed by a number or <META> followed by a number as a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2848 command to pass that number to the function as its argument. Emacs has |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2849 more than twenty characters predefined for use with `interactive'. In |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2850 almost every case, one of these options will enable you to pass the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2851 right information interactively to a function. (*Note Code Characters |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2852 for `interactive': (elisp)Interactive Codes.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2853 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2854 Consider the function `zap-to-char'. Its interactive expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2855 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2856 (interactive "p\ncZap to char: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2857 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2858 The first part of the argument to `interactive' is `p', with which you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2859 are already familiar. This argument tells Emacs to interpret a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2860 `prefix', as a number to be passed to the function. You can specify a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2861 prefix either by typing `C-u' followed by a number or by typing <META> |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2862 followed by a number. The prefix is the number of specified |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2863 characters. Thus, if your prefix is three and the specified character |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2864 is `x', then you will delete all the text up to and including the third |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2865 next `x'. If you do not set a prefix, then you delete all the text up |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2866 to and including the specified character, but no more. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2867 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2868 The `c' tells the function the name of the character to which to delete. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2869 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2870 More formally, a function with two or more arguments can have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2871 information passed to each argument by adding parts to the string that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2872 follows `interactive'. When you do this, the information is passed to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2873 each argument in the same order it is specified in the `interactive' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2874 list. In the string, each part is separated from the next part by a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2875 `\n', which is a newline. For example, you can follow `p' with a `\n' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2876 and an `cZap to char: '. This causes Emacs to pass the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2877 prefix argument (if there is one) and the character. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2878 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2879 In this case, the function definition looks like the following, where |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2880 `arg' and `char' are the symbols to which `interactive' binds the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2881 prefix argument and the specified character: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2882 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2883 (defun NAME-OF-FUNCTION (arg char) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2884 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2885 (interactive "p\ncZap to char: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2886 BODY-OF-FUNCTION...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2887 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2888 (The space after the colon in the prompt makes it look better when you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2889 are prompted. *Note The Definition of `copy-to-buffer': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2890 copy-to-buffer, for an example.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2891 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2892 When a function does not take arguments, `interactive' does not require |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2893 any. Such a function contains the simple expression `(interactive)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2894 The `mark-whole-buffer' function is like this. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2895 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2896 Alternatively, if the special letter-codes are not right for your |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2897 application, you can pass your own arguments to `interactive' as a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2898 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2899 *Note The Definition of `append-to-buffer': append-to-buffer, for an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2900 example. *Note Using `Interactive': (elisp)Using Interactive, for a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2901 more complete explanation about this technique. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2902 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2903 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2904 File: eintr, Node: Permanent Installation, Next: let, Prev: Interactive Options, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2905 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2906 3.5 Install Code Permanently |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2907 ============================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2908 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2909 When you install a function definition by evaluating it, it will stay |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2910 installed until you quit Emacs. The next time you start a new session |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2911 of Emacs, the function will not be installed unless you evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2912 function definition again. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2913 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2914 At some point, you may want to have code installed automatically |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2915 whenever you start a new session of Emacs. There are several ways of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2916 doing this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2917 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2918 * If you have code that is just for yourself, you can put the code |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2919 for the function definition in your `.emacs' initialization file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2920 When you start Emacs, your `.emacs' file is automatically |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2921 evaluated and all the function definitions within it are installed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2922 *Note Your `.emacs' File: Emacs Initialization. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2923 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2924 * Alternatively, you can put the function definitions that you want |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2925 installed in one or more files of their own and use the `load' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2926 function to cause Emacs to evaluate and thereby install each of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2927 functions in the files. *Note Loading Files: Loading Files. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2928 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2929 * Thirdly, if you have code that your whole site will use, it is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2930 usual to put it in a file called `site-init.el' that is loaded when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2931 Emacs is built. This makes the code available to everyone who uses |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2932 your machine. (See the `INSTALL' file that is part of the Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2933 distribution.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2934 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2935 Finally, if you have code that everyone who uses Emacs may want, you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2936 can post it on a computer network or send a copy to the Free Software |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2937 Foundation. (When you do this, please license the code and its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2938 documentation under a license that permits other people to run, copy, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2939 study, modify, and redistribute the code and which protects you from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2940 having your work taken from you.) If you send a copy of your code to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2941 the Free Software Foundation, and properly protect yourself and others, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2942 it may be included in the next release of Emacs. In large part, this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2943 is how Emacs has grown over the past years, by donations. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2944 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2945 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2946 File: eintr, Node: let, Next: if, Prev: Permanent Installation, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2947 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2948 3.6 `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2949 ========= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2950 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2951 The `let' expression is a special form in Lisp that you will need to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2952 use in most function definitions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2953 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2954 `let' is used to attach or bind a symbol to a value in such a way that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2955 the Lisp interpreter will not confuse the variable with a variable of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2956 the same name that is not part of the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2957 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2958 To understand why the `let' special form is necessary, consider the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2959 situation in which you own a home that you generally refer to as `the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2960 house', as in the sentence, "The house needs painting." If you are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2961 visiting a friend and your host refers to `the house', he is likely to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2962 be referring to _his_ house, not yours, that is, to a different house. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2963 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2964 If your friend is referring to his house and you think he is referring |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2965 to your house, you may be in for some confusion. The same thing could |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2966 happen in Lisp if a variable that is used inside of one function has |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2967 the same name as a variable that is used inside of another function, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2968 and the two are not intended to refer to the same value. The `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2969 special form prevents this kind of confusion. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2970 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2971 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2972 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2973 * Prevent confusion:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2974 * Parts of let Expression:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2975 * Sample let Expression:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2976 * Uninitialized let Variables:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2977 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2978 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2979 File: eintr, Node: Prevent confusion, Next: Parts of let Expression, Prev: let, Up: let |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2980 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2981 `let' Prevents Confusion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2982 ------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2983 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2984 The `let' special form prevents confusion. `let' creates a name for a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2985 "local variable" that overshadows any use of the same name outside the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2986 `let' expression. This is like understanding that whenever your host |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2987 refers to `the house', he means his house, not yours. (Symbols used in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2988 argument lists work the same way. *Note The `defun' Special Form: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2989 defun.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2990 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2991 Local variables created by a `let' expression retain their value _only_ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2992 within the `let' expression itself (and within expressions called |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2993 within the `let' expression); the local variables have no effect |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2994 outside the `let' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2995 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2996 Another way to think about `let' is that it is like a `setq' that is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2997 temporary and local. The values set by `let' are automatically undone |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2998 when the `let' is finished. The setting only affects expressions that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
2999 are inside the bounds of the `let' expression. In computer science |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3000 jargon, we would say "the binding of a symbol is visible only in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3001 functions called in the `let' form; in Emacs Lisp, scoping is dynamic, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3002 not lexical." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3003 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3004 `let' can create more than one variable at once. Also, `let' gives |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3005 each variable it creates an initial value, either a value specified by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3006 you, or `nil'. (In the jargon, this is called `binding the variable to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3007 the value'.) After `let' has created and bound the variables, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3008 executes the code in the body of the `let', and returns the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3009 the last expression in the body, as the value of the whole `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3010 expression. (`Execute' is a jargon term that means to evaluate a list; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3011 it comes from the use of the word meaning `to give practical effect to' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3012 (`Oxford English Dictionary'). Since you evaluate an expression to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3013 perform an action, `execute' has evolved as a synonym to `evaluate'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3014 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3015 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3016 File: eintr, Node: Parts of let Expression, Next: Sample let Expression, Prev: Prevent confusion, Up: let |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3017 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3018 3.6.1 The Parts of a `let' Expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3019 ------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3020 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3021 A `let' expression is a list of three parts. The first part is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3022 symbol `let'. The second part is a list, called a "varlist", each |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3023 element of which is either a symbol by itself or a two-element list, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3024 the first element of which is a symbol. The third part of the `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3025 expression is the body of the `let'. The body usually consists of one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3026 or more lists. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3027 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3028 A template for a `let' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3029 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3030 (let VARLIST BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3031 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3032 The symbols in the varlist are the variables that are given initial |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3033 values by the `let' special form. Symbols by themselves are given the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3034 initial value of `nil'; and each symbol that is the first element of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3035 two-element list is bound to the value that is returned when the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3036 interpreter evaluates the second element. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3037 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3038 Thus, a varlist might look like this: `(thread (needles 3))'. In this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3039 case, in a `let' expression, Emacs binds the symbol `thread' to an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3040 initial value of `nil', and binds the symbol `needles' to an initial |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3041 value of 3. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3042 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3043 When you write a `let' expression, what you do is put the appropriate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3044 expressions in the slots of the `let' expression template. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3045 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3046 If the varlist is composed of two-element lists, as is often the case, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3047 the template for the `let' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3048 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3049 (let ((VARIABLE VALUE) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3050 (VARIABLE VALUE) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3051 ...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3052 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3053 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3054 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3055 File: eintr, Node: Sample let Expression, Next: Uninitialized let Variables, Prev: Parts of let Expression, Up: let |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3056 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3057 3.6.2 Sample `let' Expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3058 ----------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3059 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3060 The following expression creates and gives initial values to the two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3061 variables `zebra' and `tiger'. The body of the `let' expression is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3062 list which calls the `message' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3063 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3064 (let ((zebra 'stripes) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3065 (tiger 'fierce)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3066 (message "One kind of animal has %s and another is %s." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3067 zebra tiger)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3068 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3069 Here, the varlist is `((zebra 'stripes) (tiger 'fierce))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3070 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3071 The two variables are `zebra' and `tiger'. Each variable is the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3072 element of a two-element list and each value is the second element of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3073 its two-element list. In the varlist, Emacs binds the variable `zebra' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3074 to the value `stripes'(1), and binds the variable `tiger' to the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3075 `fierce'. In this example, both values are symbols preceded by a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3076 quote. The values could just as well have been another list or a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3077 string. The body of the `let' follows after the list holding the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3078 variables. In this example, the body is a list that uses the `message' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3079 function to print a string in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3080 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3081 You may evaluate the example in the usual fashion, by placing the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3082 cursor after the last parenthesis and typing `C-x C-e'. When you do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3083 this, the following will appear in the echo area: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3084 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3085 "One kind of animal has stripes and another is fierce." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3086 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3087 As we have seen before, the `message' function prints its first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3088 argument, except for `%s'. In this example, the value of the variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3089 `zebra' is printed at the location of the first `%s' and the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3090 the variable `tiger' is printed at the location of the second `%s'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3091 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3092 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3093 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3094 (1) According to Jared Diamond in `Guns, Germs, and Steel', "... zebras |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3095 become impossibly dangerous as they grow older" but the claim here is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3096 that they do not become fierce like a tiger. (1997, W. W. Norton and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3097 Co., ISBN 0-393-03894-2, page 171) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3098 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3099 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3100 File: eintr, Node: Uninitialized let Variables, Prev: Sample let Expression, Up: let |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3101 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3102 3.6.3 Uninitialized Variables in a `let' Statement |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3103 -------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3104 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3105 If you do not bind the variables in a `let' statement to specific |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3106 initial values, they will automatically be bound to an initial value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3107 `nil', as in the following expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3108 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3109 (let ((birch 3) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3110 pine |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3111 fir |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3112 (oak 'some)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3113 (message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3114 "Here are %d variables with %s, %s, and %s value." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3115 birch pine fir oak)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3116 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3117 Here, the varlist is `((birch 3) pine fir (oak 'some))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3118 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3119 If you evaluate this expression in the usual way, the following will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3120 appear in your echo area: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3121 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3122 "Here are 3 variables with nil, nil, and some value." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3123 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3124 In this example, Emacs binds the symbol `birch' to the number 3, binds |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3125 the symbols `pine' and `fir' to `nil', and binds the symbol `oak' to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3126 the value `some'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3127 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3128 Note that in the first part of the `let', the variables `pine' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3129 `fir' stand alone as atoms that are not surrounded by parentheses; this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3130 is because they are being bound to `nil', the empty list. But `oak' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3131 bound to `some' and so is a part of the list `(oak 'some)'. Similarly, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3132 `birch' is bound to the number 3 and so is in a list with that number. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3133 (Since a number evaluates to itself, the number does not need to be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3134 quoted. Also, the number is printed in the message using a `%d' rather |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3135 than a `%s'.) The four variables as a group are put into a list to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3136 delimit them from the body of the `let'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3137 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3138 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3139 File: eintr, Node: if, Next: else, Prev: let, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3140 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3141 3.7 The `if' Special Form |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3142 ========================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3143 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3144 A third special form, in addition to `defun' and `let', is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3145 conditional `if'. This form is used to instruct the computer to make |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3146 decisions. You can write function definitions without using `if', but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3147 it is used often enough, and is important enough, to be included here. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3148 It is used, for example, in the code for the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3149 `beginning-of-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3150 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3151 The basic idea behind an `if', is that "_if_ a test is true, _then_ an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3152 expression is evaluated." If the test is not true, the expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3153 not evaluated. For example, you might make a decision such as, "if it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3154 is warm and sunny, then go to the beach!" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3155 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3156 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3157 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3158 * if in more detail:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3159 * type-of-animal in detail:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3160 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3161 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3162 File: eintr, Node: if in more detail, Next: type-of-animal in detail, Prev: if, Up: if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3163 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3164 `if' in more detail |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3165 ------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3166 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3167 An `if' expression written in Lisp does not use the word `then'; the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3168 test and the action are the second and third elements of the list whose |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3169 first element is `if'. Nonetheless, the test part of an `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3170 expression is often called the "if-part" and the second argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3171 often called the "then-part". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3172 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3173 Also, when an `if' expression is written, the true-or-false-test is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3174 usually written on the same line as the symbol `if', but the action to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3175 carry out if the test is true, the "then-part", is written on the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3176 second and subsequent lines. This makes the `if' expression easier to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3177 read. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3178 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3179 (if TRUE-OR-FALSE-TEST |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3180 ACTION-TO-CARRY-OUT-IF-TEST-IS-TRUE) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3181 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3182 The true-or-false-test will be an expression that is evaluated by the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3183 Lisp interpreter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3184 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3185 Here is an example that you can evaluate in the usual manner. The test |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3186 is whether the number 5 is greater than the number 4. Since it is, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3187 message `5 is greater than 4!' will be printed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3188 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3189 (if (> 5 4) ; if-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3190 (message "5 is greater than 4!")) ; then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3191 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3192 (The function `>' tests whether its first argument is greater than its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3193 second argument and returns true if it is.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3194 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3195 Of course, in actual use, the test in an `if' expression will not be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3196 fixed for all time as it is by the expression `(> 5 4)'. Instead, at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3197 least one of the variables used in the test will be bound to a value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3198 that is not known ahead of time. (If the value were known ahead of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3199 time, we would not need to run the test!) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3200 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3201 For example, the value may be bound to an argument of a function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3202 definition. In the following function definition, the character of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3203 animal is a value that is passed to the function. If the value bound to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3204 `characteristic' is `fierce', then the message, `It's a tiger!' will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3205 printed; otherwise, `nil' will be returned. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3206 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3207 (defun type-of-animal (characteristic) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3208 "Print message in echo area depending on CHARACTERISTIC. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3209 If the CHARACTERISTIC is the symbol `fierce', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3210 then warn of a tiger." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3211 (if (equal characteristic 'fierce) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3212 (message "It's a tiger!"))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3213 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3214 If you are reading this inside of GNU Emacs, you can evaluate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3215 function definition in the usual way to install it in Emacs, and then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3216 you can evaluate the following two expressions to see the results: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3217 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3218 (type-of-animal 'fierce) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3219 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3220 (type-of-animal 'zebra) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3221 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3222 When you evaluate `(type-of-animal 'fierce)', you will see the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3223 following message printed in the echo area: `"It's a tiger!"'; and when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3224 you evaluate `(type-of-animal 'zebra)' you will see `nil' printed in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3225 the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3226 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3227 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3228 File: eintr, Node: type-of-animal in detail, Prev: if in more detail, Up: if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3229 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3230 3.7.1 The `type-of-animal' Function in Detail |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3231 --------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3232 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3233 Let's look at the `type-of-animal' function in detail. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3234 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3235 The function definition for `type-of-animal' was written by filling the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3236 slots of two templates, one for a function definition as a whole, and a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3237 second for an `if' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3238 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3239 The template for every function that is not interactive is: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3240 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3241 (defun NAME-OF-FUNCTION (ARGUMENT-LIST) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3242 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3243 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3244 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3245 The parts of the function that match this template look like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3246 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3247 (defun type-of-animal (characteristic) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3248 "Print message in echo area depending on CHARACTERISTIC. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3249 If the CHARACTERISTIC is the symbol `fierce', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3250 then warn of a tiger." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3251 BODY: THE `if' EXPRESSION) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3252 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3253 The name of function is `type-of-animal'; it is passed the value of one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3254 argument. The argument list is followed by a multi-line documentation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3255 string. The documentation string is included in the example because it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3256 is a good habit to write documentation string for every function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3257 definition. The body of the function definition consists of the `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3258 expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3259 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3260 The template for an `if' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3261 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3262 (if TRUE-OR-FALSE-TEST |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3263 ACTION-TO-CARRY-OUT-IF-THE-TEST-RETURNS-TRUE) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3264 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3265 In the `type-of-animal' function, the code for the `if' looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3266 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3267 (if (equal characteristic 'fierce) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3268 (message "It's a tiger!"))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3269 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3270 Here, the true-or-false-test is the expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3271 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3272 (equal characteristic 'fierce) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3273 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3274 In Lisp, `equal' is a function that determines whether its first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3275 argument is equal to its second argument. The second argument is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3276 quoted symbol `'fierce' and the first argument is the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3277 symbol `characteristic'--in other words, the argument passed to this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3278 function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3279 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3280 In the first exercise of `type-of-animal', the argument `fierce' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3281 passed to `type-of-animal'. Since `fierce' is equal to `fierce', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3282 expression, `(equal characteristic 'fierce)', returns a value of true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3283 When this happens, the `if' evaluates the second argument or then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3284 of the `if': `(message "It's tiger!")'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3285 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3286 On the other hand, in the second exercise of `type-of-animal', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3287 argument `zebra' is passed to `type-of-animal'. `zebra' is not equal |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3288 to `fierce', so the then-part is not evaluated and `nil' is returned by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3289 the `if' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3290 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3291 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3292 File: eintr, Node: else, Next: Truth & Falsehood, Prev: if, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3293 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3294 3.8 If-then-else Expressions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3295 ============================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3296 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3297 An `if' expression may have an optional third argument, called the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3298 "else-part", for the case when the true-or-false-test returns false. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3299 When this happens, the second argument or then-part of the overall `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3300 expression is _not_ evaluated, but the third or else-part _is_ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3301 evaluated. You might think of this as the cloudy day alternative for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3302 the decision "if it is warm and sunny, then go to the beach, else read |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3303 a book!". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3304 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3305 The word "else" is not written in the Lisp code; the else-part of an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3306 `if' expression comes after the then-part. In the written Lisp, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3307 else-part is usually written to start on a line of its own and is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3308 indented less than the then-part: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3309 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3310 (if TRUE-OR-FALSE-TEST |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3311 ACTION-TO-CARRY-OUT-IF-THE-TEST-RETURNS-TRUE |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3312 ACTION-TO-CARRY-OUT-IF-THE-TEST-RETURNS-FALSE) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3313 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3314 For example, the following `if' expression prints the message `4 is not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3315 greater than 5!' when you evaluate it in the usual way: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3316 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3317 (if (> 4 5) ; if-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3318 (message "5 is greater than 4!") ; then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3319 (message "4 is not greater than 5!")) ; else-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3320 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3321 Note that the different levels of indentation make it easy to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3322 distinguish the then-part from the else-part. (GNU Emacs has several |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3323 commands that automatically indent `if' expressions correctly. *Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3324 GNU Emacs Helps You Type Lists: Typing Lists.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3325 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3326 We can extend the `type-of-animal' function to include an else-part by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3327 simply incorporating an additional part to the `if' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3328 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3329 You can see the consequences of doing this if you evaluate the following |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3330 version of the `type-of-animal' function definition to install it and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3331 then evaluate the two subsequent expressions to pass different |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3332 arguments to the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3333 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3334 (defun type-of-animal (characteristic) ; Second version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3335 "Print message in echo area depending on CHARACTERISTIC. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3336 If the CHARACTERISTIC is the symbol `fierce', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3337 then warn of a tiger; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3338 else say it's not fierce." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3339 (if (equal characteristic 'fierce) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3340 (message "It's a tiger!") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3341 (message "It's not fierce!"))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3342 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3343 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3344 (type-of-animal 'fierce) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3345 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3346 (type-of-animal 'zebra) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3347 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3348 When you evaluate `(type-of-animal 'fierce)', you will see the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3349 following message printed in the echo area: `"It's a tiger!"'; but when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3350 you evaluate `(type-of-animal 'zebra)', you will see `"It's not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3351 fierce!"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3352 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3353 (Of course, if the CHARACTERISTIC were `ferocious', the message `"It's |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3354 not fierce!"' would be printed; and it would be misleading! When you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3355 write code, you need to take into account the possibility that some |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3356 such argument will be tested by the `if' and write your program |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3357 accordingly.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3358 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3359 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3360 File: eintr, Node: Truth & Falsehood, Next: save-excursion, Prev: else, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3361 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3362 3.9 Truth and Falsehood in Emacs Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3363 ===================================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3364 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3365 There is an important aspect to the truth test in an `if' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3366 So far, we have spoken of `true' and `false' as values of predicates as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3367 if they were new kinds of Emacs Lisp objects. In fact, `false' is just |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3368 our old friend `nil'. Anything else--anything at all--is `true'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3369 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3370 The expression that tests for truth is interpreted as "true" if the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3371 result of evaluating it is a value that is not `nil'. In other words, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3372 the result of the test is considered true if the value returned is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3373 number such as 47, a string such as `"hello"', or a symbol (other than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3374 `nil') such as `flowers', or a list (so long as it is not empty), or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3375 even a buffer! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3376 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3377 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3378 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3379 * nil explained:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3380 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3381 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3382 File: eintr, Node: nil explained, Prev: Truth & Falsehood, Up: Truth & Falsehood |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3383 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3384 An explanation of `nil' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3385 ----------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3386 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3387 Before illustrating a test for truth, we need an explanation of `nil'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3388 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3389 In Emacs Lisp, the symbol `nil' has two meanings. First, it means the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3390 empty list. Second, it means false and is the value returned when a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3391 true-or-false-test tests false. `nil' can be written as an empty list, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3392 `()', or as `nil'. As far as the Lisp interpreter is concerned, `()' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3393 and `nil' are the same. Humans, however, tend to use `nil' for false |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3394 and `()' for the empty list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3395 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3396 In Emacs Lisp, any value that is not `nil'--is not the empty list--is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3397 considered true. This means that if an evaluation returns something |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3398 that is not an empty list, an `if' expression will test true. For |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3399 example, if a number is put in the slot for the test, it will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3400 evaluated and will return itself, since that is what numbers do when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3401 evaluated. In this conditional, the `if' expression will test true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3402 The expression tests false only when `nil', an empty list, is returned |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3403 by evaluating the expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3404 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3405 You can see this by evaluating the two expressions in the following |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3406 examples. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3407 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3408 In the first example, the number 4 is evaluated as the test in the `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3409 expression and returns itself; consequently, the then-part of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3410 expression is evaluated and returned: `true' appears in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3411 In the second example, the `nil' indicates false; consequently, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3412 else-part of the expression is evaluated and returned: `false' appears |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3413 in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3414 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3415 (if 4 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3416 'true |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3417 'false) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3418 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3419 (if nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3420 'true |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3421 'false) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3422 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3423 Incidentally, if some other useful value is not available for a test |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3424 that returns true, then the Lisp interpreter will return the symbol `t' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3425 for true. For example, the expression `(> 5 4)' returns `t' when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3426 evaluated, as you can see by evaluating it in the usual way: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3427 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3428 (> 5 4) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3429 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3430 On the other hand, this function returns `nil' if the test is false. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3431 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3432 (> 4 5) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3433 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3434 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3435 File: eintr, Node: save-excursion, Next: Review, Prev: Truth & Falsehood, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3436 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3437 3.10 `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3438 ===================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3439 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3440 The `save-excursion' function is the fourth and final special form that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3441 we will discuss in this chapter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3442 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3443 In Emacs Lisp programs used for editing, the `save-excursion' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3444 is very common. It saves the location of point and mark, executes the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3445 body of the function, and then restores point and mark to their |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3446 previous positions if their locations were changed. Its primary |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3447 purpose is to keep the user from being surprised and disturbed by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3448 unexpected movement of point or mark. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3449 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3450 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3451 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3452 * Point and mark:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3453 * Template for save-excursion:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3454 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3455 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3456 File: eintr, Node: Point and mark, Next: Template for save-excursion, Prev: save-excursion, Up: save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3457 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3458 Point and Mark |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3459 -------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3460 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3461 Before discussing `save-excursion', however, it may be useful first to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3462 review what point and mark are in GNU Emacs. "Point" is the current |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3463 location of the cursor. Wherever the cursor is, that is point. More |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3464 precisely, on terminals where the cursor appears to be on top of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3465 character, point is immediately before the character. In Emacs Lisp, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3466 point is an integer. The first character in a buffer is number one, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3467 the second is number two, and so on. The function `point' returns the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3468 current position of the cursor as a number. Each buffer has its own |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3469 value for point. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3470 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3471 The "mark" is another position in the buffer; its value can be set with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3472 a command such as `C-<SPC>' (`set-mark-command'). If a mark has been |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3473 set, you can use the command `C-x C-x' (`exchange-point-and-mark') to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3474 cause the cursor to jump to the mark and set the mark to be the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3475 previous position of point. In addition, if you set another mark, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3476 position of the previous mark is saved in the mark ring. Many mark |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3477 positions can be saved this way. You can jump the cursor to a saved |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3478 mark by typing `C-u C-<SPC>' one or more times. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3479 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3480 The part of the buffer between point and mark is called "the region". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3481 Numerous commands work on the region, including `center-region', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3482 `count-lines-region', `kill-region', and `print-region'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3483 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3484 The `save-excursion' special form saves the locations of point and mark |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3485 and restores those positions after the code within the body of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3486 special form is evaluated by the Lisp interpreter. Thus, if point were |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3487 in the beginning of a piece of text and some code moved point to the end |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3488 of the buffer, the `save-excursion' would put point back to where it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3489 was before, after the expressions in the body of the function were |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3490 evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3491 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3492 In Emacs, a function frequently moves point as part of its internal |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3493 workings even though a user would not expect this. For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3494 `count-lines-region' moves point. To prevent the user from being |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3495 bothered by jumps that are both unexpected and (from the user's point of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3496 view) unnecessary, `save-excursion' is often used to keep point and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3497 mark in the location expected by the user. The use of `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3498 is good housekeeping. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3499 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3500 To make sure the house stays clean, `save-excursion' restores the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3501 values of point and mark even if something goes wrong in the code inside |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3502 of it (or, to be more precise and to use the proper jargon, "in case of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3503 abnormal exit"). This feature is very helpful. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3504 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3505 In addition to recording the values of point and mark, `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3506 keeps track of the current buffer, and restores it, too. This means |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3507 you can write code that will change the buffer and have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3508 `save-excursion' switch you back to the original buffer. This is how |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3509 `save-excursion' is used in `append-to-buffer'. (*Note The Definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3510 of `append-to-buffer': append-to-buffer.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3511 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3512 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3513 File: eintr, Node: Template for save-excursion, Prev: Point and mark, Up: save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3514 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3515 3.10.1 Template for a `save-excursion' Expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3516 ------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3517 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3518 The template for code using `save-excursion' is simple: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3519 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3520 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3521 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3522 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3523 The body of the function is one or more expressions that will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3524 evaluated in sequence by the Lisp interpreter. If there is more than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3525 one expression in the body, the value of the last one will be returned |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3526 as the value of the `save-excursion' function. The other expressions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3527 in the body are evaluated only for their side effects; and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3528 `save-excursion' itself is used only for its side effect (which is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3529 restoring the positions of point and mark). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3530 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3531 In more detail, the template for a `save-excursion' expression looks |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3532 like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3533 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3534 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3535 FIRST-EXPRESSION-IN-BODY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3536 SECOND-EXPRESSION-IN-BODY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3537 THIRD-EXPRESSION-IN-BODY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3538 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3539 LAST-EXPRESSION-IN-BODY) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3540 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3541 An expression, of course, may be a symbol on its own or a list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3542 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3543 In Emacs Lisp code, a `save-excursion' expression often occurs within |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3544 the body of a `let' expression. It looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3545 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3546 (let VARLIST |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3547 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3548 BODY...)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3549 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3550 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3551 File: eintr, Node: Review, Next: defun Exercises, Prev: save-excursion, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3552 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3553 3.11 Review |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3554 =========== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3555 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3556 In the last few chapters we have introduced a fair number of functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3557 and special forms. Here they are described in brief, along with a few |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3558 similar functions that have not been mentioned yet. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3559 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3560 `eval-last-sexp' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3561 Evaluate the last symbolic expression before the current location |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3562 of point. The value is printed in the echo area unless the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3563 function is invoked with an argument; in that case, the output is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3564 printed in the current buffer. This command is normally bound to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3565 `C-x C-e'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3566 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3567 `defun' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3568 Define function. This special form has up to five parts: the name, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3569 a template for the arguments that will be passed to the function, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3570 documentation, an optional interactive declaration, and the body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3571 of the definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3572 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3573 For example, in an early version of Emacs, the function definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3574 was as follows. (It is slightly more complex now that it seeks |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3575 the first non-whitespace character rather than the first visible |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3576 character.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3577 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3578 (defun back-to-indentation () |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3579 "Move point to first visible character on line." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3580 (interactive) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3581 (beginning-of-line 1) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3582 (skip-chars-forward " \t")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3583 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3584 `interactive' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3585 Declare to the interpreter that the function can be used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3586 interactively. This special form may be followed by a string with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3587 one or more parts that pass the information to the arguments of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3588 function, in sequence. These parts may also tell the interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3589 to prompt for information. Parts of the string are separated by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3590 newlines, `\n'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3591 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3592 Common code characters are: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3593 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3594 `b' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3595 The name of an existing buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3596 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3597 `f' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3598 The name of an existing file. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3599 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3600 `p' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3601 The numeric prefix argument. (Note that this `p' is lower |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3602 case.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3603 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3604 `r' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3605 Point and the mark, as two numeric arguments, smallest first. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3606 This is the only code letter that specifies two successive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3607 arguments rather than one. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3608 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3609 *Note Code Characters for `interactive': (elisp)Interactive Codes, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3610 for a complete list of code characters. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3611 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3612 `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3613 Declare that a list of variables is for use within the body of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3614 `let' and give them an initial value, either `nil' or a specified |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3615 value; then evaluate the rest of the expressions in the body of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3616 the `let' and return the value of the last one. Inside the body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3617 of the `let', the Lisp interpreter does not see the values of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3618 variables of the same names that are bound outside of the `let'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3619 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3620 For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3621 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3622 (let ((foo (buffer-name)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3623 (bar (buffer-size))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3624 (message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3625 "This buffer is %s and has %d characters." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3626 foo bar)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3627 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3628 `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3629 Record the values of point and mark and the current buffer before |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3630 evaluating the body of this special form. Restore the values of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3631 point and mark and buffer afterward. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3632 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3633 For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3634 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3635 (message "We are %d characters into this buffer." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3636 (- (point) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3637 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3638 (goto-char (point-min)) (point)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3639 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3640 `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3641 Evaluate the first argument to the function; if it is true, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3642 evaluate the second argument; else evaluate the third argument, if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3643 there is one. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3644 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3645 The `if' special form is called a "conditional". There are other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3646 conditionals in Emacs Lisp, but `if' is perhaps the most commonly |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3647 used. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3648 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3649 For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3650 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3651 (if (string-equal |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3652 (number-to-string 22) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3653 (substring (emacs-version) 10 12)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3654 (message "This is version 22 Emacs") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3655 (message "This is not version 22 Emacs")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3656 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3657 `equal' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3658 `eq' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3659 Test whether two objects are the same. `equal' uses one meaning |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3660 of the word `same' and `eq' uses another: `equal' returns true if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3661 the two objects have a similar structure and contents, such as two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3662 copies of the same book. On the other hand, `eq', returns true if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3663 both arguments are actually the same object. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3664 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3665 `<' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3666 `>' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3667 `<=' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3668 `>=' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3669 The `<' function tests whether its first argument is smaller than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3670 its second argument. A corresponding function, `>', tests whether |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3671 the first argument is greater than the second. Likewise, `<=' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3672 tests whether the first argument is less than or equal to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3673 second and `>=' tests whether the first argument is greater than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3674 or equal to the second. In all cases, both arguments must be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3675 numbers or markers (markers indicate positions in buffers). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3676 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3677 `string<' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3678 `string-lessp' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3679 `string=' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3680 `string-equal' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3681 The `string-lessp' function tests whether its first argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3682 smaller than the second argument. A shorter, alternative name for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3683 the same function (a `defalias') is `string<'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3684 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3685 The arguments to `string-lessp' must be strings or symbols; the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3686 ordering is lexicographic, so case is significant. The print |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3687 names of symbols are used instead of the symbols themselves. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3688 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3689 An empty string, `""', a string with no characters in it, is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3690 smaller than any string of characters. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3691 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3692 `string-equal' provides the corresponding test for equality. Its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3693 shorter, alternative name is `string='. There are no string test |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3694 functions that correspond to >, `>=', or `<='. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3695 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3696 `message' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3697 Print a message in the echo area. The first argument is a string |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3698 that can contain `%s', `%d', or `%c' to print the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3699 arguments that follow the string. The argument used by `%s' must |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3700 be a string or a symbol; the argument used by `%d' must be a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3701 number. The argument used by `%c' must be an ASCII code number; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3702 it will be printed as the character with that ASCII code. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3703 (Various other %-sequences have not been mentioned.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3704 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3705 `setq' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3706 `set' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3707 The `setq' function sets the value of its first argument to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3708 value of the second argument. The first argument is automatically |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3709 quoted by `setq'. It does the same for succeeding pairs of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3710 arguments. Another function, `set', takes only two arguments and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3711 evaluates both of them before setting the value returned by its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3712 first argument to the value returned by its second argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3713 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3714 `buffer-name' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3715 Without an argument, return the name of the buffer, as a string. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3716 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3717 `buffer-file-name' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3718 Without an argument, return the name of the file the buffer is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3719 visiting. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3720 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3721 `current-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3722 Return the buffer in which Emacs is active; it may not be the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3723 buffer that is visible on the screen. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3724 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3725 `other-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3726 Return the most recently selected buffer (other than the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3727 passed to `other-buffer' as an argument and other than the current |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3728 buffer). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3729 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3730 `switch-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3731 Select a buffer for Emacs to be active in and display it in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3732 current window so users can look at it. Usually bound to `C-x b'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3733 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3734 `set-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3735 Switch Emacs' attention to a buffer on which programs will run. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3736 Don't alter what the window is showing. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3737 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3738 `buffer-size' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3739 Return the number of characters in the current buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3740 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3741 `point' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3742 Return the value of the current position of the cursor, as an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3743 integer counting the number of characters from the beginning of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3744 buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3745 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3746 `point-min' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3747 Return the minimum permissible value of point in the current |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3748 buffer. This is 1, unless narrowing is in effect. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3749 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3750 `point-max' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3751 Return the value of the maximum permissible value of point in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3752 current buffer. This is the end of the buffer, unless narrowing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3753 is in effect. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3754 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3755 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3756 File: eintr, Node: defun Exercises, Prev: Review, Up: Writing Defuns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3757 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3758 3.12 Exercises |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3759 ============== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3760 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3761 * Write a non-interactive function that doubles the value of its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3762 argument, a number. Make that function interactive. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3763 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3764 * Write a function that tests whether the current value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3765 `fill-column' is greater than the argument passed to the function, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3766 and if so, prints an appropriate message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3767 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3768 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3769 File: eintr, Node: Buffer Walk Through, Next: More Complex, Prev: Writing Defuns, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3770 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3771 4 A Few Buffer-Related Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3772 ******************************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3773 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3774 In this chapter we study in detail several of the functions used in GNU |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3775 Emacs. This is called a "walk-through". These functions are used as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3776 examples of Lisp code, but are not imaginary examples; with the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3777 exception of the first, simplified function definition, these functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3778 show the actual code used in GNU Emacs. You can learn a great deal from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3779 these definitions. The functions described here are all related to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3780 buffers. Later, we will study other functions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3781 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3782 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3783 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3784 * Finding More:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3785 * simplified-beginning-of-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3786 * mark-whole-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3787 * append-to-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3788 * Buffer Related Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3789 * Buffer Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3790 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3791 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3792 File: eintr, Node: Finding More, Next: simplified-beginning-of-buffer, Prev: Buffer Walk Through, Up: Buffer Walk Through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3793 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3794 4.1 Finding More Information |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3795 ============================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3796 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3797 In this walk-through, I will describe each new function as we come to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3798 it, sometimes in detail and sometimes briefly. If you are interested, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3799 you can get the full documentation of any Emacs Lisp function at any |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3800 time by typing `C-h f' and then the name of the function (and then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3801 <RET>). Similarly, you can get the full documentation for a variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3802 by typing `C-h v' and then the name of the variable (and then <RET>). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3803 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3804 When a function is written in Emacs Lisp, `describe-function' will also |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3805 tell you the location of the function definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3806 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3807 Put point into the name of the file that contains the function and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3808 press the <RET> key. In this case, <RET> means `push-button' rather |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3809 than `return' or `enter'. Emacs will take you directly to the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3810 definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3811 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3812 More generally, if you want to see a function in its original source |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3813 file, you can use the `find-tags' function to jump to it. `find-tags' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3814 works with a wide variety of languages, not just Lisp, and C, and it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3815 works with non-programming text as well. For example, `find-tags' will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3816 jump to the various nodes in the Texinfo source file of this document. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3817 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3818 The `find-tags' function depends on `tags tables' that record the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3819 locations of the functions, variables, and other items to which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3820 `find-tags' jumps. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3821 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3822 To use the `find-tags' command, type `M-.' (i.e., press the period key |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3823 while holding down the <META> key, or else type the <ESC> key and then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3824 type the period key), and then, at the prompt, type in the name of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3825 function whose source code you want to see, such as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3826 `mark-whole-buffer', and then type <RET>. Emacs will switch buffers |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3827 and display the source code for the function on your screen. To switch |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3828 back to your current buffer, type `C-x b <RET>'. (On some keyboards, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3829 the <META> key is labelled <ALT>.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3830 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3831 Depending on how the initial default values of your copy of Emacs are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3832 set, you may also need to specify the location of your `tags table', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3833 which is a file called `TAGS'. For example, if you are interested in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3834 Emacs sources, the tags table you will most likely want, if it has |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3835 already been created for you, will be in a subdirectory of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3836 `/usr/local/share/emacs/' directory; thus you would use the `M-x |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3837 visit-tags-table' command and specify a pathname such as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3838 `/usr/local/share/emacs/22.0.100/lisp/TAGS'. If the tags table has not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3839 already been created, you will have to create it yourself. It will in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3840 a file such as `/usr/local/src/emacs/src/TAGS'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3841 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3842 To create a `TAGS' file in a specific directory, switch to that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3843 directory in Emacs using `M-x cd' command, or list the directory with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3844 `C-x d' (`dired'). Then run the compile command, with `etags *.el' as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3845 the command to execute: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3846 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3847 M-x compile RET etags *.el RET |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3848 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3849 For more information, see *Note Create Your Own `TAGS' File: etags. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3850 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3851 After you become more familiar with Emacs Lisp, you will find that you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3852 will frequently use `find-tags' to navigate your way around source code; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3853 and you will create your own `TAGS' tables. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3854 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3855 Incidentally, the files that contain Lisp code are conventionally |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3856 called "libraries". The metaphor is derived from that of a specialized |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3857 library, such as a law library or an engineering library, rather than a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3858 general library. Each library, or file, contains functions that relate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3859 to a particular topic or activity, such as `abbrev.el' for handling |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3860 abbreviations and other typing shortcuts, and `help.el' for on-line |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3861 help. (Sometimes several libraries provide code for a single activity, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3862 as the various `rmail...' files provide code for reading electronic |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3863 mail.) In `The GNU Emacs Manual', you will see sentences such as "The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3864 `C-h p' command lets you search the standard Emacs Lisp libraries by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3865 topic keywords." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3866 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3867 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3868 File: eintr, Node: simplified-beginning-of-buffer, Next: mark-whole-buffer, Prev: Finding More, Up: Buffer Walk Through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3869 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3870 4.2 A Simplified `beginning-of-buffer' Definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3871 ================================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3872 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3873 The `beginning-of-buffer' command is a good function to start with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3874 since you are likely to be familiar with it and it is easy to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3875 understand. Used as an interactive command, `beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3876 moves the cursor to the beginning of the buffer, leaving the mark at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3877 previous position. It is generally bound to `M-<'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3878 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3879 In this section, we will discuss a shortened version of the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3880 that shows how it is most frequently used. This shortened function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3881 works as written, but it does not contain the code for a complex option. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3882 In another section, we will describe the entire function. (*Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3883 Complete Definition of `beginning-of-buffer': beginning-of-buffer.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3884 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3885 Before looking at the code, let's consider what the function definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3886 has to contain: it must include an expression that makes the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3887 interactive so it can be called by typing `M-x beginning-of-buffer' or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3888 by typing a keychord such as `M-<'; it must include code to leave a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3889 mark at the original position in the buffer; and it must include code |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3890 to move the cursor to the beginning of the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3891 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3892 Here is the complete text of the shortened version of the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3893 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3894 (defun simplified-beginning-of-buffer () |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3895 "Move point to the beginning of the buffer; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3896 leave mark at previous position." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3897 (interactive) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3898 (push-mark) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3899 (goto-char (point-min))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3900 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3901 Like all function definitions, this definition has five parts following |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3902 the special form `defun': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3903 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3904 1. The name: in this example, `simplified-beginning-of-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3905 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3906 2. A list of the arguments: in this example, an empty list, `()', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3907 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3908 3. The documentation string. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3909 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3910 4. The interactive expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3911 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3912 5. The body. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3913 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3914 In this function definition, the argument list is empty; this means that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3915 this function does not require any arguments. (When we look at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3916 definition for the complete function, we will see that it may be passed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3917 an optional argument.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3918 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3919 The interactive expression tells Emacs that the function is intended to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3920 be used interactively. In this example, `interactive' does not have an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3921 argument because `simplified-beginning-of-buffer' does not require one. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3922 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3923 The body of the function consists of the two lines: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3924 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3925 (push-mark) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3926 (goto-char (point-min)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3927 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3928 The first of these lines is the expression, `(push-mark)'. When this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3929 expression is evaluated by the Lisp interpreter, it sets a mark at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3930 current position of the cursor, wherever that may be. The position of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3931 this mark is saved in the mark ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3932 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3933 The next line is `(goto-char (point-min))'. This expression jumps the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3934 cursor to the minimum point in the buffer, that is, to the beginning of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3935 the buffer (or to the beginning of the accessible portion of the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3936 if it is narrowed. *Note Narrowing and Widening: Narrowing & Widening.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3937 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3938 The `push-mark' command sets a mark at the place where the cursor was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3939 located before it was moved to the beginning of the buffer by the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3940 `(goto-char (point-min))' expression. Consequently, you can, if you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3941 wish, go back to where you were originally by typing `C-x C-x'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3942 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3943 That is all there is to the function definition! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3944 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3945 When you are reading code such as this and come upon an unfamiliar |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3946 function, such as `goto-char', you can find out what it does by using |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3947 the `describe-function' command. To use this command, type `C-h f' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3948 then type in the name of the function and press <RET>. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3949 `describe-function' command will print the function's documentation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3950 string in a `*Help*' window. For example, the documentation for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3951 `goto-char' is: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3952 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3953 Set point to POSITION, a number or marker. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3954 Beginning of buffer is position (point-min), end is (point-max). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3955 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3956 The function's one argument is the desired position. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3957 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3958 (The prompt for `describe-function' will offer you the symbol under or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3959 preceding the cursor, so you can save typing by positioning the cursor |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3960 right over or after the function and then typing `C-h f <RET>'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3961 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3962 The `end-of-buffer' function definition is written in the same way as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3963 the `beginning-of-buffer' definition except that the body of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3964 function contains the expression `(goto-char (point-max))' in place of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3965 `(goto-char (point-min))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3966 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3967 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3968 File: eintr, Node: mark-whole-buffer, Next: append-to-buffer, Prev: simplified-beginning-of-buffer, Up: Buffer Walk Through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3969 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3970 4.3 The Definition of `mark-whole-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3971 ========================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3972 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3973 The `mark-whole-buffer' function is no harder to understand than the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3974 `simplified-beginning-of-buffer' function. In this case, however, we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3975 will look at the complete function, not a shortened version. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3976 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3977 The `mark-whole-buffer' function is not as commonly used as the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3978 `beginning-of-buffer' function, but is useful nonetheless: it marks a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3979 whole buffer as a region by putting point at the beginning and a mark |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3980 at the end of the buffer. It is generally bound to `C-x h'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3981 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3982 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3983 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3984 * mark-whole-buffer overview:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3985 * Body of mark-whole-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3986 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3987 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3988 File: eintr, Node: mark-whole-buffer overview, Next: Body of mark-whole-buffer, Prev: mark-whole-buffer, Up: mark-whole-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3989 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3990 An overview of `mark-whole-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3991 ---------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3992 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3993 In GNU Emacs 22, the code for the complete function looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3994 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3995 (defun mark-whole-buffer () |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3996 "Put point at beginning and mark at end of buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3997 You probably should not use this function in Lisp programs; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3998 it is usually a mistake for a Lisp function to use any subroutine |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
3999 that uses or sets the mark." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4000 (interactive) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4001 (push-mark (point)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4002 (push-mark (point-max) nil t) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4003 (goto-char (point-min))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4004 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4005 Like all other functions, the `mark-whole-buffer' function fits into |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4006 the template for a function definition. The template looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4007 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4008 (defun NAME-OF-FUNCTION (ARGUMENT-LIST) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4009 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4010 (INTERACTIVE-EXPRESSION...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4011 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4012 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4013 Here is how the function works: the name of the function is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4014 `mark-whole-buffer'; it is followed by an empty argument list, `()', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4015 which means that the function does not require arguments. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4016 documentation comes next. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4017 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4018 The next line is an `(interactive)' expression that tells Emacs that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4019 the function will be used interactively. These details are similar to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4020 the `simplified-beginning-of-buffer' function described in the previous |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4021 section. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4022 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4023 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4024 File: eintr, Node: Body of mark-whole-buffer, Prev: mark-whole-buffer overview, Up: mark-whole-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4025 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4026 4.3.1 Body of `mark-whole-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4027 --------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4028 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4029 The body of the `mark-whole-buffer' function consists of three lines of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4030 code: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4031 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4032 (push-mark (point)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4033 (push-mark (point-max) nil t) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4034 (goto-char (point-min)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4035 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4036 The first of these lines is the expression, `(push-mark (point))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4037 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4038 This line does exactly the same job as the first line of the body of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4039 the `simplified-beginning-of-buffer' function, which is written |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4040 `(push-mark)'. In both cases, the Lisp interpreter sets a mark at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4041 current position of the cursor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4042 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4043 I don't know why the expression in `mark-whole-buffer' is written |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4044 `(push-mark (point))' and the expression in `beginning-of-buffer' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4045 written `(push-mark)'. Perhaps whoever wrote the code did not know |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4046 that the arguments for `push-mark' are optional and that if `push-mark' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4047 is not passed an argument, the function automatically sets mark at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4048 location of point by default. Or perhaps the expression was written so |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4049 as to parallel the structure of the next line. In any case, the line |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4050 causes Emacs to determine the position of point and set a mark there. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4051 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4052 In earlier versions of GNU Emacs, the next line of `mark-whole-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4053 was `(push-mark (point-max))'. This expression sets a mark at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4054 point in the buffer that has the highest number. This will be the end |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4055 of the buffer (or, if the buffer is narrowed, the end of the accessible |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4056 portion of the buffer. *Note Narrowing and Widening: Narrowing & |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4057 Widening, for more about narrowing.) After this mark has been set, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4058 previous mark, the one set at point, is no longer set, but Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4059 remembers its position, just as all other recent marks are always |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4060 remembered. This means that you can, if you wish, go back to that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4061 position by typing `C-u C-<SPC>' twice. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4062 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4063 In GNU Emacs 22, the `(point-max)' is slightly more complicated. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4064 line reads |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4065 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4066 (push-mark (point-max) nil t) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4067 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4068 The expression works nearly the same as before. It sets a mark at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4069 highest numbered place in the buffer that it can. However, in this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4070 version, `push-mark' has two additional arguments. The second argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4071 to `push-mark' is `nil'. This tells the function it _should_ display a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4072 message that says `Mark set' when it pushes the mark. The third |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4073 argument is `t'. This tells `push-mark' to activate the mark when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4074 Transient Mark mode is turned on. Transient Mark mode highlights the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4075 currently active region. It is often turned off. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4076 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4077 Finally, the last line of the function is `(goto-char (point-min)))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4078 This is written exactly the same way as it is written in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4079 `beginning-of-buffer'. The expression moves the cursor to the minimum |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4080 point in the buffer, that is, to the beginning of the buffer (or to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4081 beginning of the accessible portion of the buffer). As a result of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4082 this, point is placed at the beginning of the buffer and mark is set at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4083 the end of the buffer. The whole buffer is, therefore, the region. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4084 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4085 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4086 File: eintr, Node: append-to-buffer, Next: Buffer Related Review, Prev: mark-whole-buffer, Up: Buffer Walk Through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4087 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4088 4.4 The Definition of `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4089 ======================================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4090 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4091 The `append-to-buffer' command is more complex than the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4092 `mark-whole-buffer' command. What it does is copy the region (that is, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4093 the part of the buffer between point and mark) from the current buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4094 to a specified buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4095 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4096 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4097 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4098 * append-to-buffer overview:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4099 * append interactive:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4100 * append-to-buffer body:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4101 * append save-excursion:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4102 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4103 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4104 File: eintr, Node: append-to-buffer overview, Next: append interactive, Prev: append-to-buffer, Up: append-to-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4105 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4106 An Overview of `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4107 --------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4108 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4109 The `append-to-buffer' command uses the `insert-buffer-substring' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4110 function to copy the region. `insert-buffer-substring' is described by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4111 its name: it takes a string of characters from part of a buffer, a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4112 "substring", and inserts them into another buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4113 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4114 Most of `append-to-buffer' is concerned with setting up the conditions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4115 for `insert-buffer-substring' to work: the code must specify both the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4116 buffer to which the text will go, the window it comes from and goes to, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4117 and the region that will be copied. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4118 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4119 Here is the complete text of the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4120 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4121 (defun append-to-buffer (buffer start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4122 "Append to specified buffer the text of the region. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4123 It is inserted into that buffer before its point. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4124 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4125 When calling from a program, give three arguments: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4126 BUFFER (or buffer name), START and END. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4127 START and END specify the portion of the current buffer to be copied." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4128 (interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4129 (list (read-buffer "Append to buffer: " (other-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4130 (current-buffer) t)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4131 (region-beginning) (region-end))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4132 (let ((oldbuf (current-buffer))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4133 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4134 (let* ((append-to (get-buffer-create buffer)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4135 (windows (get-buffer-window-list append-to t t)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4136 point) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4137 (set-buffer append-to) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4138 (setq point (point)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4139 (barf-if-buffer-read-only) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4140 (insert-buffer-substring oldbuf start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4141 (dolist (window windows) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4142 (when (= (window-point window) point) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4143 (set-window-point window (point)))))))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4144 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4145 The function can be understood by looking at it as a series of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4146 filled-in templates. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4147 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4148 The outermost template is for the function definition. In this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4149 function, it looks like this (with several slots filled in): |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4150 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4151 (defun append-to-buffer (buffer start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4152 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4153 (interactive ...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4154 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4155 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4156 The first line of the function includes its name and three arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4157 The arguments are the `buffer' to which the text will be copied, and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4158 the `start' and `end' of the region in the current buffer that will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4159 copied. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4160 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4161 The next part of the function is the documentation, which is clear and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4162 complete. As is conventional, the three arguments are written in upper |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4163 case so you will notice them easily. Even better, they are described |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4164 in the same order as in the argument list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4165 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4166 Note that the documentation distinguishes between a buffer and its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4167 name. (The function can handle either.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4168 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4169 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4170 File: eintr, Node: append interactive, Next: append-to-buffer body, Prev: append-to-buffer overview, Up: append-to-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4171 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4172 4.4.1 The `append-to-buffer' Interactive Expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4173 --------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4174 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4175 Since the `append-to-buffer' function will be used interactively, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4176 function must have an `interactive' expression. (For a review of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4177 `interactive', see *Note Making a Function Interactive: Interactive.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4178 The expression reads as follows: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4179 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4180 (interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4181 (list (read-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4182 "Append to buffer: " |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4183 (other-buffer (current-buffer) t)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4184 (region-beginning) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4185 (region-end))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4186 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4187 This expression is not one with letters standing for parts, as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4188 described earlier. Instead, it starts a list with thee parts. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4189 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4190 The first part of the list is an expression to read the name of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4191 buffer and return it as a string. That is `read-buffer'. The function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4192 requires a prompt as its first argument, `"Append to buffer: "'. Its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4193 second argument tells the command what value to provide if you don't |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4194 specify anything. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4195 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4196 In this case that second argument is an expression containing the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4197 function `other-buffer', an exception, and a `t', standing for true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4198 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4199 The first argument to `other-buffer', the exception, is yet another |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4200 function, `current-buffer'. That is not going to be returned. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4201 second argument is the symbol for true, `t'. that tells `other-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4202 that it may show visible buffers (except in this case, it will not show |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4203 the current buffer, which makes sense). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4204 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4205 The expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4206 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4207 (other-buffer (current-buffer) t) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4208 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4209 The second and third arguments to the `list' expression are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4210 `(region-beginning)' and `(region-end)'. These two functions specify |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4211 the beginning and end of the text to be appended. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4212 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4213 Originally, the command used the letters `B' and `r'. The whole |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4214 `interactive' expression looked like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4215 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4216 (interactive "BAppend to buffer: \nr") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4217 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4218 But when that was done, the default value of the buffer switched to was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4219 invisible. That was not wanted. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4220 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4221 (The prompt was separated from the second argument with a newline, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4222 `\n'. It was followed by an `r' that told Emacs to bind the two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4223 arguments that follow the symbol `buffer' in the function's argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4224 list (that is, `start' and `end') to the values of point and mark. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4225 That argument worked fine.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4226 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4227 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4228 File: eintr, Node: append-to-buffer body, Next: append save-excursion, Prev: append interactive, Up: append-to-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4229 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4230 4.4.2 The Body of `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4231 ------------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4232 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4233 The body of the `append-to-buffer' function begins with `let'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4234 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4235 As we have seen before (*note `let': let.), the purpose of a `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4236 expression is to create and give initial values to one or more |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4237 variables that will only be used within the body of the `let'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4238 means that such a variable will not be confused with any variable of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4239 the same name outside the `let' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4240 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4241 We can see how the `let' expression fits into the function as a whole |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4242 by showing a template for `append-to-buffer' with the `let' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4243 in outline: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4244 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4245 (defun append-to-buffer (buffer start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4246 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4247 (interactive ...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4248 (let ((VARIABLE VALUE)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4249 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4250 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4251 The `let' expression has three elements: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4252 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4253 1. The symbol `let'; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4254 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4255 2. A varlist containing, in this case, a single two-element list, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4256 `(VARIABLE VALUE)'; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4257 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4258 3. The body of the `let' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4259 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4260 In the `append-to-buffer' function, the varlist looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4261 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4262 (oldbuf (current-buffer)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4263 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4264 In this part of the `let' expression, the one variable, `oldbuf', is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4265 bound to the value returned by the `(current-buffer)' expression. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4266 variable, `oldbuf', is used to keep track of the buffer in which you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4267 are working and from which you will copy. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4268 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4269 The element or elements of a varlist are surrounded by a set of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4270 parentheses so the Lisp interpreter can distinguish the varlist from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4271 the body of the `let'. As a consequence, the two-element list within |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4272 the varlist is surrounded by a circumscribing set of parentheses. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4273 line looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4274 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4275 (let ((oldbuf (current-buffer))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4276 ... ) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4277 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4278 The two parentheses before `oldbuf' might surprise you if you did not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4279 realize that the first parenthesis before `oldbuf' marks the boundary |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4280 of the varlist and the second parenthesis marks the beginning of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4281 two-element list, `(oldbuf (current-buffer))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4282 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4283 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4284 File: eintr, Node: append save-excursion, Prev: append-to-buffer body, Up: append-to-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4285 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4286 4.4.3 `save-excursion' in `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4287 -------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4288 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4289 The body of the `let' expression in `append-to-buffer' consists of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4290 `save-excursion' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4291 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4292 The `save-excursion' function saves the locations of point and mark, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4293 and restores them to those positions after the expressions in the body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4294 of the `save-excursion' complete execution. In addition, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4295 `save-excursion' keeps track of the original buffer, and restores it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4296 This is how `save-excursion' is used in `append-to-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4297 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4298 Incidentally, it is worth noting here that a Lisp function is normally |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4299 formatted so that everything that is enclosed in a multi-line spread is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4300 indented more to the right than the first symbol. In this function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4301 definition, the `let' is indented more than the `defun', and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4302 `save-excursion' is indented more than the `let', like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4303 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4304 (defun ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4305 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4306 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4307 (let... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4308 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4309 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4310 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4311 This formatting convention makes it easy to see that the lines in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4312 body of the `save-excursion' are enclosed by the parentheses associated |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4313 with `save-excursion', just as the `save-excursion' itself is enclosed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4314 by the parentheses associated with the `let': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4315 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4316 (let ((oldbuf (current-buffer))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4317 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4318 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4319 (set-buffer ...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4320 (insert-buffer-substring oldbuf start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4321 ...)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4322 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4323 The use of the `save-excursion' function can be viewed as a process of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4324 filling in the slots of a template: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4325 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4326 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4327 FIRST-EXPRESSION-IN-BODY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4328 SECOND-EXPRESSION-IN-BODY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4329 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4330 LAST-EXPRESSION-IN-BODY) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4331 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4332 In this function, the body of the `save-excursion' contains only one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4333 expression, the `let*' expression. You know about a `let' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4334 The `let*' function is different. It has a `*' in its name. It |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4335 enables Emacs to set each variable in its varlist in sequence, one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4336 after another. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4337 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4338 Its critical feature is that variables later in the varlist can make |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4339 use of the values to which Emacs set variables earlier in the varlist. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4340 *Note The `let*' expression: fwd-para let. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4341 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4342 We will skip functions like `let*' and focus on two: the `set-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4343 function and the `insert-buffer-substring' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4344 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4345 In the old days, the `set-buffer' expression was simply |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4346 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4347 (set-buffer (get-buffer-create buffer)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4348 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4349 but now it is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4350 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4351 (set-buffer append-to) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4352 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4353 `append-to' is bound to `(get-buffer-create buffer)' earlier on in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4354 `let*' expression. That extra binding would not be necessary except |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4355 for that `append-to' is used later in the varlist as an argument to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4356 `get-buffer-window-list'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4357 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4358 The `append-to-buffer' function definition inserts text from the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4359 in which you are currently to a named buffer. It happens that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4360 `insert-buffer-substring' copies text from another buffer to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4361 current buffer, just the reverse--that is why the `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4362 definition starts out with a `let' that binds the local symbol `oldbuf' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4363 to the value returned by `current-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4364 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4365 The `insert-buffer-substring' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4366 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4367 (insert-buffer-substring oldbuf start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4368 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4369 The `insert-buffer-substring' function copies a string _from_ the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4370 buffer specified as its first argument and inserts the string into the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4371 present buffer. In this case, the argument to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4372 `insert-buffer-substring' is the value of the variable created and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4373 bound by the `let', namely the value of `oldbuf', which was the current |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4374 buffer when you gave the `append-to-buffer' command. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4375 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4376 After `insert-buffer-substring' has done its work, `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4377 will restore the action to the original buffer and `append-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4378 will have done its job. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4379 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4380 Written in skeletal form, the workings of the body look like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4381 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4382 (let (BIND-`oldbuf'-TO-VALUE-OF-`current-buffer') |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4383 (save-excursion ; Keep track of buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4384 CHANGE-BUFFER |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4385 INSERT-SUBSTRING-FROM-`oldbuf'-INTO-BUFFER) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4386 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4387 CHANGE-BACK-TO-ORIGINAL-BUFFER-WHEN-FINISHED |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4388 LET-THE-LOCAL-MEANING-OF-`oldbuf'-DISAPPEAR-WHEN-FINISHED |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4389 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4390 In summary, `append-to-buffer' works as follows: it saves the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4391 the current buffer in the variable called `oldbuf'. It gets the new |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4392 buffer (creating one if need be) and switches Emacs' attention to it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4393 Using the value of `oldbuf', it inserts the region of text from the old |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4394 buffer into the new buffer; and then using `save-excursion', it brings |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4395 you back to your original buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4396 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4397 In looking at `append-to-buffer', you have explored a fairly complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4398 function. It shows how to use `let' and `save-excursion', and how to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4399 change to and come back from another buffer. Many function definitions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4400 use `let', `save-excursion', and `set-buffer' this way. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4401 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4402 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4403 File: eintr, Node: Buffer Related Review, Next: Buffer Exercises, Prev: append-to-buffer, Up: Buffer Walk Through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4404 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4405 4.5 Review |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4406 ========== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4407 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4408 Here is a brief summary of the various functions discussed in this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4409 chapter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4410 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4411 `describe-function' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4412 `describe-variable' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4413 Print the documentation for a function or variable. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4414 Conventionally bound to `C-h f' and `C-h v'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4415 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4416 `find-tag' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4417 Find the file containing the source for a function or variable and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4418 switch buffers to it, positioning point at the beginning of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4419 item. Conventionally bound to `M-.' (that's a period following the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4420 <META> key). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4421 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4422 `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4423 Save the location of point and mark and restore their values after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4424 the arguments to `save-excursion' have been evaluated. Also, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4425 remember the current buffer and return to it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4426 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4427 `push-mark' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4428 Set mark at a location and record the value of the previous mark |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4429 on the mark ring. The mark is a location in the buffer that will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4430 keep its relative position even if text is added to or removed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4431 from the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4432 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4433 `goto-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4434 Set point to the location specified by the value of the argument, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4435 which can be a number, a marker, or an expression that returns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4436 the number of a position, such as `(point-min)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4437 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4438 `insert-buffer-substring' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4439 Copy a region of text from a buffer that is passed to the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4440 as an argument and insert the region into the current buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4441 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4442 `mark-whole-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4443 Mark the whole buffer as a region. Normally bound to `C-x h'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4444 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4445 `set-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4446 Switch the attention of Emacs to another buffer, but do not change |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4447 the window being displayed. Used when the program rather than a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4448 human is to work on a different buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4449 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4450 `get-buffer-create' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4451 `get-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4452 Find a named buffer or create one if a buffer of that name does not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4453 exist. The `get-buffer' function returns `nil' if the named |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4454 buffer does not exist. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4455 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4456 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4457 File: eintr, Node: Buffer Exercises, Prev: Buffer Related Review, Up: Buffer Walk Through |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4458 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4459 4.6 Exercises |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4460 ============= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4461 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4462 * Write your own `simplified-end-of-buffer' function definition; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4463 then test it to see whether it works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4464 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4465 * Use `if' and `get-buffer' to write a function that prints a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4466 message telling you whether a buffer exists. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4467 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4468 * Using `find-tag', find the source for the `copy-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4469 function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4470 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4471 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4472 File: eintr, Node: More Complex, Next: Narrowing & Widening, Prev: Buffer Walk Through, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4473 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4474 5 A Few More Complex Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4475 ****************************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4476 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4477 In this chapter, we build on what we have learned in previous chapters |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4478 by looking at more complex functions. The `copy-to-buffer' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4479 illustrates use of two `save-excursion' expressions in one definition, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4480 while the `insert-buffer' function illustrates use of an asterisk in an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4481 `interactive' expression, use of `or', and the important distinction |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4482 between a name and the object to which the name refers. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4483 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4484 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4485 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4486 * copy-to-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4487 * insert-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4488 * beginning-of-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4489 * Second Buffer Related Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4490 * optional Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4491 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4492 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4493 File: eintr, Node: copy-to-buffer, Next: insert-buffer, Prev: More Complex, Up: More Complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4494 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4495 5.1 The Definition of `copy-to-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4496 ====================================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4497 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4498 After understanding how `append-to-buffer' works, it is easy to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4499 understand `copy-to-buffer'. This function copies text into a buffer, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4500 but instead of adding to the second buffer, it replaces all the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4501 previous text in the second buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4502 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4503 The body of `copy-to-buffer' looks like this, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4504 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4505 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4506 (interactive "BCopy to buffer: \nr") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4507 (let ((oldbuf (current-buffer))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4508 (with-current-buffer (get-buffer-create buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4509 (barf-if-buffer-read-only) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4510 (erase-buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4511 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4512 (insert-buffer-substring oldbuf start end))))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4513 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4514 The `copy-to-buffer' function has a simpler `interactive' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4515 than `append-to-buffer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4516 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4517 The definition then says |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4518 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4519 (with-current-buffer (get-buffer-create buffer) ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4520 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4521 First, look at the earliest inner expression; that is evaluated first. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4522 That expression starts with `get-buffer-create buffer'. The function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4523 tells the computer to use the buffer with the name specified as the one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4524 to which you are copying, or if such a buffer does not exist, to create |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4525 it. Then, the `with-current-buffer' function evaluates its body with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4526 that buffer temporarily current. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4527 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4528 (This demonstrates another way to shift the computer's attention but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4529 not the user's. The `append-to-buffer' function showed how to do the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4530 same with `save-excursion' and `set-buffer'. `with-current-buffer' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4531 a newer, and arguably easier, mechanism.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4532 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4533 The `barf-if-buffer-read-only' function sends you an error message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4534 saying the buffer is read-only if you cannot modify it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4535 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4536 The next line has the `erase-buffer' function as its sole contents. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4537 That function erases the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4538 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4539 Finally, the last two lines contain the `save-excursion' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4540 with `insert-buffer-substring' as its body. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4541 `insert-buffer-substring' expression copies the text from the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4542 you are in (and you have not seen the computer shift its attention, so |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4543 you don't know that that buffer is now called `oldbuf'). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4544 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4545 Incidentally, this is what is meant by `replacement'. To replace text, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4546 Emacs erases the previous text and then inserts new text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4547 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4548 In outline, the body of `copy-to-buffer' looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4549 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4550 (let (BIND-`oldbuf'-TO-VALUE-OF-`current-buffer') |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4551 (WITH-THE-BUFFER-YOU-ARE-COPYING-TO |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4552 (BUT-DO-NOT-ERASE-OR-COPY-TO-A-READ-ONLY-BUFFER) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4553 (erase-buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4554 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4555 INSERT-SUBSTRING-FROM-`oldbuf'-INTO-BUFFER))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4556 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4557 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4558 File: eintr, Node: insert-buffer, Next: beginning-of-buffer, Prev: copy-to-buffer, Up: More Complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4559 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4560 5.2 The Definition of `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4561 ===================================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4562 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4563 `insert-buffer' is yet another buffer-related function. This command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4564 copies another buffer _into_ the current buffer. It is the reverse of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4565 `append-to-buffer' or `copy-to-buffer', since they copy a region of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4566 text _from_ the current buffer to another buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4567 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4568 Here is a discussion based on the original code. The code was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4569 simplified in 2003 and is harder to understand. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4570 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4571 *Note New Body for `insert-buffer': New insert-buffer, to see a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4572 discussion of the new body.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4573 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4574 In addition, this code illustrates the use of `interactive' with a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4575 buffer that might be "read-only" and the important distinction between |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4576 the name of an object and the object actually referred to. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4577 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4578 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4579 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4580 * insert-buffer code:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4581 * insert-buffer interactive:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4582 * insert-buffer body:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4583 * if & or:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4584 * Insert or:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4585 * Insert let:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4586 * New insert-buffer :: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4587 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4588 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4589 File: eintr, Node: insert-buffer code, Next: insert-buffer interactive, Prev: insert-buffer, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4590 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4591 The Code for `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4592 ---------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4593 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4594 Here is the earlier code: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4595 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4596 (defun insert-buffer (buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4597 "Insert after point the contents of BUFFER. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4598 Puts mark after the inserted text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4599 BUFFER may be a buffer or a buffer name." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4600 (interactive "*bInsert buffer: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4601 (or (bufferp buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4602 (setq buffer (get-buffer buffer))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4603 (let (start end newmark) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4604 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4605 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4606 (set-buffer buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4607 (setq start (point-min) end (point-max))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4608 (insert-buffer-substring buffer start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4609 (setq newmark (point))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4610 (push-mark newmark))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4611 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4612 As with other function definitions, you can use a template to see an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4613 outline of the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4614 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4615 (defun insert-buffer (buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4616 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4617 (interactive "*bInsert buffer: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4618 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4619 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4620 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4621 File: eintr, Node: insert-buffer interactive, Next: insert-buffer body, Prev: insert-buffer code, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4622 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4623 5.2.1 The Interactive Expression in `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4624 --------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4625 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4626 In `insert-buffer', the argument to the `interactive' declaration has |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4627 two parts, an asterisk, `*', and `bInsert buffer: '. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4628 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4629 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4630 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4631 * Read-only buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4632 * b for interactive:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4633 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4634 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4635 File: eintr, Node: Read-only buffer, Next: b for interactive, Prev: insert-buffer interactive, Up: insert-buffer interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4636 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4637 A Read-only Buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4638 .................. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4639 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4640 The asterisk is for the situation when the current buffer is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4641 read-only buffer--a buffer that cannot be modified. If `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4642 is called when the current buffer is read-only, a message to this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4643 effect is printed in the echo area and the terminal may beep or blink |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4644 at you; you will not be permitted to insert anything into current |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4645 buffer. The asterisk does not need to be followed by a newline to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4646 separate it from the next argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4647 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4648 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4649 File: eintr, Node: b for interactive, Prev: Read-only buffer, Up: insert-buffer interactive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4650 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4651 `b' in an Interactive Expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4652 ................................ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4653 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4654 The next argument in the interactive expression starts with a lower |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4655 case `b'. (This is different from the code for `append-to-buffer', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4656 which uses an upper-case `B'. *Note The Definition of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4657 `append-to-buffer': append-to-buffer.) The lower-case `b' tells the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4658 Lisp interpreter that the argument for `insert-buffer' should be an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4659 existing buffer or else its name. (The upper-case `B' option provides |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4660 for the possibility that the buffer does not exist.) Emacs will prompt |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4661 you for the name of the buffer, offering you a default buffer, with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4662 name completion enabled. If the buffer does not exist, you receive a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4663 message that says "No match"; your terminal may beep at you as well. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4664 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4665 The new and simplified code generates a list for `interactive'. It |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4666 uses the `barf-if-buffer-read-only' and `read-buffer' functions with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4667 which we are already familiar and the `progn' special form with which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4668 we are not. (It will be described later.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4669 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4670 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4671 File: eintr, Node: insert-buffer body, Next: if & or, Prev: insert-buffer interactive, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4672 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4673 5.2.2 The Body of the `insert-buffer' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4674 ---------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4675 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4676 The body of the `insert-buffer' function has two major parts: an `or' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4677 expression and a `let' expression. The purpose of the `or' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4678 is to ensure that the argument `buffer' is bound to a buffer and not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4679 just the name of a buffer. The body of the `let' expression contains |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4680 the code which copies the other buffer into the current buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4681 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4682 In outline, the two expressions fit into the `insert-buffer' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4683 like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4684 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4685 (defun insert-buffer (buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4686 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4687 (interactive "*bInsert buffer: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4688 (or ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4689 ... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4690 (let (VARLIST) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4691 BODY-OF-`let'... ) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4692 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4693 To understand how the `or' expression ensures that the argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4694 `buffer' is bound to a buffer and not to the name of a buffer, it is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4695 first necessary to understand the `or' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4696 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4697 Before doing this, let me rewrite this part of the function using `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4698 so that you can see what is done in a manner that will be familiar. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4699 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4700 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4701 File: eintr, Node: if & or, Next: Insert or, Prev: insert-buffer body, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4702 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4703 5.2.3 `insert-buffer' With an `if' Instead of an `or' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4704 ----------------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4705 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4706 The job to be done is to make sure the value of `buffer' is a buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4707 itself and not the name of a buffer. If the value is the name, then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4708 the buffer itself must be got. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4709 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4710 You can imagine yourself at a conference where an usher is wandering |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4711 around holding a list with your name on it and looking for you: the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4712 usher is "bound" to your name, not to you; but when the usher finds you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4713 and takes your arm, the usher becomes "bound" to you. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4714 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4715 In Lisp, you might describe this situation like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4716 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4717 (if (not (holding-on-to-guest)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4718 (find-and-take-arm-of-guest)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4719 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4720 We want to do the same thing with a buffer--if we do not have the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4721 buffer itself, we want to get it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4722 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4723 Using a predicate called `bufferp' that tells us whether we have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4724 buffer (rather than its name), we can write the code like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4725 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4726 (if (not (bufferp buffer)) ; if-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4727 (setq buffer (get-buffer buffer))) ; then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4728 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4729 Here, the true-or-false-test of the `if' expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4730 `(not (bufferp buffer))'; and the then-part is the expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4731 `(setq buffer (get-buffer buffer))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4732 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4733 In the test, the function `bufferp' returns true if its argument is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4734 buffer--but false if its argument is the name of the buffer. (The last |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4735 character of the function name `bufferp' is the character `p'; as we |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4736 saw earlier, such use of `p' is a convention that indicates that the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4737 function is a predicate, which is a term that means that the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4738 will determine whether some property is true or false. *Note Using the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4739 Wrong Type Object as an Argument: Wrong Type of Argument.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4740 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4741 The function `not' precedes the expression `(bufferp buffer)', so the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4742 true-or-false-test looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4743 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4744 (not (bufferp buffer)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4745 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4746 `not' is a function that returns true if its argument is false and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4747 false if its argument is true. So if `(bufferp buffer)' returns true, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4748 the `not' expression returns false and vice-verse: what is "not true" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4749 is false and what is "not false" is true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4750 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4751 Using this test, the `if' expression works as follows: when the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4752 of the variable `buffer' is actually a buffer rather than its name, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4753 true-or-false-test returns false and the `if' expression does not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4754 evaluate the then-part. This is fine, since we do not need to do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4755 anything to the variable `buffer' if it really is a buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4756 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4757 On the other hand, when the value of `buffer' is not a buffer itself, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4758 but the name of a buffer, the true-or-false-test returns true and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4759 then-part of the expression is evaluated. In this case, the then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4760 is `(setq buffer (get-buffer buffer))'. This expression uses the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4761 `get-buffer' function to return an actual buffer itself, given its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4762 name. The `setq' then sets the variable `buffer' to the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4763 buffer itself, replacing its previous value (which was the name of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4764 buffer). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4765 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4766 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4767 File: eintr, Node: Insert or, Next: Insert let, Prev: if & or, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4768 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4769 5.2.4 The `or' in the Body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4770 -------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4771 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4772 The purpose of the `or' expression in the `insert-buffer' function is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4773 to ensure that the argument `buffer' is bound to a buffer and not just |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4774 to the name of a buffer. The previous section shows how the job could |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4775 have been done using an `if' expression. However, the `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4776 function actually uses `or'. To understand this, it is necessary to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4777 understand how `or' works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4778 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4779 An `or' function can have any number of arguments. It evaluates each |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4780 argument in turn and returns the value of the first of its arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4781 that is not `nil'. Also, and this is a crucial feature of `or', it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4782 does not evaluate any subsequent arguments after returning the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4783 non-`nil' value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4784 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4785 The `or' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4786 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4787 (or (bufferp buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4788 (setq buffer (get-buffer buffer))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4789 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4790 The first argument to `or' is the expression `(bufferp buffer)'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4791 expression returns true (a non-`nil' value) if the buffer is actually a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4792 buffer, and not just the name of a buffer. In the `or' expression, if |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4793 this is the case, the `or' expression returns this true value and does |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4794 not evaluate the next expression--and this is fine with us, since we do |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4795 not want to do anything to the value of `buffer' if it really is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4796 buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4797 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4798 On the other hand, if the value of `(bufferp buffer)' is `nil', which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4799 it will be if the value of `buffer' is the name of a buffer, the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4800 interpreter evaluates the next element of the `or' expression. This is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4801 the expression `(setq buffer (get-buffer buffer))'. This expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4802 returns a non-`nil' value, which is the value to which it sets the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4803 variable `buffer'--and this value is a buffer itself, not the name of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4804 buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4805 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4806 The result of all this is that the symbol `buffer' is always bound to a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4807 buffer itself rather than to the name of a buffer. All this is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4808 necessary because the `set-buffer' function in a following line only |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4809 works with a buffer itself, not with the name to a buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4810 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4811 Incidentally, using `or', the situation with the usher would be written |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4812 like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4813 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4814 (or (holding-on-to-guest) (find-and-take-arm-of-guest)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4815 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4816 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4817 File: eintr, Node: Insert let, Next: New insert-buffer, Prev: Insert or, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4818 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4819 5.2.5 The `let' Expression in `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4820 --------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4821 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4822 After ensuring that the variable `buffer' refers to a buffer itself and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4823 not just to the name of a buffer, the `insert-buffer function' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4824 continues with a `let' expression. This specifies three local |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4825 variables, `start', `end', and `newmark' and binds them to the initial |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4826 value `nil'. These variables are used inside the remainder of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4827 `let' and temporarily hide any other occurrence of variables of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4828 same name in Emacs until the end of the `let'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4829 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4830 The body of the `let' contains two `save-excursion' expressions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4831 First, we will look at the inner `save-excursion' expression in detail. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4832 The expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4833 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4834 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4835 (set-buffer buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4836 (setq start (point-min) end (point-max))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4837 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4838 The expression `(set-buffer buffer)' changes Emacs' attention from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4839 current buffer to the one from which the text will copied. In that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4840 buffer, the variables `start' and `end' are set to the beginning and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4841 end of the buffer, using the commands `point-min' and `point-max'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4842 Note that we have here an illustration of how `setq' is able to set two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4843 variables in the same expression. The first argument of `setq' is set |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4844 to the value of its second, and its third argument is set to the value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4845 of its fourth. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4846 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4847 After the body of the inner `save-excursion' is evaluated, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4848 `save-excursion' restores the original buffer, but `start' and `end' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4849 remain set to the values of the beginning and end of the buffer from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4850 which the text will be copied. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4851 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4852 The outer `save-excursion' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4853 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4854 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4855 (INNER-`save-excursion'-EXPRESSION |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4856 (GO-TO-NEW-BUFFER-AND-SET-`start'-AND-`end') |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4857 (insert-buffer-substring buffer start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4858 (setq newmark (point))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4859 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4860 The `insert-buffer-substring' function copies the text _into_ the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4861 current buffer _from_ the region indicated by `start' and `end' in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4862 `buffer'. Since the whole of the second buffer lies between `start' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4863 and `end', the whole of the second buffer is copied into the buffer you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4864 are editing. Next, the value of point, which will be at the end of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4865 inserted text, is recorded in the variable `newmark'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4866 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4867 After the body of the outer `save-excursion' is evaluated, point and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4868 mark are relocated to their original places. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4869 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4870 However, it is convenient to locate a mark at the end of the newly |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4871 inserted text and locate point at its beginning. The `newmark' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4872 variable records the end of the inserted text. In the last line of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4873 `let' expression, the `(push-mark newmark)' expression function sets a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4874 mark to this location. (The previous location of the mark is still |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4875 accessible; it is recorded on the mark ring and you can go back to it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4876 with `C-u C-<SPC>'.) Meanwhile, point is located at the beginning of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4877 the inserted text, which is where it was before you called the insert |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4878 function, the position of which was saved by the first `save-excursion'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4879 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4880 The whole `let' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4881 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4882 (let (start end newmark) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4883 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4884 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4885 (set-buffer buffer) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4886 (setq start (point-min) end (point-max))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4887 (insert-buffer-substring buffer start end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4888 (setq newmark (point))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4889 (push-mark newmark)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4890 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4891 Like the `append-to-buffer' function, the `insert-buffer' function uses |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4892 `let', `save-excursion', and `set-buffer'. In addition, the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4893 illustrates one way to use `or'. All these functions are building |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4894 blocks that we will find and use again and again. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4895 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4896 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4897 File: eintr, Node: New insert-buffer, Prev: Insert let, Up: insert-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4898 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4899 5.2.6 New Body for `insert-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4900 ---------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4901 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4902 The body in the GNU Emacs 22 version is more confusing than the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4903 original. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4904 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4905 It consists of two expressions, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4906 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4907 (push-mark |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4908 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4909 (insert-buffer-substring (get-buffer buffer)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4910 (point))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4911 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4912 nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4913 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4914 except, and this is what confuses novices, very important work is done |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4915 inside the `push-mark' expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4916 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4917 The `get-buffer' function returns a buffer with the name provided. You |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4918 will note that the function is _not_ called `get-buffer-create'; it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4919 does not create a buffer if one does not already exist. The buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4920 returned by `get-buffer', an existing buffer, is passed to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4921 `insert-buffer-substring', which inserts the whole of the buffer (since |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4922 you did not specify anything else). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4923 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4924 The location into which the buffer is inserted is recorded by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4925 `push-mark'. Then the function returns `nil', the value of its last |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4926 command. Put another way, the `insert-buffer' function exists only to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4927 produce a side effect, inserting another buffer, not to return any |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4928 value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4929 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4930 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4931 File: eintr, Node: beginning-of-buffer, Next: Second Buffer Related Review, Prev: insert-buffer, Up: More Complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4932 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4933 5.3 Complete Definition of `beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4934 ================================================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4935 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4936 The basic structure of the `beginning-of-buffer' function has already |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4937 been discussed. (*Note A Simplified `beginning-of-buffer' Definition: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4938 simplified-beginning-of-buffer.) This section describes the complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4939 part of the definition. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4940 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4941 As previously described, when invoked without an argument, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4942 `beginning-of-buffer' moves the cursor to the beginning of the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4943 (in truth, the accessible portion of the buffer), leaving the mark at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4944 the previous position. However, when the command is invoked with a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4945 number between one and ten, the function considers that number to be a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4946 fraction of the length of the buffer, measured in tenths, and Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4947 moves the cursor that fraction of the way from the beginning of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4948 buffer. Thus, you can either call this function with the key command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4949 `M-<', which will move the cursor to the beginning of the buffer, or |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4950 with a key command such as `C-u 7 M-<' which will move the cursor to a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4951 point 70% of the way through the buffer. If a number bigger than ten |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4952 is used for the argument, it moves to the end of the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4953 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4954 The `beginning-of-buffer' function can be called with or without an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4955 argument. The use of the argument is optional. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4956 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4957 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4958 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4959 * Optional Arguments:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4960 * beginning-of-buffer opt arg:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4961 * beginning-of-buffer complete:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4962 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4963 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4964 File: eintr, Node: Optional Arguments, Next: beginning-of-buffer opt arg, Prev: beginning-of-buffer, Up: beginning-of-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4965 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4966 5.3.1 Optional Arguments |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4967 ------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4968 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4969 Unless told otherwise, Lisp expects that a function with an argument in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4970 its function definition will be called with a value for that argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4971 If that does not happen, you get an error and a message that says |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4972 `Wrong number of arguments'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4973 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4974 However, optional arguments are a feature of Lisp: a particular |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4975 "keyword" is used to tell the Lisp interpreter that an argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4976 optional. The keyword is `&optional'. (The `&' in front of `optional' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4977 is part of the keyword.) In a function definition, if an argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4978 follows the keyword `&optional', no value need be passed to that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4979 argument when the function is called. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4980 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4981 The first line of the function definition of `beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4982 therefore looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4983 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4984 (defun beginning-of-buffer (&optional arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4985 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4986 In outline, the whole function looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4987 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4988 (defun beginning-of-buffer (&optional arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4989 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4990 (interactive "P") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4991 (or (IS-THE-ARGUMENT-A-CONS-CELL arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4992 (and ARE-BOTH-TRANSIENT-MARK-MODE-AND-MARK-ACTIVE-TRUE) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4993 (push-mark)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4994 (let (DETERMINE-SIZE-AND-SET-IT) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4995 (goto-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4996 (IF-THERE-IS-AN-ARGUMENT |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4997 FIGURE-OUT-WHERE-TO-GO |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4998 ELSE-GO-TO |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
4999 (point-min)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5000 DO-NICETY |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5001 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5002 The function is similar to the `simplified-beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5003 function except that the `interactive' expression has `"P"' as an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5004 argument and the `goto-char' function is followed by an if-then-else |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5005 expression that figures out where to put the cursor if there is an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5006 argument that is not a cons cell. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5007 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5008 (Since I do not explain a cons cell for many more chapters, please |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5009 consider ignoring the function `consp'. *Note How Lists are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5010 Implemented: List Implementation, and *Note Cons Cell and List Types: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5011 (elisp)Cons Cell Type.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5012 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5013 The `"P"' in the `interactive' expression tells Emacs to pass a prefix |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5014 argument, if there is one, to the function in raw form. A prefix |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5015 argument is made by typing the <META> key followed by a number, or by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5016 typing `C-u' and then a number. (If you don't type a number, `C-u' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5017 defaults to a cons cell with a 4. A lowercase `"p"' in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5018 `interactive' expression causes the function to convert a prefix arg to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5019 a number.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5020 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5021 The true-or-false-test of the `if' expression looks complex, but it is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5022 not: it checks whether `arg' has a value that is not `nil' and whether |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5023 it is a cons cell. (That is what `consp' does; it checks whether its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5024 argument is a cons cell.) If `arg' has a value that is not `nil' (and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5025 is not a cons cell), which will be the case if `beginning-of-buffer' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5026 called with a numeric argument, then this true-or-false-test will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5027 return true and the then-part of the `if' expression will be evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5028 On the other hand, if `beginning-of-buffer' is not called with an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5029 argument, the value of `arg' will be `nil' and the else-part of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5030 `if' expression will be evaluated. The else-part is simply |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5031 `point-min', and when this is the outcome, the whole `goto-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5032 expression is `(goto-char (point-min))', which is how we saw the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5033 `beginning-of-buffer' function in its simplified form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5034 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5035 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5036 File: eintr, Node: beginning-of-buffer opt arg, Next: beginning-of-buffer complete, Prev: Optional Arguments, Up: beginning-of-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5037 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5038 5.3.2 `beginning-of-buffer' with an Argument |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5039 -------------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5040 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5041 When `beginning-of-buffer' is called with an argument, an expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5042 evaluated which calculates what value to pass to `goto-char'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5043 expression is rather complicated at first sight. It includes an inner |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5044 `if' expression and much arithmetic. It looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5045 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5046 (if (> (buffer-size) 10000) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5047 ;; Avoid overflow for large buffer sizes! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5048 (* (prefix-numeric-value arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5049 (/ size 10)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5050 (/ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5051 (+ 10 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5052 (* |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5053 size (prefix-numeric-value arg))) 10))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5054 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5055 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5056 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5057 * Disentangle beginning-of-buffer:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5058 * Large buffer case:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5059 * Small buffer case:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5060 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5061 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5062 File: eintr, Node: Disentangle beginning-of-buffer, Next: Large buffer case, Prev: beginning-of-buffer opt arg, Up: beginning-of-buffer opt arg |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5063 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5064 Disentangle `beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5065 ................................. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5066 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5067 Like other complex-looking expressions, the conditional expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5068 within `beginning-of-buffer' can be disentangled by looking at it as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5069 parts of a template, in this case, the template for an if-then-else |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5070 expression. In skeletal form, the expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5071 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5072 (if (BUFFER-IS-LARGE |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5073 DIVIDE-BUFFER-SIZE-BY-10-AND-MULTIPLY-BY-ARG |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5074 ELSE-USE-ALTERNATE-CALCULATION |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5075 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5076 The true-or-false-test of this inner `if' expression checks the size of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5077 the buffer. The reason for this is that the old Version 18 Emacs used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5078 numbers that are no bigger than eight million or so and in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5079 computation that followed, the programmer feared that Emacs might try |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5080 to use over-large numbers if the buffer were large. The term |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5081 `overflow', mentioned in the comment, means numbers that are over |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5082 large. Version 21 Emacs uses larger numbers, but this code has not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5083 been touched, if only because people now look at buffers that are far, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5084 far larger than ever before. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5085 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5086 There are two cases: if the buffer is large and if it is not. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5087 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5088 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5089 File: eintr, Node: Large buffer case, Next: Small buffer case, Prev: Disentangle beginning-of-buffer, Up: beginning-of-buffer opt arg |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5090 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5091 What happens in a large buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5092 .............................. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5093 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5094 In `beginning-of-buffer', the inner `if' expression tests whether the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5095 size of the buffer is greater than 10,000 characters. To do this, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5096 uses the `>' function and the computation of `size' that comes from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5097 let expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5098 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5099 In the old days, the function `buffer-size' was used. Not only was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5100 that function called several times, it gave the size of the whole |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5101 buffer, not the accessible part. The computation makes much more sense |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5102 when it handles just the accessible part. (*Note Narrowing and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5103 Widening: Narrowing & Widening, for more information on focusing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5104 attention to an `accessible' part.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5105 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5106 The line looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5107 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5108 (if (> size 10000) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5109 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5110 When the buffer is large, the then-part of the `if' expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5111 evaluated. It reads like this (after formatting for easy reading): |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5112 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5113 (* |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5114 (prefix-numeric-value arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5115 (/ size 10)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5116 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5117 This expression is a multiplication, with two arguments to the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5118 `*'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5119 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5120 The first argument is `(prefix-numeric-value arg)'. When `"P"' is used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5121 as the argument for `interactive', the value passed to the function as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5122 its argument is passed a "raw prefix argument", and not a number. (It |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5123 is a number in a list.) To perform the arithmetic, a conversion is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5124 necessary, and `prefix-numeric-value' does the job. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5125 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5126 The second argument is `(/ size 10)'. This expression divides the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5127 numeric value by ten -- the numeric value of the size of the accessible |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5128 portion of the buffer. This produces a number that tells how many |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5129 characters make up one tenth of the buffer size. (In Lisp, `/' is used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5130 for division, just as `*' is used for multiplication.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5131 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5132 In the multiplication expression as a whole, this amount is multiplied |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5133 by the value of the prefix argument--the multiplication looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5134 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5135 (* NUMERIC-VALUE-OF-PREFIX-ARG |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5136 NUMBER-OF-CHARACTERS-IN-ONE-TENTH-OF-THE-ACCESSIBLE-BUFFER) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5137 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5138 If, for example, the prefix argument is `7', the one-tenth value will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5139 be multiplied by 7 to give a position 70% of the way through. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5140 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5141 The result of all this is that if the accessible portion of the buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5142 is large, the `goto-char' expression reads like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5143 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5144 (goto-char (* (prefix-numeric-value arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5145 (/ size 10))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5146 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5147 This puts the cursor where we want it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5148 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5149 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5150 File: eintr, Node: Small buffer case, Prev: Large buffer case, Up: beginning-of-buffer opt arg |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5151 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5152 What happens in a small buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5153 .............................. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5154 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5155 If the buffer contains fewer than 10,000 characters, a slightly |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5156 different computation is performed. You might think this is not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5157 necessary, since the first computation could do the job. However, in a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5158 small buffer, the first method may not put the cursor on exactly the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5159 desired line; the second method does a better job. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5160 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5161 The code looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5162 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5163 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5164 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5165 This is code in which you figure out what happens by discovering how the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5166 functions are embedded in parentheses. It is easier to read if you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5167 reformat it with each expression indented more deeply than its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5168 enclosing expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5169 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5170 (/ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5171 (+ 10 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5172 (* |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5173 size |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5174 (prefix-numeric-value arg))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5175 10)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5176 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5177 Looking at parentheses, we see that the innermost operation is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5178 `(prefix-numeric-value arg)', which converts the raw argument to a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5179 number. In the following expression, this number is multiplied by the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5180 size of the accessible portion of the buffer: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5181 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5182 (* size (prefix-numeric-value arg)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5183 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5184 This multiplication creates a number that may be larger than the size of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5185 the buffer--seven times larger if the argument is 7, for example. Ten |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5186 is then added to this number and finally the large number is divided by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5187 ten to provide a value that is one character larger than the percentage |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5188 position in the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5189 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5190 The number that results from all this is passed to `goto-char' and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5191 cursor is moved to that point. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5192 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5193 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5194 File: eintr, Node: beginning-of-buffer complete, Prev: beginning-of-buffer opt arg, Up: beginning-of-buffer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5195 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5196 5.3.3 The Complete `beginning-of-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5197 ---------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5198 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5199 Here is the complete text of the `beginning-of-buffer' function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5200 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5201 (defun beginning-of-buffer (&optional arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5202 "Move point to the beginning of the buffer; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5203 leave mark at previous position. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5204 With \\[universal-argument] prefix, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5205 do not set mark at previous position. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5206 With numeric arg N, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5207 put point N/10 of the way from the beginning. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5208 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5209 If the buffer is narrowed, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5210 this command uses the beginning and size |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5211 of the accessible part of the buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5212 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5213 Don't use this command in Lisp programs! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5214 \(goto-char (point-min)) is faster |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5215 and avoids clobbering the mark." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5216 (interactive "P") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5217 (or (consp arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5218 (and transient-mark-mode mark-active) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5219 (push-mark)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5220 (let ((size (- (point-max) (point-min)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5221 (goto-char (if (and arg (not (consp arg))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5222 (+ (point-min) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5223 (if (> size 10000) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5224 ;; Avoid overflow for large buffer sizes! |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5225 (* (prefix-numeric-value arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5226 (/ size 10)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5227 (/ (+ 10 (* size (prefix-numeric-value arg))) 10))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5228 (point-min)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5229 (if arg (forward-line 1))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5230 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5231 Except for two small points, the previous discussion shows how this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5232 function works. The first point deals with a detail in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5233 documentation string, and the second point concerns the last line of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5234 the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5235 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5236 In the documentation string, there is reference to an expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5237 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5238 \\[universal-argument] |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5239 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5240 A `\\' is used before the first square bracket of this expression. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5241 This `\\' tells the Lisp interpreter to substitute whatever key is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5242 currently bound to the `[...]'. In the case of `universal-argument', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5243 that is usually `C-u', but it might be different. (*Note Tips for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5244 Documentation Strings: (elisp)Documentation Tips, for more information.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5245 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5246 Finally, the last line of the `beginning-of-buffer' command says to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5247 move point to the beginning of the next line if the command is invoked |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5248 with an argument: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5249 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5250 (if arg (forward-line 1))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5251 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5252 This puts the cursor at the beginning of the first line after the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5253 appropriate tenths position in the buffer. This is a flourish that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5254 means that the cursor is always located _at least_ the requested tenths |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5255 of the way through the buffer, which is a nicety that is, perhaps, not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5256 necessary, but which, if it did not occur, would be sure to draw |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5257 complaints. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5258 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5259 On the other hand, it also means that if you specify the command with a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5260 `C-u', but without a number, that is to say, if the `raw prefix |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5261 argument' is simply a cons cell, then the command puts you at the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5262 beginning of the second line ... I don't know whether this is intended |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5263 or whether no one has dealt with the code to avoid this happening. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5264 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5265 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5266 File: eintr, Node: Second Buffer Related Review, Next: optional Exercise, Prev: beginning-of-buffer, Up: More Complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5267 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5268 5.4 Review |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5269 ========== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5270 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5271 Here is a brief summary of some of the topics covered in this chapter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5272 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5273 `or' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5274 Evaluate each argument in sequence, and return the value of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5275 first argument that is not `nil'; if none return a value that is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5276 not `nil', return `nil'. In brief, return the first true value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5277 the arguments; return a true value if one _or_ any of the others |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5278 are true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5279 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5280 `and' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5281 Evaluate each argument in sequence, and if any are `nil', return |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5282 `nil'; if none are `nil', return the value of the last argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5283 In brief, return a true value only if all the arguments are true; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5284 return a true value if one _and_ each of the others is true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5285 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5286 `&optional' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5287 A keyword used to indicate that an argument to a function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5288 definition is optional; this means that the function can be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5289 evaluated without the argument, if desired. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5290 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5291 `prefix-numeric-value' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5292 Convert the `raw prefix argument' produced by `(interactive "P")' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5293 to a numeric value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5294 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5295 `forward-line' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5296 Move point forward to the beginning of the next line, or if the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5297 argument is greater than one, forward that many lines. If it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5298 can't move as far forward as it is supposed to, `forward-line' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5299 goes forward as far as it can and then returns a count of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5300 number of additional lines it was supposed to move but couldn't. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5301 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5302 `erase-buffer' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5303 Delete the entire contents of the current buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5304 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5305 `bufferp' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5306 Return `t' if its argument is a buffer; otherwise return `nil'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5307 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5308 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5309 File: eintr, Node: optional Exercise, Prev: Second Buffer Related Review, Up: More Complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5310 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5311 5.5 `optional' Argument Exercise |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5312 ================================ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5313 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5314 Write an interactive function with an optional argument that tests |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5315 whether its argument, a number, is greater than or equal to, or else, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5316 less than the value of `fill-column', and tells you which, in a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5317 message. However, if you do not pass an argument to the function, use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5318 56 as a default value. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5319 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5320 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5321 File: eintr, Node: Narrowing & Widening, Next: car cdr & cons, Prev: More Complex, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5322 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5323 6 Narrowing and Widening |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5324 ************************ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5325 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5326 Narrowing is a feature of Emacs that makes it possible for you to focus |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5327 on a specific part of a buffer, and work without accidentally changing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5328 other parts. Narrowing is normally disabled since it can confuse |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5329 novices. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5330 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5331 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5332 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5333 * Narrowing advantages:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5334 * save-restriction:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5335 * what-line:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5336 * narrow Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5337 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5338 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5339 File: eintr, Node: Narrowing advantages, Next: save-restriction, Prev: Narrowing & Widening, Up: Narrowing & Widening |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5340 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5341 The Advantages of Narrowing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5342 =========================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5343 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5344 With narrowing, the rest of a buffer is made invisible, as if it weren't |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5345 there. This is an advantage if, for example, you want to replace a word |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5346 in one part of a buffer but not in another: you narrow to the part you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5347 want and the replacement is carried out only in that section, not in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5348 the rest of the buffer. Searches will only work within a narrowed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5349 region, not outside of one, so if you are fixing a part of a document, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5350 you can keep yourself from accidentally finding parts you do not need |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5351 to fix by narrowing just to the region you want. (The key binding for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5352 `narrow-to-region' is `C-x n n'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5353 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5354 However, narrowing does make the rest of the buffer invisible, which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5355 can scare people who inadvertently invoke narrowing and think they have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5356 deleted a part of their file. Moreover, the `undo' command (which is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5357 usually bound to `C-x u') does not turn off narrowing (nor should it), |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5358 so people can become quite desperate if they do not know that they can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5359 return the rest of a buffer to visibility with the `widen' command. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5360 (The key binding for `widen' is `C-x n w'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5361 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5362 Narrowing is just as useful to the Lisp interpreter as to a human. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5363 Often, an Emacs Lisp function is designed to work on just part of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5364 buffer; or conversely, an Emacs Lisp function needs to work on all of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5365 buffer that has been narrowed. The `what-line' function, for example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5366 removes the narrowing from a buffer, if it has any narrowing and when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5367 it has finished its job, restores the narrowing to what it was. On the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5368 other hand, the `count-lines' function, which is called by `what-line', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5369 uses narrowing to restrict itself to just that portion of the buffer in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5370 which it is interested and then restores the previous situation. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5371 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5372 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5373 File: eintr, Node: save-restriction, Next: what-line, Prev: Narrowing advantages, Up: Narrowing & Widening |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5374 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5375 6.1 The `save-restriction' Special Form |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5376 ======================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5377 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5378 In Emacs Lisp, you can use the `save-restriction' special form to keep |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5379 track of whatever narrowing is in effect, if any. When the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5380 interpreter meets with `save-restriction', it executes the code in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5381 body of the `save-restriction' expression, and then undoes any changes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5382 to narrowing that the code caused. If, for example, the buffer is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5383 narrowed and the code that follows `save-restriction' gets rid of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5384 narrowing, `save-restriction' returns the buffer to its narrowed region |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5385 afterwards. In the `what-line' command, any narrowing the buffer may |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5386 have is undone by the `widen' command that immediately follows the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5387 `save-restriction' command. Any original narrowing is restored just |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5388 before the completion of the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5389 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5390 The template for a `save-restriction' expression is simple: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5391 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5392 (save-restriction |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5393 BODY... ) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5394 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5395 The body of the `save-restriction' is one or more expressions that will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5396 be evaluated in sequence by the Lisp interpreter. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5397 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5398 Finally, a point to note: when you use both `save-excursion' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5399 `save-restriction', one right after the other, you should use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5400 `save-excursion' outermost. If you write them in reverse order, you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5401 may fail to record narrowing in the buffer to which Emacs switches |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5402 after calling `save-excursion'. Thus, when written together, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5403 `save-excursion' and `save-restriction' should be written like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5404 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5405 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5406 (save-restriction |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5407 BODY...)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5408 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5409 In other circumstances, when not written together, the `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5410 and `save-restriction' special forms must be written in the order |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5411 appropriate to the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5412 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5413 For example, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5414 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5415 (save-restriction |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5416 (widen) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5417 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5418 BODY...)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5419 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5420 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5421 File: eintr, Node: what-line, Next: narrow Exercise, Prev: save-restriction, Up: Narrowing & Widening |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5422 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5423 6.2 `what-line' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5424 =============== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5425 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5426 The `what-line' command tells you the number of the line in which the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5427 cursor is located. The function illustrates the use of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5428 `save-restriction' and `save-excursion' commands. Here is the original |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5429 text of the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5430 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5431 (defun what-line () |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5432 "Print the current line number (in the buffer) of point." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5433 (interactive) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5434 (save-restriction |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5435 (widen) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5436 (save-excursion |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5437 (beginning-of-line) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5438 (message "Line %d" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5439 (1+ (count-lines 1 (point))))))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5440 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5441 (In recent versions of GNU Emacs, the `what-line' function has been |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5442 expanded to tell you your line number in a narrowed buffer as well as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5443 your line number in a widened buffer. The recent version is more |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5444 complex than the version shown here. If you feel adventurous, you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5445 might want to look at it after figuring out how this version works. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5446 You will probably need to use `C-h f' (`describe-function'). The newer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5447 version uses a conditional to determine whether the buffer has been |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5448 narrowed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5449 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5450 (Also, it uses `line-number-at-pos', which among other simple |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5451 expressions, such as `(goto-char (point-min))', moves point to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5452 beginning of the current line with `(forward-line 0)' rather than |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5453 `beginning-of-line'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5454 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5455 The `what-line' function as shown here has a documentation line and is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5456 interactive, as you would expect. The next two lines use the functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5457 `save-restriction' and `widen'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5458 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5459 The `save-restriction' special form notes whatever narrowing is in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5460 effect, if any, in the current buffer and restores that narrowing after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5461 the code in the body of the `save-restriction' has been evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5462 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5463 The `save-restriction' special form is followed by `widen'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5464 function undoes any narrowing the current buffer may have had when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5465 `what-line' was called. (The narrowing that was there is the narrowing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5466 that `save-restriction' remembers.) This widening makes it possible |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5467 for the line counting commands to count from the beginning of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5468 buffer. Otherwise, they would have been limited to counting within the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5469 accessible region. Any original narrowing is restored just before the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5470 completion of the function by the `save-restriction' special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5471 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5472 The call to `widen' is followed by `save-excursion', which saves the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5473 location of the cursor (i.e., of point) and of the mark, and restores |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5474 them after the code in the body of the `save-excursion' uses the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5475 `beginning-of-line' function to move point. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5476 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5477 (Note that the `(widen)' expression comes between the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5478 `save-restriction' and `save-excursion' special forms. When you write |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5479 the two `save- ...' expressions in sequence, write `save-excursion' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5480 outermost.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5481 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5482 The last two lines of the `what-line' function are functions to count |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5483 the number of lines in the buffer and then print the number in the echo |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5484 area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5485 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5486 (message "Line %d" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5487 (1+ (count-lines 1 (point))))))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5488 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5489 The `message' function prints a one-line message at the bottom of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5490 Emacs screen. The first argument is inside of quotation marks and is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5491 printed as a string of characters. However, it may contain a `%d' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5492 expression to print a following argument. `%d' prints the argument as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5493 a decimal, so the message will say something such as `Line 243'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5494 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5495 The number that is printed in place of the `%d' is computed by the last |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5496 line of the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5497 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5498 (1+ (count-lines 1 (point))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5499 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5500 What this does is count the lines from the first position of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5501 buffer, indicated by the `1', up to `(point)', and then add one to that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5502 number. (The `1+' function adds one to its argument.) We add one to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5503 it because line 2 has only one line before it, and `count-lines' counts |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5504 only the lines _before_ the current line. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5505 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5506 After `count-lines' has done its job, and the message has been printed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5507 in the echo area, the `save-excursion' restores point and mark to their |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5508 original positions; and `save-restriction' restores the original |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5509 narrowing, if any. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5510 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5511 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5512 File: eintr, Node: narrow Exercise, Prev: what-line, Up: Narrowing & Widening |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5513 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5514 6.3 Exercise with Narrowing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5515 =========================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5516 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5517 Write a function that will display the first 60 characters of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5518 current buffer, even if you have narrowed the buffer to its latter half |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5519 so that the first line is inaccessible. Restore point, mark, and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5520 narrowing. For this exercise, you need to use a whole potpourri of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5521 functions, including `save-restriction', `widen', `goto-char', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5522 `point-min', `message', and `buffer-substring'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5523 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5524 (`buffer-substring' is a previously unmentioned function you will have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5525 to investigate yourself; or perhaps you will have to use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5526 `buffer-substring-no-properties' or `filter-buffer-substring' ..., yet |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5527 other functions. Text properties are a feature otherwise not discussed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5528 here. *Note Text Properties: (elisp)Text Properties. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5529 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5530 Additionally, do you really need `goto-char' or `point-min'? Or can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5531 you write the function without them?) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5532 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5533 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5534 File: eintr, Node: car cdr & cons, Next: Cutting & Storing Text, Prev: Narrowing & Widening, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5535 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5536 7 `car', `cdr', `cons': Fundamental Functions |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5537 ********************************************* |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5538 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5539 In Lisp, `car', `cdr', and `cons' are fundamental functions. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5540 `cons' function is used to construct lists, and the `car' and `cdr' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5541 functions are used to take them apart. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5542 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5543 In the walk through of the `copy-region-as-kill' function, we will see |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5544 `cons' as well as two variants on `cdr', namely, `setcdr' and `nthcdr'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5545 (*Note copy-region-as-kill::.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5546 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5547 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5548 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5549 * Strange Names:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5550 * car & cdr:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5551 * cons:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5552 * nthcdr:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5553 * nth:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5554 * setcar:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5555 * setcdr:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5556 * cons Exercise:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5557 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5558 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5559 File: eintr, Node: Strange Names, Next: car & cdr, Prev: car cdr & cons, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5560 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5561 Strange Names |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5562 ============= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5563 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5564 The name of the `cons' function is not unreasonable: it is an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5565 abbreviation of the word `construct'. The origins of the names for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5566 `car' and `cdr', on the other hand, are esoteric: `car' is an acronym |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5567 from the phrase `Contents of the Address part of the Register'; and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5568 `cdr' (pronounced `could-er') is an acronym from the phrase `Contents |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5569 of the Decrement part of the Register'. These phrases refer to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5570 specific pieces of hardware on the very early computer on which the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5571 original Lisp was developed. Besides being obsolete, the phrases have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5572 been completely irrelevant for more than 25 years to anyone thinking |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5573 about Lisp. Nonetheless, although a few brave scholars have begun to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5574 use more reasonable names for these functions, the old terms are still |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5575 in use. In particular, since the terms are used in the Emacs Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5576 source code, we will use them in this introduction. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5577 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5578 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5579 File: eintr, Node: car & cdr, Next: cons, Prev: Strange Names, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5580 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5581 7.1 `car' and `cdr' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5582 =================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5583 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5584 The CAR of a list is, quite simply, the first item in the list. Thus |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5585 the CAR of the list `(rose violet daisy buttercup)' is `rose'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5586 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5587 If you are reading this in Info in GNU Emacs, you can see this by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5588 evaluating the following: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5589 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5590 (car '(rose violet daisy buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5591 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5592 After evaluating the expression, `rose' will appear in the echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5593 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5594 Clearly, a more reasonable name for the `car' function would be `first' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5595 and this is often suggested. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5596 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5597 `car' does not remove the first item from the list; it only reports |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5598 what it is. After `car' has been applied to a list, the list is still |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5599 the same as it was. In the jargon, `car' is `non-destructive'. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5600 feature turns out to be important. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5601 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5602 The CDR of a list is the rest of the list, that is, the `cdr' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5603 returns the part of the list that follows the first item. Thus, while |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5604 the CAR of the list `'(rose violet daisy buttercup)' is `rose', the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5605 rest of the list, the value returned by the `cdr' function, is `(violet |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5606 daisy buttercup)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5607 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5608 You can see this by evaluating the following in the usual way: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5609 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5610 (cdr '(rose violet daisy buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5611 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5612 When you evaluate this, `(violet daisy buttercup)' will appear in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5613 echo area. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5614 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5615 Like `car', `cdr' does not remove any elements from the list--it just |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5616 returns a report of what the second and subsequent elements are. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5617 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5618 Incidentally, in the example, the list of flowers is quoted. If it were |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5619 not, the Lisp interpreter would try to evaluate the list by calling |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5620 `rose' as a function. In this example, we do not want to do that. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5621 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5622 Clearly, a more reasonable name for `cdr' would be `rest'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5623 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5624 (There is a lesson here: when you name new functions, consider very |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5625 carefully what you are doing, since you may be stuck with the names for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5626 far longer than you expect. The reason this document perpetuates these |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5627 names is that the Emacs Lisp source code uses them, and if I did not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5628 use them, you would have a hard time reading the code; but do, please, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5629 try to avoid using these terms yourself. The people who come after you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5630 will be grateful to you.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5631 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5632 When `car' and `cdr' are applied to a list made up of symbols, such as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5633 the list `(pine fir oak maple)', the element of the list returned by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5634 the function `car' is the symbol `pine' without any parentheses around |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5635 it. `pine' is the first element in the list. However, the CDR of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5636 list is a list itself, `(fir oak maple)', as you can see by evaluating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5637 the following expressions in the usual way: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5638 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5639 (car '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5640 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5641 (cdr '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5642 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5643 On the other hand, in a list of lists, the first element is itself a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5644 list. `car' returns this first element as a list. For example, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5645 following list contains three sub-lists, a list of carnivores, a list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5646 of herbivores and a list of sea mammals: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5647 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5648 (car '((lion tiger cheetah) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5649 (gazelle antelope zebra) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5650 (whale dolphin seal))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5651 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5652 In this example, the first element or CAR of the list is the list of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5653 carnivores, `(lion tiger cheetah)', and the rest of the list is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5654 `((gazelle antelope zebra) (whale dolphin seal))'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5655 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5656 (cdr '((lion tiger cheetah) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5657 (gazelle antelope zebra) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5658 (whale dolphin seal))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5659 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5660 It is worth saying again that `car' and `cdr' are non-destructive--that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5661 is, they do not modify or change lists to which they are applied. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5662 is very important for how they are used. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5663 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5664 Also, in the first chapter, in the discussion about atoms, I said that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5665 in Lisp, "certain kinds of atom, such as an array, can be separated |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5666 into parts; but the mechanism for doing this is different from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5667 mechanism for splitting a list. As far as Lisp is concerned, the atoms |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5668 of a list are unsplittable." (*Note Lisp Atoms::.) The `car' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5669 `cdr' functions are used for splitting lists and are considered |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5670 fundamental to Lisp. Since they cannot split or gain access to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5671 parts of an array, an array is considered an atom. Conversely, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5672 other fundamental function, `cons', can put together or construct a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5673 list, but not an array. (Arrays are handled by array-specific |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5674 functions. *Note Arrays: (elisp)Arrays.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5675 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5676 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5677 File: eintr, Node: cons, Next: nthcdr, Prev: car & cdr, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5678 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5679 7.2 `cons' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5680 ========== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5681 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5682 The `cons' function constructs lists; it is the inverse of `car' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5683 `cdr'. For example, `cons' can be used to make a four element list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5684 from the three element list, `(fir oak maple)': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5685 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5686 (cons 'pine '(fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5687 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5688 After evaluating this list, you will see |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5689 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5690 (pine fir oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5691 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5692 appear in the echo area. `cons' causes the creation of a new list in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5693 which the element is followed by the elements of the original list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5694 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5695 We often say that ``cons' puts a new element at the beginning of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5696 list; it attaches or pushes elements onto the list', but this phrasing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5697 can be misleading, since `cons' does not change an existing list, but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5698 creates a new one. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5699 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5700 Like `car' and `cdr', `cons' is non-destructive. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5701 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5702 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5703 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5704 * Build a list:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5705 * length:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5706 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5707 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5708 File: eintr, Node: Build a list, Next: length, Prev: cons, Up: cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5709 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5710 Build a list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5711 ------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5712 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5713 `cons' must have a list to attach to.(1) You cannot start from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5714 absolutely nothing. If you are building a list, you need to provide at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5715 least an empty list at the beginning. Here is a series of `cons' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5716 expressions that build up a list of flowers. If you are reading this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5717 in Info in GNU Emacs, you can evaluate each of the expressions in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5718 usual way; the value is printed in this text after `=>', which you may |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5719 read as `evaluates to'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5720 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5721 (cons 'buttercup ()) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5722 => (buttercup) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5723 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5724 (cons 'daisy '(buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5725 => (daisy buttercup) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5726 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5727 (cons 'violet '(daisy buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5728 => (violet daisy buttercup) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5729 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5730 (cons 'rose '(violet daisy buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5731 => (rose violet daisy buttercup) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5732 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5733 In the first example, the empty list is shown as `()' and a list made |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5734 up of `buttercup' followed by the empty list is constructed. As you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5735 can see, the empty list is not shown in the list that was constructed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5736 All that you see is `(buttercup)'. The empty list is not counted as an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5737 element of a list because there is nothing in an empty list. Generally |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5738 speaking, an empty list is invisible. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5739 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5740 The second example, `(cons 'daisy '(buttercup))' constructs a new, two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5741 element list by putting `daisy' in front of `buttercup'; and the third |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5742 example constructs a three element list by putting `violet' in front of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5743 `daisy' and `buttercup'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5744 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5745 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5746 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5747 (1) Actually, you can `cons' an element to an atom to produce a dotted |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5748 pair. Dotted pairs are not discussed here; see *Note Dotted Pair |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5749 Notation: (elisp)Dotted Pair Notation. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5750 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5751 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5752 File: eintr, Node: length, Prev: Build a list, Up: cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5753 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5754 7.2.1 Find the Length of a List: `length' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5755 ----------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5756 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5757 You can find out how many elements there are in a list by using the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5758 function `length', as in the following examples: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5759 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5760 (length '(buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5761 => 1 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5762 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5763 (length '(daisy buttercup)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5764 => 2 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5765 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5766 (length (cons 'violet '(daisy buttercup))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5767 => 3 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5768 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5769 In the third example, the `cons' function is used to construct a three |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5770 element list which is then passed to the `length' function as its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5771 argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5772 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5773 We can also use `length' to count the number of elements in an empty |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5774 list: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5775 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5776 (length ()) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5777 => 0 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5778 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5779 As you would expect, the number of elements in an empty list is zero. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5780 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5781 An interesting experiment is to find out what happens if you try to find |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5782 the length of no list at all; that is, if you try to call `length' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5783 without giving it an argument, not even an empty list: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5784 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5785 (length ) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5786 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5787 What you see, if you evaluate this, is the error message |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5788 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5789 Lisp error: (wrong-number-of-arguments length 0) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5790 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5791 This means that the function receives the wrong number of arguments, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5792 zero, when it expects some other number of arguments. In this case, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5793 one argument is expected, the argument being a list whose length the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5794 function is measuring. (Note that _one_ list is _one_ argument, even |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5795 if the list has many elements inside it.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5796 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5797 The part of the error message that says `length' is the name of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5798 function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5799 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5800 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5801 File: eintr, Node: nthcdr, Next: nth, Prev: cons, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5802 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5803 7.3 `nthcdr' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5804 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5805 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5806 The `nthcdr' function is associated with the `cdr' function. What it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5807 does is take the CDR of a list repeatedly. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5808 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5809 If you take the CDR of the list `(pine fir oak maple)', you will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5810 returned the list `(fir oak maple)'. If you repeat this on what was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5811 returned, you will be returned the list `(oak maple)'. (Of course, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5812 repeated CDRing on the original list will just give you the original |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5813 CDR since the function does not change the list. You need to evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5814 the CDR of the CDR and so on.) If you continue this, eventually you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5815 will be returned an empty list, which in this case, instead of being |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5816 shown as `()' is shown as `nil'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5817 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5818 For review, here is a series of repeated CDRs, the text following the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5819 `=>' shows what is returned. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5820 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5821 (cdr '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5822 =>(fir oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5823 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5824 (cdr '(fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5825 => (oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5826 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5827 (cdr '(oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5828 =>(maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5829 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5830 (cdr '(maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5831 => nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5832 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5833 (cdr 'nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5834 => nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5835 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5836 (cdr ()) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5837 => nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5838 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5839 You can also do several CDRs without printing the values in between, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5840 like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5841 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5842 (cdr (cdr '(pine fir oak maple))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5843 => (oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5844 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5845 In this example, the Lisp interpreter evaluates the innermost list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5846 first. The innermost list is quoted, so it just passes the list as it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5847 is to the innermost `cdr'. This `cdr' passes a list made up of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5848 second and subsequent elements of the list to the outermost `cdr', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5849 which produces a list composed of the third and subsequent elements of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5850 the original list. In this example, the `cdr' function is repeated and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5851 returns a list that consists of the original list without its first two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5852 elements. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5853 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5854 The `nthcdr' function does the same as repeating the call to `cdr'. In |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5855 the following example, the argument 2 is passed to the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5856 `nthcdr', along with the list, and the value returned is the list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5857 without its first two items, which is exactly the same as repeating |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5858 `cdr' twice on the list: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5859 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5860 (nthcdr 2 '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5861 => (oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5862 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5863 Using the original four element list, we can see what happens when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5864 various numeric arguments are passed to `nthcdr', including 0, 1, and 5: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5865 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5866 ;; Leave the list as it was. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5867 (nthcdr 0 '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5868 => (pine fir oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5869 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5870 ;; Return a copy without the first element. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5871 (nthcdr 1 '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5872 => (fir oak maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5873 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5874 ;; Return a copy of the list without three elements. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5875 (nthcdr 3 '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5876 => (maple) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5877 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5878 ;; Return a copy lacking all four elements. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5879 (nthcdr 4 '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5880 => nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5881 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5882 ;; Return a copy lacking all elements. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5883 (nthcdr 5 '(pine fir oak maple)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5884 => nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5885 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5886 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5887 File: eintr, Node: nth, Next: setcar, Prev: nthcdr, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5888 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5889 7.4 `nth' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5890 ========= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5891 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5892 The `nthcdr' function takes the CDR of a list repeatedly. The `nth' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5893 function takes the CAR of the result returned by `nthcdr'. It returns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5894 the Nth element of the list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5895 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5896 Thus, if it were not defined in C for speed, the definition of `nth' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5897 would be: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5898 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5899 (defun nth (n list) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5900 "Returns the Nth element of LIST. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5901 N counts from zero. If LIST is not that long, nil is returned." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5902 (car (nthcdr n list))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5903 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5904 (Originally, `nth' was defined in Emacs Lisp in `subr.el', but its |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5905 definition was redone in C in the 1980s.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5906 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5907 The `nth' function returns a single element of a list. This can be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5908 very convenient. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5909 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5910 Note that the elements are numbered from zero, not one. That is to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5911 say, the first element of a list, its CAR is the zeroth element. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5912 is called `zero-based' counting and often bothers people who are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5913 accustomed to the first element in a list being number one, which is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5914 `one-based'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5915 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5916 For example: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5917 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5918 (nth 0 '("one" "two" "three")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5919 => "one" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5920 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5921 (nth 1 '("one" "two" "three")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5922 => "two" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5923 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5924 It is worth mentioning that `nth', like `nthcdr' and `cdr', does not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5925 change the original list--the function is non-destructive. This is in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5926 sharp contrast to the `setcar' and `setcdr' functions. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5927 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5928 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5929 File: eintr, Node: setcar, Next: setcdr, Prev: nth, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5930 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5931 7.5 `setcar' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5932 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5933 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5934 As you might guess from their names, the `setcar' and `setcdr' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5935 functions set the CAR or the CDR of a list to a new value. They |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5936 actually change the original list, unlike `car' and `cdr' which leave |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5937 the original list as it was. One way to find out how this works is to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5938 experiment. We will start with the `setcar' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5939 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5940 First, we can make a list and then set the value of a variable to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5941 list, using the `setq' function. Here is a list of animals: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5942 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5943 (setq animals '(antelope giraffe lion tiger)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5944 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5945 If you are reading this in Info inside of GNU Emacs, you can evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5946 this expression in the usual fashion, by positioning the cursor after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5947 the expression and typing `C-x C-e'. (I'm doing this right here as I |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5948 write this. This is one of the advantages of having the interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5949 built into the computing environment. Incidentally, when there is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5950 nothing on the line after the final parentheses, such as a comment, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5951 point can be on the next line. Thus, if your cursor is in the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5952 column of the next line, you do not need to move it. Indeed, Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5953 permits any amount of white space after the final parenthesis.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5954 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5955 When we evaluate the variable `animals', we see that it is bound to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5956 list `(antelope giraffe lion tiger)': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5957 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5958 animals |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5959 => (antelope giraffe lion tiger) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5960 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5961 Put another way, the variable `animals' points to the list `(antelope |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5962 giraffe lion tiger)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5963 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5964 Next, evaluate the function `setcar' while passing it two arguments, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5965 the variable `animals' and the quoted symbol `hippopotamus'; this is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5966 done by writing the three element list `(setcar animals 'hippopotamus)' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5967 and then evaluating it in the usual fashion: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5968 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5969 (setcar animals 'hippopotamus) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5970 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5971 After evaluating this expression, evaluate the variable `animals' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5972 again. You will see that the list of animals has changed: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5973 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5974 animals |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5975 => (hippopotamus giraffe lion tiger) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5976 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5977 The first element on the list, `antelope' is replaced by `hippopotamus'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5978 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5979 So we can see that `setcar' did not add a new element to the list as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5980 `cons' would have; it replaced `antelope' with `hippopotamus'; it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5981 _changed_ the list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5982 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5983 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5984 File: eintr, Node: setcdr, Next: cons Exercise, Prev: setcar, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5985 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5986 7.6 `setcdr' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5987 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5988 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5989 The `setcdr' function is similar to the `setcar' function, except that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5990 the function replaces the second and subsequent elements of a list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5991 rather than the first element. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5992 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5993 (To see how to change the last element of a list, look ahead to *Note |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5994 The `kill-new' function: kill-new function, which uses the `nthcdr' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5995 `setcdr' functions.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5996 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5997 To see how this works, set the value of the variable to a list of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5998 domesticated animals by evaluating the following expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
5999 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6000 (setq domesticated-animals '(horse cow sheep goat)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6001 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6002 If you now evaluate the list, you will be returned the list `(horse cow |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6003 sheep goat)': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6004 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6005 domesticated-animals |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6006 => (horse cow sheep goat) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6007 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6008 Next, evaluate `setcdr' with two arguments, the name of the variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6009 which has a list as its value, and the list to which the CDR of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6010 first list will be set; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6011 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6012 (setcdr domesticated-animals '(cat dog)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6013 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6014 If you evaluate this expression, the list `(cat dog)' will appear in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6015 the echo area. This is the value returned by the function. The result |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6016 we are interested in is the "side effect", which we can see by |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6017 evaluating the variable `domesticated-animals': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6018 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6019 domesticated-animals |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6020 => (horse cat dog) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6021 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6022 Indeed, the list is changed from `(horse cow sheep goat)' to `(horse |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6023 cat dog)'. The CDR of the list is changed from `(cow sheep goat)' to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6024 `(cat dog)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6025 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6026 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6027 File: eintr, Node: cons Exercise, Prev: setcdr, Up: car cdr & cons |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6028 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6029 7.7 Exercise |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6030 ============ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6031 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6032 Construct a list of four birds by evaluating several expressions with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6033 `cons'. Find out what happens when you `cons' a list onto itself. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6034 Replace the first element of the list of four birds with a fish. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6035 Replace the rest of that list with a list of other fish. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6036 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6037 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6038 File: eintr, Node: Cutting & Storing Text, Next: List Implementation, Prev: car cdr & cons, Up: Top |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6039 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6040 8 Cutting and Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6041 ************************** |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6042 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6043 Whenever you cut or clip text out of a buffer with a `kill' command in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6044 GNU Emacs, it is stored in a list and you can bring it back with a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6045 `yank' command. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6046 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6047 (The use of the word `kill' in Emacs for processes which specifically |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6048 _do not_ destroy the values of the entities is an unfortunate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6049 historical accident. A much more appropriate word would be `clip' since |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6050 that is what the kill commands do; they clip text out of a buffer and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6051 put it into storage from which it can be brought back. I have often |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6052 been tempted to replace globally all occurrences of `kill' in the Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6053 sources with `clip' and all occurrences of `killed' with `clipped'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6054 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6055 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6056 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6057 * Storing Text:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6058 * zap-to-char:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6059 * kill-region:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6060 * copy-region-as-kill:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6061 * Digression into C:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6062 * defvar:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6063 * cons & search-fwd Review:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6064 * search Exercises:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6065 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6066 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6067 File: eintr, Node: Storing Text, Next: zap-to-char, Prev: Cutting & Storing Text, Up: Cutting & Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6068 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6069 Storing Text in a List |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6070 ====================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6071 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6072 When text is cut out of a buffer, it is stored on a list. Successive |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6073 pieces of text are stored on the list successively, so the list might |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6074 look like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6075 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6076 ("a piece of text" "previous piece") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6077 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6078 The function `cons' can be used to create a new list from a piece of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6079 text (an `atom', to use the jargon) and an existing list, like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6080 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6081 (cons "another piece" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6082 '("a piece of text" "previous piece")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6083 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6084 If you evaluate this expression, a list of three elements will appear in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6085 the echo area: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6086 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6087 ("another piece" "a piece of text" "previous piece") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6088 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6089 With the `car' and `nthcdr' functions, you can retrieve whichever piece |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6090 of text you want. For example, in the following code, `nthcdr 1 ...' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6091 returns the list with the first item removed; and the `car' returns the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6092 first element of that remainder--the second element of the original |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6093 list: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6094 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6095 (car (nthcdr 1 '("another piece" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6096 "a piece of text" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6097 "previous piece"))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6098 => "a piece of text" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6099 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6100 The actual functions in Emacs are more complex than this, of course. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6101 The code for cutting and retrieving text has to be written so that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6102 Emacs can figure out which element in the list you want--the first, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6103 second, third, or whatever. In addition, when you get to the end of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6104 the list, Emacs should give you the first element of the list, rather |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6105 than nothing at all. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6106 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6107 The list that holds the pieces of text is called the "kill ring". This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6108 chapter leads up to a description of the kill ring and how it is used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6109 by first tracing how the `zap-to-char' function works. This function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6110 uses (or `calls') a function that invokes a function that manipulates |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6111 the kill ring. Thus, before reaching the mountains, we climb the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6112 foothills. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6113 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6114 A subsequent chapter describes how text that is cut from the buffer is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6115 retrieved. *Note Yanking Text Back: Yanking. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6116 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6117 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6118 File: eintr, Node: zap-to-char, Next: kill-region, Prev: Storing Text, Up: Cutting & Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6119 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6120 8.1 `zap-to-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6121 ================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6122 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6123 The `zap-to-char' function changed a little between GNU Emacs version |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6124 19 and GNU Emacs version 22. However, `zap-to-char' calls another |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6125 function, `kill-region', which enjoyed a major rewrite. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6126 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6127 The `kill-region' function in Emacs 19 is complex, but does not use |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6128 code that is important at this time. We will skip it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6129 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6130 The `kill-region' function in Emacs 22 is easier to read than the same |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6131 function in Emacs 19 and introduces a very important concept, that of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6132 error handling. We will walk through the function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6133 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6134 But first, let us look at the interactive `zap-to-char' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6135 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6136 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6137 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6138 * Complete zap-to-char:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6139 * zap-to-char interactive:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6140 * zap-to-char body:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6141 * search-forward:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6142 * progn:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6143 * Summing up zap-to-char:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6144 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6145 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6146 File: eintr, Node: Complete zap-to-char, Next: zap-to-char interactive, Prev: zap-to-char, Up: zap-to-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6147 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6148 The Complete `zap-to-char' Implementation |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6149 ----------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6150 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6151 The GNU Emacs version 19 and version 21 implementations of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6152 `zap-to-char' function are nearly identical in form, and they work |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6153 alike. The function removes the text in the region between the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6154 location of the cursor (i.e., of point) up to and including the next |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6155 occurrence of a specified character. The text that `zap-to-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6156 removes is put in the kill ring; and it can be retrieved from the kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6157 ring by typing `C-y' (`yank'). If the command is given an argument, it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6158 removes text through that number of occurrences. Thus, if the cursor |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6159 were at the beginning of this sentence and the character were `s', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6160 `Thus' would be removed. If the argument were two, `Thus, if the curs' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6161 would be removed, up to and including the `s' in `cursor'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6162 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6163 If the specified character is not found, `zap-to-char' will say "Search |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6164 failed", tell you the character you typed, and not remove any text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6165 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6166 In order to determine how much text to remove, `zap-to-char' uses a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6167 search function. Searches are used extensively in code that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6168 manipulates text, and we will focus attention on them as well as on the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6169 deletion command. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6170 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6171 Here is the complete text of the version 22 implementation of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6172 function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6173 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6174 (defun zap-to-char (arg char) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6175 "Kill up to and including ARG'th occurrence of CHAR. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6176 Case is ignored if `case-fold-search' is non-nil in the current buffer. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6177 Goes backward if ARG is negative; error if CHAR not found." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6178 (interactive "p\ncZap to char: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6179 (if (char-table-p translation-table-for-input) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6180 (setq char (or (aref translation-table-for-input char) char))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6181 (kill-region (point) (progn |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6182 (search-forward (char-to-string char) nil nil arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6183 (point)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6184 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6185 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6186 File: eintr, Node: zap-to-char interactive, Next: zap-to-char body, Prev: Complete zap-to-char, Up: zap-to-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6187 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6188 8.1.1 The `interactive' Expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6189 ---------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6190 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6191 The interactive expression in the `zap-to-char' command looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6192 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6193 (interactive "p\ncZap to char: ") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6194 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6195 The part within quotation marks, `"p\ncZap to char: "', specifies two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6196 different things. First, and most simply, is the `p'. This part is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6197 separated from the next part by a newline, `\n'. The `p' means that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6198 the first argument to the function will be passed the value of a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6199 `processed prefix'. The prefix argument is passed by typing `C-u' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6200 a number, or `M-' and a number. If the function is called |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6201 interactively without a prefix, 1 is passed to this argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6202 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6203 The second part of `"p\ncZap to char: "' is `cZap to char: '. In this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6204 part, the lower case `c' indicates that `interactive' expects a prompt |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6205 and that the argument will be a character. The prompt follows the `c' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6206 and is the string `Zap to char: ' (with a space after the colon to make |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6207 it look good). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6208 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6209 What all this does is prepare the arguments to `zap-to-char' so they |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6210 are of the right type, and give the user a prompt. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6211 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6212 In a read-only buffer, the `zap-to-char' function copies the text to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6213 the kill ring, but does not remove it. The echo area displays a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6214 message saying that the buffer is read-only. Also, the terminal may |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6215 beep or blink at you. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6216 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6217 Let us continue with the interactive specification. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6218 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6219 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6220 File: eintr, Node: zap-to-char body, Next: search-forward, Prev: zap-to-char interactive, Up: zap-to-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6221 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6222 8.1.2 The Body of `zap-to-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6223 ------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6224 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6225 The body of the `zap-to-char' function contains the code that kills |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6226 (that is, removes) the text in the region from the current position of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6227 the cursor up to and including the specified character. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6228 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6229 The documentation is thorough. You do need to know the jargon meaning |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6230 of the word `kill'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6231 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6232 The first part of the code looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6233 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6234 (if (char-table-p translation-table-for-input) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6235 (setq char (or (aref translation-table-for-input char) char))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6236 (kill-region (point) (progn |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6237 (search-forward (char-to-string char) nil nil arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6238 (point))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6239 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6240 `char-table-p' is an hitherto unseen function. It determines whether |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6241 its argument is a character table. When it is, it sets the character |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6242 passed to `zap-to-char' to one of them, if that character exists, or to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6243 the character itself. (This becomes important for certain characters |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6244 in non-European languages. The `aref' function extracts an element |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6245 from an array. It is an array-specific function that is not described |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6246 in this document. *Note Arrays: (elisp)Arrays.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6247 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6248 `(point)' is the current position of the cursor. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6249 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6250 The next part of the code is an expression using `progn'. The body of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6251 the `progn' consists of calls to `search-forward' and `point'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6252 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6253 It is easier to understand how `progn' works after learning about |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6254 `search-forward', so we will look at `search-forward' and then at |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6255 `progn'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6256 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6257 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6258 File: eintr, Node: search-forward, Next: progn, Prev: zap-to-char body, Up: zap-to-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6259 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6260 8.1.3 The `search-forward' Function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6261 ----------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6262 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6263 The `search-forward' function is used to locate the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6264 zapped-for-character in `zap-to-char'. If the search is successful, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6265 `search-forward' leaves point immediately after the last character in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6266 the target string. (In `zap-to-char', the target string is just one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6267 character long. `zap-to-char' uses the function `char-to-string' to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6268 ensure that the computer treats that character as a string.) If the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6269 search is backwards, `search-forward' leaves point just before the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6270 first character in the target. Also, `search-forward' returns `t' for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6271 true. (Moving point is therefore a `side effect'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6272 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6273 In `zap-to-char', the `search-forward' function looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6274 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6275 (search-forward (char-to-string char) nil nil arg) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6276 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6277 The `search-forward' function takes four arguments: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6278 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6279 1. The first argument is the target, what is searched for. This must |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6280 be a string, such as `"z"'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6281 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6282 As it happens, the argument passed to `zap-to-char' is a single |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6283 character. Because of the way computers are built, the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6284 interpreter may treat a single character as being different from a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6285 string of characters. Inside the computer, a single character has |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6286 a different electronic format than a string of one character. (A |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6287 single character can often be recorded in the computer using |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6288 exactly one byte; but a string may be longer, and the computer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6289 needs to be ready for this.) Since the `search-forward' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6290 searches for a string, the character that the `zap-to-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6291 function receives as its argument must be converted inside the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6292 computer from one format to the other; otherwise the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6293 `search-forward' function will fail. The `char-to-string' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6294 function is used to make this conversion. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6295 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6296 2. The second argument bounds the search; it is specified as a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6297 position in the buffer. In this case, the search can go to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6298 end of the buffer, so no bound is set and the second argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6299 `nil'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6300 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6301 3. The third argument tells the function what it should do if the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6302 search fails--it can signal an error (and print a message) or it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6303 can return `nil'. A `nil' as the third argument causes the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6304 function to signal an error when the search fails. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6305 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6306 4. The fourth argument to `search-forward' is the repeat count--how |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6307 many occurrences of the string to look for. This argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6308 optional and if the function is called without a repeat count, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6309 this argument is passed the value 1. If this argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6310 negative, the search goes backwards. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6311 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6312 In template form, a `search-forward' expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6313 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6314 (search-forward "TARGET-STRING" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6315 LIMIT-OF-SEARCH |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6316 WHAT-TO-DO-IF-SEARCH-FAILS |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6317 REPEAT-COUNT) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6318 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6319 We will look at `progn' next. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6320 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6321 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6322 File: eintr, Node: progn, Next: Summing up zap-to-char, Prev: search-forward, Up: zap-to-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6323 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6324 8.1.4 The `progn' Special Form |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6325 ------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6326 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6327 `progn' is a special form that causes each of its arguments to be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6328 evaluated in sequence and then returns the value of the last one. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6329 preceding expressions are evaluated only for the side effects they |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6330 perform. The values produced by them are discarded. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6331 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6332 The template for a `progn' expression is very simple: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6333 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6334 (progn |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6335 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6336 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6337 In `zap-to-char', the `progn' expression has to do two things: put |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6338 point in exactly the right position; and return the location of point |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6339 so that `kill-region' will know how far to kill to. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6340 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6341 The first argument to the `progn' is `search-forward'. When |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6342 `search-forward' finds the string, the function leaves point |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6343 immediately after the last character in the target string. (In this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6344 case the target string is just one character long.) If the search is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6345 backwards, `search-forward' leaves point just before the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6346 character in the target. The movement of point is a side effect. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6347 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6348 The second and last argument to `progn' is the expression `(point)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6349 This expression returns the value of point, which in this case will be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6350 the location to which it has been moved by `search-forward'. (In the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6351 source, a line that tells the function to go to the previous character, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6352 if it is going forward, was commented out in 1999; I don't remember |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6353 whether that feature or mis-feature was ever a part of the distributed |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6354 source.) The value of `point' is returned by the `progn' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6355 and is passed to `kill-region' as `kill-region''s second argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6356 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6357 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6358 File: eintr, Node: Summing up zap-to-char, Prev: progn, Up: zap-to-char |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6359 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6360 8.1.5 Summing up `zap-to-char' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6361 ------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6362 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6363 Now that we have seen how `search-forward' and `progn' work, we can see |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6364 how the `zap-to-char' function works as a whole. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6365 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6366 The first argument to `kill-region' is the position of the cursor when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6367 the `zap-to-char' command is given--the value of point at that time. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6368 Within the `progn', the search function then moves point to just after |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6369 the zapped-to-character and `point' returns the value of this location. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6370 The `kill-region' function puts together these two values of point, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6371 the first one as the beginning of the region and the second one as the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6372 end of the region, and removes the region. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6373 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6374 The `progn' special form is necessary because the `kill-region' command |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6375 takes two arguments; and it would fail if `search-forward' and `point' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6376 expressions were written in sequence as two additional arguments. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6377 `progn' expression is a single argument to `kill-region' and returns |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6378 the one value that `kill-region' needs for its second argument. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6379 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6380 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6381 File: eintr, Node: kill-region, Next: copy-region-as-kill, Prev: zap-to-char, Up: Cutting & Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6382 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6383 8.2 `kill-region' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6384 ================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6385 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6386 The `zap-to-char' function uses the `kill-region' function. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6387 function clips text from a region and copies that text to the kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6388 ring, from which it may be retrieved. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6389 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6390 The Emacs 22 version of that function uses `condition-case' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6391 `copy-region-as-kill', both of which we will explain. `condition-case' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6392 is an important special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6393 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6394 In essence, the `kill-region' function calls `condition-case', which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6395 takes three arguments. In this function, the first argument does |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6396 nothing. The second argument contains the code that does the work when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6397 all goes well. The third argument contains the code that is called in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6398 the event of an error. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6399 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6400 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6401 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6402 * Complete kill-region:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6403 * condition-case:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6404 * Lisp macro:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6405 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6406 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6407 File: eintr, Node: Complete kill-region, Next: condition-case, Prev: kill-region, Up: kill-region |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6408 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6409 The Complete `kill-region' Definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6410 ------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6411 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6412 We will go through the `condition-case' code in a moment. First, let |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6413 us look at the definition of `kill-region', with comments added: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6414 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6415 (defun kill-region (beg end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6416 "Kill (\"cut\") text between point and mark. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6417 This deletes the text from the buffer and saves it in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6418 The command \\[yank] can retrieve it from there. ... " |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6419 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6420 ;; * Since order matters, pass point first. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6421 (interactive (list (point) (mark))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6422 ;; * And tell us if we cannot cut the text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6423 (unless (and beg end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6424 (error "The mark is not set now, so there is no region")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6425 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6426 ;; * `condition-case' takes three arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6427 ;; If the first argument is nil, as it is here, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6428 ;; information about the error signal is not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6429 ;; stored for use by another function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6430 (condition-case nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6431 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6432 ;; * The second argument to `condition-case' tells the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6433 ;; Lisp interpreter what to do when all goes well. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6434 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6435 ;; It starts with a `let' function that extracts the string |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6436 ;; and tests whether it exists. If so (that is what the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6437 ;; `when' checks), it calls an `if' function that determines |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6438 ;; whether the previous command was another call to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6439 ;; `kill-region'; if it was, then the new text is appended to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6440 ;; the previous text; if not, then a different function, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6441 ;; `kill-new', is called. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6442 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6443 ;; The `kill-append' function concatenates the new string and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6444 ;; the old. The `kill-new' function inserts text into a new |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6445 ;; item in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6446 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6447 ;; `when' is an `if' without an else-part. The second `when' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6448 ;; again checks whether the current string exists; in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6449 ;; addition, it checks whether the previous command was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6450 ;; another call to `kill-region'. If one or the other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6451 ;; condition is true, then it sets the current command to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6452 ;; be `kill-region'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6453 (let ((string (filter-buffer-substring beg end t))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6454 (when string ;STRING is nil if BEG = END |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6455 ;; Add that string to the kill ring, one way or another. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6456 (if (eq last-command 'kill-region) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6457 ;; - `yank-handler' is an optional argument to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6458 ;; `kill-region' that tells the `kill-append' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6459 ;; `kill-new' functions how deal with properties |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6460 ;; added to the text, such as `bold' or `italics'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6461 (kill-append string (< end beg) yank-handler) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6462 (kill-new string nil yank-handler))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6463 (when (or string (eq last-command 'kill-region)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6464 (setq this-command 'kill-region)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6465 nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6466 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6467 ;; * The third argument to `condition-case' tells the interpreter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6468 ;; what to do with an error. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6469 ;; The third argument has a conditions part and a body part. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6470 ;; If the conditions are met (in this case, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6471 ;; if text or buffer are read-only) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6472 ;; then the body is executed. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6473 ;; The first part of the third argument is the following: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6474 ((buffer-read-only text-read-only) ;; the if-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6475 ;; ... the then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6476 (copy-region-as-kill beg end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6477 ;; Next, also as part of the then-part, set this-command, so |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6478 ;; it will be set in an error |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6479 (setq this-command 'kill-region) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6480 ;; Finally, in the then-part, send a message if you may copy |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6481 ;; the text to the kill ring without signally an error, but |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6482 ;; don't if you may not. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6483 (if kill-read-only-ok |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6484 (progn (message "Read only text copied to kill ring") nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6485 (barf-if-buffer-read-only) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6486 ;; If the buffer isn't read-only, the text is. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6487 (signal 'text-read-only (list (current-buffer))))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6488 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6489 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6490 File: eintr, Node: condition-case, Next: Lisp macro, Prev: Complete kill-region, Up: kill-region |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6491 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6492 8.2.1 `condition-case' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6493 ---------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6494 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6495 As we have seen earlier (*note Generate an Error Message: Making |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6496 Errors.), when the Emacs Lisp interpreter has trouble evaluating an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6497 expression, it provides you with help; in the jargon, this is called |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6498 "signaling an error". Usually, the computer stops the program and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6499 shows you a message. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6500 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6501 However, some programs undertake complicated actions. They should not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6502 simply stop on an error. In the `kill-region' function, the most |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6503 likely error is that you will try to kill text that is read-only and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6504 cannot be removed. So the `kill-region' function contains code to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6505 handle this circumstance. This code, which makes up the body of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6506 `kill-region' function, is inside of a `condition-case' special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6507 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6508 The template for `condition-case' looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6509 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6510 (condition-case |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6511 VAR |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6512 BODYFORM |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6513 ERROR-HANDLER...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6514 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6515 The second argument, BODYFORM, is straightforward. The |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6516 `condition-case' special form causes the Lisp interpreter to evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6517 the code in BODYFORM. If no error occurs, the special form returns the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6518 code's value and produces the side-effects, if any. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6519 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6520 In short, the BODYFORM part of a `condition-case' expression determines |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6521 what should happen when everything works correctly. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6522 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6523 However, if an error occurs, among its other actions, the function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6524 generating the error signal will define one or more error condition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6525 names. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6526 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6527 An error handler is the third argument to `condition case'. An error |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6528 handler has two parts, a CONDITION-NAME and a BODY. If the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6529 CONDITION-NAME part of an error handler matches a condition name |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6530 generated by an error, then the BODY part of the error handler is run. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6531 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6532 As you will expect, the CONDITION-NAME part of an error handler may be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6533 either a single condition name or a list of condition names. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6534 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6535 Also, a complete `condition-case' expression may contain more than one |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6536 error handler. When an error occurs, the first applicable handler is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6537 run. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6538 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6539 Lastly, the first argument to the `condition-case' expression, the VAR |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6540 argument, is sometimes bound to a variable that contains information |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6541 about the error. However, if that argument is nil, as is the case in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6542 `kill-region', that information is discarded. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6543 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6544 In brief, in the `kill-region' function, the code `condition-case' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6545 works like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6546 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6547 IF NO ERRORS, RUN ONLY THIS CODE |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6548 BUT, IF ERRORS, RUN THIS OTHER CODE. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6549 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6550 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6551 File: eintr, Node: Lisp macro, Prev: condition-case, Up: kill-region |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6552 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6553 8.2.2 Lisp macro |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6554 ---------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6555 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6556 The part of the `condition-case' expression that is evaluated in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6557 expectation that all goes well has a `when'. The code uses `when' to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6558 determine whether the `string' variable points to text that exists. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6559 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6560 A `when' expression is simply a programmers' convenience. It is an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6561 `if' without the possibility of an else clause. In your mind, you can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6562 replace `when' with `if' and understand what goes on. That is what the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6563 Lisp interpreter does. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6564 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6565 Technically speaking, `when' is a Lisp macro. A Lisp "macro" enables |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6566 you to define new control constructs and other language features. It |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6567 tells the interpreter how to compute another Lisp expression which will |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6568 in turn compute the value. In this case, the `other expression' is an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6569 `if' expression. For more about Lisp macros, see *Note Macros: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6570 (elisp)Macros. The C programming language also provides macros. These |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6571 are different, but also useful. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6572 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6573 If the string has content, then another conditional expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6574 executed. This is an `if' with both a then-part and an else-part. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6575 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6576 (if (eq last-command 'kill-region) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6577 (kill-append string (< end beg) yank-handler) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6578 (kill-new string nil yank-handler)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6579 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6580 The then-part is evaluated if the previous command was another call to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6581 `kill-region'; if not, the else-part is evaluated. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6582 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6583 `yank-handler' is an optional argument to `kill-region' that tells the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6584 `kill-append' and `kill-new' functions how deal with properties added |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6585 to the text, such as `bold' or `italics'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6586 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6587 `last-command' is a variable that comes with Emacs that we have not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6588 seen before. Normally, whenever a function is executed, Emacs sets the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6589 value of `last-command' to the previous command. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6590 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6591 In this segment of the definition, the `if' expression checks whether |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6592 the previous command was `kill-region'. If it was, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6593 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6594 (kill-append string (< end beg) yank-handler) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6595 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6596 concatenates a copy of the newly clipped text to the just previously |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6597 clipped text in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6598 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6599 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6600 File: eintr, Node: copy-region-as-kill, Next: Digression into C, Prev: kill-region, Up: Cutting & Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6601 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6602 8.3 `copy-region-as-kill' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6603 ========================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6604 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6605 The `copy-region-as-kill' function copies a region of text from a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6606 buffer and (via either `kill-append' or `kill-new') saves it in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6607 `kill-ring'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6608 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6609 If you call `copy-region-as-kill' immediately after a `kill-region' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6610 command, Emacs appends the newly copied text to the previously copied |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6611 text. This means that if you yank back the text, you get it all, from |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6612 both this and the previous operation. On the other hand, if some other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6613 command precedes the `copy-region-as-kill', the function copies the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6614 text into a separate entry in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6615 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6616 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6617 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6618 * Complete copy-region-as-kill:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6619 * copy-region-as-kill body:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6620 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6621 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6622 File: eintr, Node: Complete copy-region-as-kill, Next: copy-region-as-kill body, Prev: copy-region-as-kill, Up: copy-region-as-kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6623 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6624 The complete `copy-region-as-kill' function definition |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6625 ------------------------------------------------------ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6626 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6627 Here is the complete text of the version 22 `copy-region-as-kill' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6628 function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6629 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6630 (defun copy-region-as-kill (beg end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6631 "Save the region as if killed, but don't kill it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6632 In Transient Mark mode, deactivate the mark. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6633 If `interprogram-cut-function' is non-nil, also save the text for a window |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6634 system cut and paste." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6635 (interactive "r") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6636 (if (eq last-command 'kill-region) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6637 (kill-append (filter-buffer-substring beg end) (< end beg)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6638 (kill-new (filter-buffer-substring beg end))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6639 (if transient-mark-mode |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6640 (setq deactivate-mark t)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6641 nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6642 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6643 As usual, this function can be divided into its component parts: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6644 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6645 (defun copy-region-as-kill (ARGUMENT-LIST) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6646 "DOCUMENTATION..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6647 (interactive "r") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6648 BODY...) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6649 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6650 The arguments are `beg' and `end' and the function is interactive with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6651 `"r"', so the two arguments must refer to the beginning and end of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6652 region. If you have been reading though this document from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6653 beginning, understanding these parts of a function is almost becoming |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6654 routine. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6655 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6656 The documentation is somewhat confusing unless you remember that the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6657 word `kill' has a meaning different from usual. The `Transient Mark' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6658 and `interprogram-cut-function' comments explain certain side-effects. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6659 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6660 After you once set a mark, a buffer always contains a region. If you |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6661 wish, you can use Transient Mark mode to highlight the region |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6662 temporarily. (No one wants to highlight the region all the time, so |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6663 Transient Mark mode highlights it only at appropriate times. Many |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6664 people turn off Transient Mark mode, so the region is never |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6665 highlighted.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6666 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6667 Also, a windowing system allows you to copy, cut, and paste among |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6668 different programs. In the X windowing system, for example, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6669 `interprogram-cut-function' function is `x-select-text', which works |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6670 with the windowing system's equivalent of the Emacs kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6671 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6672 The body of the `copy-region-as-kill' function starts with an `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6673 clause. What this clause does is distinguish between two different |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6674 situations: whether or not this command is executed immediately after a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6675 previous `kill-region' command. In the first case, the new region is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6676 appended to the previously copied text. Otherwise, it is inserted into |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6677 the beginning of the kill ring as a separate piece of text from the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6678 previous piece. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6679 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6680 The last two lines of the function prevent the region from lighting up |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6681 if Transient Mark mode is turned on. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6682 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6683 The body of `copy-region-as-kill' merits discussion in detail. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6684 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6685 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6686 File: eintr, Node: copy-region-as-kill body, Prev: Complete copy-region-as-kill, Up: copy-region-as-kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6687 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6688 8.3.1 The Body of `copy-region-as-kill' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6689 --------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6690 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6691 The `copy-region-as-kill' function works in much the same way as the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6692 `kill-region' function. Both are written so that two or more kills in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6693 a row combine their text into a single entry. If you yank back the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6694 text from the kill ring, you get it all in one piece. Moreover, kills |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6695 that kill forward from the current position of the cursor are added to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6696 the end of the previously copied text and commands that copy text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6697 backwards add it to the beginning of the previously copied text. This |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6698 way, the words in the text stay in the proper order. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6699 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6700 Like `kill-region', the `copy-region-as-kill' function makes use of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6701 `last-command' variable that keeps track of the previous Emacs command. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6702 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6703 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6704 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6705 * last-command & this-command:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6706 * kill-append function:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6707 * kill-new function:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6708 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6709 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6710 File: eintr, Node: last-command & this-command, Next: kill-append function, Prev: copy-region-as-kill body, Up: copy-region-as-kill body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6711 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6712 `last-command' and `this-command' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6713 ................................. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6714 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6715 Normally, whenever a function is executed, Emacs sets the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6716 `this-command' to the function being executed (which in this case would |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6717 be `copy-region-as-kill'). At the same time, Emacs sets the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6718 `last-command' to the previous value of `this-command'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6719 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6720 In the first part of the body of the `copy-region-as-kill' function, an |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6721 `if' expression determines whether the value of `last-command' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6722 `kill-region'. If so, the then-part of the `if' expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6723 evaluated; it uses the `kill-append' function to concatenate the text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6724 copied at this call to the function with the text already in the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6725 element (the CAR) of the kill ring. On the other hand, if the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6726 `last-command' is not `kill-region', then the `copy-region-as-kill' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6727 function attaches a new element to the kill ring using the `kill-new' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6728 function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6729 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6730 The `if' expression reads as follows; it uses `eq', which is a function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6731 we have not yet seen: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6732 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6733 (if (eq last-command 'kill-region) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6734 ;; then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6735 (kill-append (filter-buffer-substring beg end) (< end beg)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6736 ;; else-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6737 (kill-new (filter-buffer-substring beg end))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6738 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6739 (The `filter-buffer-substring' function returns a filtered substring of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6740 the buffer, if any. Optionally--the arguments are not here, so neither |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6741 is done--the function may delete the initial text or return the text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6742 without its properties; this function is a replacement for the older |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6743 `buffer-substring' function, which came before text properties were |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6744 implemented.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6745 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6746 The `eq' function tests whether its first argument is the same Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6747 object as its second argument. The `eq' function is similar to the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6748 `equal' function in that it is used to test for equality, but differs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6749 in that it determines whether two representations are actually the same |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6750 object inside the computer, but with different names. `equal' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6751 determines whether the structure and contents of two expressions are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6752 the same. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6753 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6754 If the previous command was `kill-region', then the Emacs Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6755 interpreter calls the `kill-append' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6756 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6757 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6758 File: eintr, Node: kill-append function, Next: kill-new function, Prev: last-command & this-command, Up: copy-region-as-kill body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6759 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6760 The `kill-append' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6761 .......................... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6762 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6763 The `kill-append' function looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6764 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6765 (defun kill-append (string before-p &optional yank-handler) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6766 "Append STRING to the end of the latest kill in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6767 If BEFORE-P is non-nil, prepend STRING to the kill. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6768 ... " |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6769 (let* ((cur (car kill-ring))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6770 (kill-new (if before-p (concat string cur) (concat cur string)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6771 (or (= (length cur) 0) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6772 (equal yank-handler (get-text-property 0 'yank-handler cur))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6773 yank-handler))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6774 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6775 The `kill-append' function is fairly straightforward. It uses the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6776 `kill-new' function, which we will discuss in more detail in a moment. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6777 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6778 (Also, the function provides an optional argument called |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6779 `yank-handler'; when invoked, this argument tells the function how to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6780 deal with properties added to the text, such as `bold' or `italics'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6781 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6782 It has a `let*' function to set the value of the first element of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6783 kill ring to `cur'. (I do not know why the function does not use `let' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6784 instead; only one value is set in the expression. Perhaps this is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6785 bug that produces no problems?) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6786 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6787 Consider the conditional that is one of the two arguments to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6788 `kill-new'. It uses `concat' to concatenate the new text to the CAR of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6789 the kill ring. Whether it prepends or appends the text depends on the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6790 results of an `if' expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6791 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6792 (if before-p ; if-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6793 (concat string cur) ; then-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6794 (concat cur string)) ; else-part |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6795 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6796 If the region being killed is before the region that was killed in the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6797 last command, then it should be prepended before the material that was |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6798 saved in the previous kill; and conversely, if the killed text follows |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6799 what was just killed, it should be appended after the previous text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6800 The `if' expression depends on the predicate `before-p' to decide |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6801 whether the newly saved text should be put before or after the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6802 previously saved text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6803 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6804 The symbol `before-p' is the name of one of the arguments to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6805 `kill-append'. When the `kill-append' function is evaluated, it is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6806 bound to the value returned by evaluating the actual argument. In this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6807 case, this is the expression `(< end beg)'. This expression does not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6808 directly determine whether the killed text in this command is located |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6809 before or after the kill text of the last command; what it does is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6810 determine whether the value of the variable `end' is less than the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6811 value of the variable `beg'. If it is, it means that the user is most |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6812 likely heading towards the beginning of the buffer. Also, the result |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6813 of evaluating the predicate expression, `(< end beg)', will be true and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6814 the text will be prepended before the previous text. On the other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6815 hand, if the value of the variable `end' is greater than the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6816 the variable `beg', the text will be appended after the previous text. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6817 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6818 When the newly saved text will be prepended, then the string with the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6819 new text will be concatenated before the old text: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6820 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6821 (concat string cur) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6822 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6823 But if the text will be appended, it will be concatenated after the old |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6824 text: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6825 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6826 (concat cur string)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6827 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6828 To understand how this works, we first need to review the `concat' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6829 function. The `concat' function links together or unites two strings |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6830 of text. The result is a string. For example: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6831 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6832 (concat "abc" "def") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6833 => "abcdef" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6834 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6835 (concat "new " |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6836 (car '("first element" "second element"))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6837 => "new first element" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6838 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6839 (concat (car |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6840 '("first element" "second element")) " modified") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6841 => "first element modified" |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6842 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6843 We can now make sense of `kill-append': it modifies the contents of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6844 kill ring. The kill ring is a list, each element of which is saved |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6845 text. The `kill-append' function uses the `kill-new' function which in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6846 turn uses the `setcar' function. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6847 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6848 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6849 File: eintr, Node: kill-new function, Prev: kill-append function, Up: copy-region-as-kill body |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6850 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6851 The `kill-new' function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6852 ....................... |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6853 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6854 The `kill-new' function looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6855 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6856 (defun kill-new (string &optional replace yank-handler) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6857 "Make STRING the latest kill in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6858 Set `kill-ring-yank-pointer' to point to it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6859 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6860 If `interprogram-cut-function' is non-nil, apply it to STRING. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6861 Optional second argument REPLACE non-nil means that STRING will replace |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6862 the front of the kill ring, rather than being added to the list. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6863 ..." |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6864 (if (> (length string) 0) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6865 (if yank-handler |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6866 (put-text-property 0 (length string) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6867 'yank-handler yank-handler string)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6868 (if yank-handler |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6869 (signal 'args-out-of-range |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6870 (list string "yank-handler specified for empty string")))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6871 (if (fboundp 'menu-bar-update-yank-menu) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6872 (menu-bar-update-yank-menu string (and replace (car kill-ring)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6873 (if (and replace kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6874 (setcar kill-ring string) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6875 (push string kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6876 (if (> (length kill-ring) kill-ring-max) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6877 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6878 (setq kill-ring-yank-pointer kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6879 (if interprogram-cut-function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6880 (funcall interprogram-cut-function string (not replace)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6881 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6882 (Notice that the function is not interactive.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6883 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6884 As usual, we can look at this function in parts. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6885 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6886 The function definition has an optional `yank-handler' argument, which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6887 when invoked tells the function how to deal with properties added to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6888 the text, such as `bold' or `italics'. We will skip that. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6889 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6890 The first line of the documentation makes sense: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6891 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6892 Make STRING the latest kill in the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6893 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6894 Let's skip over the rest of the documentation for the moment. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6895 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6896 Also, let's skip over the initial `if' expression and those lines of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6897 code involving `menu-bar-update-yank-menu'. We will explain them below. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6898 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6899 The critical lines are these: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6900 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6901 (if (and replace kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6902 ;; then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6903 (setcar kill-ring string) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6904 ;; else |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6905 (push string kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6906 (setq kill-ring (cons string kill-ring)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6907 (if (> (length kill-ring) kill-ring-max) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6908 ;; avoid overly long kill ring |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6909 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6910 (setq kill-ring-yank-pointer kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6911 (if interprogram-cut-function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6912 (funcall interprogram-cut-function string (not replace)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6913 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6914 The conditional test is `(and replace kill-ring)'. This will be true |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6915 when two conditions are met: the kill ring has something in it, and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6916 the `replace' variable is true. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6917 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6918 When the `kill-append' function sets `replace' to be true and when the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6919 kill ring has at least one item in it, the `setcar' expression is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6920 executed: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6921 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6922 (setcar kill-ring string) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6923 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6924 The `setcar' function actually changes the first element of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6925 `kill-ring' list to the value of `string'. It replaces the first |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6926 element. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6927 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6928 On the other hand, if the kill ring is empty, or replace is false, the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6929 else-part of the condition is executed: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6930 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6931 (push string kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6932 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6933 `push' puts its first argument onto the second. It is the same as the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6934 older |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6935 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6936 (setq kill-ring (cons string kill-ring)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6937 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6938 or the newer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6939 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6940 (add-to-list kill-ring string) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6941 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6942 When it is false, the expression first constructs a new version of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6943 kill ring by prepending `string' to the existing kill ring as a new |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6944 element (that is what the `push' does). Then it executes a second `if' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6945 clause. This second `if' clause keeps the kill ring from growing too |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6946 long. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6947 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6948 Let's look at these two expressions in order. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6949 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6950 The `push' line of the else-part sets the new value of the kill ring to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6951 what results from adding the string being killed to the old kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6952 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6953 We can see how this works with an example. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6954 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6955 First, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6956 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6957 (setq example-list '("here is a clause" "another clause")) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6958 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6959 After evaluating this expression with `C-x C-e', you can evaluate |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6960 `example-list' and see what it returns: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6961 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6962 example-list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6963 => ("here is a clause" "another clause") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6964 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6965 Now, we can add a new element on to this list by evaluating the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6966 following expression: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6967 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6968 (push "a third clause" example-list) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6969 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6970 When we evaluate `example-list', we find its value is: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6971 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6972 example-list |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6973 => ("a third clause" "here is a clause" "another clause") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6974 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6975 Thus, the third clause is added to the list by `push'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6976 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6977 Now for the second part of the `if' clause. This expression keeps the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6978 kill ring from growing too long. It looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6979 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6980 (if (> (length kill-ring) kill-ring-max) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6981 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6982 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6983 The code checks whether the length of the kill ring is greater than the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6984 maximum permitted length. This is the value of `kill-ring-max' (which |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6985 is 60, by default). If the length of the kill ring is too long, then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6986 this code sets the last element of the kill ring to `nil'. It does |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6987 this by using two functions, `nthcdr' and `setcdr'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6988 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6989 We looked at `setcdr' earlier (*note `setcdr': setcdr.). It sets the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6990 CDR of a list, just as `setcar' sets the CAR of a list. In this case, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6991 however, `setcdr' will not be setting the CDR of the whole kill ring; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6992 the `nthcdr' function is used to cause it to set the CDR of the next to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6993 last element of the kill ring--this means that since the CDR of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6994 next to last element is the last element of the kill ring, it will set |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6995 the last element of the kill ring. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6996 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6997 The `nthcdr' function works by repeatedly taking the CDR of a list--it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6998 takes the CDR of the CDR of the CDR ... It does this N times and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
6999 returns the results. (*Note `nthcdr': nthcdr.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7000 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7001 Thus, if we had a four element list that was supposed to be three |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7002 elements long, we could set the CDR of the next to last element to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7003 `nil', and thereby shorten the list. (If you sent the last element to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7004 some other value than `nil', which you could do, then you would not |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7005 have shortened the list. *Note `setcdr': setcdr.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7006 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7007 You can see shortening by evaluating the following three expressions in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7008 turn. First set the value of `trees' to `(maple oak pine birch)', then |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7009 set the CDR of its second CDR to `nil' and then find the value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7010 `trees': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7011 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7012 (setq trees '(maple oak pine birch)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7013 => (maple oak pine birch) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7014 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7015 (setcdr (nthcdr 2 trees) nil) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7016 => nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7017 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7018 trees |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7019 => (maple oak pine) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7020 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7021 (The value returned by the `setcdr' expression is `nil' since that is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7022 what the CDR is set to.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7023 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7024 To repeat, in `kill-new', the `nthcdr' function takes the CDR a number |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7025 of times that is one less than the maximum permitted size of the kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7026 ring and `setcdr' sets the CDR of that element (which will be the rest |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7027 of the elements in the kill ring) to `nil'. This prevents the kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7028 ring from growing too long. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7029 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7030 The next to last expression in the `kill-new' function is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7031 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7032 (setq kill-ring-yank-pointer kill-ring) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7033 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7034 The `kill-ring-yank-pointer' is a global variable that is set to be the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7035 `kill-ring'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7036 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7037 Even though the `kill-ring-yank-pointer' is called a `pointer', it is a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7038 variable just like the kill ring. However, the name has been chosen to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7039 help humans understand how the variable is used. The variable is used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7040 in functions such as `yank' and `yank-pop' (*note Yanking Text Back: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7041 Yanking.). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7042 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7043 Now, to return to an early expression in the body of the function: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7044 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7045 (if (fboundp 'menu-bar-update-yank-menu) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7046 (menu-bar-update-yank-menu string (and replace (car kill-ring)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7047 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7048 It starts with an `if' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7049 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7050 In this case, the expression tests first to see whether |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7051 `menu-bar-update-yank-menu' exists as a function, and if so, calls it. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7052 The `fboundp' function returns true if the symbol it is testing has a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7053 function definition that `is not void'. If the symbol's function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7054 definition were void, we would receive an error message, as we did when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7055 we created errors intentionally (*note Generate an Error Message: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7056 Making Errors.). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7057 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7058 The then-part contains an expression whose first element is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7059 function `and'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7060 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7061 The `and' special form evaluates each of its arguments until one of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7062 arguments returns a value of `nil', in which case the `and' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7063 returns `nil'; however, if none of the arguments returns a value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7064 `nil', the value resulting from evaluating the last argument is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7065 returned. (Since such a value is not `nil', it is considered true in |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7066 Emacs Lisp.) In other words, an `and' expression returns a true value |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7067 only if all its arguments are true. (*Note Second Buffer Related |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7068 Review::.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7069 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7070 The expression determines whether the second argument to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7071 `menu-bar-update-yank-menu' is true or not. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7072 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7073 `menu-bar-update-yank-menu' is one of the functions that make it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7074 possible to use the `Select and Paste' menu in the Edit item of a menu |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7075 bar; using a mouse, you can look at the various pieces of text you have |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7076 saved and select one piece to paste. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7077 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7078 The last expression in the `kill-new' function adds the newly copied |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7079 string to whatever facility exists for copying and pasting among |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7080 different programs running in a windowing system. In the X Windowing |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7081 system, for example, the `x-select-text' function takes the string and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7082 stores it in memory operated by X. You can paste the string in another |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7083 program, such as an Xterm. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7084 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7085 The expression looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7086 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7087 (if interprogram-cut-function |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7088 (funcall interprogram-cut-function string (not replace)))) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7089 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7090 If an `interprogram-cut-function' exists, then Emacs executes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7091 `funcall', which in turn calls its first argument as a function and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7092 passes the remaining arguments to it. (Incidentally, as far as I can |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7093 see, this `if' expression could be replaced by an `and' expression |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7094 similar to the one in the first part of the function.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7095 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7096 We are not going to discuss windowing systems and other programs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7097 further, but merely note that this is a mechanism that enables GNU |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7098 Emacs to work easily and well with other programs. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7099 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7100 This code for placing text in the kill ring, either concatenated with |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7101 an existing element or as a new element, leads us to the code for |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7102 bringing back text that has been cut out of the buffer--the yank |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7103 commands. However, before discussing the yank commands, it is better |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7104 to learn how lists are implemented in a computer. This will make clear |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7105 such mysteries as the use of the term `pointer'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7106 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7107 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7108 File: eintr, Node: Digression into C, Next: defvar, Prev: copy-region-as-kill, Up: Cutting & Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7109 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7110 8.4 Digression into C |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7111 ===================== |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7112 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7113 The `copy-region-as-kill' function (*note `copy-region-as-kill': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7114 copy-region-as-kill.) uses the `filter-buffer-substring' function, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7115 which in turn uses the `delete-and-extract-region' function. It |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7116 removes the contents of a region and you cannot get them back. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7117 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7118 Unlike the other code discussed here, the `delete-and-extract-region' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7119 function is not written in Emacs Lisp; it is written in C and is one of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7120 the primitives of the GNU Emacs system. Since it is very simple, I |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7121 will digress briefly from Lisp and describe it here. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7122 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7123 Like many of the other Emacs primitives, `delete-and-extract-region' is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7124 written as an instance of a C macro, a macro being a template for code. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7125 The complete macro looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7126 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7127 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7128 Sbuffer_substring_no_properties, 2, 2, 0, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7129 doc: /* Return the characters of part of the buffer, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7130 without the text properties. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7131 The two arguments START and END are character positions; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7132 they can be in either order. */) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7133 (start, end) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7134 Lisp_Object start, end; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7135 { |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7136 register int b, e; |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7137 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7138 validate_region (&start, &end); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7139 b = XINT (start); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7140 e = XINT (end); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7141 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7142 return make_buffer_string (b, e, 0); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7143 } |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7144 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7145 Without going into the details of the macro writing process, let me |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7146 point out that this macro starts with the word `DEFUN'. The word |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7147 `DEFUN' was chosen since the code serves the same purpose as `defun' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7148 does in Lisp. (The `DEFUN' C macro is defined in `emacs/src/lisp.h'.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7149 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7150 The word `DEFUN' is followed by seven parts inside of parentheses: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7151 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7152 * The first part is the name given to the function in Lisp, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7153 `delete-and-extract-region'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7154 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7155 * The second part is the name of the function in C, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7156 `Fdelete_and_extract_region'. By convention, it starts with `F'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7157 Since C does not use hyphens in names, underscores are used |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7158 instead. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7159 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7160 * The third part is the name for the C constant structure that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7161 records information on this function for internal use. It is the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7162 name of the function in C but begins with an `S' instead of an `F'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7163 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7164 * The fourth and fifth parts specify the minimum and maximum number |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7165 of arguments the function can have. This function demands exactly |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7166 2 arguments. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7167 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7168 * The sixth part is nearly like the argument that follows the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7169 `interactive' declaration in a function written in Lisp: a letter |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7170 followed, perhaps, by a prompt. The only difference from the Lisp |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7171 is when the macro is called with no arguments. Then you write a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7172 `0' (which is a `null string'), as in this macro. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7173 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7174 If you were to specify arguments, you would place them between |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7175 quotation marks. The C macro for `goto-char' includes `"NGoto |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7176 char: "' in this position to indicate that the function expects a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7177 raw prefix, in this case, a numerical location in a buffer, and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7178 provides a prompt. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7179 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7180 * The seventh part is a documentation string, just like the one for a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7181 function written in Emacs Lisp, except that every newline must be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7182 written explicitly as `\n' followed by a backslash and carriage |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7183 return. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7184 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7185 Thus, the first two lines of documentation for `goto-char' are |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7186 written like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7187 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7188 "Set point to POSITION, a number or marker.\n\ |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7189 Beginning of buffer is position (point-min), end is (point-max). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7190 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7191 In a C macro, the formal parameters come next, with a statement of what |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7192 kind of object they are, followed by what might be called the `body' of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7193 the macro. For `delete-and-extract-region' the `body' consists of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7194 following four lines: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7195 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7196 validate_region (&start, &end); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7197 if (XINT (start) == XINT (end)) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7198 return build_string (""); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7199 return del_range_1 (XINT (start), XINT (end), 1, 1); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7200 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7201 The `validate_region' function checks whether the values passed as |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7202 the beginning and end of the region are the proper type and are within |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7203 range. If the beginning and end positions are the same, then return |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7204 and empty string. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7205 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7206 The `del_range_1' function actually deletes the text. It is a complex |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7207 function we will not look into. It updates the buffer and does other |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7208 things. However, it is worth looking at the two arguments passed to |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7209 `del_range'. These are `XINT (start)' and `XINT (end)'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7210 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7211 As far as the C language is concerned, `start' and `end' are two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7212 integers that mark the beginning and end of the region to be deleted(1). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7213 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7214 In early versions of Emacs, these two numbers were thirty-two bits |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7215 long, but the code is slowly being generalized to handle other lengths. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7216 Three of the available bits are used to specify the type of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7217 information; the remaining bits are used as `content'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7218 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7219 `XINT' is a C macro that extracts the relevant number from the longer |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7220 collection of bits; the three other bits are discarded. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7221 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7222 The command in `delete-and-extract-region' looks like this: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7223 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7224 del_range_1 (XINT (start), XINT (end), 1, 1); |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7225 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7226 It deletes the region between the beginning position, `start', and the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7227 ending position, `end'. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7228 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7229 From the point of view of the person writing Lisp, Emacs is all very |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7230 simple; but hidden underneath is a great deal of complexity to make it |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7231 all work. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7232 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7233 ---------- Footnotes ---------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7234 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7235 (1) More precisely, and requiring more expert knowledge to understand, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7236 the two integers are of type `Lisp_Object', which can also be a C union |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7237 instead of an integer type. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7238 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7239 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7240 File: eintr, Node: defvar, Next: cons & search-fwd Review, Prev: Digression into C, Up: Cutting & Storing Text |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7241 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7242 8.5 Initializing a Variable with `defvar' |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7243 ========================================= |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7244 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7245 The `copy-region-as-kill' function is written in Emacs Lisp. Two |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7246 functions within it, `kill-append' and `kill-new', copy a region in a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7247 buffer and save it in a variable called the `kill-ring'. This section |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7248 describes how the `kill-ring' variable is created and initialized using |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7249 the `defvar' special form. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7250 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7251 (Again we note that the term `kill-ring' is a misnomer. The text that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7252 is clipped out of the buffer can be brought back; it is not a ring of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7253 corpses, but a ring of resurrectable text.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7254 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7255 In Emacs Lisp, a variable such as the `kill-ring' is created and given |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7256 an initial value by using the `defvar' special form. The name comes |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7257 from "define variable". |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7258 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7259 The `defvar' special form is similar to `setq' in that it sets the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7260 value of a variable. It is unlike `setq' in two ways: first, it only |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7261 sets the value of the variable if the variable does not already have a |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7262 value. If the variable already has a value, `defvar' does not override |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7263 the existing value. Second, `defvar' has a documentation string. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7264 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7265 (Another special form, `defcustom', is designed for variables that |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7266 people customize. It has more features than `defvar'. (*Note Setting |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7267 Variables with `defcustom': defcustom.) |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7268 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7269 * Menu: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7270 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7271 * See variable current value:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7272 * defvar and asterisk:: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7273 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7274 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7275 File: eintr, Node: See variable current value, Next: defvar and asterisk, Prev: defvar, Up: defvar |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7276 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7277 Seeing the Current Value of a Variable |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7278 -------------------------------------- |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7279 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7280 You can see the current value of a variable, any variable, by using the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7281 `describe-variable' function, which is usually invoked by typing `C-h |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7282 v'. If you type `C-h v' and then `kill-ring' (followed by <RET>) when |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7283 prompted, you will see what is in your current kill ring--this may be |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7284 quite a lot! Conversely, if you have been doing nothing this Emacs |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7285 session except read this document, you may have nothing in it. Also, |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7286 you will see the documentation for `kill-ring': |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7287 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7288 Documentation: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7289 List of killed text sequences. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7290 Since the kill ring is supposed to interact nicely with cut-and-paste |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7291 facilities offered by window systems, use of this variable should |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7292 interact nicely with `interprogram-cut-function' and |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7293 `interprogram-paste-function'. The functions `kill-new', |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7294 `kill-append', and `current-kill' are supposed to implement this |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7295 interaction; you may want to use them instead of manipulating the kill |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7296 ring directly. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7297 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7298 The kill ring is defined by a `defvar' in the following way: |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7299 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7300 (defvar kill-ring nil |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7301 "List of killed text sequences. |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7302 ...") |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7303 |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7304 In this variable definition, the variable is given an initial value of |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7305 `nil', which makes sense, since if you have saved nothing, you want |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7306 nothing back if you give a `yank' command. The documentation string is |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7307 written just like the documentation string of a `defun'. As with the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7308 documentation string of the `defun', the first line of the |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7309 documentation should be a complete sentence, since some commands, like |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7310 `apropos', print only the first line of documentation. Succeeding |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7311 lines should not be indented; otherwise they look odd when you use `C-h |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7312 v' (`describe-variable'). |
dcc218a536a8
info/eintr-1: Updated Info file to Third Edition for
Robert J. Chassell <bob@rattlesnake.com>
parents:
diff
changeset
|
7313 |