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