Mercurial > emacs
comparison lispintro/emacs-lisp-intro.texi @ 73852:1629ec038cb6
(beginning of emacs-lisp-intro.texi): Add `other shell commands' to
produce additional output formats; total is now ten.
(A Loop with an Incrementing Counter, and others): Ensure Info menus
will appear in short windows.
(Disentangle beginning-of-buffer): Replace `version 21' with `more
recent versions'.
(Simple Extension): Show how to handle multiple versions by adding
an alternative with a test of `>= 21'
author | Robert J. Chassell <bob@rattlesnake.com> |
---|---|
date | Thu, 09 Nov 2006 17:04:48 +0000 |
parents | a44deabfa735 |
children | 55e5dc416293 |
comparison
equal
deleted
inserted
replaced
73851:cf6323762282 | 73852:1629ec038cb6 |
---|---|
22 @c clear print-postscript-figures | 22 @c clear print-postscript-figures |
23 @c --------- | 23 @c --------- |
24 | 24 |
25 @comment %**end of header | 25 @comment %**end of header |
26 | 26 |
27 @set edition-number 3.06 | 27 @set edition-number 3.07 |
28 @set update-date 6 November 2006 | 28 @set update-date 9 November 2006 |
29 | 29 |
30 @ignore | 30 @ignore |
31 ## Summary of shell commands to create various output formats: | 31 ## Summary of shell commands to create various output formats: |
32 | 32 |
33 pushd /usr/local/src/emacs/lispintro/ | 33 pushd /usr/local/src/emacs/lispintro/ |
34 ## pushd /u/intro/ | 34 ## pushd /u/intro/ |
35 | 35 |
36 ## Info output | 36 ## Info output |
37 # makeinfo --no-split --paragraph-indent=0 --verbose emacs-lisp-intro.texi | |
38 makeinfo --paragraph-indent=0 --verbose emacs-lisp-intro.texi | 37 makeinfo --paragraph-indent=0 --verbose emacs-lisp-intro.texi |
39 | 38 |
40 ## ;; (progn (when (bufferp (get-buffer "*info*")) (kill-buffer "*info*")) (info "../info/eintr")) | 39 ## ;; (progn (when (bufferp (get-buffer "*info*")) (kill-buffer "*info*")) (info "/usr/local/src/emacs/info/eintr")) |
41 | 40 |
42 ## DVI output | 41 ## DVI output |
43 texi2dvi emacs-lisp-intro.texi | 42 texi2dvi emacs-lisp-intro.texi |
44 | 43 |
45 ## View DVI output; see below also | 44 ## xdvi -margins 24pt -topmargin 4pt -offsets 24pt -geometry 760x1140 -s 5 -useTeXpages -mousemode 1 emacs-lisp-intro.dvi & |
46 # xdvi -margins 24pt -topmargin 4pt -offsets 24pt -geometry 760x1140 -s 5 -useTeXpages -mousemode 1 emacs-lisp-intro.dvi & | |
47 | 45 |
48 ## HTML output | 46 ## HTML output |
49 makeinfo --html --no-split --verbose emacs-lisp-intro.texi | 47 makeinfo --html --no-split --verbose emacs-lisp-intro.texi |
48 | |
49 ## galeon emacs-lisp-intro.html | |
50 | 50 |
51 ## Plain text output | 51 ## Plain text output |
52 makeinfo --fill-column=70 --no-split --paragraph-indent=0 \ | 52 makeinfo --fill-column=70 --no-split --paragraph-indent=0 \ |
53 --verbose --no-headers --output=emacs-lisp-intro.txt emacs-lisp-intro.texi | 53 --verbose --no-headers --output=emacs-lisp-intro.txt emacs-lisp-intro.texi |
54 | 54 |
55 ## DocBook output | |
56 makeinfo --docbook --no-split --paragraph-indent=0 \ | |
57 --verbose emacs-lisp-intro.texi | |
58 | |
59 ## XML output | |
60 makeinfo --xml --no-split --paragraph-indent=0 \ | |
61 --verbose emacs-lisp-intro.texi | |
62 | |
63 popd | 55 popd |
64 | |
65 #### (You must be in the same directory as the viewed file.) | |
66 | |
67 ## View DVI output | |
68 xdvi emacs-lisp-intro.dvi & | |
69 | |
70 ## View HTML output | |
71 galeon emacs-lisp-intro.html | |
72 | |
73 ## View Info output with standalone reader | |
74 info emacs-lisp-intro.info | |
75 | |
76 ## popd | |
77 | |
78 | 56 |
79 # as user `root' | 57 # as user `root' |
80 # insert thumbdrive | 58 # insert thumbdrive |
81 mtusb # mount -v -t ext3 /dev/sda /mnt | 59 mtusb # mount -v -t ext3 /dev/sda /mnt |
82 cp -v /u/intro/emacs-lisp-intro.texi /mnt/backup/intro/emacs-lisp-intro.texi | 60 cp -v /u/intro/emacs-lisp-intro.texi /mnt/backup/intro/emacs-lisp-intro.texi |
83 umtusb # umount -v /mnt | 61 umtusb # umount -v /mnt |
84 # remove thumbdrive | 62 # remove thumbdrive |
63 | |
64 ## Other shell commands | |
65 | |
66 pushd /usr/local/src/emacs/lispintro/ | |
67 ## pushd /u/intro/ | |
68 | |
69 ## PDF | |
70 texi2dvi --pdf emacs-lisp-intro.texi | |
71 # xpdf emacs-lisp-intro.pdf & | |
72 | |
73 ## DocBook -- note file extension | |
74 makeinfo --docbook --no-split --paragraph-indent=0 \ | |
75 --verbose --output=emacs-lisp-intro.docbook emacs-lisp-intro.texi | |
76 | |
77 ## XML with a Texinfo DTD -- note file extension | |
78 makeinfo --xml --no-split --paragraph-indent=0 \ | |
79 --verbose --output=emacs-lisp-intro.texinfoxml emacs-lisp-intro.texi | |
80 | |
81 ## PostScript (needs DVI) | |
82 # gv emacs-lisp-intro.ps & | |
83 # Create DVI if we lack it | |
84 # texi2dvi emacs-lisp-intro.texi | |
85 dvips emacs-lisp-intro.dvi -o emacs-lisp-intro.ps | |
86 | |
87 ## RTF (needs HTML) | |
88 # Use OpenOffice to view RTF | |
89 # Create HTML if we lack it | |
90 # makeinfo --no-split --html emacs-lisp-intro.texi | |
91 /usr/local/src/html2rtf.pl emacs-lisp-intro.html | |
92 | |
93 ## LaTeX (needs RTF) | |
94 /usr/bin/rtf2latex emacs-lisp-intro.rtf | |
95 | |
96 popd | |
85 | 97 |
86 @end ignore | 98 @end ignore |
87 | 99 |
88 @c ================ Included Figures ================ | 100 @c ================ Included Figures ================ |
89 | 101 |
379 * Complications:: Variables, Special forms, Lists within. | 391 * Complications:: Variables, Special forms, Lists within. |
380 * Byte Compiling:: Specially processing code for speed. | 392 * Byte Compiling:: Specially processing code for speed. |
381 | 393 |
382 Evaluation | 394 Evaluation |
383 | 395 |
396 * How the Interpreter Acts:: Returns and Side Effects... | |
384 * Evaluating Inner Lists:: Lists within lists... | 397 * Evaluating Inner Lists:: Lists within lists... |
385 | 398 |
386 Variables | 399 Variables |
387 | 400 |
388 * fill-column Example:: | 401 * fill-column Example:: |
612 | 625 |
613 * Looping with while:: Repeat so long as test returns true. | 626 * Looping with while:: Repeat so long as test returns true. |
614 * Loop Example:: A @code{while} loop that uses a list. | 627 * Loop Example:: A @code{while} loop that uses a list. |
615 * print-elements-of-list:: Uses @code{while}, @code{car}, @code{cdr}. | 628 * print-elements-of-list:: Uses @code{while}, @code{car}, @code{cdr}. |
616 * Incrementing Loop:: A loop with an incrementing counter. | 629 * Incrementing Loop:: A loop with an incrementing counter. |
630 * Incrementing Loop Details:: | |
617 * Decrementing Loop:: A loop with a decrementing counter. | 631 * Decrementing Loop:: A loop with a decrementing counter. |
618 | 632 |
619 A Loop with an Incrementing Counter | 633 Details of an Incrementing Loop |
620 | 634 |
621 * Incrementing Example:: Counting pebbles in a triangle. | 635 * Incrementing Example:: Counting pebbles in a triangle. |
622 * Inc Example parts:: The parts of the function definition. | 636 * Inc Example parts:: The parts of the function definition. |
623 * Inc Example altogether:: Putting the function definition together. | 637 * Inc Example altogether:: Putting the function definition together. |
624 | 638 |
707 * lengths-list-many-files:: Return a list of the lengths of defuns. | 721 * lengths-list-many-files:: Return a list of the lengths of defuns. |
708 * append:: Attach one list to another. | 722 * append:: Attach one list to another. |
709 | 723 |
710 Prepare the Data for Display in a Graph | 724 Prepare the Data for Display in a Graph |
711 | 725 |
726 * Data for Display in Detail:: | |
712 * Sorting:: Sorting lists. | 727 * Sorting:: Sorting lists. |
713 * Files List:: Making a list of files. | 728 * Files List:: Making a list of files. |
714 * Counting function definitions:: | 729 * Counting function definitions:: |
715 | 730 |
716 Readying a Graph | 731 Readying a Graph |
747 * edebug:: How to use Edebug, a source level debugger. | 762 * edebug:: How to use Edebug, a source level debugger. |
748 * Debugging Exercises:: | 763 * Debugging Exercises:: |
749 | 764 |
750 Handling the Kill Ring | 765 Handling the Kill Ring |
751 | 766 |
767 * What the Kill Ring Does:: | |
752 * current-kill:: | 768 * current-kill:: |
753 * yank:: Paste a copy of a clipped element. | 769 * yank:: Paste a copy of a clipped element. |
754 * yank-pop:: Insert element pointed to. | 770 * yank-pop:: Insert element pointed to. |
755 * ring file:: | 771 * ring file:: |
756 | 772 |
758 | 774 |
759 * Understanding current-kill:: | 775 * Understanding current-kill:: |
760 | 776 |
761 @code{current-kill} in Outline | 777 @code{current-kill} in Outline |
762 | 778 |
779 * Body of current-kill:: | |
763 * Digression concerning error:: How to mislead humans, but not computers. | 780 * Digression concerning error:: How to mislead humans, but not computers. |
764 * Determining the Element:: | 781 * Determining the Element:: |
765 | 782 |
766 A Graph with Labelled Axes | 783 A Graph with Labelled Axes |
767 | 784 |
771 * print-X-axis:: Print a horizontal label. | 788 * print-X-axis:: Print a horizontal label. |
772 * Print Whole Graph:: The function to print a complete graph. | 789 * Print Whole Graph:: The function to print a complete graph. |
773 | 790 |
774 The @code{print-Y-axis} Function | 791 The @code{print-Y-axis} Function |
775 | 792 |
793 * print-Y-axis in Detail:: | |
776 * Height of label:: What height for the Y axis? | 794 * Height of label:: What height for the Y axis? |
777 * Compute a Remainder:: How to compute the remainder of a division. | 795 * Compute a Remainder:: How to compute the remainder of a division. |
778 * Y Axis Element:: Construct a line for the Y axis. | 796 * Y Axis Element:: Construct a line for the Y axis. |
779 * Y-axis-column:: Generate a list of Y axis labels. | 797 * Y-axis-column:: Generate a list of Y axis labels. |
780 * print-Y-axis Penultimate:: A not quite final version. | 798 * print-Y-axis Penultimate:: A not quite final version. |
1624 `evaluates the expression'. I've used this term several times before. | 1642 `evaluates the expression'. I've used this term several times before. |
1625 The word comes from its use in everyday language, `to ascertain the | 1643 The word comes from its use in everyday language, `to ascertain the |
1626 value or amount of; to appraise', according to @cite{Webster's New | 1644 value or amount of; to appraise', according to @cite{Webster's New |
1627 Collegiate Dictionary}. | 1645 Collegiate Dictionary}. |
1628 | 1646 |
1647 @menu | |
1648 * How the Interpreter Acts:: | |
1649 * Evaluating Inner Lists:: | |
1650 @end menu | |
1651 | |
1652 @node How the Interpreter Acts, Evaluating Inner Lists, Evaluation, Evaluation | |
1653 @ifnottex | |
1654 @unnumberedsubsec How the Lisp Interpreter Acts | |
1655 @end ifnottex | |
1656 | |
1657 @cindex @samp{returned value} explained | |
1629 After evaluating an expression, the Lisp interpreter will most likely | 1658 After evaluating an expression, the Lisp interpreter will most likely |
1630 @dfn{return} the value that the computer produces by carrying out the | 1659 @dfn{return} the value that the computer produces by carrying out the |
1631 instructions it found in the function definition, or perhaps it will | 1660 instructions it found in the function definition, or perhaps it will |
1632 give up on that function and produce an error message. (The interpreter | 1661 give up on that function and produce an error message. (The interpreter |
1633 may also find itself tossed, so to speak, to a different function or it | 1662 may also find itself tossed, so to speak, to a different function or it |
1645 | 1674 |
1646 In summary, evaluating a symbolic expression most commonly causes the | 1675 In summary, evaluating a symbolic expression most commonly causes the |
1647 Lisp interpreter to return a value and perhaps carry out a side effect; | 1676 Lisp interpreter to return a value and perhaps carry out a side effect; |
1648 or else produce an error. | 1677 or else produce an error. |
1649 | 1678 |
1650 @menu | 1679 @node Evaluating Inner Lists, , How the Interpreter Acts, Evaluation |
1651 * Evaluating Inner Lists:: | |
1652 @end menu | |
1653 | |
1654 @node Evaluating Inner Lists, , Evaluation, Evaluation | |
1655 @comment node-name, next, previous, up | 1680 @comment node-name, next, previous, up |
1656 @subsection Evaluating Inner Lists | 1681 @subsection Evaluating Inner Lists |
1657 @cindex Inner list evaluation | 1682 @cindex Inner list evaluation |
1658 @cindex Evaluating inner lists | 1683 @cindex Evaluating inner lists |
1659 | 1684 |
4499 @need 1250 | 4524 @need 1250 |
4500 For example, | 4525 For example, |
4501 | 4526 |
4502 @smallexample | 4527 @smallexample |
4503 @group | 4528 @group |
4504 (if (string-equal | 4529 (if (= 22 emacs-major-version) |
4505 (number-to-string 22) | |
4506 (substring (emacs-version) 10 12)) | |
4507 (message "This is version 22 Emacs") | 4530 (message "This is version 22 Emacs") |
4508 (message "This is not version 22 Emacs")) | 4531 (message "This is not version 22 Emacs")) |
4509 @end group | 4532 @end group |
4510 @end smallexample | 4533 @end smallexample |
4511 | |
4512 @item equal | |
4513 @itemx eq | |
4514 Test whether two objects are the same. @code{equal} uses one meaning | |
4515 of the word `same' and @code{eq} uses another: @code{equal} returns | |
4516 true if the two objects have a similar structure and contents, such as | |
4517 two copies of the same book. On the other hand, @code{eq}, returns | |
4518 true if both arguments are actually the same object. | |
4519 @findex equal | |
4520 @findex eq | |
4521 | 4534 |
4522 @need 1250 | 4535 @need 1250 |
4523 @item < | 4536 @item < |
4524 @itemx > | 4537 @itemx > |
4525 @itemx <= | 4538 @itemx <= |
4535 @need 800 | 4548 @need 800 |
4536 @item = | 4549 @item = |
4537 The @code{=} function tests whether two arguments, both numbers or | 4550 The @code{=} function tests whether two arguments, both numbers or |
4538 markers, are equal. | 4551 markers, are equal. |
4539 | 4552 |
4553 @need 1250 | |
4554 @item equal | |
4555 @itemx eq | |
4556 Test whether two objects are the same. @code{equal} uses one meaning | |
4557 of the word `same' and @code{eq} uses another: @code{equal} returns | |
4558 true if the two objects have a similar structure and contents, such as | |
4559 two copies of the same book. On the other hand, @code{eq}, returns | |
4560 true if both arguments are actually the same object. | |
4561 @findex equal | |
4562 @findex eq | |
4563 | |
4564 @need 1250 | |
4540 @item string< | 4565 @item string< |
4541 @itemx string-lessp | 4566 @itemx string-lessp |
4542 @itemx string= | 4567 @itemx string= |
4543 @itemx string-equal | 4568 @itemx string-equal |
4544 The @code{string-lessp} function tests whether its first argument is | 4569 The @code{string-lessp} function tests whether its first argument is |
5658 * insert-buffer interactive:: | 5683 * insert-buffer interactive:: |
5659 * insert-buffer body:: | 5684 * insert-buffer body:: |
5660 * if & or:: | 5685 * if & or:: |
5661 * Insert or:: | 5686 * Insert or:: |
5662 * Insert let:: | 5687 * Insert let:: |
5663 * New insert-buffer :: | 5688 * New insert-buffer:: |
5664 @end menu | 5689 @end menu |
5665 | 5690 |
5666 @node insert-buffer code, insert-buffer interactive, insert-buffer, insert-buffer | 5691 @node insert-buffer code, insert-buffer interactive, insert-buffer, insert-buffer |
5667 @ifnottex | 5692 @ifnottex |
5668 @unnumberedsubsec The Code for @code{insert-buffer} | 5693 @unnumberedsubsec The Code for @code{insert-buffer} |
5932 | 5957 |
5933 @smallexample | 5958 @smallexample |
5934 (or (holding-on-to-guest) (find-and-take-arm-of-guest)) | 5959 (or (holding-on-to-guest) (find-and-take-arm-of-guest)) |
5935 @end smallexample | 5960 @end smallexample |
5936 | 5961 |
5937 @node Insert let, New insert-buffer , Insert or, insert-buffer | 5962 @node Insert let, New insert-buffer, Insert or, insert-buffer |
5938 @comment node-name, next, previous, up | 5963 @comment node-name, next, previous, up |
5939 @subsection The @code{let} Expression in @code{insert-buffer} | 5964 @subsection The @code{let} Expression in @code{insert-buffer} |
5940 | 5965 |
5941 After ensuring that the variable @code{buffer} refers to a buffer itself | 5966 After ensuring that the variable @code{buffer} refers to a buffer itself |
5942 and not just to the name of a buffer, the @code{insert-buffer function} | 5967 and not just to the name of a buffer, the @code{insert-buffer function} |
6031 function uses @code{let}, @code{save-excursion}, and | 6056 function uses @code{let}, @code{save-excursion}, and |
6032 @code{set-buffer}. In addition, the function illustrates one way to | 6057 @code{set-buffer}. In addition, the function illustrates one way to |
6033 use @code{or}. All these functions are building blocks that we will | 6058 use @code{or}. All these functions are building blocks that we will |
6034 find and use again and again. | 6059 find and use again and again. |
6035 | 6060 |
6036 @node New insert-buffer , , Insert let, insert-buffer | 6061 @node New insert-buffer, , Insert let, insert-buffer |
6037 @comment node-name, next, previous, up | 6062 @comment node-name, next, previous, up |
6038 @subsection New Body for @code{insert-buffer} | 6063 @subsection New Body for @code{insert-buffer} |
6039 @findex insert-buffer, new version body | 6064 @findex insert-buffer, new version body |
6040 @findex new version body for insert-buffer | 6065 @findex new version body for insert-buffer |
6041 | 6066 |
6233 @var{else-use-alternate-calculation} | 6258 @var{else-use-alternate-calculation} |
6234 @end group | 6259 @end group |
6235 @end smallexample | 6260 @end smallexample |
6236 | 6261 |
6237 The true-or-false-test of this inner @code{if} expression checks the | 6262 The true-or-false-test of this inner @code{if} expression checks the |
6238 size of the buffer. The reason for this is that the old Version 18 | 6263 size of the buffer. The reason for this is that the old version 18 |
6239 Emacs used numbers that are no bigger than eight million or so | 6264 Emacs used numbers that are no bigger than eight million or so and in |
6240 and in the computation that followed, the programmer feared that Emacs | 6265 the computation that followed, the programmer feared that Emacs might |
6241 might try to use over-large numbers if the buffer were large. The | 6266 try to use over-large numbers if the buffer were large. The term |
6242 term `overflow', mentioned in the comment, means numbers that are over | 6267 `overflow', mentioned in the comment, means numbers that are over |
6243 large. Version 21 Emacs uses larger numbers, but this code has not | 6268 large. More recent versions of Emacs use larger numbers, but this |
6244 been touched, if only because people now look at buffers that are far, | 6269 code has not been touched, if only because people now look at buffers |
6245 far larger than ever before. | 6270 that are far, far larger than ever before. |
6246 | 6271 |
6247 There are two cases: if the buffer is large and if it is not. | 6272 There are two cases: if the buffer is large and if it is not. |
6248 | 6273 |
6249 @node Large buffer case, Small buffer case, Disentangle beginning-of-buffer, beginning-of-buffer opt arg | 6274 @node Large buffer case, Small buffer case, Disentangle beginning-of-buffer, beginning-of-buffer opt arg |
6250 @comment node-name, next, previous, up | 6275 @comment node-name, next, previous, up |
10394 @menu | 10419 @menu |
10395 * Looping with while:: | 10420 * Looping with while:: |
10396 * Loop Example:: | 10421 * Loop Example:: |
10397 * print-elements-of-list:: | 10422 * print-elements-of-list:: |
10398 * Incrementing Loop:: | 10423 * Incrementing Loop:: |
10424 * Incrementing Loop Details:: | |
10399 * Decrementing Loop:: | 10425 * Decrementing Loop:: |
10400 @end menu | 10426 @end menu |
10401 | 10427 |
10402 @node Looping with while, Loop Example, while, while | 10428 @node Looping with while, Loop Example, while, while |
10403 @ifnottex | 10429 @ifnottex |
10615 the function @code{print} does) and then the value returned by the | 10641 the function @code{print} does) and then the value returned by the |
10616 function is printed. Since the last expression in the function is the | 10642 function is printed. Since the last expression in the function is the |
10617 @code{while} loop, and since @code{while} loops always return | 10643 @code{while} loop, and since @code{while} loops always return |
10618 @code{nil}, a @code{nil} is printed after the last element of the list. | 10644 @code{nil}, a @code{nil} is printed after the last element of the list. |
10619 | 10645 |
10620 @node Incrementing Loop, Decrementing Loop, print-elements-of-list, while | 10646 @node Incrementing Loop, Incrementing Loop Details, print-elements-of-list, while |
10621 @comment node-name, next, previous, up | 10647 @comment node-name, next, previous, up |
10622 @subsection A Loop with an Incrementing Counter | 10648 @subsection A Loop with an Incrementing Counter |
10623 | 10649 |
10624 A loop is not useful unless it stops when it ought. Besides | 10650 A loop is not useful unless it stops when it ought. Besides |
10625 controlling a loop with a list, a common way of stopping a loop is to | 10651 controlling a loop with a list, a common way of stopping a loop is to |
10626 write the first argument as a test that returns false when the correct | 10652 write the first argument as a test that returns false when the correct |
10627 number of repetitions are complete. This means that the loop must | 10653 number of repetitions are complete. This means that the loop must |
10628 have a counter---an expression that counts how many times the loop | 10654 have a counter---an expression that counts how many times the loop |
10629 repeats itself. | 10655 repeats itself. |
10630 | 10656 |
10631 The test can be an expression such as @code{(< count desired-number)} | 10657 @node Incrementing Loop Details, Decrementing Loop, Incrementing Loop, while |
10632 which returns @code{t} for true if the value of @code{count} is less | 10658 @ifnottex |
10633 than the @code{desired-number} of repetitions and @code{nil} for false if | 10659 @unnumberedsubsec Details of an Incrementing Loop |
10634 the value of @code{count} is equal to or is greater than the | 10660 @end ifnottex |
10635 @code{desired-number}. The expression that increments the count can be | 10661 |
10636 a simple @code{setq} such as @code{(setq count (1+ count))}, where | 10662 The test for a loop with an incrementing counter can be an expression |
10663 such as @code{(< count desired-number)} which returns @code{t} for | |
10664 true if the value of @code{count} is less than the | |
10665 @code{desired-number} of repetitions and @code{nil} for false if the | |
10666 value of @code{count} is equal to or is greater than the | |
10667 @code{desired-number}. The expression that increments the count can | |
10668 be a simple @code{setq} such as @code{(setq count (1+ count))}, where | |
10637 @code{1+} is a built-in function in Emacs Lisp that adds 1 to its | 10669 @code{1+} is a built-in function in Emacs Lisp that adds 1 to its |
10638 argument. (The expression @w{@code{(1+ count)}} has the same result as | 10670 argument. (The expression @w{@code{(1+ count)}} has the same result |
10639 @w{@code{(+ count 1)}}, but is easier for a human to read.) | 10671 as @w{@code{(+ count 1)}}, but is easier for a human to read.) |
10640 | 10672 |
10641 @need 1250 | 10673 @need 1250 |
10642 The template for a @code{while} loop controlled by an incrementing | 10674 The template for a @code{while} loop controlled by an incrementing |
10643 counter looks like this: | 10675 counter looks like this: |
10644 | 10676 |
10659 * Incrementing Example:: | 10691 * Incrementing Example:: |
10660 * Inc Example parts:: | 10692 * Inc Example parts:: |
10661 * Inc Example altogether:: | 10693 * Inc Example altogether:: |
10662 @end menu | 10694 @end menu |
10663 | 10695 |
10664 @node Incrementing Example, Inc Example parts, Incrementing Loop, Incrementing Loop | 10696 @node Incrementing Example, Inc Example parts, Incrementing Loop Details, Incrementing Loop Details |
10665 @unnumberedsubsubsec Example with incrementing counter | 10697 @unnumberedsubsubsec Example with incrementing counter |
10666 | 10698 |
10667 Suppose you are playing on the beach and decide to make a triangle of | 10699 Suppose you are playing on the beach and decide to make a triangle of |
10668 pebbles, putting one pebble in the first row, two in the second row, | 10700 pebbles, putting one pebble in the first row, two in the second row, |
10669 three in the third row and so on, like this: | 10701 three in the third row and so on, like this: |
10726 process of adding two numbers is repeated again and again until the last | 10758 process of adding two numbers is repeated again and again until the last |
10727 row has been added to the total of all the preceding rows. In a more | 10759 row has been added to the total of all the preceding rows. In a more |
10728 complex loop the repetitive action might not be so simple, but it will | 10760 complex loop the repetitive action might not be so simple, but it will |
10729 be simpler than doing everything all at once. | 10761 be simpler than doing everything all at once. |
10730 | 10762 |
10731 @node Inc Example parts, Inc Example altogether, Incrementing Example, Incrementing Loop | 10763 @node Inc Example parts, Inc Example altogether, Incrementing Example, Incrementing Loop Details |
10732 @unnumberedsubsubsec The parts of the function definition | 10764 @unnumberedsubsubsec The parts of the function definition |
10733 | 10765 |
10734 The preceding analysis gives us the bones of our function definition: | 10766 The preceding analysis gives us the bones of our function definition: |
10735 first, we will need a variable that we can call @code{total} that will | 10767 first, we will need a variable that we can call @code{total} that will |
10736 be the total number of pebbles. This will be the value returned by | 10768 be the total number of pebbles. This will be the value returned by |
10820 | 10852 |
10821 @smallexample | 10853 @smallexample |
10822 (setq row-number (1+ row-number)) | 10854 (setq row-number (1+ row-number)) |
10823 @end smallexample | 10855 @end smallexample |
10824 | 10856 |
10825 @node Inc Example altogether, , Inc Example parts, Incrementing Loop | 10857 @node Inc Example altogether, , Inc Example parts, Incrementing Loop Details |
10826 @unnumberedsubsubsec Putting the function definition together | 10858 @unnumberedsubsubsec Putting the function definition together |
10827 | 10859 |
10828 We have created the parts for the function definition; now we need to | 10860 We have created the parts for the function definition; now we need to |
10829 put them together. | 10861 put them together. |
10830 | 10862 |
10930 | 10962 |
10931 @noindent | 10963 @noindent |
10932 The sum of the first four numbers is 10 and the sum of the first seven | 10964 The sum of the first four numbers is 10 and the sum of the first seven |
10933 numbers is 28. | 10965 numbers is 28. |
10934 | 10966 |
10935 @node Decrementing Loop, , Incrementing Loop, while | 10967 @node Decrementing Loop, , Incrementing Loop Details, while |
10936 @comment node-name, next, previous, up | 10968 @comment node-name, next, previous, up |
10937 @subsection Loop with a Decrementing Counter | 10969 @subsection Loop with a Decrementing Counter |
10938 | 10970 |
10939 Another common way to write a @code{while} loop is to write the test | 10971 Another common way to write a @code{while} loop is to write the test |
10940 so that it determines whether a counter is greater than zero. So long | 10972 so that it determines whether a counter is greater than zero. So long |
15515 those here work when this Info file and the Emacs sources are located | 15547 those here work when this Info file and the Emacs sources are located |
15516 in their customary places. To change the expressions, copy them to | 15548 in their customary places. To change the expressions, copy them to |
15517 the @file{*scratch*} buffer, edit them, and then evaluate them. | 15549 the @file{*scratch*} buffer, edit them, and then evaluate them. |
15518 | 15550 |
15519 The results are shown after the @samp{@result{}}. (These results are | 15551 The results are shown after the @samp{@result{}}. (These results are |
15520 for files from Emacs Version 22.1.1; files from other versions of | 15552 for files from Emacs version 22.1.1; files from other versions of |
15521 Emacs may produce different results.) | 15553 Emacs may produce different results.) |
15522 | 15554 |
15523 @c !!! 22.1.1 lisp sources location here | 15555 @c !!! 22.1.1 lisp sources location here |
15524 @smallexample | 15556 @smallexample |
15525 @group | 15557 @group |
15566 | 15598 |
15567 In brief, we need to go through the lengths' list produced by the | 15599 In brief, we need to go through the lengths' list produced by the |
15568 @code{recursive-lengths-list-many-files} function and count the number | 15600 @code{recursive-lengths-list-many-files} function and count the number |
15569 of defuns within each range of lengths, and produce a list of those | 15601 of defuns within each range of lengths, and produce a list of those |
15570 numbers. | 15602 numbers. |
15603 | |
15604 @menu | |
15605 * Data for Display in Detail:: | |
15606 * Sorting:: | |
15607 * Files List:: | |
15608 * Counting function definitions:: | |
15609 @end menu | |
15610 | |
15611 @node Data for Display in Detail, Sorting, Prepare the data, Prepare the data | |
15612 @ifnottex | |
15613 @unnumberedsubsec The Data for Display in Detail | |
15614 @end ifnottex | |
15571 | 15615 |
15572 Based on what we have done before, we can readily foresee that it | 15616 Based on what we have done before, we can readily foresee that it |
15573 should not be too hard to write a function that `@sc{cdr}s' down the | 15617 should not be too hard to write a function that `@sc{cdr}s' down the |
15574 lengths' list, looks at each element, determines which length range it | 15618 lengths' list, looks at each element, determines which length range it |
15575 is in, and increments a counter for that range. | 15619 is in, and increments a counter for that range. |
15581 either be in the same length range or in adjacent ranges. Second, by | 15625 either be in the same length range or in adjacent ranges. Second, by |
15582 inspecting a sorted list, we can discover the highest and lowest | 15626 inspecting a sorted list, we can discover the highest and lowest |
15583 number, and thereby determine the largest and smallest length range | 15627 number, and thereby determine the largest and smallest length range |
15584 that we will need. | 15628 that we will need. |
15585 | 15629 |
15586 @menu | 15630 @node Sorting, Files List, Data for Display in Detail, Prepare the data |
15587 * Sorting:: | |
15588 * Files List:: | |
15589 * Counting function definitions:: | |
15590 @end menu | |
15591 | |
15592 @node Sorting, Files List, Prepare the data, Prepare the data | |
15593 @subsection Sorting Lists | 15631 @subsection Sorting Lists |
15594 @findex sort | 15632 @findex sort |
15595 | 15633 |
15596 Emacs contains a function to sort lists, called (as you might guess) | 15634 Emacs contains a function to sort lists, called (as you might guess) |
15597 @code{sort}. The @code{sort} function takes two arguments, the list | 15635 @code{sort}. The @code{sort} function takes two arguments, the list |
17762 from @code{bookmark-set} to @code{wordstar-mode}. Of course, you may | 17800 from @code{bookmark-set} to @code{wordstar-mode}. Of course, you may |
17763 come to use a `rare' function frequently. When you do, you should | 17801 come to use a `rare' function frequently. When you do, you should |
17764 load that function's file with a @code{load} expression in your | 17802 load that function's file with a @code{load} expression in your |
17765 @file{.emacs} file. | 17803 @file{.emacs} file. |
17766 | 17804 |
17767 In my @file{.emacs} file for Emacs version 22, I load 14 libraries | 17805 In my @file{.emacs} file, I load 14 libraries that contain functions |
17768 that contain functions that would otherwise be autoloaded. (Actually, | 17806 that would otherwise be autoloaded. (Actually, it would have been |
17769 it would have been better to include these files in my `dumped' Emacs, | 17807 better to include these files in my `dumped' Emacs, but I forgot. |
17770 but I forgot. @xref{Building Emacs, , Building Emacs, elisp, The GNU | 17808 @xref{Building Emacs, , Building Emacs, elisp, The GNU Emacs Lisp |
17771 Emacs Lisp Reference Manual}, and the @file{INSTALL} file for more | 17809 Reference Manual}, and the @file{INSTALL} file for more about |
17772 about dumping.) | 17810 dumping.) |
17773 | 17811 |
17774 You may also want to include autoloaded expressions in your @file{.emacs} | 17812 You may also want to include autoloaded expressions in your @file{.emacs} |
17775 file. @code{autoload} is a built-in function that takes up to five | 17813 file. @code{autoload} is a built-in function that takes up to five |
17776 arguments, the final three of which are optional. The first argument | 17814 arguments, the final three of which are optional. The first argument |
17777 is the name of the function to be autoloaded; the second is the name | 17815 is the name of the function to be autoloaded; the second is the name |
17920 ;; If tooltips turned on, make tips appear promptly | 17958 ;; If tooltips turned on, make tips appear promptly |
17921 (setq tooltip-delay 0.1) ; default is 0.7 second | 17959 (setq tooltip-delay 0.1) ; default is 0.7 second |
17922 ) | 17960 ) |
17923 @end group | 17961 @end group |
17924 @end smallexample | 17962 @end smallexample |
17963 | |
17964 @need 1250 | |
17965 Alternatively, since @code{blink-cursor-mode} has existed since Emacs | |
17966 version 21 and is likely to continue, you could write | |
17967 | |
17968 @smallexample | |
17969 @group | |
17970 (when (>= emacs-major-version 21) | |
17971 (blink-cursor-mode 0) | |
17972 @end group | |
17973 @end smallexample | |
17974 | |
17975 @noindent | |
17976 and add other expressions, too. | |
17977 | |
17925 | 17978 |
17926 @node X11 Colors, Miscellaneous, Simple Extension, Emacs Initialization | 17979 @node X11 Colors, Miscellaneous, Simple Extension, Emacs Initialization |
17927 @section X11 Colors | 17980 @section X11 Colors |
17928 | 17981 |
17929 You can specify colors when you use Emacs with the MIT X Windowing | 17982 You can specify colors when you use Emacs with the MIT X Windowing |
19091 | 19144 |
19092 This appendix describes the @code{current-kill} function as well as | 19145 This appendix describes the @code{current-kill} function as well as |
19093 both the @code{yank} and the @code{yank-pop} commands, but first, | 19146 both the @code{yank} and the @code{yank-pop} commands, but first, |
19094 consider the workings of the kill ring. | 19147 consider the workings of the kill ring. |
19095 | 19148 |
19149 @menu | |
19150 * What the Kill Ring Does:: | |
19151 * current-kill:: | |
19152 * yank:: | |
19153 * yank-pop:: | |
19154 * ring file:: | |
19155 @end menu | |
19156 | |
19157 @node What the Kill Ring Does, current-kill, Kill Ring, Kill Ring | |
19158 @ifnottex | |
19159 @unnumberedsec What the Kill Ring Does | |
19160 @end ifnottex | |
19161 | |
19096 @need 1250 | 19162 @need 1250 |
19097 The kill ring has a default maximum length of sixty items; this number | 19163 The kill ring has a default maximum length of sixty items; this number |
19098 is too large for an explanation. Instead, set it to four. Please | 19164 is too large for an explanation. Instead, set it to four. Please |
19099 evaluate the following: | 19165 evaluate the following: |
19100 | 19166 |
19161 | 19227 |
19162 @smallexample | 19228 @smallexample |
19163 (setq kill-ring-max old-kill-ring-max) | 19229 (setq kill-ring-max old-kill-ring-max) |
19164 @end smallexample | 19230 @end smallexample |
19165 | 19231 |
19166 @menu | 19232 @node current-kill, yank, What the Kill Ring Does, Kill Ring |
19167 * current-kill:: | |
19168 * yank:: | |
19169 * yank-pop:: | |
19170 * ring file:: | |
19171 @end menu | |
19172 | |
19173 @node current-kill, yank, Kill Ring, Kill Ring | |
19174 @comment node-name, next, previous, up | 19233 @comment node-name, next, previous, up |
19175 @appendixsec The @code{current-kill} Function | 19234 @appendixsec The @code{current-kill} Function |
19176 @findex current-kill | 19235 @findex current-kill |
19177 | 19236 |
19178 The @code{current-kill} function changes the element in the kill ring | 19237 The @code{current-kill} function changes the element in the kill ring |
19180 @code{kill-new} function sets @code{kill-ring-yank-pointer} to point | 19239 @code{kill-new} function sets @code{kill-ring-yank-pointer} to point |
19181 to the latest element of the the kill ring. The @code{kill-new} | 19240 to the latest element of the the kill ring. The @code{kill-new} |
19182 function is used directly or indirectly by @code{kill-append}, | 19241 function is used directly or indirectly by @code{kill-append}, |
19183 @code{copy-region-as-kill}, @code{kill-ring-save}, @code{kill-line}, | 19242 @code{copy-region-as-kill}, @code{kill-ring-save}, @code{kill-line}, |
19184 and @code{kill-region}.) | 19243 and @code{kill-region}.) |
19244 | |
19245 @menu | |
19246 * Code for current-kill:: | |
19247 * Understanding current-kill:: | |
19248 @end menu | |
19249 | |
19250 @node Code for current-kill, Understanding current-kill, current-kill, current-kill | |
19251 @ifnottex | |
19252 @unnumberedsubsec The code for @code{current-kill} | |
19253 @end ifnottex | |
19254 | |
19185 | 19255 |
19186 @need 1500 | 19256 @need 1500 |
19187 The @code{current-kill} function is used by @code{yank} and by | 19257 The @code{current-kill} function is used by @code{yank} and by |
19188 @code{yank-pop}. Here is the code for @code{current-kill}: | 19258 @code{yank-pop}. Here is the code for @code{current-kill}: |
19189 | 19259 |
19236 | 19306 |
19237 @smallexample | 19307 @smallexample |
19238 (setq kill-ring-yank-pointer kill-ring) | 19308 (setq kill-ring-yank-pointer kill-ring) |
19239 @end smallexample | 19309 @end smallexample |
19240 | 19310 |
19241 @menu | 19311 @node Understanding current-kill, , Code for current-kill, current-kill |
19242 * Understanding current-kill:: | |
19243 @end menu | |
19244 | |
19245 @node Understanding current-kill, , current-kill, current-kill | |
19246 @ifnottex | 19312 @ifnottex |
19247 @unnumberedsubsec @code{current-kill} in Outline | 19313 @unnumberedsubsec @code{current-kill} in Outline |
19248 @end ifnottex | 19314 @end ifnottex |
19249 | 19315 |
19250 The @code{current-kill} function looks complex, but as usual, it can | 19316 The @code{current-kill} function looks complex, but as usual, it can |
19260 @end group | 19326 @end group |
19261 @end smallexample | 19327 @end smallexample |
19262 | 19328 |
19263 This function takes two arguments, one of which is optional. It has a | 19329 This function takes two arguments, one of which is optional. It has a |
19264 documentation string. It is @emph{not} interactive. | 19330 documentation string. It is @emph{not} interactive. |
19331 | |
19332 @menu | |
19333 * Body of current-kill:: | |
19334 * Digression concerning error:: | |
19335 * Determining the Element:: | |
19336 @end menu | |
19337 | |
19338 @node Body of current-kill, Digression concerning error, Understanding current-kill, Understanding current-kill | |
19339 @ifnottex | |
19340 @unnumberedsubsubsec The Body of @code{current-kill} | |
19341 @end ifnottex | |
19265 | 19342 |
19266 The body of the function definition is a @code{let} expression, which | 19343 The body of the function definition is a @code{let} expression, which |
19267 itself has a body as well as a @var{varlist}. | 19344 itself has a body as well as a @var{varlist}. |
19268 | 19345 |
19269 The @code{let} expression declares a variable that will be only usable | 19346 The @code{let} expression declares a variable that will be only usable |
19339 Next, either the optional @code{do-not-move} argument is true or the | 19416 Next, either the optional @code{do-not-move} argument is true or the |
19340 current value of @code{kill-ring-yank-pointer} is set to point to the | 19417 current value of @code{kill-ring-yank-pointer} is set to point to the |
19341 list. Finally, another expression returns the first element of the | 19418 list. Finally, another expression returns the first element of the |
19342 list even if the @code{do-not-move} argument is true. | 19419 list even if the @code{do-not-move} argument is true. |
19343 | 19420 |
19344 @menu | 19421 @node Digression concerning error, Determining the Element, Body of current-kill, Understanding current-kill |
19345 * Digression concerning error:: | |
19346 * Determining the Element :: | |
19347 @end menu | |
19348 | |
19349 @node Digression concerning error, Determining the Element , Understanding current-kill, Understanding current-kill | |
19350 @ifnottex | 19422 @ifnottex |
19351 @unnumberedsubsubsec Digression about the word `error' | 19423 @unnumberedsubsubsec Digression about the word `error' |
19352 @end ifnottex | 19424 @end ifnottex |
19353 | 19425 |
19354 In my opinion, it is slightly misleading, at least to humans, to use | 19426 In my opinion, it is slightly misleading, at least to humans, to use |
19366 that a human who is acting virtuously, by exploring his or her | 19438 that a human who is acting virtuously, by exploring his or her |
19367 environment, is making an error. This is bad. Even though the computer | 19439 environment, is making an error. This is bad. Even though the computer |
19368 takes the same steps as it does when there is an `error', a term such as | 19440 takes the same steps as it does when there is an `error', a term such as |
19369 `cancel' would have a clearer connotation. | 19441 `cancel' would have a clearer connotation. |
19370 | 19442 |
19371 @node Determining the Element , , Digression concerning error, Understanding current-kill | 19443 @node Determining the Element, , Digression concerning error, Understanding current-kill |
19372 @ifnottex | 19444 @ifnottex |
19373 @unnumberedsubsubsec Determining the Element | 19445 @unnumberedsubsubsec Determining the Element |
19374 @end ifnottex | 19446 @end ifnottex |
19375 | 19447 |
19376 Among other actions, the else-part of the @code{if} expression sets | 19448 Among other actions, the else-part of the @code{if} expression sets |
19848 | 19920 |
19849 @noindent | 19921 @noindent |
19850 The function should be passed the height of the graph, and then should | 19922 The function should be passed the height of the graph, and then should |
19851 construct and insert the appropriate numbers and marks. | 19923 construct and insert the appropriate numbers and marks. |
19852 | 19924 |
19925 @menu | |
19926 * print-Y-axis in Detail:: | |
19927 * Height of label:: | |
19928 * Compute a Remainder:: | |
19929 * Y Axis Element:: | |
19930 * Y-axis-column:: | |
19931 * print-Y-axis Penultimate:: | |
19932 @end menu | |
19933 | |
19934 @node print-Y-axis in Detail, Height of label, print-Y-axis, print-Y-axis | |
19935 @ifnottex | |
19936 @unnumberedsubsec The @code{print-Y-axis} Function in Detail | |
19937 @end ifnottex | |
19938 | |
19853 It is easy enough to see in the figure what the Y axis label should | 19939 It is easy enough to see in the figure what the Y axis label should |
19854 look like; but to say in words, and then to write a function | 19940 look like; but to say in words, and then to write a function |
19855 definition to do the job is another matter. It is not quite true to | 19941 definition to do the job is another matter. It is not quite true to |
19856 say that we want a number and a tic every five lines: there are only | 19942 say that we want a number and a tic every five lines: there are only |
19857 three lines between the @samp{1} and the @samp{5} (lines 2, 3, and 4), | 19943 three lines between the @samp{1} and the @samp{5} (lines 2, 3, and 4), |
19859 and 9). It is better to say that we want a number and a tic mark on | 19945 and 9). It is better to say that we want a number and a tic mark on |
19860 the base line (number 1) and then that we want a number and a tic on | 19946 the base line (number 1) and then that we want a number and a tic on |
19861 the fifth line from the bottom and on every line that is a multiple of | 19947 the fifth line from the bottom and on every line that is a multiple of |
19862 five. | 19948 five. |
19863 | 19949 |
19864 @menu | 19950 @node Height of label, Compute a Remainder, print-Y-axis in Detail, print-Y-axis |
19865 * Height of label:: | |
19866 * Compute a Remainder:: | |
19867 * Y Axis Element:: | |
19868 * Y-axis-column:: | |
19869 * print-Y-axis Penultimate:: | |
19870 @end menu | |
19871 | |
19872 @node Height of label, Compute a Remainder, print-Y-axis, print-Y-axis | |
19873 @ifnottex | 19951 @ifnottex |
19874 @unnumberedsubsec What height should the label be? | 19952 @unnumberedsubsec What height should the label be? |
19875 @end ifnottex | 19953 @end ifnottex |
19876 | 19954 |
19877 The next issue is what height the label should be? Suppose the maximum | 19955 The next issue is what height the label should be? Suppose the maximum |