1 @node The REPL, Index, Installation, Top
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.
13 * Customization and tips::
16 @node Starting the REPL, First aids, The REPL, The REPL
17 @section Starting the 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.
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
50 @node First aids, Switching context, Starting the REPL, The REPL
53 @img{repl-menu, right}
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
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
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 still not enough, Geiser can jump, via @kbd{M-.}, to the
155 symbol's definition. A buffer with the corresponding file will pop up,
156 with its point resting upon the identifier's defining form. When you're
157 done inspecting, @kbd{M-,} will bring you back to where you were. As we
158 will see, these commands are also available in scheme buffers.
160 Finally, Geiser can produce for you a list, classified by kind, of the
161 identifiers exported by a given module: all you need to do is press
162 @kbd{C-c d}, and type or complete the desired module's name.
166 The list of exported bindings is shown in a buffer belonging to Geiser's
167 documentation browser, of which more details are given in forthcoming
168 sections (but just perusing it's associated key bindings, by any of the
169 methods we've already used for the REPL, will give you enough
170 information to use it effectively enough).
172 @node Customization and tips, , Let Geiser spy, The REPL
173 @section Customization and tips
175 The looks and ways of the REPL can be fine-tuned via a bunch of
176 customization variables. You can see and modify them all in the
177 corresponding customization group (by using the menu entry or the good
178 old @kbd{M-x customize-group geiser-repl}), or by setting them in your
179 Emacs initialization files (as a rule, all knobs in Geiser are turnable
180 this way: you don't need to use customization buffers if you don't like
183 I'm documenting below a proper subset of those settings, together with
186 @subsubheading Choosing a Scheme implementation
187 Instead of using the generic @command{run-geiser} command, you can start
188 directly your Scheme of choice via @command{run-racket} or
189 @command{run-guile}. @anchor{active-implementations} In addition, the
190 variable @var{geiser-active-implementations} contains a list of those
191 Schemes Geiser should be aware of. Thus, if you happen to be, say, a
192 racketeer not to be beguiled by other schemes, you can tell Geiser to
193 forget about the richness of the Scheme ecosystem with something like
195 (setq geiser-active-implementations '(racket))
197 @noindent in your initialisation files.
199 @anchor{impl-binary} When starting a new REPL, Geiser assumes, by
200 default, that the corresponding Scheme binary is in your path. If that's
201 not the case, the variables to tweak are @var{geiser-guile-binary} and
202 @var{geiser-racket-binary}, which should be set to a string with the
203 path to the adequate binary.
205 @subsubheading History
207 By default, Geiser won't record duplicates in your input history. If you
208 prefer it did, just set @var{geiser-repl-history-no-dups-p} to
209 @code{nil}. History entries are persistent across REPL sessions: they're
210 saved in implementation-specific files whose location is controlled by
211 the variable @var{geiser-repl-history-filename}. For example, my Geiser
212 configuration includes the following line:
214 (setq geiser-repl-history-filename "~/.emacs.d/geiser-history")
216 @noindent which makes the files @file{geiser-history.guile} and
217 @file{geiser-history.racket} to live inside my home's @file{.emacs.d}
223 @c TeX-master: "geiser"