Documentation tweaking
[geiser.git] / doc / repl.texi
blob9adb971d8f3b5bc450456e8c6d2ca279f05612cf
1 @node The REPL, 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 @imgc{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 @cindex remote REPL
49 @cindex connect to server
50 If you use Guile, there's an alternative way of starting a Geiser REPL:
51 you can connect to a remote Guile process, provided the latter is
52 running a REPL server. For that to happen, you just need to start your
53 Guile process (outside Emacs) passing to it the flag @code{--listen}.
54 Then, come back to Emacs and execute @kbd{M-x connect-to-guile}. You'll
55 be asked for a host and a port, with suitable default values (Guile's
56 @code{--listen} flag accepts an optional port as argument (as in
57 @code{--listen=1969}), if you don't want to use the default). And voila,
58 you'll have a Geiser REPL that is served by the remote Guile process in
59 a dedicated thread, meaning that your Guile can go on doing whatever it
60 was doing while you tinker with it from Emacs. Note, however,
61 that all Guile threads share the heap, so that you'll be able to
62 interact with those other threads in the running scheme from Emacs in a
63 variety of ways. For starters, all you (re)defintions will be visible
64 everywhere. That's dangerous, but will come in handy when you need to
65 debug your running webserver.
67 Nothing that fanciful this far, but there's more to Geiser's @repl{}. On
68 to the next section!
70 @node First aids, Switching context, Starting the REPL, The REPL
71 @section First aids
73 @img{repl-menu, right}
74 @cindex REPL commands
75 A quick way of seeing what else Geiser's @repl{} can do for you, is to
76 display the corresponding entry up there in your menu bar. No, i don't
77 normally use menus either; but they can come in handy until you've
78 memorized Geiser's commands, as a learning device. And yes, i usually
79 run Emacs inside a terminal, but one can always use
80 @uref{http://www.emacswiki.org/emacs/LaCarte, La Carte} to access the
81 menus in a convenient enough fashion.
83 Or just press @kbd{C-h m} and be done with that.
85 Among the commands at your disposal, we find the familiar input
86 navigation keys, with a couple twists. By default, @kbd{M-p} and
87 @kbd{M-n} are bound to @i{matching} items in your input history. That
88 is, they'll find the previous or next sexp that starts with the current
89 input prefix (defined as the text between the end of the prompt and your
90 current position, a.k.a. @dfn{point}, in the buffer). For going up and
91 down the list unconditionally, just use @kbd{C-c M-p} and @kbd{C-c M-n}.
92 In addition, navigation is sexp- rather than line-based.
94 There are also a few commands to twiddle with the Scheme process.
95 @kbd{C-c C-q} will gently ask it to quit, while @kbd{C-u C-c C-q} will
96 mercilessly kill the process (but not before stowing your history in the
97 file system). Unless you're using a remote REPL, that is, in which case
98 both commands will just sever the connection and leave the remote
99 process alone. A softer nuke is performed by @kbd{C-c C-k}: some (rare,
100 i promise) times, Geiser's @repl{} can get confused by the input
101 received from then underlying Scheme (specially if you have multiple
102 threads writing to the standard ports), and become irresponsive; you can
103 try this command to try to revive it without killing the process or
104 closing your connection. Finally, if worse comes to worst and the
105 process is dead, @kbd{C-c C-z} will restart it (but the same shortcut,
106 issued when the @repl{} is alive, will bring you back to the buffer you
107 came from, as explained @ref{switching-repl-buff,,here}).
109 The remaining commands are meatier, and deserve sections of their own.
111 @node Switching context, Completion and error handling, First aids, The REPL
112 @section Switching context
114 @cindex current module, in REPL
115 In tune with Geiser's @ref{current-module,,modus operandi}, evaluations
116 in the @repl{} take place in the namespace of the current module. As
117 noted above, the @repl{}'s prompt tells you the name of the current
118 module. To switch to a different one, you can use the command
119 @command{switch-to-geiser-module}, bound to @kbd{C-c C-m}. You'll notice
120 that Geiser simply uses a couple of meta-commands provided by the Scheme
121 @repl{} (the stock @command{,m} in Guile and @command{,enter} in
122 Racket), and that it doesn't even try to hide that fact. That means that
123 you can freely use said native ways directly at the @repl{}, and Geiser
124 will be happy to oblige.
126 @cindex current module, change
127 Once you enter a new module, only those bindings visible in its
128 namespace will be available to your evaluations. All schemes supported
129 by Geiser provide a way to import new modules in the current namespace.
130 Again, there's a Geiser command, @command{geiser-repl-import-module}, to
131 invoke such functionality, bound this time to @kbd{C-c C-i}. And, again,
132 you'll see Geiser just introducing the native incantation for you, and
133 you're free to use such incantations by hand whenever you want.
135 One convenience provided by these two Geiser commands is that completion
136 is available when introducing the new module name, using the
137 @kbd{@key{TAB}} key. Pressing it at the command's prompt will offer you
138 a prefix-aware list of available module names.
140 @imgc{mod-completion}
142 Which brings me to the next group of @repl{} commands.
144 @node Completion and error handling, Autodoc and friends, Switching context, The REPL
145 @section Completion and error handling
147 @cindex completion, module name
148 We've already seen Geiser completion of module names in action at the
149 mini-buffer. You won't be surprised to know that it's also available at
150 the @repl{} buffer itself. There, you can use either @kbd{C-.} or
151 @kbd{M-`} to complete module names, and @kbd{@key{TAB}} or
152 @kbd{M-@key{TAB}} to complete identifiers. Geiser will know what
153 identifiers are bound in the current module and show you a list of those
154 starting with the prefix at point. Needless to say, this is not a static
155 list, and it will grow as you define or import new bindings in the
156 namespace at hand.
158 REPL buffers use Emacs' compilation mode to highlight errors reported by
159 the Scheme interpreter, and you can use the @command{next-error} command
160 (@kbd{M-g n}) to jump to their location. By default, every time you
161 enter a new expression for evaluation old error messages are forgotten,
162 so that @kbd{M-g n} will always jump to errors related to the last
163 evaluation request, if any. If you prefer a not so forgetful REPL, set
164 the customization variable @code{geiser-repl-forget-old-errors-p} to
165 @code{nil}. Note, however, that even when that variable is left as
166 @kbd{t}, you can always jump to an old error by moving to its line at
167 the REPL and pressing return.
169 @node Autodoc and friends, Customization and tips, Completion and error handling, The REPL
170 @section Autodoc and friends
172 Oftentimes, there's more you'll want to know about an identifier
173 besides its name: what module does it belong to? is it a procedure and,
174 if so, what arguments does it take? Geiser tries to help you answering
175 those questions too.
177 @cindex autodoc, in the REPL
178 Actually, if you've been playing with the @repl{} as you read, you might
179 have notice some frantic activity taking place in the minibuffer every
180 now and then. That was Geiser trying to be helpful (while, hopefully,
181 not being clippy), or, more concretely, what i call, for want of a
182 better name, its @dfn{autodoc} mode. Whenever it's active (did you
183 notice that @i{A} in the mode-line?), Geiser's gerbils will be scanning
184 what you type and showing (unless you silent them with @kbd{C-c C-a})
185 information about the identifier nearest to point.
187 @imgc{repl-autodoc}
189 If that identifier corresponds to a variable visible in the current
190 namespace, you'll see the module it belongs to and its value. For
191 procedures and macros, autodoc will display, instead of their value, the
192 argument names (or an underscore if Geiser cannot determine the name
193 used in the definition). Optional arguments are surrounded by square
194 brackets, and, when the optional argument has a default value, it's
195 represented by a list made up of its name and that value. When the
196 argument is a keyword argument, its name is preceded by a colon.
198 @cindex help on identifier
199 If that's not enough documentation for you, @kbd{C-c C-d d} will open a
200 separate documentation buffer with help on the symbol at point. For some
201 implementations (e.g. Racket), this separate buffer will actually be a
202 web page displaying the corresponding page in the manual, while for
203 implementations supporting docstrings (e.g. (you guessed it) Guile)
204 it'll be a real Emacs buffer displaying that information.
206 @cindex jump, at the REPL
207 If that's still not enough, Geiser can jump, via @kbd{M-.}, to the
208 symbol's definition. A buffer with the corresponding file will pop up,
209 with its point resting upon the identifier's defining form. When you're
210 done inspecting, @kbd{M-,} will bring you back to where you were. As we
211 will see, these commands are also available in scheme buffers. @kbd{M-.}
212 also works for modules: if your point is on an unambiguous module name,
213 the file where it's defined will be opened for you.
215 @cindex module exports
216 @anchor{repl-mod}
217 Finally, Geiser can produce for you a list, classified by kind, of the
218 identifiers exported by a given module: all you need to do is press
219 @kbd{C-c C-d m}, and type or complete the desired module's name.
221 @imgc{repl-mod}
223 The list of exported bindings is shown in a buffer belonging to Geiser's
224 documentation browser, of which more details are given in forthcoming
225 sections (but just perusing its associated key bindings, by any of the
226 methods we've already used for the @repl{}, will give you enough
227 information to use it effectively enough).
229 @node Customization and tips,  , Autodoc and friends, The REPL
230 @section Customization and tips
232 @cindex REPL customization
233 The looks and ways of the @repl{} can be fine-tuned via a bunch of
234 customization variables. You can see and modify them all in the
235 corresponding customization group (by using the menu entry or the good
236 old @kbd{M-x customize-group geiser-repl}), or by setting them in your
237 Emacs initialization files (as a rule, all knobs in Geiser are turnable
238 this way: you don't need to use customization buffers if you don't like
239 them).
241 I'm documenting below a proper subset of those settings, together with
242 some related tips.
244 @subsubheading Choosing a Scheme implementation
245 @cindex scheme implementation, choosing
246 @anchor{choosing-impl}
247 Instead of using the generic @command{run-geiser} command, you can start
248 directly your Scheme of choice via @command{run-racket} or
249 @command{run-guile}. @anchor{active-implementations} In addition, the
250 variable @code{geiser-active-implementations} contains a list of those
251 Schemes Geiser should be aware of. Thus, if you happen to be, say, a
252 racketeer not to be beguiled by other schemes, you can tell Geiser to
253 forget about the richness of the Scheme ecosystem with something like
254 @example
255 (setq geiser-active-implementations '(racket))
256 @end example
257 @noindent in your initialisation files.
259 @cindex scheme binary
260 @cindex scheme executable path
261 @anchor{impl-binary} When starting a new @repl{}, Geiser assumes, by
262 default, that the corresponding Scheme binary is in your path. If that's
263 not the case, the variables to tweak are @code{geiser-guile-binary} and
264 @code{geiser-racket-binary}, which should be set to a string with the
265 full path to the requisite binary.
267 @cindex scheme load path
268 @cindex scheme init file
269 @cindex GUILE_LOAD_PATH
270 @cindex PLTCOLLECTS
271 You can also specify a couple more initialisation parameters. For Guile,
272 @code{geiser-guile-load-path} is a list of paths to add to its load path
273 when it's started, while @code{geiser-guile-init-file} is the path to an
274 initialisation file to be loaded on startup. The equivalent variables
275 for Racket are @code{geiser-racket-collects} and
276 @code{geiser-racket-init-file}.
278 @subsubheading History
280 By default, Geiser won't record duplicates in your input history. If you
281 prefer it did, just set @code{geiser-repl-history-no-dups-p} to
282 @code{nil}. History entries are persistent across @repl{} sessions:
283 they're saved in implementation-specific files whose location is
284 controlled by the variable @code{geiser-repl-history-filename}. For
285 example, my Geiser configuration includes the following line:
286 @example
287 (setq geiser-repl-history-filename "~/.emacs.d/geiser-history")
288 @end example
289 @noindent which makes the files @file{geiser-history.guile} and
290 @file{geiser-history.racket} to live inside my home's @file{.emacs.d}
291 directory.
293 @subsubheading Autodoc
295 @cindex autodoc, disabling
296 @cindex peace and quiet
297 If you happen to love peace and quiet and prefer to keep your @repl{}'s
298 echo area free from autodoc's noise, @code{geiser-repl-autodoc-p} is the
299 customization variable for you: set it to @code{nil} and autodoc will be
300 disabled by default in new @repl{}s. You can always bring the fairies
301 back, on a per @repl{} basis, using @kbd{C-c C-a}.
303 @subsubheading Remote connections
305 @cindex port, default
306 @cindex host, default
307 When using @code{connect-to-guile} or @code{geiser-connect}, you'll be
308 prompted for a host and a port, defaulting to localhost and 37146. You
309 can change those defaults customizing @code{geiser-repl-default-host}
310 and @code{geiser-repl-default-port}, respectfully.
312 @c Local Variables:
313 @c mode: texinfo
314 @c TeX-master: "geiser"
315 @c End: