dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

parens.texi (30510B)


      1 @node Between the parens, Cheat sheet, The REPL, Top
      2 @chapter Between the parens
      3 
      4 A good REPL is a must, but just about half the story of a good Scheme
      5 hacking environment.  Well, perhaps a bit more than a half; but, at any
      6 rate, one surely needs also a pleasant way of editing source code.  Don't
      7 pay attention to naysayers: Emacs comes with an excellent editor
      8 included for about any language on Earth, and just the best one when
      9 that language is sexpy (especially if you use
     10 @ifhtml
     11 @ref{paredit,,Paredit}).
     12 @end ifhtml
     13 @ifnothtml
     14 Paredit).
     15 @end ifnothtml
     16 Geiser's support for writing Scheme code adds to Emacs'
     17 @code{scheme-mode}, rather than supplanting it; and it does so by means
     18 of a minor mode (unimaginatively dubbed @code{geiser-mode}) that defines
     19 a bunch of new commands to try and, with the help of the same Scheme
     20 process giving you the REPL, make those Scheme buffers come to life.
     21 
     22 @menu
     23 * Activating Geiser::
     24 * The source and the REPL::
     25 * Documentation helpers::
     26 * To eval or not to eval::
     27 * To err perchance to debug::
     28 * Jumping around::
     29 * Geiser writes for you::
     30 @end menu
     31 
     32 @node Activating Geiser, The source and the REPL, Between the parens, Between the parens
     33 @section Activating Geiser
     34 
     35 @cindex geiser-mode
     36 @img{geiser-mode, right}
     37 With Geiser installed following any of the
     38 procedures described in @ref{The quick and easy way} or @ref{From the
     39 source's mouth}, Emacs will automatically activate @i{geiser-mode} when
     40 opening a Scheme buffer.  Geiser also instructs Emacs to consider files
     41 with the extension @file{rkt} part of the family, so that, in principle,
     42 there's nothing you need to do to ensure that Geiser's extensions will
     43 be available, out of the box, when you start editing Scheme code.
     44 
     45 Indications that everything is working according to plan include the
     46 'Geiser' minor mode indicator in your mode-line and the appearance of a
     47 new entry for Geiser in the menu bar.  If, moreover, the mode-line
     48 indicator is the name of a Scheme implementation, you're indeed in a
     49 perfect world; otherwise, don't despair and keep on reading: i'll tell
     50 you how to fix that in a moment.
     51 
     52 @cindex geiser-mode commands
     53 The menu provides a good synopsis of everything Geiser brings to the
     54 party, including those keyboard shortcuts we Emacsers love.  If you're
     55 seeing the name of your favourite Scheme implementation in the
     56 mode-line, have a running REPL and are comfortable with Emacs, you can
     57 stop reading now and, instead, discover Geiser's joys by yourself.  I've
     58 tried to make Geiser as self-documenting as any self-respecting Emacs
     59 package should be.  If you follow this route, make sure to take a look at
     60 Geiser's customization buffers (@kbd{M-x customize-group @key{RET}
     61 geiser}): there's lot of fine-tuning available there.  You might also
     62 want to take a glance at
     63 @ifhtml
     64 our @ref{Cheat sheet,,cheat sheet}.
     65 @end ifhtml
     66 @ifnothtml
     67 the tables in @pxref{Cheat sheet, our cheat sheet}.
     68 @end ifnothtml
     69 
     70 Since @i{geiser-mode} is a minor mode, you can toggle it with
     71 @kbd{M-x geiser-mode}, and control its activation in hooks with the
     72 functions @code{turn-on-geiser-mode} and @code{turn-off-geiser-mode}.
     73 If, for some reason i cannot fathom, you prefer @i{geiser-mode} not
     74 to be active by default, customizing @code{geiser-mode-auto-p} to
     75 @code{nil} will do the trick.
     76 
     77 @cindex scheme file extensions
     78 And if you happen to use a funky extension for your Scheme files that is
     79 not recognised as such by Emacs, just tell her about it with:
     80 
     81 @example
     82 (add-to-list 'auto-mode-alist '("\\.funky-extension\\'" . scheme-mode))
     83 @end example
     84 
     85 @cindex useless wretch
     86 Now, @i{geiser-mode} is just a useless wretch unless there's a running
     87 Scheme process backing it up.  Meaning that virtually all the commands it
     88 provides require a REPL up and running, preferably corresponding to
     89 the correct Scheme implementation.  In the following section, we'll see
     90 how to make sure that that's actually the case.
     91 
     92 @node The source and the REPL, Documentation helpers, Activating Geiser, Between the parens
     93 @section The source and the REPL
     94 
     95 As i've already mentioned a couple of times, @i{geiser-mode} needs a
     96 running REPL to be operative.  Thus, a common usage pattern will be
     97 for you to first call @code{geiser}
     98 @ifhtml
     99 (or @ref{choosing-impl,,one of its variants}),
    100 @end ifhtml
    101 @ifnothtml
    102 (or one of its variants, e.g. @code{run-guile}),
    103 @end ifnothtml
    104 and then open some Scheme files;
    105 but there's nothing wrong in first opening a couple Scheme buffers and
    106 then starting the REPL (you can even find it more convenient, since
    107 pressing @kbd{C-c C-z} in a Scheme buffer will start the REPL for
    108 you).  Since Geiser supports more than one Scheme implementation, though,
    109 there's the problem of knowing which of them is to be associated with
    110 each Scheme source file.  Serviceable as it is, @i{geiser-mode} will try
    111 to guess the correct implementation for you, according to the algorithm
    112 described below.
    113 @ifhtml
    114 If you find that Geiser is already guessing right the Scheme
    115 implementation, feel free to skip to the @ref{switching-repl-buff,,next
    116 subsection}.
    117 @end ifhtml
    118 
    119 @subsubheading How Geiser associates a REPL to your Scheme buffer
    120 @cindex scheme implementation, choosing
    121 @anchor{repl-association} To determine what Scheme implementation
    122 corresponds to a given source file, Geiser uses the following algorithm:
    123 
    124 @enumerate
    125 @item
    126 If the file-local variable @code{geiser-scheme-implementation} is
    127 defined, its value is used.  A common way of setting buffer-local
    128 variables is to put them in a comment near the beginning of the file,
    129 surrounded by @code{-*-} marks, as in:
    130 
    131 @example
    132 ;; -*- geiser-scheme-implementation: guile -*-
    133 @end example
    134 
    135 @item
    136 If you've customized @code{geiser-active-implementations} so that it's a
    137 single-element
    138 @ifhtml
    139 list (as explained in @ref{choosing-impl,,here}),
    140 @end ifhtml
    141 @ifnothtml
    142 list,
    143 @end ifnothtml
    144 that element is used as the chosen implementation.
    145 @item
    146 The contents of the file is scanned for hints on its associated
    147 implementation.  For instance, files that contain a @code{#lang}
    148 directive will be considered Racket source code, while those with a
    149 @code{define-module} form in them will be assigned to a Guile REPL.
    150 @item
    151 The current buffer's file name is checked against the rules given in
    152 @code{geiser-implementations-alist}, and the first match is applied.  You
    153 can provide your own rules by customizing this variable, as explained
    154 below.
    155 @item
    156 If we haven't been lucky this far and you have customized
    157 @code{geiser-default-implementation} to the name of a supported
    158 implementation, we'll follow your lead.
    159 @item
    160 See?  That's the problem of being a smart aleck: one's always outsmarted
    161 by people around.  At this point, @i{geiser-mode} will humbly give up and
    162 ask you to explicitly choose the Scheme implementation.
    163 @end enumerate
    164 
    165 As you can see in the list above, there are several ways to influence
    166 Geiser's guessing by means of customizable variables.  The most direct (and
    167 most impoverishing) is probably limiting the active implementations to a
    168 single one, while customizing @code{geiser-implementations-alist} is the
    169 most flexible (and, unsurprisingly, also the most complex).  Here's the
    170 default value for the latter variable:
    171 
    172 @example
    173 (((regexp "\\.scm$") guile)
    174  ((regexp "\\.ss$") racket)
    175  ((regexp "\\.rkt$") racket))
    176 @end example
    177 
    178 @noindent
    179 which describes the simple heuristic that files with @file{.scm} as
    180 extension are by default associated to a Guile REPL while those ending
    181 in @file{.ss} or @file{.rkt} correspond to Racket's implementation (with
    182 the caveat that these rules are applied only if the previous heuristics
    183 have failed to detect the correct implementation, and that they'll match
    184 only if the corresponding implementation is active).  You can add rules
    185 to @code{geiser-implementations-alist} (or replace all of them) by
    186 customizing it.  Besides regular expressions, you can also use a
    187 directory name; for instance, the following snippet:
    188 
    189 @example
    190 (eval-after-load "geiser-impl"
    191   '(add-to-list 'geiser-implementations-alist
    192                 '((dir "/home/jao/prj/frob") guile)))
    193 @end example
    194 
    195 @noindent
    196 will add a new rule that says that any file inside my
    197 @file{/home/jao/prj/frob} directory (or, recursively, any of its
    198 children) is to be assigned to Guile.  Since rules are first matched,
    199 first served, this new rule will take precedence over the default ones.
    200 
    201 @cindex autostart REPL
    202 @cindex start REPL, automatically
    203 A final tip: if you want Geiser to start automatically a REPL for you if
    204 it notices that there's no one active when it enters @i{geiser-mode},
    205 you can customize @code{geiser-mode-start-repl-p} to @code{t}.
    206 
    207 @subsubheading Managing multiple scheme projects
    208 @cindex dir-locals
    209 @cindex project.el
    210 @cindex projectile
    211 @cindex projects
    212 @anchor{repl-per-project} By default, Geiser will re-use a single REPL
    213 for all buffers sharing the same scheme implementation.  This works well
    214 enough in many cases, but may become problematic (or at least annoying)
    215 when working on multiple projects with separate dependencies and include
    216 paths.
    217 
    218 @cindex geiser-repl-per-project-p
    219 Geiser provides optional support for using separate REPLs for each
    220 project, which can be enabled by customizing
    221 @code{geiser-repl-current-project-function} and selecting your Emacs
    222 project-management library of choice (eg. @code{project.el} or
    223 @code{projectile}).  With this configured, if you want new REPLs to
    224 automatically associate themselves with the current project, so that all
    225 Geiser commands will ignore REPLs that are not associated with the
    226 project, customize the toggle @code{geiser-repl-per-project-p} to
    227 @code{t} and you're all set up.
    228 
    229 @cindex geiser-repl-add-project-path-p
    230 This can be very convenient when used with a @file{.dir-locals.el} in
    231 the project root to set include paths, ensuring that Geiser REPLs will
    232 always know where to find your project's modules or dependencies.
    233 Geiser automatically handles the common case of the project root
    234 belonging to the load path: unless you tell it otherwise (using the
    235 customisable flag @code{geiser-repl-add-project-path-p}, which defaults
    236 to @code{t}), it will add the result of calling
    237 @code{geiser-repl-current-project-function} to the REPLs load path on
    238 startup.
    239 
    240 @subsubheading Switching between source files and the REPL
    241 @cindex switching to REPL
    242 @cindex switching to source
    243 @anchor{switching-repl-buff} Once you have a working @i{geiser-mode},
    244 you can switch from Scheme source buffers to the REPL or @kbd{C-c
    245 C-z}.  Those shortcuts map to the interactive command
    246 @code{geiser-repl-switch}.
    247 
    248 @cindex switching to module
    249 If you use a numeric prefix, as in @kbd{C-u C-c C-z}, besides being
    250 teleported to the REPL, the latter will switch to the namespace of the
    251 Scheme source file, as if you had used @kbd{C-c C-m} in the REPL, with
    252 the source file's module as argument;
    253 cf. discussion in
    254 @altr{Switching context,,Switching context,. This}
    255 command is also bound to @kbd{C-c C-a}.
    256 
    257 Once you're in the REPL, the same @kbd{C-c C-z} shortcut will bring
    258 you back to the buffer you jumped from, provided you don't kill the
    259 Scheme process in between.  This is why the command is called
    260 @i{geiser-repl-switch} instead of @i{switch-to-repl}, and what makes it
    261 really handy, if you ask me.
    262 
    263 @cindex switching schemes
    264 If for some reason you're not happy with the Scheme implementation that
    265 Geiser has assigned to your file, you can change it with @kbd{C-c C-s},
    266 and you probably should take a look at
    267 @ifhtml
    268 @ref{repl-association,,the previous subsection}
    269 @end ifhtml
    270 @ifnothtml
    271 the previous subsection
    272 @end ifnothtml
    273 to make sure that Geiser
    274 doesn't get confused again.
    275 
    276 @subsubheading A note about context
    277 As explained before (@pxref{Modus operandi}), all Geiser activities take
    278 place in the context of the @i{current namespace}, which, for Scheme
    279 buffers, corresponds to the module that the Scheme implementation
    280 associates to the source file at hand (for instance, in Racket, there's
    281 a one-to-one correspondence between paths and modules, while Guile
    282 relies on explicit @code{define-module} forms in the source file).
    283 
    284 Now that we have @code{geiser-mode} happily alive in our Scheme buffers
    285 and communicating with the right REPL instance, let us see what it
    286 can do for us, besides jumping to and fro.
    287 
    288 @node Documentation helpers, To eval or not to eval, The source and the REPL, Between the parens
    289 @section Documentation helpers
    290 
    291 @subsubheading Autodoc redux
    292 
    293 @cindex autodoc, in scheme buffers
    294 The first thing you will notice by moving around Scheme source is that,
    295 every now and then, the echo area lights up with the same autodoc
    296 messages we know and love from our REPL forays.  This happens every
    297 time the Scheme process is able to recognise an identifier in the
    298 buffer, and provide information either on its value (for variables) or
    299 on its arity and the name of its formal arguments (for procedures and
    300 macros).  That information will only be available if the module the
    301 identifier belongs to has been loaded in the running Scheme image.  So it
    302 can be the case that, at first, no autodoc is shown for identifiers
    303 defined in the file you're editing.  But as soon as you evaluate them
    304 (either individually or collectively using any of the devices described
    305 in @ref{To eval or not to eval}) their signatures will start appearing
    306 in the echo area.
    307 
    308 @cindex disabling autodoc
    309 @cindex manual autodoc
    310 Autodoc activation is controlled by a minor mode, @code{geiser-autodoc},
    311 which you can toggle with @kbd{M-x geiser-autodoc-mode}, or its associated
    312 keyboard shortcut, @kbd{C-c C-d a}.  That @t{/A} indicator in the
    313 mode-line is telling you that autodoc is active.  If you prefer that it
    314 be inactive by default (e.g., because you're connecting to a really
    315 remote scheme and want to minimize network exchanges), just set
    316 @code{geiser-mode-autodoc-p} to @code{nil} in your customization files.
    317 Even when autodoc mode is off, you can use @code{geiser-autodoc-show},
    318 bound by default to @kbd{C-c C-d s}, to show the autodoc string for the
    319 symbol at point.
    320 
    321 @cindex autodoc explained
    322 @img{autodoc-scm, right}
    323 The way autodoc displays information deserves
    324 some explanation.  It will first show the name of the module where the
    325 identifier at hand is defined, followed by a colon and the identifier
    326 itself.  If the latter corresponds to a procedure or macro, it will be
    327 followed by a list of argument names, starting with the ones that are
    328 required.  Then there comes a list of optional arguments, if any,
    329 enclosed in parentheses.  When an optional argument has a default value
    330 (or a form defining its default value), autodoc will display it after
    331 the argument name.  When the optional arguments are keywords, their names
    332 are prefixed with ``#:'' (i.e., their names @i{are} keywords).  An
    333 ellipsis (@dots{}) serves as a marker of an indeterminate number of
    334 parameters, as is the case with @i{rest} arguments or when autodoc
    335 cannot fathom the exact number of arguments (this is often the case with
    336 macros defined using @code{syntax-case}).  Another way in which autodoc
    337 displays its ignorance is by using an underscore to display parameters
    338 whose name is beyond its powers.
    339 
    340 @img{autodoc-multi, right}
    341 It can also be the case that a function or
    342 macro has more than one signature (e.g., functions defined using
    343 @code{case-lambda}, or some @code{syntax-rules} macros, for which Geiser
    344 has often the black magic necessary to retrieve their actual arities).
    345 In those cases, autodoc shows all known signatures (using the above
    346 rules for each one) separated by a vertical bar (|).
    347 
    348 As you have already noticed, the whole autodoc message is enclosed in
    349 parentheses.  After all, we're talking about Scheme here.
    350 
    351 @cindex autodoc for variables
    352 @img{autodoc-var, right}
    353 Finally, life is much easier when your cursor
    354 is on a symbol corresponding to a plain variable: you'll see in the echo
    355 area its name, preceded by the module where it's defined, and followed
    356 by its value, with an intervening arrow for greater effect.  This time,
    357 there are no enclosing parentheses (i hope you see the logic in my
    358 madness).
    359 
    360 @cindex autodoc customized
    361 You can change the way Geiser displays the module/identifier combo by
    362 customizing @code{geiser-autodoc-identifier-format}.  For example, if you
    363 wanted a tilde surrounded by spaces instead of a colon as a separator,
    364 you would write something like:
    365 
    366 @example
    367 (setq geiser-autodoc-identifier-format "%s ~ %s")
    368 @end example
    369 
    370 @noindent
    371 in your Emacs initialisation files.  There's also a face
    372 (@code{geiser-font-lock-autodoc-identifier}) that you can customize (for
    373 instance, with @kbd{M-x customize-face}) to change the appearance of the
    374 text.  And another one (@code{geiser-font-lock-autodoc-current-arg}) that
    375 controls how the current argument position is highlighted.
    376 
    377 @subsubheading Other documentation commands
    378 
    379 @anchor{doc-browser}Sometimes, autodoc won't provide enough information
    380 for you to understand what a function does.  In those cases, you can ask
    381 Geiser to ask the running Scheme for further information on a given
    382 identifier or module.
    383 
    384 @cindex documentation for symbol
    385 @cindex docstrings, maybe
    386 For symbols, the incantation is @kbd{M-x geiser-doc-symbol-at-point}, or
    387 @kbd{C-c C-d C-d} for short.  If the associated Scheme supports
    388 docstrings (as, for instance, Guile does), you'll be teleported to a new
    389 Emacs buffer displaying Geiser's documentation browser, filled with
    390 information about the identifier, including its docstring (if any;
    391 unfortunately, that an implementation supports docstrings doesn't mean
    392 that they're used everywhere).
    393 
    394 @imgc{docstring}
    395 
    396 Pressing @kbd{q} in the documentation buffer will bring you back,
    397 enlightened, to where you were.  There's also a handful of other
    398 navigation commands available in that buffer, which you can discover by
    399 means of its menu or via the good old @kbd{C-h m} command.  And feel free
    400 to use the navigation buttons and hyperlinks that justify my calling
    401 this buffer a documentation browser.
    402 
    403 For Racket, which does not support docstrings out of the box, this
    404 command will provide less information, but the documentation browser
    405 will display the corresponding contract when it's available, as well as
    406 some other tidbits for re-exported identifiers.
    407 
    408 @imgc{docstring-racket}
    409 
    410 You can also ask Geiser to display information about a module, in the
    411 form of a list of its exported identifiers, using @kbd{C-c C-d C-m},
    412 exactly as you would do in
    413 @altr{repl-mod,the REPL,The REPL,.}
    414 
    415 In both cases, the documentation browser will show a couple of buttons
    416 giving you access to further documentation.  First, you'll see a button
    417 named @i{source}: pressing it you'll jump to the symbol's definition.
    418 The second button, dubbed @i{manual}, will open the Scheme
    419 implementation's manual page for the symbol at hand.  For Racket, that
    420 will open your web browser displaying the corresponding reference's page
    421 (using the HTML browser in Racket's configuration, which you can edit in
    422 DrRacket's preferences dialog, or by setting
    423 @code{plt:framework-pref:external-browser} directly in
    424 @file{~/.racket/racket-prefs.rktd}), while in Guile a lookup will be
    425 performed in the texinfo manual.
    426 
    427 @cindex Guile info nodes
    428 For Guile, the manual lookup uses the info indexes in the standard
    429 Guile info nodes, which are usually named ``guile'' or ``guile-2.0''.
    430 If yours are named differently, just add your name to the customizable
    431 variable @code{geiser-guile-manual-lookup-nodes}.
    432 
    433 A list of all navigation commands in the documentation browser is
    434 available in
    435 @altr{Documentation browser,our cheat-sheet,Documentation browser,.}
    436 
    437 @cindex opening manual pages
    438 You can also skip the documentation browser and jump directly to the
    439 manual page for the symbol at point with the command
    440 @code{geiser-doc-look-up-manual}, bound to @kbd{C-c C-d i}.
    441 
    442 @node To eval or not to eval, To err perchance to debug, Documentation helpers, Between the parens
    443 @section To eval or not to eval
    444 
    445 @cindex philosophy
    446 @cindex incremental development
    447 One of Geiser's main goals is to facilitate incremental development.
    448 You might have noticed that i've made a big fuss of Geiser's ability to
    449 recognize context, by dint of being aware of the namespace where its
    450 operations happen.
    451 
    452 That awareness is especially important when evaluating code in your
    453 scheme buffers, using the commands described below.  They allow you to
    454 send code to the running Scheme with a granularity ranging from whole
    455 files to single s-expressions.  That code will be evaluated in the module
    456 associated with the file you're editing, allowing you to redefine values
    457 and procedures to your heart's (and other modules') content.
    458 
    459 @cindex incremental development, evil
    460 Macros are, of course, another kettle of fish: one needs to re-evaluate
    461 uses of a macro after redefining it.  That's not a limitation imposed by
    462 Geiser, but a consequence of how macros work in Scheme (and other
    463 Lisps).  There's also the risk that you lose track of what's actually
    464 defined and what's not during a given session.  But,
    465 @uref{https://jaortega.wordpress.com/2009/03/29/from-my-cold-prying-hands,
    466 in my opinion}, those are limitations we lispers are aware of, and they
    467 don't force us to throw the baby with the bathwater and ditch
    468 incremental evaluation.  Some people disagree; if you happen to find
    469 @uref{https://blog.racket-lang.org/2009/03/the-drscheme-repl-isnt-the-one-in-emacs.html,
    470 their arguments} convincing, you don't have to throw away Geiser
    471 together with the baby: @kbd{M-x geiser-restart-repl} will let you
    472 restart the REPL as many times as you see fit.  Moreover, you can invoke
    473 @kbd{geiser-compile-current-buffer} and @kbd{geiser-load-current-buffer}
    474 with a prefix argument (that'd be something like @kbd{C-u C-c C-k} for
    475 compilation, for instance), to tell Geiser to restart the REPL
    476 associated with a buffer before compiling or loading its current
    477 contents.
    478 
    479 @cindex evaluation
    480 @cindex incremental development, not evil
    481 For all of you auld bearded lispers still with me, here are some of the
    482 commands performing incremental evaluation in Geiser.
    483 
    484 @code{geiser-eval-last-sexp}, bound to @kbd{C-x C-e}, will eval the
    485 s-expression just before point.  If you use a prefix, as in @kbd{C-u C-x
    486 C-e}, besides evaluating it the expression is inserted in the the
    487 buffer.
    488 
    489 @code{geiser-eval-definition}, bound to @kbd{C-M-x}, finds the topmost
    490 definition containing point and sends it for evaluation.  The variant
    491 @code{geiser-eval-definition-and-go} (@kbd{C-c M-e}) works in the same
    492 way, but it also teleports you to REPL after the evaluation.
    493 
    494 @code{geiser-eval-region}, bound to @kbd{C-c C-r}, evals the current
    495 region.  Again, there's an @i{and-go} version available,
    496 @code{geiser-eval-region-and-go}, bound to @kbd{C-c M-r}.  And, if you
    497 want to extend the evaluated region to the whole buffer, there is
    498 @code{geiser-eval-buffer}, bound to @kbd{C-c C-b} and its companion
    499 @code{geiser-eval-buffer-and-go}, bound to @kbd{C-c M-b}.
    500 
    501 @cindex evaluating images
    502 @cindex image display
    503 For all the commands above, the result of the evaluation is displayed in
    504 the minibuffer, unless it causes a (Scheme-side) error (@pxref{To err
    505 perchance to debug}), or, for schemes supporting them (such as Racket),
    506 the evaluation yields an image, in which case you'll see it in popping
    507 up in the Geiser debug buffer (if your Emacs runs under the auspices of
    508 a graphical toolkit), or via an external viewer if you set
    509 @code{geiser-image-viewer} to the path of an appropriate visualization
    510 program (see also @ref{Seeing is believing} for more on image support).
    511 
    512 At the risk of repeating myself, i'll remind you that all these
    513 evaluations will take place in the namespace of the module corresponding
    514 to the Scheme file from which you're sending your code, which, in
    515 general, will be different from the REPL's current module.  And, if all
    516 goes according to plan, (re)defined variables and procedures should be
    517 immediately visible inside and, if exported, outside their module.
    518 
    519 Besides evaluating expressions, definitions and regions, you can also
    520 macro-expand them.  The corresponding key bindings start with the prefix
    521 @kbd{C-c C-m} and end, respectively, with @kbd{C-e}, @kbd{C-x} and
    522 @kbd{C-r}.  The result of the macro expansion always appears in a pop up
    523 buffer.
    524 
    525 @cindex interrupt evaluation
    526 All the evaluations and expansions performed by the commands above are
    527 asynchronous@footnote{For local REPLs, where we can easily send an
    528 interrupt signal to the scheme process; remote REPLs are another kettle
    529 of fish in this regard, and generally interruptions are supported:
    530 you'll just have to kill the connection if caught in a loop.}, so that
    531 you can move around while the answer is being computed.  The command
    532 @code{geiser-eval-interrupt}, bound to @kbd{C-c C-i} will interrupt any
    533 on-going evaluation and, when the scheme implementation supports a
    534 debugger, bring you to a buffer where you can perform buffer actions in
    535 the interrupted evaluation's context.
    536 
    537 Oh, didn't i mention we have support for debuggers?  Let's talk about
    538 that next.
    539 
    540 @node To err perchance to debug, Jumping around, To eval or not to eval, Between the parens
    541 @section To err: perchance to debug
    542 
    543 @cindex to err is schemey
    544 @cindex backtraces
    545 When an error occurs during evaluation, it will be reported according to
    546 the capabilities of the underlying Scheme REPL.
    547 
    548 @cindex error buffer
    549 In most schemes, you'll be presented with a backtrace, in a new buffer
    550 where file paths locating the origin of the error are click-able (you
    551 can navigate them using the @key{TAB} key, and use @key{RET} or the
    552 mouse to jump to the offending spot; or invoke Emacs' stock commands
    553 @code{next-error} and @code{previous-error}, bound to @kbd{M-g n} and
    554 @kbd{M-g p} by default).
    555 
    556 @imgc{eval-error}
    557 
    558 By default, Geiser will tele-transport your pointer to the debug buffer:
    559 if you prefer to stay in the source buffer, set
    560 @code{geiser-debug-jump-to-debug} to nil.
    561 
    562 For schemes with good debug support (Guile is one), the debug buffers
    563 offer a @i{debugging menu}, accesible via the @code{,} (that's a comma)
    564 key.  If you press it, a transient menu will appear, offering you a
    565 variety of actions, including showing local variable values or a more
    566 detailed backtrace or frame display.  This is the same interface you'll
    567 encounter the in case of interrupted evaluations, either by your
    568 explicit @kbd{C-c C-i} command or because a breakpoint has been
    569 previosuly set.
    570 
    571 In addition, Geiser will sometimes report warnings for otherwise
    572 successful evaluations.  In those cases, it won't enter the debugger,
    573 just report the warnings in a debug buffer.
    574 
    575 @node Jumping around, Geiser writes for you, To err perchance to debug, Between the parens
    576 @section Jumping around
    577 
    578 @cindex jumping in scheme buffers
    579 This one feature is as sweet as it is easy to explain: @kbd{M-.}
    580 (@code{geiser-edit-symbol-at-point}) will open the file where the
    581 identifier around point is defined and land your point on its
    582 definition.  To return to where you were, press @kbd{M-,}
    583 (@code{geiser-pop-symbol-stack}).  This command works also for module
    584 names: Geiser first tries to locate a definition for the identifier at
    585 point and, if that fails, a module with that name; if the latter
    586 succeeds, the file where the module is defined will pop up.
    587 
    588 Sometimes, the underlying Scheme will tell Geiser only the file where
    589 the symbol is defined, but Geiser will use some heuristics (read,
    590 regular expressions) to locate the exact line and bring you there.  Thus,
    591 if you find Geiser systematically missing your definitions, send a
    592 message to the @email{geiser-users@@nongnu.org, mailing list}, and we'll
    593 try to make the algorithm smarter.
    594 
    595 @cindex jumping customized
    596 You can control how the destination buffer pops up by setting
    597 @code{geiser-edit-symbol-method} to either @code{nil} (to open the file
    598 in the current window), @code{'window} (other window in the same frame)
    599 or @code{'frame} (in a new frame).
    600 
    601 @node Geiser writes for you,  , Jumping around, Between the parens
    602 @section Geiser writes for you
    603 
    604 @cindex completion in scheme buffers
    605 No self-respecting programming mode would be complete without
    606 completion.  In geiser-mode, identifier completion is bound to
    607 @kbd{M-@key{TAB}}, and will offer all visible identifiers starting with
    608 the prefix before point.  Visible here means all symbols imported or
    609 defined in the current namespace plus locally bound ones.  E.g., if
    610 you're at the end of the following partial expression:
    611 
    612 @example
    613 (let ((default 42))
    614   (frob def
    615 @end example
    616 
    617 @noindent
    618 and press @kbd{M-@key{TAB}}, one of the possible completions will be
    619 @code{default}.
    620 
    621 @cindex partial completion
    622 After obtaining the list of completions from the running Scheme, Geiser
    623 uses the standard Emacs completion machinery to display them.  That
    624 means, among other things, that partial completion is available: just
    625 try to complete @code{d-s} or @code{w-o-t-s} to see why this is a good
    626 thing.  Partial completion won't work if you have disabled it globally in
    627 your Emacs configuration: if you don't know what i'm talking about,
    628 never mind: Geiser's partial completion will work for you out of the
    629 box.
    630 
    631 @cindex smart tabs
    632 If you find the @kbd{M} modifier annoying, you always have the option to
    633 activate @code{geiser-smart-tab-mode}, which will make the @key{TAB} key
    634 double duty as the regular Emacs indentation command (when the cursor is
    635 not near a symbol) and Geiser's completion function.  If you want this
    636 smarty pants mode always on in Scheme buffers, customize
    637 @code{geiser-mode-smart-tab-p} to @code{t}.
    638 
    639 @cindex completion for module names
    640 Geiser also knows how to complete module names: if no completion for the
    641 prefix at point is found among the currently visible bindings, it will
    642 try to find a module name that matches it.  You can also request
    643 explicitly completion only over module names using @kbd{M-`} (that's a
    644 backtick).
    645 
    646 Besides completion, there's also this little command,
    647 @code{geiser-squarify}, which will toggle the delimiters of the
    648 innermost list around point between round and square brackets.  It is
    649 bound to @kbd{C-c C-e [}.  With a numeric prefix (as in, say, @kbd{M-2
    650 C-c C-e [}), it will perform that many toggles, forward for positive
    651 values and backward for negative ones.
    652 
    653 @subheading Caveat about completion
    654 
    655 It is possible for Geiser to hang your Emacs process when trying to
    656 complete symbols. This can happen in the REPL itself or even in a
    657 Scheme buffer that is attached to the REPL process. For more details
    658 on how to fix this problem, @ref{completion-caveat,,Caveat about
    659 completion & the REPL}
    660 
    661 @c Local Variables:
    662 @c mode: texinfo
    663 @c TeX-master: "geiser"
    664 @c End: