More documentation
[geiser.git] / doc / repl.texi
blobce0eaffca20dacae5e61c58409fcfa305161a6e2
1 @node The REPL, Fun between the parens, Installation, Top
2 @chapter The REPL
3 @anchor{quick-start}
4 If you've followed the indications in @ref{Setting it up}, your Emacs is
5 now ready to start playing. Otherwise, i'll wait for you: when you're
6 ready, just come back here and proceed to the following sections.
8 @menu
9 * Starting the REPL::
10 * First aids::
11 * Switching context::
12 * Completion and error handling::
13 * Autodoc and friends::
14 * Customization and tips::
15 @end menu
17 @node Starting the REPL, First aids, The REPL, The REPL
18 @section Starting the REPL
20 @cindex REPL
21 To start a Scheme @repl{} (meaning, a scheme process offering you a
22 Read-Eval-Print Loop), Geiser provides the generic interactive command
23 @command{run-geiser}. If you run it (via, as is customary in Emacs,
24 @kbd{M-x run-geiser}, you'll be saluted by a prompt asking which one of
25 the supported implementations you want to launch (yes, you can stop the
26 asking: see @ref{active-implementations,,below}). Tabbing for completion
27 will offer you, as of this writing, @code{guile} and @code{racket}. Just
28 choose your poison, and a new @repl{} buffer will pop-up.
30 @image{img/repls}
32 If all went according to plan, you'll be facing an
33 implementation-dependent banner, followed by an interactive prompt.
34 Going according to plan includes having the executable of the Scheme you
35 chose in your path. If that's not the case, you can tell Emacs where it
36 is, as described @ref{impl-binary,, below}. Returning to our @repl{},
37 the first thing to notice is that the funny prompt is telling you your
38 current module: its name is the part just after the @@ sign (in Guile,
39 that means @code{guile-user}, while Racket's top namespace doesn't have
40 a name; cf. @ref{Switching context} below). Other than that, this is
41 pretty much equivalent to having a command-line interpreter in a
42 terminal, with a bunch of add-ons that we'll be reviewing below. You can
43 start typing sexps right there: Geiser will only dispatch them for
44 evaluation when they're complete, and will indent new lines properly
45 until then. It will also keep track of your input, maintaining a history
46 file that will be reloaded whenever you restart the @repl{}.
48 Nothing that fanciful this far, but there's more to Geiser's @repl{}. On
49 to the next section!
51 @node First aids, Switching context, Starting the REPL, The REPL
52 @section First aids
54 @img{repl-menu, right}
55 @cindex REPL commands
56 A quick way of seeing what else Geiser's @repl{} can do for you, is to
57 display the corresponding entry up there in your menu bar. No, i don't
58 normally use menus either; but they can come in handy until you've
59 memorized Geiser's commands, as a learning device. And yes, i usually
60 run Emacs inside a terminal, but one can always use
61 @uref{http://www.emacswiki.org/emacs/LaCarte, La Carte} to access the
62 menus in a convenient enough fashion.
64 Or just press @kbd{C-h m} and be done with that.
66 Among the commands at your disposal, we find the familiar input
67 navigation keys, with a couple twists. By default, @kbd{M-p} and
68 @kbd{M-n} are bound to @i{matching} items in your input history. That
69 is, they'll find the previous or next sexp that starts with the current
70 input prefix (defined as the text between the end of the prompt and your
71 current position, a.k.a. @dfn{point}, in the buffer). For going up and
72 down the list unconditionally, just use @kbd{C-c M-p} and @kbd{C-c M-n}.
73 In addition, navigation is sexp- rather than line-based.
75 There are also a few commands to twiddle with the Scheme process.
76 @kbd{C-c C-q} will gently ask it to quit, while @kbd{C-u C-c C-q} will
77 mercilessly kill the process (but not before stowing your history in the
78 file system). A softer nuke is performed by @kbd{C-c C-k}: some (rare, i
79 promise) times, Geiser's @repl{} can get confused by the input received
80 from then underlying Scheme (specially if you have multiple threads
81 writing to the standard ports), and become irresponsive; you can try
82 this command to try to revive it without killing the process. Finally,
83 if worse comes to worst and the process is dead, @kbd{C-c C-z} will
84 restart it (but the same shortcut, issued when the @repl{} is alive,
85 will bring you back to the buffer you came from, as explained
86 @ref{switching-repl-buff,,here}).
88 The remaining commands are meatier, and deserve sections of their own.
90 @node Switching context, Completion and error handling, First aids, The REPL
91 @section Switching context
93 @cindex current module, in REPL
94 In tune with Geiser's @ref{current-module,,modus operandi}, evaluations
95 in the @repl{} take place if the namespace of the current module. As
96 noted above, the @repl{}'s prompt tells you the name of the current
97 module. To switch to a different one, you can use the command
98 @command{switch-to-geiser-module}, bound to @kbd{C-c C-m}. You'll notice
99 that Geiser simply uses the underlying Scheme's native namespace
100 switching facilities (@command{,m} in Guile and @command{enter!} in
101 Racket), and that it doesn't even try to hide that fact. That means that
102 you can freely use said native ways directly at the @repl{}, and Geiser
103 will be happy to oblige.
105 @cindex current module, change
106 Once you enter a new module, only those bindings visible in its
107 namespace will be available to your evaluations. All schemes supported
108 by Geiser provide a way to import new modules in the current namespace.
109 Again, there's a Geiser command, @command{geiser-repl-import-module}, to
110 invoke such functionality, bound this time to @kbd{C-c C-i}. And, again,
111 you'll see Geiser just introducing the native incantation for you, and
112 you're free to use such incantations by hand whenever you want.
114 One convenience provided by these two Geiser commands is that completion
115 is available when introducing the new module name, using the
116 @kbd{@key{TAB}} key. Pressing it at the command's prompt will offer you
117 a prefix-aware list of available module names.
119 @image{img/mod-completion}
121 Which brings me to the next group of @repl{} commands.
123 @node Completion and error handling, Autodoc and friends, Switching context, The REPL
124 @section Completion and error handling
126 @cindex completion, module name
127 We've already seen Geiser completion of module names in action at the
128 mini-buffer. You won't be surprised to know that it's also available at
129 the @repl{} buffer itself. There, you can use either @kbd{C-.} or
130 @kbd{M-`} to complete module names, and @kbd{@key{TAB}} or
131 @kbd{M-@key{TAB}} to complete identifiers. Geiser will know what
132 identifiers are bound in the current module and show you a list of those
133 starting with the prefix at point. Needless to say, this is not a static
134 list, and it will grow as you define or import new bindings in the
135 namespace at hand.
137 REPL buffers use Emacs' compilation mode to highlight errors reported by
138 the Scheme interpreter, and you can use the @command{next-error} command
139 (@kbd{M-g n}) to jump to their location. By default, every time you
140 enter a new expression for evaluation old error messages are forgotten,
141 so that @kbd{M-g n} will always jump to errors related to the last
142 evaluation request, if any. If you prefer a not so forgetful REPL, set
143 the customization variable @code{geiser-repl-forget-old-errors-p} to
144 @code{nil}. Note, however, that even when that variable is left as
145 @kbd{t}, you can always jump to an old error by moving to its line at
146 the REPL and pressing return.
148 @node Autodoc and friends, Customization and tips, Completion and error handling, The REPL
149 @section Autodoc and friends
151 Oftentimes, there's more you'll want to know about an identifier
152 besides its name: what module does it belong to? is it a procedure and,
153 if so, what arguments does it take? Geiser tries to help you answering
154 those questions too.
156 @cindex autodoc, in the REPL
157 Actually, if you've been playing with the @repl{} as you read, you might
158 have notice some frantic activity taking place in the minibuffer every
159 now and then. That was Geiser trying to be helpful (while, hopefully,
160 not being clippy), or, more concretely, what i call, for want of a
161 better name, its @dfn{autodoc} mode. Whenever it's active (did you
162 notice that @i{A} in the mode-line?), Geiser's gerbils will be scanning
163 what you type and showing (unless you silent them with @kbd{C-c C-a})
164 information about the identifier nearest to point.
166 @image{img/repl-autodoc}
168 If that identifier corresponds to a variable visible in the current
169 namespace, you'll see the module it belongs to and its value. For
170 procedures and macros, autodoc will display, instead of their value, the
171 argument names (or an underscore if Geiser cannot determine the name
172 used in the definition). Optional arguments are surrounded by square
173 brackets, and, when the optional argument has a default value, it's
174 represented by a list made up of its name and that value. When the
175 argument is a keyword argument, its name is preceded by a colon.
177 @cindex help on identifier
178 If that's not enough documentation for you, @kbd{C-c C-d d} will open a
179 separate documentation buffer with help on the symbol at point. For some
180 implementations (e.g. Racket), this separate buffer will actually be a
181 web page displaying the corresponding page in the manual, while for
182 implementations supporting docstrings (e.g. (you guessed it) Guile)
183 it'll be a real Emacs buffer displaying that information.
185 @cindex jump, at the REPL
186 If that's still not enough, Geiser can jump, via @kbd{M-.}, to the
187 symbol's definition. A buffer with the corresponding file will pop up,
188 with its point resting upon the identifier's defining form. When you're
189 done inspecting, @kbd{M-,} will bring you back to where you were. As we
190 will see, these commands are also available in scheme buffers.
192 @cindex module exports
193 @anchor{repl-mod}
194 Finally, Geiser can produce for you a list, classified by kind, of the
195 identifiers exported by a given module: all you need to do is press
196 @kbd{C-c C-d m}, and type or complete the desired module's name.
198 @image{img/repl-mod}
200 The list of exported bindings is shown in a buffer belonging to Geiser's
201 documentation browser, of which more details are given in forthcoming
202 sections (but just perusing it's associated key bindings, by any of the
203 methods we've already used for the @repl{}, will give you enough
204 information to use it effectively enough).
206 @node Customization and tips,  , Autodoc and friends, The REPL
207 @section Customization and tips
209 @cindex REPL customization
210 The looks and ways of the @repl{} can be fine-tuned via a bunch of
211 customization variables. You can see and modify them all in the
212 corresponding customization group (by using the menu entry or the good
213 old @kbd{M-x customize-group geiser-repl}), or by setting them in your
214 Emacs initialization files (as a rule, all knobs in Geiser are turnable
215 this way: you don't need to use customization buffers if you don't like
216 them).
218 I'm documenting below a proper subset of those settings, together with
219 some related tips.
221 @subsubheading Choosing a Scheme implementation
222 @cindex scheme implementation, choosing
223 @anchor{choosing-impl}
224 Instead of using the generic @command{run-geiser} command, you can start
225 directly your Scheme of choice via @command{run-racket} or
226 @command{run-guile}. @anchor{active-implementations} In addition, the
227 variable @code{geiser-active-implementations} contains a list of those
228 Schemes Geiser should be aware of. Thus, if you happen to be, say, a
229 racketeer not to be beguiled by other schemes, you can tell Geiser to
230 forget about the richness of the Scheme ecosystem with something like
231 @example
232 (setq geiser-active-implementations '(racket))
233 @end example
234 @noindent in your initialisation files.
236 @cindex scheme binary
237 @cindex scheme executable path
238 @anchor{impl-binary} When starting a new @repl{}, Geiser assumes, by
239 default, that the corresponding Scheme binary is in your path. If that's
240 not the case, the variables to tweak are @code{geiser-guile-binary} and
241 @code{geiser-racket-binary}, which should be set to a string with the
242 full path to the requisite binary.
244 @cindex scheme load path
245 @cindex scheme init file
246 @cindex GUILE_LOAD_PATH
247 @cindex PLTCOLLECTS
248 You can also specify a couple more initialisation parameters. For Guile,
249 @code{geiser-guile-load-path} is a list of paths to add to its load path
250 when it's started, while @code{geiser-guile-init-file} is the path to an
251 initialisation file to be loaded on startup. The equivalent variables
252 for Racket are @code{geiser-racket-collects} and
253 @code{geiser-racket-init-file}.
255 @subsubheading History
257 By default, Geiser won't record duplicates in your input history. If you
258 prefer it did, just set @code{geiser-repl-history-no-dups-p} to
259 @code{nil}. History entries are persistent across @repl{} sessions:
260 they're saved in implementation-specific files whose location is
261 controlled by the variable @code{geiser-repl-history-filename}. For
262 example, my Geiser configuration includes the following line:
263 @example
264 (setq geiser-repl-history-filename "~/.emacs.d/geiser-history")
265 @end example
266 @noindent which makes the files @file{geiser-history.guile} and
267 @file{geiser-history.racket} to live inside my home's @file{.emacs.d}
268 directory.
270 @subsubheading Autodoc
272 @cindex autodoc, disabling
273 @cindex peace and quiet
274 If you happen to love peace and quiet and prefer to keep your @repl{}'s
275 echo area free from autodoc's noise, @code{geiser-repl-autodoc-p} is the
276 customization variable for you: set it to @code{nil} and autodoc will be
277 disabled by default in new @repl{}s. You can always bring the fairies
278 back, on a per @repl{} basis, using @kbd{C-c C-a}.
280 @c Local Variables:
281 @c mode: texinfo
282 @c TeX-master: "geiser"
283 @c End: