Commit | Line | Data |
---|---|---|
2da09c3f MV |
1 | @c -*-texinfo-*- |
2 | @c This is part of the GNU Guile Reference Manual. | |
3 | @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004 | |
4 | @c Free Software Foundation, Inc. | |
5 | @c See the file guile.texi for copying conditions. | |
6 | ||
a0e07ba4 NJ |
7 | @page |
8 | @node Readline Support | |
9 | @chapter Readline Support | |
10 | ||
11 | @c FIXME::martin: Review me! | |
12 | ||
13 | @cindex readline | |
14 | @cindex command line history | |
15 | Guile comes with an interface module to the readline library. This | |
16 | makes interactive use much more convenient, because of the command-line | |
17 | editing features of readline. Using @code{(ice-9 readline)}, you can | |
18 | navigate through the current input line with the cursor keys, retrieve | |
19 | older command lines from the input history and even search through the | |
20 | history entries. | |
21 | ||
22 | @menu | |
23 | * Loading Readline Support:: How to load readline support into Guile. | |
24 | * Readline Options:: How to modify readline's behaviour. | |
25 | @end menu | |
26 | ||
27 | ||
28 | @node Loading Readline Support | |
29 | @section Loading Readline Support | |
30 | ||
31 | The module is not loaded by default and so has to be loaded and | |
32 | activated explicitly. This is done with two simple lines of code: | |
33 | ||
4b83d327 | 34 | @findex activate-readline |
a0e07ba4 NJ |
35 | @lisp |
36 | (use-modules (ice-9 readline)) | |
37 | (activate-readline) | |
38 | @end lisp | |
39 | ||
40 | @c FIXME::martin: Review me! | |
41 | ||
42 | The first line will load the necessary code, and the second will | |
43 | activate readline's features for the REPL. If you plan to use this | |
44 | module often, you should save these to lines to your @file{.guile} | |
45 | personal startup file. | |
46 | ||
47 | You will notice that the REPL's behaviour changes a bit when you have | |
85a9b4ed | 48 | loaded the readline module. For example, when you press Enter before |
a0e07ba4 NJ |
49 | typing in the closing parentheses of a list, you will see the |
50 | @dfn{continuation} prompt, three dots: @code{...} This gives you a nice | |
51 | visual feedback when trying to match parentheses. To make this even | |
52 | easier, @dfn{bouncing parentheses} are implemented. That means that | |
53 | when you type in a closing parentheses, the cursor will jump to the | |
85a9b4ed | 54 | corresponding opening parenthesis for a short time, making it trivial to make |
a0e07ba4 NJ |
55 | them match. |
56 | ||
57 | Once the readline module is activated, all lines entered interactively | |
58 | will be stored in a history and can be recalled later using the | |
59 | cursor-up and -down keys. Readline also understands the Emacs keys for | |
60 | navigating through the command line and history. | |
61 | ||
62 | When you quit your Guile session by evaluating @code{(quit)} or pressing | |
63 | Ctrl-D, the history will be saved to the file @file{.guile_history} and | |
64 | read in when you start Guile for the next time. Thus you can start a | |
65 | new Guile session and still have the (probably long-winded) definition | |
66 | expressions available. | |
67 | ||
68 | ||
69 | @node Readline Options | |
70 | @section Readline Options | |
71 | ||
72 | @c FIXME::martin: Review me! | |
73 | ||
74 | @cindex readline options | |
75 | The readline interface module can be configured in several ways to | |
76 | better suit the user's needs. Configuration is done via the readline | |
77 | module's options interface, in a similar way to the evaluator and | |
c936bede | 78 | debugging options (@pxref{User level options interfaces}.) |
a0e07ba4 | 79 | |
4b83d327 KR |
80 | @findex readline-options |
81 | @findex readline-enable | |
82 | @findex readline-disable | |
83 | @findex readline-set! | |
a0e07ba4 NJ |
84 | Here is the list of readline options generated by typing |
85 | @code{(readline-options 'full)} in Guile. You can also see the | |
86 | default values. | |
87 | ||
88 | @smalllisp | |
89 | bounce-parens 500 Time (ms) to show matching opening parenthesis (0 = off). | |
90 | history-length 200 History length. | |
91 | history-file yes Use history file. | |
92 | @end smalllisp | |
93 | ||
94 | The history length specifies how many input lines will be remembered. | |
95 | If the history contains that many lines and additional lines are | |
96 | entered, the oldest lines will be lost. You can switch on/off the | |
97 | usage of the history file using the following call. | |
98 | ||
99 | @lisp | |
100 | (readline-disable 'history) | |
101 | @end lisp | |
102 | ||
103 | The readline options interface can only be used @emph{after} loading | |
104 | the readline module, because it is defined in that module. | |
105 | ||
106 | ||
107 | @page | |
108 | @node Value History | |
109 | @chapter Value History | |
110 | ||
111 | @c FIXME::martin: Review me! | |
112 | ||
113 | @cindex value history | |
114 | Another module which makes command line usage more convenient is | |
115 | @code{(ice-9 history)}. This module will change the REPL so that each | |
116 | value which is evaluated and printed will be remembered under a name | |
117 | constructed from the dollar character (@code{$}) and the number of the | |
118 | evaluated expression. | |
119 | ||
120 | Consider an example session. | |
121 | ||
122 | @example | |
123 | guile> (use-modules (ice-9 history)) | |
124 | guile> 1 | |
125 | $1 = 1 | |
126 | guile> (+ $1 $1) | |
127 | $2 = 2 | |
128 | guile> (* $2 $2) | |
129 | $3 = 4 | |
130 | @end example | |
131 | ||
132 | After loading the value history module @code{(ice-9 history)}, one | |
133 | (trivial) expression is evaluated. The result is stored into the | |
134 | variable @code{$1}. This fact is indicated by the output @code{$1 = }, | |
135 | which is also caused by @code{(ice-9 history)}. In the next line, this | |
136 | variable is used two times, to produce the value @code{$2}, which in | |
137 | turn is used in the calculation for @code{$3}. | |
138 | ||
139 | ||
140 | @c Local Variables: | |
141 | @c TeX-master: "guile.texi" | |
142 | @c End: |