REPL: new doc bindings in tune with those in scheme buffers.
[geiser.git] / doc / repl.texi
blob3541954abca65ff2d735230c5df7d179a307e517
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 * Let Geiser spy::
13 * Customization and tips::
14 @end menu
16 @node Starting the REPL, First aids, The REPL, The REPL
17 @section Starting the REPL
19 @cindex REPL
20 To start a Scheme REPL (meaning, a scheme process offering you a
21 Read-Eval-Print Loop), Geiser provides the generic interactive command
22 @command{run-geiser}. If you run it (via, as is customary in Emacs,
23 @kbd{M-x run-geiser}, you'll be saluted by a prompt asking which one of
24 the supported implementations you want to launch (yes, you can stop the
25 asking: see @ref{active-implementations,,below}). Tabbing for completion
26 will offer you, as of this writing, @code{guile} and @code{racket}. Just
27 choose your poison, and a new REPL buffer will pop-up.
29 @image{img/repls}
31 If all went according to plan, you'll be facing an
32 implementation-dependent banner, followed by an interactive prompt.
33 Going according to plan includes having the executable of the Scheme you
34 chose in your path. If that's not the case, you can tell Emacs where it
35 is, as described @ref{impl-binary,, below}. Returning to our REPL, the
36 first thing to notice is that the funny prompt is telling you your
37 current module: its name is the part just after the @@ sign (in Guile,
38 that means @code{guile-user}, while Racket's top namespace doesn't have
39 a name; cf. @ref{Switching context} below). Other than that, this is
40 pretty much equivalent to having a command-line interpreter in a
41 terminal, with a bunch of add-ons that we'll be reviewing below. You can
42 start typing sexps right there: Geiser will only dispatch them for
43 evaluation when they're complete, and will indent new lines properly
44 until then. It will also keep track of your input, maintaining a history
45 file that will be reloaded whenever you restart the REPL.
47 Nothing that fanciful this far, but there's more to Geiser's REPL. On to
48 the next section!
50 @node First aids, Switching context, Starting the REPL, The REPL
51 @section First aids
53 @img{repl-menu, right}
54 @cindex REPL commands
55 A quick way of seeing what else Geiser's REPL can do for you, is to
56 display the corresponding entry up there in your menu bar. No, i don't
57 normally use menus either; but they can come in handy until you've
58 memorized Geiser's commands, as a learning device. And yes, i usually
59 run Emacs inside a terminal, but one can always use
60 @uref{http://www.emacswiki.org/emacs/LaCarte, La Carte} to access the
61 menus in a convenient enough fashion.
63 Or just press @kbd{C-h m} and be done with that.
65 Among the commands at your disposal, we find the familiar input
66 navigation keys, with a couple twists. By default, @kbd{M-p} and
67 @kbd{M-n} are bound to @i{matching} items in your input history. That
68 is, they'll find the previous or next sexp that starts with the current
69 input prefix (defined as the text between the end of the prompt and your
70 current position, a.k.a. @dfn{point}, in the buffer). For going up and
71 down the list unconditionally, just use @kbd{C-c M-p} and @kbd{C-c M-n}.
72 In addition, navigation is sexp- rather than line-based.
74 There are also a few commands to twiddle with the Scheme process.
75 @kbd{C-c C-q} will mercilessly kill it (but not before stowing your
76 history in the file system). A softer nuke is performed by @kbd{C-c
77 C-k}: some (rare, i promise) times, Geiser's REPL can get confused by
78 the input received from then underlying Scheme (specially if you have
79 multiple threads writing to the standard ports), and become
80 irresponsive; you can try this command to try to revive it without
81 killing the process. Finally, if worse comes to worst and the process is
82 dead, @kbd{C-c z} will restart it.
84 The remaining commands are meatier, and deserve sections of their own.
86 @node Switching context, Let Geiser spy, First aids, The REPL
87 @section Switching context
89 @cindex current module
90 In tune with Geiser's @ref{current-module,,modus operandi}, evaluations
91 in the REPL take place if the namespace of the current module. As noted
92 above, the REPL's prompt tells you the name of the current module. To
93 switch to a different one, you can use the command
94 @command{switch-to-geiser-module}, bound to @kbd{C-c m}. You'll notice
95 that Geiser simply uses the underlying Scheme's native namespace switching
96 facilities (@command{,m} in Guile and @command{enter!} in Racket), and
97 that it doesn't even try to hide that fact. That means that you can
98 freely use said native ways directly at the REPL, and Geiser will be
99 happy to oblige.
101 Once you enter a new module, only those bindings visible in its
102 namespace will be available to your evaluations. All schemes supported
103 by Geiser provide a way to import new modules in the current namespace.
104 Again, there's a Geiser command, @command{geiser-repl-import-module}, to
105 invoke such functionality, bound this time to @kbd{C-c i}. And, again,
106 you'll see Geiser just introducing the native incantation for you, and
107 you're free to use such incantations by hand whenever you want.
109 One convenience provided by these two Geiser commands is that completion
110 is available when introducing the new module name, using the
111 @kbd{@key{TAB}} key. Pressing it at the command's prompt will offer you
112 a prefix-aware list of available module names.
114 @image{img/mod-completion}
116 Which brings me to the next group of REPL commands.
118 @node Let Geiser spy, Customization and tips, Switching context, The REPL
119 @section Let Geiser spy, write and jump for you
121 We've already seen Geiser completion of module names in action at the
122 mini-buffer. You won't be surprised to know that it's also available at
123 the REPL buffer itself. There, you can use either @kbd{C-.} or @kbd{M-`}
124 to complete module names, and @kbd{@key{TAB}} or @kbd{M-@key{TAB}} to
125 complete identifiers. Geiser will know what identifiers are bound in the
126 current module and show you a list of those starting with the prefix at
127 point. Needless to say, this is not a static list, and it will grow as
128 you define or import new bindings in the namespace at hand.
130 But, oftentimes, there's more you'll want to know about an identifier
131 besides its name: what module does it belong to? is it a procedure and,
132 if so, what arguments does it take? Geiser tries to help you answering
133 those questions too.
135 Actually, if you've been playing with the REPL as you read, you might
136 have notice some frantic activity taking place in the minibuffer every
137 now and then. That was Geiser trying to be helpful (while, hopefully,
138 not being clippy), or, more concretely, what i call, for want of a
139 better name, its @dfn{autodoc} mode. Whenever it's active (did you
140 notice that @i{A} in the mode-line?), Geiser's gerbils will be scanning
141 what you type and showing (unless you silent them with @kbd{C-c a})
142 arity information about the procedure nearest to point.
144 @image{img/repl-autodoc}
146 That information includes the procedure's name, prefixed with the name
147 of the module it belongs to, followed by the name of its arguments (or
148 an underscore if Geiser cannot determine the name used in the
149 definition). Optional arguments are surrounded by square brackets, and,
150 when the optional argument has a default value, it's represented by a
151 list made up of its name and that value. When the argument is a keyword
152 argument, its name is preceded by a colon.
154 If that's not enough documentation for you, @kbd{C-c C-d d} will open a
155 separate documentation buffer with help on the symbol at point. For some
156 implementations (e.g. Racket), this separate buffer will actually be a
157 web page displaying the corresponding page in the manual, while for
158 implementations supporting docstrings (e.g. (you guessed it) Guile)
159 it'll be a real Emacs buffer displaying that information.
161 If that's still not enough, Geiser can jump, via @kbd{M-.}, to the
162 symbol's definition. A buffer with the corresponding file will pop up,
163 with its point resting upon the identifier's defining form. When you're
164 done inspecting, @kbd{M-,} will bring you back to where you were. As we
165 will see, these commands are also available in scheme buffers.
167 Finally, Geiser can produce for you a list, classified by kind, of the
168 identifiers exported by a given module: all you need to do is press
169 @kbd{C-c C-d m}, and type or complete the desired module's name.
171 @image{img/repl-mod}
173 The list of exported bindings is shown in a buffer belonging to Geiser's
174 documentation browser, of which more details are given in forthcoming
175 sections (but just perusing it's associated key bindings, by any of the
176 methods we've already used for the REPL, will give you enough
177 information to use it effectively enough).
179 @node Customization and tips,  , Let Geiser spy, The REPL
180 @section Customization and tips
182 The looks and ways of the REPL can be fine-tuned via a bunch of
183 customization variables. You can see and modify them all in the
184 corresponding customization group (by using the menu entry or the good
185 old @kbd{M-x customize-group geiser-repl}), or by setting them in your
186 Emacs initialization files (as a rule, all knobs in Geiser are turnable
187 this way: you don't need to use customization buffers if you don't like
188 them).
190 I'm documenting below a proper subset of those settings, together with
191 some related tips.
193 @subsubheading Choosing a Scheme implementation
194 Instead of using the generic @command{run-geiser} command, you can start
195 directly your Scheme of choice via @command{run-racket} or
196 @command{run-guile}. @anchor{active-implementations} In addition, the
197 variable @var{geiser-active-implementations} contains a list of those
198 Schemes Geiser should be aware of. Thus, if you happen to be, say, a
199 racketeer not to be beguiled by other schemes, you can tell Geiser to
200 forget about the richness of the Scheme ecosystem with something like
201 @example
202 (setq geiser-active-implementations '(racket))
203 @end example
204 @noindent in your initialisation files.
206 @anchor{impl-binary} When starting a new REPL, Geiser assumes, by
207 default, that the corresponding Scheme binary is in your path. If that's
208 not the case, the variables to tweak are @var{geiser-guile-binary} and
209 @var{geiser-racket-binary}, which should be set to a string with the
210 path to the adequate binary.
212 @subsubheading History
214 By default, Geiser won't record duplicates in your input history. If you
215 prefer it did, just set @var{geiser-repl-history-no-dups-p} to
216 @code{nil}. History entries are persistent across REPL sessions: they're
217 saved in implementation-specific files whose location is controlled by
218 the variable @var{geiser-repl-history-filename}. For example, my Geiser
219 configuration includes the following line:
220 @example
221 (setq geiser-repl-history-filename "~/.emacs.d/geiser-history")
222 @end example
223 @noindent which makes the files @file{geiser-history.guile} and
224 @file{geiser-history.racket} to live inside my home's @file{.emacs.d}
225 directory.
228 @c Local Variables:
229 @c mode: texinfo
230 @c TeX-master: "geiser"
231 @c End: