dotemacs

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

sly.texi (112238B)


      1 \input texinfo
      2 @c %**start of header
      3 @setfilename sly.info
      4 
      5 @iftex
      6 @documentencoding UTF-8
      7 @codequoteundirected on
      8 @codequotebacktick on
      9 @end iftex
     10 
     11 @dircategory Emacs
     12 @direntry
     13 * SLY: (sly).    Common-Lisp IDE
     14 @end direntry
     15 @c %**end of header
     16 
     17 @set SLYVER 1.0.42
     18 @set UPDATED @today{}
     19 @set TITLE SLY User Manual
     20 @settitle @value{TITLE}, version @value{SLYVER}
     21 
     22 @copying
     23 Written for SLIME Luke Gorrie and others, rewritten by João
     24 Távora for SLY.
     25 
     26 This file has been placed in the public domain.
     27 @end copying
     28 
     29 @c For screenshots use
     30 
     31 @c (make-frame '((height . 32) (width . 90) (font . "Andale Mono 13")))
     32 @c (make-frame '((height . 32) (width . 90) (font . "DejaVu Sans Mono 10")))
     33 @c M-x load-theme RET base16-bright-light RET
     34 
     35 @c preferably on Mac OSX, then Cmd-Shift-4 SPC and click the window
     36 
     37 
     38 @titlepage
     39 @title @value{TITLE}
     40 @sp 10
     41 @example
     42           _____    __   __  __
     43          / ___/   / /   \ \/ /               |\      _,,,---,,_
     44          \__ \   / /     \  /                /,`.-'`'    -.  ;-;;,_
     45         ___/ /  / /___   / /                |,4-  ) )-,_..;\ (  `'-'
     46        /____/  /_____/  /_/                '---''(_/--'  `-'\_)
     47 
     48 @end example
     49 @sp 10
     50 @subtitle version @value{SLYVER}
     51 @page
     52 @insertcopying
     53 
     54 @end titlepage
     55 
     56 @c Macros
     57 
     58 @macro SLY
     59 @acronym{SLY}
     60 @end macro
     61 
     62 @macro SLIME
     63 @acronym{SLIME}
     64 @end macro
     65 
     66 @macro SLY-DB
     67 @acronym{SLY-DB}
     68 @end macro
     69 
     70 @macro REPL
     71 @acronym{REPL}
     72 @end macro
     73 
     74 @macro Git
     75 @acronym{Git}
     76 @end macro
     77 
     78 @macro kbditem{key, command}
     79 @item \key\
     80 @itemx M-x \command\
     81 @kindex \key\
     82 @findex \command\
     83 @c
     84 @end macro
     85 
     86 @macro kbditempair{key1, key2, command1, command2}
     87 @item \key1\, M-x \command1\
     88 @itemx \key2\, M-x \command2\
     89 @kindex \key1\
     90 @kindex \key2\
     91 @findex \command1\
     92 @findex \command2\
     93 @c
     94 @end macro
     95 
     96 @macro cmditem{command}
     97 @item M-x \command\
     98 @findex \command\
     99 @c
    100 @end macro
    101 
    102 @macro kbdanchorc{key, command, comment}
    103 @anchor{\command\}
    104 @item \key\
    105 @code{\command\}
    106 @i{\comment\}@*
    107 @end macro
    108 
    109 @macro fcnindex{name}
    110 @item \name\
    111 @xref{\name\}.
    112 @end macro
    113 
    114 @c Merge the variable and concept indices because both are rather short
    115 @synindex cp vr
    116 
    117 
    118 @c @setchapternewpage off
    119 @c @shortcontents
    120 @contents
    121 
    122 @ifnottex
    123 @node Top
    124 @top SLY
    125 
    126 @SLY{} is a Common Lisp IDE for Emacs. This is the manual for version
    127 @value{SLYVER}. (Last updated @value{UPDATED})
    128 
    129 @insertcopying
    130 @end ifnottex
    131 
    132 @menu
    133 * Introduction::
    134 * Getting started::
    135 * A SLY tour for SLIME users::
    136 * Working with source files::
    137 * Common functionality::
    138 * SLY REPL and other special buffers::
    139 * Customization::
    140 * Tips and Tricks::
    141 * Extensions::
    142 * Credits::
    143 * Key Index::
    144 * Command Index::
    145 * Variable Index::
    146 
    147 @detailmenu
    148  --- The Detailed Node Listing ---
    149 
    150 Getting started
    151 
    152 * Platforms::
    153 * Downloading::
    154 * Basic setup::
    155 * Running::
    156 * Basic customization::
    157 * Multiple Lisps::
    158 
    159 Working with source files
    160 
    161 * Evaluation::
    162 * Compilation::
    163 * Autodoc::
    164 * Semantic indentation::
    165 * Reader conditionals::
    166 * Macro-expansion::
    167 
    168 Common functionality
    169 
    170 * Finding definitions::
    171 * Cross-referencing::
    172 * Completion::
    173 * Interactive objects::
    174 * Documentation::
    175 * Multiple connections::
    176 * Disassembly::
    177 * Recovery::
    178 * Temporary buffers::
    179 * Multi-threading::
    180 
    181 SLY REPL and other special buffers
    182 
    183 * REPL::
    184 * Inspector::
    185 * Debugger::
    186 * Trace Dialog::
    187 * Stickers::
    188 
    189 SLY REPL: the ``top level''
    190 
    191 * REPL commands::
    192 * REPL output::
    193 * REPL backreferences::
    194 
    195 The SLY-DB Debugger
    196 
    197 * Examining frames::
    198 * Restarts::
    199 * Frame Navigation::
    200 * Miscellaneous::
    201 
    202 Customization
    203 
    204 * Emacs-side::
    205 * Lisp-side customization::
    206 
    207 Emacs-side
    208 
    209 * Keybindings::
    210 * Keymaps::
    211 * Defcustom variables::
    212 * Hooks::
    213 
    214 Lisp-side (Slynk)
    215 
    216 * Communication style::
    217 * Other configurables::
    218 
    219 Tips and Tricks
    220 
    221 * Connecting to a remote Lisp::
    222 * Loading Slynk faster::
    223 * Auto-SLY::
    224 * REPLs and game loops::
    225 * Controlling SLY from outside Emacs::
    226 
    227 Connecting to a remote Lisp
    228 
    229 * Setting up the Lisp image::
    230 * Setting up Emacs::
    231 * Setting up pathname translations::
    232 
    233 Extensions
    234 
    235 * Loading and unloading::
    236 * More contribs::
    237 
    238 More contribs
    239 
    240 * TRAMP Support::
    241 * Scratch Buffer::
    242 
    243 @end detailmenu
    244 @end menu
    245 
    246 @node Introduction
    247 @chapter Introduction
    248 
    249 @SLY{} is Sylvester the Cat's Common Lisp IDE.  It extends Emacs with
    250 support for interactive programming in Common Lisp.
    251 
    252 The features are centered around an Emacs minor-mode called
    253 @code{sly-mode}, which complements the standard major-mode
    254 @code{lisp-mode} for editing Lisp source files.  @code{sly-mode}
    255 adds support for interacting with a running Common Lisp process for
    256 compilation, debugging, documentation lookup, and so on.
    257 
    258 @SLY{} attempts to follow the example of Emacs's own native Emacs-Lisp
    259 environment.  Many of the keybindings and interface concepts used to
    260 interact with Emacs's Elisp machine are reused in @SLY{} to interact
    261 with the underlying Common Lisp run-times.  Emacs makes requests to
    262 these processes, asking them to compile files or code snippets; deliver
    263 introspection information various objects; or invoke commands or
    264 debugging restarts.
    265 
    266 Internally, @SLY{}'s user-interface, written in Emacs Lisp, is connected
    267 via sockets to one or more instances of a server program called
    268 ``Slynk'' that is running in the Lisp processes.
    269 
    270 The two sides communicate using a Remote Procedure Call (@acronym{RPC})
    271 protocol.  The Lisp-side server is primarily written in portable Common
    272 Lisp.  However, because some non-standard functionality is provided
    273 differently by each Lisp implementation (SBCL, CMUCL, Allegro, etc...)
    274 the Lisp-side server is again split into two parts -- portable and
    275 non-portable implementation -- which communicate using a well-defined
    276 interface.  Each Lisp implementation provides a separate implementation
    277 of that interface, making @SLY{} as a whole readily portable.
    278 
    279 @SLY{} is a direct fork of @acronym{SLIME}, the ``Superior Lisp
    280 Interaction Mode for Emacs'', which itself derived from previous Emacs
    281 programs such as @acronym{SLIM} and @acronym{ILISP}.  If you already
    282 know @acronym{SLIME}, @SLY{}'s closeness to it is immediately apparent.
    283 However, where @acronym{SLIME} has traditionally focused on the
    284 stability of its core functionality, @SLY{} aims for a richer feature
    285 set, a more consistent user interface, and an experience generally
    286 closer to Emacs' own.
    287 
    288 To understand the differences between the two projects read
    289 @SLY{}'s @uref{https://github.com/joaotavora/sly/blob/master/NEWS.md,,NEWS.md}
    290 file.  For a hand-on approach to these differences you might want to
    291 @ref{A SLY tour for SLIME users}.
    292 
    293 @node Getting started
    294 @chapter Getting started
    295 
    296 This chapter tells you how to get @SLY{} up and running.
    297 
    298 @menu
    299 * Platforms::
    300 * Downloading::
    301 * Basic setup::
    302 * Running::
    303 * Basic customization::
    304 * Multiple Lisps::
    305 @end menu
    306 
    307 @node Platforms
    308 @section Supported Platforms
    309 
    310 @SLY{} supports a wide range of operating systems and Lisp
    311 implementations. @SLY{} runs on Unix systems, Mac OSX, and Microsoft
    312 Windows. GNU Emacs versions 24.4 and above are supported. @emph{XEmacs
    313 or Emacs 23 are notably not supported}.
    314 
    315 The supported Lisp implementations, roughly ordered from the
    316 best-supported, are:
    317 
    318 @itemize @bullet
    319 @item
    320 CMU Common Lisp (@acronym{CMUCL}), 19d or newer
    321 @item
    322 Steel Bank Common Lisp (@acronym{SBCL}), 1.0 or newer
    323 @item
    324 Clozure Common Lisp (@acronym{CCL}), version 1.3 or newer
    325 @item
    326 LispWorks, version 4.3 or newer
    327 @item
    328 Allegro Common Lisp (@acronym{ACL}), version 6 or newer
    329 @item
    330 @acronym{CLISP}, version 2.35 or newer
    331 @item
    332 Armed Bear Common Lisp (@acronym{ABCL})
    333 @item
    334 Scieneer Common Lisp (@acronym{SCL}), version 1.2.7 or newer
    335 @item
    336 Embedded Common Lisp (@acronym{ECL})
    337 @item
    338 ManKai Common Lisp (@acronym{MKCL})
    339 @item
    340 Clasp
    341 @end itemize
    342 
    343 Most features work uniformly across implementations, but some are
    344 prone to variation. These include the precision of placing
    345 compiler-note annotations, @acronym{XREF} support, and fancy debugger
    346 commands (like ``restart frame'').
    347 
    348 @node Downloading
    349 @section Downloading SLY
    350 
    351 By far the easiest method for getting @SLY{} up and running is using
    352 Emacs’ package system configured to the popular MELPA repository. This
    353 snippet of code should already be in your configuration:
    354 
    355 @example
    356 (add-to-list 'package-archives
    357              '("melpa" . "https://melpa.org/packages/"))
    358 (package-initialize)
    359 @end example
    360 
    361 You should now be able to issue the command @kbd{M-x package-install},
    362 choose @kbd{sly} and have it be downloaded and installed
    363 automatically. If you don’t find it in the list, ensure you
    364 run @kbd{M-x package-refresh-contents} first.
    365 
    366 In other situations, such as when developing @SLY{} itself, you can
    367 access the @Git{} repository directly:
    368 
    369 @example
    370 git clone https://github.com/joaotavora/sly.git
    371 @end example
    372 
    373 If you want to hack on @SLY{}, use Github's @emph{fork} functionality
    374 and submit a @emph{pull request}. Be sure to first read the
    375 @uref{https://github.com/joaotavora/sly/blob/master/CONTRIBUTING.md,,CONTRIBUTING.md} file first.
    376 
    377 @node Basic setup
    378 @section Basic setup
    379 
    380 If you installed @SLY{} from MELPA, it is quite possible that you
    381 don’t need any more configuration, provided that @SLY{} can find a
    382 suitable Lisp executable in your @code{PATH} environment variable.
    383 
    384 Otherwise, you need to tell it where a Lisp program can be found, so
    385 customize the variable @code{inferior-lisp-program} (@pxref{Defcustom
    386 variables}) or add a line like this one to your @file{~/.emacs}
    387 or @file{~/.emacs.d/init.el} (@pxref{Emacs Init File}).
    388 
    389 @example
    390 (setq inferior-lisp-program "/opt/sbcl/bin/sbcl")
    391 @end example
    392 
    393 After evaluating this, you should be able to execute @kbd{M-x sly} and
    394 be greeted with a @REPL{}.
    395 
    396 If you cloned from the @Git{} repository, you’ll have to add a couple
    397 of more lines to your initialization file configuration:
    398 
    399 @example
    400 (add-to-list 'load-path "~/dir/to/cloned/sly")
    401 (require 'sly-autoloads)
    402 @end example
    403 
    404 @node Running
    405 @section Running SLY
    406 
    407 @SLY{} can either ask Emacs to start its own Lisp subprocesss or
    408 connect to a running process on a local or remote machine.
    409 
    410 The first alternative is more common for local development and is
    411 started via @kbd{M-x sly}. The ``inferior'' Lisp process thus started
    412 is told to load the Lisp-side server known as ``Slynk'' and then a
    413 socket connection is established between Emacs and Lisp. Finally
    414 a @REPL{} buffer is created where you can enter Lisp expressions for
    415 evaluation.
    416 
    417 The second alternative uses @kbd{M-x sly-connect}. This assumes that
    418 that a Slynk server is running on some local or remote host, and
    419 listening on a given port. @kbd{M-x sly-connect} prompts the user for
    420 these values, and upon connection the @REPL{} is established.
    421 
    422 @node Basic customization
    423 @section Basic customization
    424 
    425 A big part of Emacs, and Emacs’s extensions, are its near-infinite
    426 customization possibilities. @SLY{} is no exception, because it runs
    427 on both Emacs and the Lisp process, there are layers of Emacs-side
    428 customization and Lisp-side customization. But don’t be put off by
    429 this! @SLY{} tries hard to provide sensible defaults that don’t
    430 ``hide'' any fanciness beneath layers of complicated code, so that
    431 even a setup with no customization at all exposes @SLY{}’s most
    432 important functionality.
    433 
    434 Emacs-side customization is usually done via Emacs-lisp code snippets
    435 added to the user’s initialization file, usually @file{$HOME/.emacs} or
    436 @file{$HOME/.emacs.d/init.el} (@pxref{Emacs Init File}).
    437 
    438 90% of Emacs-lisp customization happens in either ``keymaps'' or
    439 ``hooks'' (@pxref{Emacs-side}). Still on the Emacs side, there is also a
    440 separate interface, appropriately called @code{customize} (or sometimes
    441 just @code{custom}), that uses a nicer UI with mouse-clickable buttons
    442 to set some special variables. See @xref{Defcustom variables}.
    443 
    444 Lisp-side customization is done exclusively via Common Lisp code
    445 snippets added to the user’s @file{$HOME/.slynkrc}
    446 file. See @xref{Lisp-side customization}.
    447 
    448 As a preview, take this simple example of a frequently customized part of
    449 @SLY{}: its keyboard shortcuts, known as ``keybindings''. In the
    450 following snippet @kbd{M-h} is added to @code{sly-prefix-map} thus
    451 yielding @kbd{C-c M-h} as a shortcut to
    452 the @code{sly-documentation-lookup} command.
    453 
    454 @example
    455 (eval-after-load 'sly
    456   `(define-key sly-prefix-map (kbd "M-h") 'sly-documentation-lookup))
    457 @end example
    458 
    459 @node Multiple Lisps
    460 @section Multiple Lisps
    461 
    462 By default, the command @kbd{M-x sly} starts the program specified
    463 with @code{inferior-lisp-program}, a variable that you can customize
    464 (@pxref{Defcustom variables}).  However, if you invoke @kbd{M-x sly}
    465 with a @emph{prefix argument}, meaning you type @kbd{C-u M-x sly} then
    466 Emacs prompts for the program which should be started instead.
    467 
    468 If you need to do this frequently or if the command involves long
    469 filenames it's more convenient to set
    470 the @code{sly-lisp-implementations} variable in your initialization file
    471 (@pxref{Emacs Init File}).  For example here we define two programs:
    472 
    473 @lisp
    474 (setq sly-lisp-implementations
    475       '((cmucl ("cmucl" "-quiet"))
    476         (sbcl ("/opt/sbcl/bin/sbcl") :coding-system utf-8-unix)))
    477 @end lisp
    478 
    479 Now, if you invoke @SLY{} with a @emph{negative} prefix argument,
    480 @kbd{M-- M-x sly}, you can select a program from that list. When
    481 called without a prefix, either the name specified in
    482 @code{sly-default-lisp}, or the first item of the list will be used.
    483 The elements of the list should look like
    484 
    485 @lisp
    486 (NAME (PROGRAM PROGRAM-ARGS...) &key CODING-SYSTEM INIT INIT-FUNCTION ENV)
    487 @end lisp
    488 
    489 @table @code
    490 @item NAME
    491 is a symbol and is used to identify the program.
    492 @item PROGRAM
    493 is the filename of the program.  Note that the filename can contain
    494 spaces.
    495 @item PROGRAM-ARGS
    496 is a list of command line arguments.
    497 @item CODING-SYSTEM
    498 the coding system for the connection.  (@pxref{sly-net-coding-system})x
    499 @item INIT
    500 should be a function which takes two arguments: a filename and a
    501 character encoding.  The function should return a Lisp expression as a
    502 string which instructs Lisp to start the Slynk server and to write the
    503 port number to the file.  At startup, @SLY{} starts the Lisp process
    504 and sends the result of this function to Lisp's standard input.  As
    505 default, @code{sly-init-command} is used.  An example is shown in
    506 @ref{init-example,,Loading Slynk faster}.
    507 @item INIT-FUNCTION
    508 should be a function which takes no arguments.  It is called after
    509 the connection is established. (See also @ref{sly-connected-hook}.)
    510 @item ENV
    511 specifies a list of environment variables for the subprocess. E.g.
    512 @lisp
    513 (sbcl-cvs ("/home/me/sbcl-cvs/src/runtime/sbcl"
    514            "--core" "/home/me/sbcl-cvs/output/sbcl.core")
    515           :env ("SBCL_HOME=/home/me/sbcl-cvs/contrib/"))
    516 @end lisp
    517 initializes @code{SBCL_HOME} in the subprocess.
    518 @end table
    519 
    520 @node A SLY tour for SLIME users
    521 @chapter A SLY tour for SLIME users
    522 
    523 The chances are that if you’re into Common Lisp, you already know about
    524 @SLIME{}, the project that originated @SLY{}.  Itself originating in
    525 older Emacs extensions @acronym{SLIM} and @acronym{ILISP}, @SLIME{} has
    526 been around for at least a decade longer than @SLY{} and is quite an
    527 amazing IDE.  It seems reasonable to assume that most Lispers have some
    528 experience with it, and perhaps it is an even more reasonable idea to
    529 provide, in the form of a quick tutorial, a hands-on overview of some of
    530 the improvements of @SLY{} over @SLIME{}.
    531 
    532 When you start @SLY{} with @kbd{M-x sly} (@pxref{Basic setup}) you are
    533 greeted with its @REPL{}, a common starting point of Lisp hacking
    534 sessions.  This has been completely redesigned in @SLY{}: you can spawn
    535 multiple REPL sessions with @code{sly-mrepl-new}; copy objects from most
    536 places directly into it (with @kbd{M-RET} and @kbd{M-S-RET}); and use a
    537 much more powerful incremental history search engine (with @kbd{C-r}).
    538 
    539 @*@image{images/tutorial-1,350pt}@*
    540 
    541 Starting from the new @REPL{}, let's showcase some of @SLY{}’s features.
    542 Let’s pretend we want to hack an existing Lisp project, say @SLY{}
    543 itself, or rather a part of its Lisp server which is called Slynk.
    544 Let's pretend we're intrigued by the way its ``flex''-style completion
    545 works.  What is ``flex''-style completion, you ask?  Well, if you're at
    546 the @REPL{} you can try it now: it's a way of @kbd{TAB}-completing
    547 (@pxref{Completion}) symbol names based on educated guesses of a few
    548 letters. Thus if we type @code{mvbind}, @SLY{} guesses that we probably
    549 meant @code{multiple-value-bind}, and if we type @code{domat} it might
    550 possibly guess @code{cl-ppcre:do-matches}.  Let's dig into the code that
    551 makes this happen.
    552 
    553 Where should we start though, if we know very little about this project?
    554 Well, a good point to start is always the @emph{apropos} functionality,
    555 which is a @code{grep} of sorts, but symbolic rather than purely
    556 textual.  In @SLY{}, @code{sly-apropos} will use the @code{CL-PPCRE}
    557 library if it finds is it loaded, else it falls back to a regex-less
    558 mode of searching.  If you
    559 have @uref{https://www.quicklisp.org/beta/,Quicklisp} you need only
    560 type @code{(ql:quickload :cl-ppcre)} from the @REPL{}.
    561 
    562 So if we want to hack on @SLY{}'s ``flex-completion'' functionality, but
    563 we don't any of its symbol's names.  We type
    564 @kbd{C-c C-d C-z} (the shortcut for @kbd{M-x sly-apropos-all}) and
    565 then type in ``sly.*flex'' at the prompt, followed by @kbd{enter}
    566 or @kbd{return} (abbreviated @code{RET} or @kbd{C-m}). @SLY{} should
    567 now present all Lisp symbols matching your search pattern.
    568 
    569 @*@image{images/tutorial-2,350pt}@*
    570 
    571 In the @code{apropos} buffer, let’s examine, by right-clicking it, the
    572 symbol @code{SLY-COMPLETIONS:FLEX-COMPLETIONS}.  We’ll be presented with
    573 a context menu with options for describing the symbol, inspecting it, or
    574 navigating to its source definition.  In general, the Lisp-side objects
    575 that SLY presents --- symbols, CLOS objects, function calls, etc... ---
    576 are right-clickable buttons with such a context menu
    577 (@pxref{Interactive objects}).  For now, let’s navigate to the source
    578 definition of the symbol by choosing ``Go To source'' from the menu.  We
    579 could also have just pressed @kbd{M-.} on the symbol, of course.
    580 
    581 From the Lisp source buffer that we landed on (probably
    582 @file{slynk-completion.lisp}), let’s @emph{trace} the newly found function
    583 @code{SLY-COMPLETIONS:FLEX-COMPLETIONS}.  However, instead of using the
    584 regular @code{CL:TRACE}, we’ll use @SLY{}’s Trace Dialog functionality.
    585 This is how we set it up:
    586 
    587 @enumerate
    588 
    589 @item
    590 first type @kbd{C-c C-t} on the function’s name, or enter that in the
    591 minibuffer prompt;
    592 
    593 @item
    594 now, open the Trace Dialog in a new window by typing @kbd{C-c T} (that’s
    595 a capital @code{T}).  We should already see our traced function under
    596 the heading ``Traced specs'';
    597 
    598 @item
    599 thirdly, for good measure, let’s also trace the nearby
    600 function @code{SLY-COMPLETIONS::FLEX-SCORE} by also typing @kbd{C-c C-t}
    601 on its name, or just entering it in the minibuffer prompt.
    602 
    603 @end enumerate
    604 
    605 Now let’s return to the REPL by switching to its
    606 @code{*sly-mrepl ...} buffer or typing @kbd{C-c C-z}. In the REPL, let’s try to
    607 complete some typical Lisp string by typing just @code{desbind} and then
    608 typing @kbd{TAB}. We should see a window popup including the desired
    609 completion @code{destructuring-bind} (it should also be the top
    610 match). Of course, we could now select some completion from the list,
    611 but instead let's just type @kbd{C-g} to dismiss
    612 the @code{*sly-completions*} window, since  we wanted to test
    613 completion, not write any actual @code{destructuring-bind} expression.
    614 
    615 Remember the traced functions in the Trace Dialog?  Let’s see if we got
    616 any traces: let's type @kbd{C-c T} to switch to that buffer, and then
    617 type capital @kbd{G}. This should produce a fair number of traces
    618 organized in a call graph.
    619 
    620 @*@image{images/tutorial-3,350pt}@*
    621 
    622 We can later learn more about this mode (@pxref{Trace Dialog}), but for
    623 now let’s again pretend we expected the function @code{FLEX-SCORE} to
    624 return a wildly different score for
    625 @code{COMMON-LISP:DESTRUCTURING-BIND}.  In that case we should like to
    626 witness said @code{FLEX-SCORE} function respond to any implementation
    627 improvements we perform.  To do so, it's useful to be able to surgically
    628 re-run that function with those very same arguments.  Let's do this by
    629 finding the function call in the Trace Dialog window, right-clicking it
    630 with the mouse and selecting ``Copy call to REPL''.  As an alternative,
    631 pressing @kbd{M-S-RET} on it also works.  Whichever way we do this, we
    632 are automatically transported to the REPL again, where the desired
    633 function call has already been typed out for us at the command prompt,
    634 awaiting a confirmation @kbd{RET}, which will run the function call.
    635 The call may look strange, though:
    636 
    637 @example
    638 ; The actual arguments passed to trace 15
    639 "desbind"
    640 "COMMON-LISP:DESTRUCTURING-BIND"
    641 (12 13 14 26 27 28 29)
    642 SLYNK-COMPLETION> (slynk-completion::flex-score #v1:0 #v1:1 #v1:2)
    643 0.003030303 (0.30303028%)
    644 SLYNK-COMPLETION>
    645 @end example
    646 
    647 @*@image{images/tutorial-4,350pt}@*
    648 
    649 So here’s what’s going on: to copy the call to the REPL, @SLY{} first
    650 copied over its actual arguments, and then wrote the function using
    651 special @emph{backreferences} to those arguments in the correct place.
    652 These are the @code{#v4:0} and @code{#v4:1} bits seen at the command
    653 prompt.  Let’s go ahead and put the cursor on them (or hover the mouse).
    654 See how this makes them highlight the corresponding object a few lines
    655 above in the buffer?  Later, you can also try typing ``#v'' at the REPL
    656 to incrementally write your own backreferences.
    657 
    658 For one final demonstration, let’s now suppose say we are still
    659 intrigued by how that function (@code{FLEX-SCORE}) works internally. So let's navigate to
    660 its definition using @kbd{M-.} again (or just open
    661 the @file{slynk-completion.lisp} buffer that you probably still have
    662 open). The function’s code might look like this:
    663 
    664 @example
    665 (defun flex-score (pattern string indexes)
    666   "Score the match of PATTERN on STRING.
    667 INDEXES as calculated by FLEX-MATCHES"
    668   ;; FIXME: hideously naive scoring
    669   (declare (ignore pattern))
    670   (float
    671    (/ 1
    672       (* (length string)
    673          (max 1
    674               (reduce #'+
    675                       (loop for (a b) on indexes
    676                             while b
    677                             collect (- b a 1))))))))
    678 @end example
    679 
    680 Can this function be working correctly?  What do all those expressions
    681 return?  Should we reach for good old C-style @code{printf}?  Let's try
    682 ``stickers'' instead.  SLY's stickers are a form of non-intrusive
    683 function instrumentation that work like carefully crafted @code{print}
    684 or @code{(format t ...)}), but are much easier to work with.  You can
    685 later read more about them (@pxref{Stickers}), but for now you can just
    686 think of them as colorful labels placed on s-exp’s.  Let’s place a bunch
    687 here, like this:
    688 
    689 @enumerate
    690 
    691 @item
    692 on the last line of @code{flex-score}, place your cursor on the first
    693 open parenthesis of that line (the opening parenthesis of the expression
    694 @code{(- b a 1)}) and press @kbd{C-c C-s C-s};
    695 
    696 @item
    697 now do the same for the symbol @code{indexes} a couple of lines above;
    698 
    699 @item
    700 again, the same for the expressions @code{(loop...)},
    701 @code{(reduce...)}, @code{(max...)}, @code{(length...)},
    702 @code{(*...)}, @code{(/... )} and @code{(float...)}.  You could have
    703 done this in any order, by the way;
    704 
    705 @end enumerate
    706 
    707 Now let’s recompile this definition with @kbd{C-c C-c}.  Beside the
    708 minibuffer note something about stickers being ``armed'' our function
    709 should now look like a rainbow in blue.
    710 
    711 @*@image{images/tutorial-5,350pt}@*
    712 
    713 Now we return to the @SLY{} REPL, but this time let’s use @kbd{C-c ~}
    714 (that’s @kbd{C-c} followed by ``tilde'') to do so.  This syncs the
    715 REPL’s local package and local directory to the Lisp file that we’re
    716 visiting.  This is something not strictly necessary here but generally
    717 convenient when hacking on a system, because you can now call functions
    718 from the file you came from without package-qualification.
    719 
    720 Now, to re-run the newly instrumented function, by calling it with the
    721 same arguments.  No need to type all that again, because this REPL
    722 supports reverse history i-search, remember?  So just type the
    723 binding @kbd{C-r} and then type something like @kbd{scor} to search
    724 history backwards and arrive at the function call copied to the REPL
    725 earlier.  Type @kbd{RET} once to confirm that's the call your after,
    726 and @kbd{RET} again to evaluate it.  Because those @code{#v...}
    727 backreferences are still trained specifically on those very same
    728 function arguments, you can be sure that the function call is
    729 equivalent.
    730 
    731 We can now use the @kbd{C-c C-s C-r} to @emph{replay} the sticker
    732 recordings of this last function call.  This is a kind of slow
    733 walk-through conducted in separate navigation window
    734 called @code{*sly-stickers-replay*} which pops up.  There we can see the
    735 Lisp value(s) that each sticker @code{eval}’ed to each time (or a note
    736 if it exited non-locally).  We can navigate recordings with @kbd{n} and
    737 @kbd{p}, and do the usual things allowed by interactive objects like
    738 inspecting them and returning them to the REPL. If you need help, toggle
    739 help by typing @kbd{h}.  There are lots of options here for navigating
    740 stickers, ignoring some stickers, etc.  When we’re done in this window,
    741 we press @kbd{q} to quit.
    742 
    743 @*@image{images/tutorial-6,350pt}@*
    744 
    745 Finally, we declare that we’re finished debugging @code{FLEX-MATCHES}.
    746 Even though stickers don’t get saved to the file in any way, we decide
    747 we’re not interested in them anymore.  So let’s open the ``SLY'' menu in
    748 the menu bar, find the ``Delete stickers from top-level form'' option
    749 under the ``Stickers'' sub-menu, and click it.  Alternatively, we could
    750 have typed @kbd{C-u C-c C-s C-s}.
    751 
    752 @node Working with source files
    753 @chapter Working with source files
    754 
    755 @SLY{}'s commands when editing a Lisp file are provided via
    756 @code{sly-editing-mode}, a minor-mode used in conjunction with Emacs's
    757 @code{lisp-mode}.
    758 
    759 This chapter describes @SLY{}’s commands for editing and working in
    760 Lisp source buffers. There are, of course, more @SLY{}’s commands that
    761 also apply to these buffers (@pxref{Common functionality}), but
    762 with very few exceptions these commands will always be run from
    763 a @code{.lisp} file.
    764 
    765 @menu
    766 * Evaluation::
    767 * Compilation::
    768 * Autodoc::
    769 * Semantic indentation::
    770 * Reader conditionals::
    771 * Macro-expansion::
    772 @end menu
    773 
    774 @node Evaluation
    775 @section Evaluating code
    776 
    777 These commands each evaluate a Common Lisp expression in a different
    778 way. Usually they mimic commands for evaluating Emacs Lisp code. By
    779 default they show their results in the echo area, but a prefix
    780 argument @kbd{C-u} inserts the results into the current buffer, while
    781 a negative prefix argument @kbd{M--} sends them to the kill ring.
    782 
    783 @table @kbd
    784 
    785 @kbditem{C-x C-e, sly-eval-last-expression}
    786 
    787 Evaluate the expression before point and show the result in the echo
    788 area.
    789 
    790 @kbditem{C-M-x, sly-eval-defun}
    791 Evaluate the current toplevel form and show the result in the echo
    792 area.  `C-M-x' treats `defvar' expressions specially.  Normally,
    793 evaluating a `defvar' expression does nothing if the variable it
    794 defines already has a value.  But `C-M-x' unconditionally resets the
    795 variable to the initial value specified in the `defvar' expression.
    796 This special feature is convenient for debugging Lisp programs.
    797 
    798 @end table
    799 
    800 If @kbd{C-M-x} or @kbd{C-x C-e} is given a numeric argument, it
    801 inserts the value into the current buffer, rather than displaying it
    802 in the echo area.
    803 
    804 @table @kbd
    805 @kbditem{C-c :, sly-interactive-eval}
    806 Evaluate an expression read from the minibuffer.
    807 
    808 @kbditem{C-c C-r, sly-eval-region}
    809 Evaluate the region.
    810 
    811 @kbditem{C-c C-p, sly-pprint-eval-last-expression}
    812 Evaluate the expression before point and pretty-print the result in a
    813 fresh buffer.
    814 
    815 @kbditem{C-c E, sly-edit-value}
    816 Edit the value of a setf-able form in a new buffer @file{*Edit <form>*}.
    817 The value is inserted into a temporary buffer for editing and then set
    818 in Lisp when committed with @kbd{C-c C-c}.
    819 
    820 @kbditem{C-c C-u, sly-undefine-function}
    821 Undefine the function, with @code{fmakunbound}, for the symbol at
    822 point.
    823 
    824 @end table
    825 
    826 @node Compilation
    827 @section Compiling functions and files
    828 
    829 @cindex Compilation
    830 
    831 @SLY{} has fancy commands for compiling functions, files, and
    832 packages. The fancy part is that notes and warnings offered by the
    833 Lisp compiler are intercepted and annotated directly onto the
    834 corresponding expressions in the Lisp source buffer. (Give it a try to
    835 see what this means.)
    836 
    837 @table @kbd
    838 @cindex Compiling Functions
    839 @kbditem{C-c C-c, sly-compile-defun}
    840 Compile the top-level form at point.  The region blinks shortly to
    841 give some feedback which part was chosen.
    842 
    843 With (positive) prefix argument the form is compiled with maximal
    844 debug settings (@kbd{C-u C-c C-c}). With negative prefix argument it is compiled for
    845 speed (@kbd{M-- C-c C-c}). If a numeric argument is passed set debug or speed settings
    846 to it depending on its sign.
    847 
    848 The code for the region is executed after compilation.  In principle,
    849 the command writes the region to a file, compiles that file, and loads
    850 the resulting code.
    851 
    852 This compilation may arm stickers (@pxref{Stickers}).
    853 
    854 @kbditem{C-c C-k, sly-compile-and-load-file}
    855 Compile and load the current buffer's source file.  If the compilation
    856 step fails, the file is not loaded.  It's not always easy to tell
    857 whether the compilation failed: occasionally you may end up in the
    858 debugger during the load step.
    859 
    860 With (positive) prefix argument the file is compiled with maximal
    861 debug settings (@kbd{C-u C-c C-k}). With negative prefix argument it is compiled for
    862 speed (@kbd{M-- C-c C-k}). If a numeric argument is passed set debug or speed settings
    863 to it depending on its sign.
    864 
    865 This compilation may arm stickers (@pxref{Stickers}).
    866 
    867 @kbditem{C-c M-k, sly-compile-file}
    868 Compile (but don't load) the current buffer's source file.
    869 
    870 @kbditem{C-c C-l, sly-load-file}
    871 Load a Lisp file.  This command uses the Common Lisp LOAD function.
    872 
    873 @cmditem{sly-compile-region}
    874 Compile the selected region.
    875 
    876 This compilation may arm stickers (@pxref{Stickers}).
    877 
    878 @end table
    879 
    880 The annotations are indicated as underlining on source forms. The
    881 compiler message associated with an annotation can be read either by
    882 placing the mouse over the text or with the selection commands below.
    883 
    884 @table @kbd
    885 @kbditem{M-n, sly-next-note}
    886 Move the point to the next compiler note and displays the note.
    887 
    888 @kbditem{M-p, sly-previous-note}
    889 Move the point to the previous compiler note and displays the note.
    890 
    891 @kbditem{C-c M-c, sly-remove-notes}
    892 Remove all annotations from the buffer.
    893 
    894 @kbditem{C-x `, next-error}
    895 Visit the next-error message.  This is not actually a @SLY{} command
    896 but @SLY{} creates a hidden buffer so that most of the Compilation
    897 mode commands (@inforef{Compilation Mode,, emacs}) work similarly for
    898 Lisp as for batch compilers.
    899 
    900 @end table
    901 
    902 @node Autodoc
    903 @section Autodoc
    904 
    905 SLY automatically shows information about symbols near the point. For
    906 function names the argument list is displayed, and for global
    907 variables, the value.  Autodoc is implemented by means
    908 of @code{eldoc-mode} of Emacs.
    909 
    910 @table @kbd
    911 @cmditem{sly-arglist NAME}
    912 Show the argument list of the function NAME.
    913 
    914 @cmditem{sly-autodoc-mode}
    915 Toggles autodoc-mode on or off according to the argument, and
    916 toggles the mode when invoked without argument.
    917 @cmditem{sly-autodoc-manually}
    918 Like sly-autodoc, but when called twice,
    919 or after sly-autodoc was already automatically called,
    920 display multiline arglist.
    921 @end table
    922 
    923 If @code{sly-autodoc-use-multiline-p} is set to non-nil,
    924 allow long autodoc messages to resize echo area display.
    925 
    926 @code{autodoc-mode} is a SLY extension  and can be turned off if you
    927 so wish (@pxref{Extensions})
    928 
    929 @node Semantic indentation
    930 @section Semantic indentation
    931 
    932 @SLY{} automatically discovers how to indent the macros in your Lisp
    933 system. To do this the Lisp side scans all the macros in the system and
    934 reports to Emacs all the ones with @code{&body} arguments. Emacs then
    935 indents these specially, putting the first arguments four spaces in and
    936 the ``body'' arguments just two spaces, as usual.
    937 
    938 This should ``just work.'' If you are a lucky sort of person you needn't
    939 read the rest of this section.
    940 
    941 To simplify the implementation, @SLY{} doesn't distinguish between
    942 macros with the same symbol-name but different packages. This makes it
    943 fit nicely with Emacs's indentation code. However, if you do have
    944 several macros with the same symbol-name then they will all be indented
    945 the same way, arbitrarily using the style from one of their
    946 arglists. You can find out which symbols are involved in collisions
    947 with:
    948 
    949 @example
    950 (slynk:print-indentation-lossage)
    951 @end example
    952 
    953 If a collision causes you irritation, don't have a nervous breakdown,
    954 just override the Elisp symbol's @code{sly-common-lisp-indent-function}
    955 property to your taste. @SLY{} won't override your custom settings, it
    956 just tries to give you good defaults.
    957 
    958 A more subtle issue is that imperfect caching is used for the sake of
    959 performance. @footnote{@emph{Of course} we made sure it was actually too
    960 slow before making the ugly optimization.}
    961 
    962 In an ideal world, Lisp would automatically scan every symbol for
    963 indentation changes after each command from Emacs. However, this is too
    964 expensive to do every time. Instead Lisp usually just scans the symbols
    965 whose home package matches the one used by the Emacs buffer where the
    966 request comes from. That is sufficient to pick up the indentation of
    967 most interactively-defined macros. To catch the rest we make a full scan
    968 of every symbol each time a new Lisp package is created between commands
    969 -- that takes care of things like new systems being loaded.
    970 
    971 You can use @kbd{M-x sly-update-indentation} to force all symbols to
    972 be scanned for indentation information.
    973 
    974 @node Reader conditionals
    975 @section Reader conditional fontification
    976 
    977 @SLY{} automatically evaluates reader-conditional expressions, like
    978 @code{#+linux}, in source buffers and ``grays out'' code that will be
    979 skipped for the current Lisp connection.
    980 
    981 @node Macro-expansion
    982 @section Macro-expansion commands
    983 
    984 @cindex Macros
    985 
    986 @table @kbd
    987 @kbditem{C-c C-m, sly-expand-1}
    988 Macroexpand (or compiler-macroexpand) the expression at point
    989 once.  If invoked with a prefix argument use macroexpand instead or
    990 macroexpand-1 (or compiler-macroexpand instead of
    991 compiler-macroexpand-1).
    992 
    993 @cmditem{sly-macroexpand-1}
    994 Macroexpand the expression at point once.  If invoked with a prefix
    995 argument, use macroexpand instead of macroexpand-1.
    996 
    997 @kbditem{C-c M-m, sly-macroexpand-all}
    998 Fully macroexpand the expression at point.
    999 
   1000 @cmditem{sly-compiler-macroexpand-1}
   1001 Display the compiler-macro expansion of sexp at point.
   1002 
   1003 @cmditem{sly-compiler-macroexpand}
   1004 Repeatedly expand compiler macros of sexp at point.
   1005 
   1006 @cmditem{sly-format-string-expand}
   1007 Expand the format-string at point and display it.
   1008 With prefix arg, or if no string at point, prompt the user for a
   1009 string to expand.
   1010 
   1011 @end table
   1012 
   1013 Within a sly macroexpansion buffer some extra commands are provided
   1014 (these commands are always available but are only bound to keys in a
   1015 macroexpansion buffer).
   1016 
   1017 @table @kbd
   1018 @kbditem{C-c C-m, sly-macroexpand-1-inplace}
   1019 Just like sly-macroexpand-1 but the original form is replaced with
   1020 the expansion.
   1021 
   1022 @c @anchor{sly-macroexpand-1-inplace}
   1023 @kbditem{g, sly-macroexpand-1-inplace}
   1024 The last macroexpansion is performed again, the current contents of
   1025 the macroexpansion buffer are replaced with the new expansion.
   1026 
   1027 @kbditem{q, sly-temp-buffer-quit}
   1028 Close the expansion buffer.
   1029 
   1030 @kbditem{C-_, sly-macroexpand-undo}
   1031 Undo last macroexpansion operation.
   1032 
   1033 @end table
   1034 
   1035 @node Common functionality
   1036 @chapter Common functionality
   1037 
   1038 This chapter describes the commands available throughout
   1039 @SLY{}-enabled buffers, which are not only Lisp source buffers, but
   1040 every auxiliary buffer created by @SLY{}, such as the @REPL{},
   1041 Inspector, etc (@pxref{SLY REPL and other special buffers}) In
   1042 general, it’s a good bet that if the buffer’s name starts with
   1043 @code{*sly-...*}, these commands and functionality will be available
   1044 there.
   1045 
   1046 @menu
   1047 * Finding definitions::
   1048 * Cross-referencing::
   1049 * Completion::
   1050 * Interactive objects::
   1051 * Documentation::
   1052 * Multiple connections::
   1053 * Disassembly::
   1054 * Recovery::
   1055 * Temporary buffers::
   1056 * Multi-threading::
   1057 @end menu
   1058 
   1059 @node Finding definitions
   1060 @section Finding definitions
   1061 
   1062 One of the most used keybindings across all of @SLY{} is the
   1063 familiar @kbd{M-.} binding for @kbd{sly-edit-definition}.
   1064 
   1065 Here's the gist of it: when pressed with the cursor over a symbol
   1066 name, that symbol's name definition is looked up by the Lisp process,
   1067 thus producing a Lisp source location, which might be a file, or a
   1068 file-less buffer. For convenience, a type of ``breadcrumb'' is left
   1069 behind at the original location where @kbd{M-.} was pressed, so that
   1070 another keybinding @kbd{M-,} takes the user back to the original
   1071 location. Thus multiple @kbd{M-.} trace a path through lisp sources
   1072 that can be traced back with an equal number of @kbd{M-,}.
   1073 
   1074 @table @kbd
   1075 @kbditem{M-., sly-edit-definition}
   1076 Go to the definition of the symbol at point.
   1077 
   1078 @item M-,
   1079 @itemx M-*
   1080 @itemx M-x sly-pop-find-definition-stack
   1081 @kindex M-,
   1082 @findex sly-pop-find-definition-stack
   1083 Go back to the point where @kbd{M-.} was invoked. This gives multi-level
   1084 backtracking when @kbd{M-.} has been used several times.
   1085 
   1086 @kbditem{C-x 4 ., sly-edit-definition-other-window}
   1087 Like @code{sly-edit-definition} but switches to the other window to
   1088 edit the definition in.
   1089 
   1090 @kbditem{C-x 5 ., sly-edit-definition-other-frame}
   1091 Like @code{sly-edit-definition} but opens another frame to edit the
   1092 definition in.
   1093 @end table
   1094 
   1095 The behaviour of the @kbd{M-.} binding is sometimes affected by the
   1096 type of symbol you are giving it.
   1097 
   1098 @itemize @bullet
   1099 @item
   1100 For single functions or variables, @kbd{M-.} immediately switches
   1101 the current window's buffer and position to the target @code{defun} or
   1102 @code{defvar}.
   1103 
   1104 @item
   1105 For symbols with more than one associated definition, say, generic
   1106 functions, the same @kbd{M-.} finds all methods and presents these
   1107 results in separate window displaying a special @code{*sly-xref*}
   1108 buffer (@pxref{Cross-referencing}).
   1109 @end itemize
   1110 
   1111 @node Cross-referencing
   1112 @section Cross-referencing
   1113 
   1114 Finding and presenting the definition of a function is actually the
   1115 most elementary aspect of broader @emph{cross-referencing} facilities
   1116 framework in @SLY{}. There are other types of questions about the
   1117 source code relations that you can ask the Lisp process.@footnote{This
   1118 depends on the underlying implementation of some of these facilities:
   1119 for systems with no built-in @acronym{XREF} support @SLY{} queries a
   1120 portable
   1121 @acronym{XREF} package, which is taken from the @cite{CMU AI
   1122 Repository} and bundled with @SLY{}.}
   1123 
   1124 The following keybindings behave much like the @kbd{M-.} keybinding
   1125 (@pxref{Finding definitions}): when pressed as is they make a query
   1126 about the symbol at point, but with a @kbd{C-u} prefix argument they
   1127 prompt the user for a symbol. Importantly, they always popup a
   1128 transient @code{*sly-xref*} buffer in a different window.
   1129 
   1130 @table @kbd
   1131 @kbditem{M-?, sly-edit-uses}
   1132 Find all the references to this symbol, whatever the type of that
   1133 reference.
   1134 
   1135 @kbditem{C-c C-w C-c, sly-who-calls}
   1136 Show function callers.
   1137 
   1138 @kbditem{C-c C-w C-w, sly-calls-who}
   1139 Show all known callees.
   1140 
   1141 @kbditem{C-c C-w C-r, sly-who-references}
   1142 Show references to global variable.
   1143 
   1144 @kbditem{C-c C-w C-b, sly-who-binds}
   1145 Show bindings of a global variable.
   1146 
   1147 @kbditem{C-c C-w C-s, sly-who-sets}
   1148 Show assignments to a global variable.
   1149 
   1150 @kbditem{C-c C-w C-m, sly-who-macroexpands}
   1151 Show expansions of a macro.
   1152 
   1153 @cmditem{sly-who-specializes}
   1154 Show all known methods specialized on a class.
   1155 
   1156 @end table
   1157 
   1158 There are two further ``List callers/callees'' commands that operate
   1159 by rummaging through function objects on the heap at a low-level to
   1160 discover the call graph. They are only available with some Lisp
   1161 systems, and are most useful as a fallback when precise @acronym{XREF}
   1162 information is unavailable.
   1163 
   1164 @table @kbd
   1165 @kbditem{C-c <, sly-list-callers}
   1166 List callers of a function.
   1167 
   1168 @kbditem{C-c >, sly-list-callees}
   1169 List callees of a function.
   1170 
   1171 @end table
   1172 
   1173 In the resulting @code{*sly-xref*} buffer, these commands are
   1174 available:
   1175 
   1176 @table @kbd
   1177 @kbditem{RET, sly-show-xref}
   1178 Show definition at point in the other window. Do not leave
   1179 the @code{*sly-xref} buffer.
   1180 
   1181 @kbditem{Space, sly-goto-xref}
   1182 Show definition at point in the other window and close
   1183 the @code{*sly-xref} buffer.
   1184 
   1185 @kbditem{C-c C-c, sly-recompile-xref}
   1186 Recompile definition at point. Uses prefix arguments like
   1187 @code{sly-compile-defun}.
   1188 
   1189 @kbditem{C-c C-k, sly-recompile-all-xrefs}
   1190 Recompile all definitions. Uses prefix arguments like
   1191 @code{sly-compile-defun}.
   1192 
   1193 @end table
   1194 
   1195 @node Completion
   1196 @section Auto-completion
   1197 
   1198 @cindex Completion
   1199 @cindex Symbol Completion
   1200 
   1201 Completion commands are used to complete a symbol or form based on
   1202 what is already present at point. Emacs has many completion mechanisms
   1203 that @SLY{} tries to mimic as much as possible.
   1204 
   1205 SLY provides two styles of completion. The choice between them happens
   1206 in the Emacs customization variable
   1207 @pxref{sly-complete-symbol-function}, which can be set to two values,
   1208 or methods:
   1209 
   1210 @enumerate
   1211 @item @code{sly-flex-completions}
   1212 This method is speculative. It assumes that the letters you've already
   1213 typed aren't necessarily an exact prefix of the symbol you're thinking
   1214 of. Therefore, any possible completion that contains these letters, in
   1215 the order that you have typed them, is potentially a match. Completion
   1216 matches are then sorted according to a score that should reflect the
   1217 probability that you really meant that them.
   1218 
   1219 Flex completion implies that the package-qualification needed to
   1220 access some symbols is automatically discovered for you. However, to
   1221 avoid searching too many symbols unnecessarily, this method makes some
   1222 minimal assumptions that you can override: it assumes, for example,
   1223 that you don't normally want to complete to fully qualified internal
   1224 symbols, but will do so if it finds two consecutive colons (@code{::})
   1225 in your initial pattern. Similarly, it assumes that if you start a
   1226 completion on a word starting @code{:}, you must mean a keyword (a
   1227 symbol from the keyword package.)
   1228 
   1229 Here are the top results for some typical searches.
   1230 
   1231 @example
   1232 CL-USER> (quiloa<TAB>)         ->  (ql:quickload)
   1233 CL-USER> (mvbind<TAB>)         ->  (multiple-value-bind)
   1234 CL-USER> (scan<TAB>)           ->  (ppcre:scan)
   1235 CL-USER> (p::scan<TAB>)        ->  (ppcre::scanner)
   1236 CL-USER> (setf locadirs<TAB>)  ->  (setf ql:*local-project-directories*)
   1237 CL-USER> foobar                ->  asdf:monolithic-binary-op
   1238 @end example
   1239 
   1240 @item @code{sly-simple-completions}
   1241 This method uses ``classical'' completion on an exact prefix. Although
   1242 poorer, this is simpler, more predictable and closer to the default
   1243 Emacs completion method. You type a prefix for a symbol reference and
   1244 @SLY{} let's you choose from symbols whose beginnings match it
   1245 exactly.
   1246 @end enumerate
   1247 
   1248 As an enhancement in @SLY{} over Emacs' built-in completion styles,
   1249 when the @code{*sly-completions*} buffer pops up, some keybindings are
   1250 momentarily diverted to it:
   1251 
   1252 @table @kbd
   1253 @item C-n
   1254 @itemx <down>
   1255 @itemx M-x sly-next-completion
   1256 @kindex C-n
   1257 @findex sly-next-completion
   1258 Select the next completion.
   1259 
   1260 @item C-p
   1261 @itemx <up>
   1262 @itemx M-x sly-prev-completion
   1263 @kindex C-p
   1264 @findex sly-prev-completion
   1265 Select the previous completion.
   1266 
   1267 @item tab
   1268 @itemx RET
   1269 @itemx M-x sly-choose-completion
   1270 @kindex tab
   1271 @findex sly-choose-completion
   1272 Choose the currently selected completion and enter it at point.
   1273 @end table
   1274 
   1275 As soon as the user selects a completion or gives up by
   1276 pressing @kbd{C-g} or moves out of the symbol being completed, the
   1277 @code{*sly-completions*} buffer is closed.
   1278 
   1279 @node Interactive objects
   1280 @section Interactive objects
   1281 
   1282 In many buffers and modes in @SLY{}, there are snippets of text that
   1283 represent objects ``living'' in the Lisp process connected to @SLY{}.
   1284 These regions are known in @SLY{} as interactive values or objects.
   1285 You can tell these objects from regular text by their distinct
   1286 ``face'', is Emacs parlance for text colour, or decoration.  Another
   1287 way to check if bit of text is an interactive object is to hover above
   1288 it with the mouse and right-click (@kbd{<mouse-3>}) it: a context menu
   1289 will appear listing actions that you can take on that object.
   1290 
   1291 @c Yet another way to discover these objects is
   1292 @c with @kbd{sly-button-forward} and @kbd{sly-button-backward}
   1293 
   1294 Depending on the mode, different actions may be active for different
   1295 types of objects. Actions can also be invoked using keybindings active
   1296 only when the cursor is on the button.
   1297 
   1298 @table @kbd
   1299 
   1300 @item @kbd{M-RET}, ``Copy to REPL''
   1301 
   1302 Copy the object to the main @REPL{} (@pxref{REPL output} and @pxref{REPL
   1303 backreferences}).
   1304 
   1305 @item @kbd{M-S-RET}, ``Copy call to REPL''
   1306 
   1307 An experimental feature. On some backtrace frames in the Debugger
   1308 (@pxref{Debugger}) and Trace Dialog (@pxref{Trace Dialog}), copy
   1309 the object to the main @REPL{}. That’s @emph{meta-shift-return}, by
   1310 the way, there’s no capital ``S''.
   1311 
   1312 @item @kbd{.},''Go To Source''
   1313 
   1314 For function symbols, debugger frames, or traced function calls, go to
   1315 the Lisp source, much like with @kbd{M-.}.
   1316 
   1317 @item @kbd{v},''Show Source''
   1318 
   1319 For function symbols, debugger frames, or traced function calls, show
   1320 the Lisp source in another window, but don’t switch to it.
   1321 
   1322 @item @kbd{p},''Pretty Print''
   1323 
   1324 Pretty print the object in a separate buffer, much
   1325 like @code{sly-pprint-eval-last-expression}.
   1326 
   1327 @item @kbd{i},''Inspect''
   1328 
   1329 Inspect the object in a separate inspector buffer (@pxref{Inspector}).
   1330 
   1331 @item @kbd{d},''Describe''
   1332 
   1333 Describe the object in a separate buffer using Lisp’s
   1334 @code{CL:DESCRIBE}.
   1335 
   1336 @end table
   1337 
   1338 @node Documentation
   1339 @section Documentation commands
   1340 
   1341 @SLY{}'s online documentation commands follow the example of Emacs
   1342 Lisp. The commands all share the common prefix @kbd{C-c C-d} and allow
   1343 the final key to be modified or unmodified (@pxref{Keybindings}.)
   1344 
   1345 @table @kbd
   1346 
   1347 @cmditem{sly-info}
   1348 This command should land you in an electronic version of this very
   1349 manual that you can read inside Emacs.
   1350 
   1351 @kbditem{C-c C-d C-d, sly-describe-symbol}
   1352 Describe the symbol at point.
   1353 
   1354 @kbditem{C-c C-d C-f, sly-describe-function}
   1355 Describe the function at point.
   1356 
   1357 @kbditem{C-c C-d C-a, sly-apropos}
   1358 Perform an apropos search on Lisp symbol names for a regular expression
   1359 match and display their documentation strings. By default the external
   1360 symbols of all packages are searched. With a prefix argument you can choose a
   1361 specific package and whether to include unexported symbols.
   1362 
   1363 @kbditem{C-c C-d C-z, sly-apropos-all}
   1364 Like @code{sly-apropos} but also includes internal symbols by default.
   1365 
   1366 @kbditem{C-c C-d C-p, sly-apropos-package}
   1367 Show apropos results of all symbols in a package. This command is for
   1368 browsing a package at a high-level. With package-name completion it
   1369 also serves as a rudimentary Smalltalk-ish image-browser.
   1370 
   1371 @kbditem{C-c C-d C-h, sly-hyperspec-lookup}
   1372 Lookup the symbol at point in the @cite{Common Lisp Hyperspec}. This
   1373 uses the familiar @file{hyperspec.el} to show the appropriate section
   1374 in a web browser. The Hyperspec is found either on the Web or in
   1375 @code{common-lisp-hyperspec-root}, and the browser is selected by
   1376 @code{browse-url-browser-function}.
   1377 
   1378 Note: this is one case where @kbd{C-c C-d h} is @emph{not} the same as
   1379 @kbd{C-c C-d C-h}.
   1380 
   1381 @kbditem{C-c C-d ~, hyperspec-lookup-format}
   1382 Lookup a @emph{format character} in the @cite{Common Lisp Hyperspec}.
   1383 
   1384 @kbditem{C-c C-d #, hyperspec-lookup-reader-macro}
   1385 Lookup a @emph{reader macro} in the @cite{Common Lisp Hyperspec}.
   1386 @end table
   1387 
   1388 @node Multiple connections
   1389 @section Multiple connections
   1390 
   1391 @SLY{} is able to connect to multiple Lisp processes at the same
   1392 time. The @kbd{M-x sly} command, when invoked with a prefix
   1393 argument, will offer to create an additional Lisp process if one is
   1394 already running. This is often convenient, but it requires some
   1395 understanding to make sure that your @SLY{} commands execute in the
   1396 Lisp that you expect them to.
   1397 
   1398 Some @SLY{} buffers are tied to specific Lisp processes. It’s easy
   1399 read that from the buffer’s name which will usually be
   1400 @code{*sly-<something> for <connection>*}, where @code{connection} is
   1401 the name of the connection.
   1402 
   1403 Each Lisp connection has its own main @acronym{REPL} buffer
   1404 (@pxref{REPL}), and all expressions entered or @SLY{} commands invoked
   1405 in that buffer are sent to the associated connection. Other buffers
   1406 created by @SLY{} are similarly tied to the connections they originate
   1407 from, including @SLY-DB{} buffers (@pxref{Debugger}), apropos result
   1408 listings, and so on. These buffers are the result of some interaction
   1409 with a Lisp process, so commands in them always go back to that same
   1410 process.
   1411 
   1412 Commands executed in other places, such as @code{sly-mode} source
   1413 buffers, always use the ``default'' connection. Usually this is the
   1414 most recently established connection, but this can be reassigned via
   1415 the ``connection list'' buffer:
   1416 
   1417 @table @kbd
   1418 @kbditem{C-c C-x c, sly-list-connections}
   1419 Pop up a buffer listing the established connections.
   1420 
   1421 @kbditem{C-c C-x n, sly-next-connection}
   1422 Switch to the next Lisp connection by cycling through all connections.
   1423 
   1424 @kbditem{C-c C-x p, sly-prev-connection}
   1425 Switch to the previous Lisp connection by cycling through all connections.
   1426 
   1427 @end table
   1428 
   1429 The buffer displayed by @code{sly-list-connections} gives a one-line
   1430 summary of each connection. The summary shows the connection's serial
   1431 number, the name of the Lisp implementation, and other details of the
   1432 Lisp process. The current ``default'' connection is indicated with an
   1433 asterisk.
   1434 
   1435 The commands available in the connection-list buffer are:
   1436 
   1437 @table @kbd
   1438 @kbditem{RET, sly-goto-connection}
   1439 Pop to the @acronym{REPL} buffer of the connection at point.
   1440 
   1441 @kbditem{d, sly-connection-list-make-default}
   1442 Make the connection at point the ``default'' connection. It will then
   1443 be used for commands in @code{sly-mode} source buffers.
   1444 
   1445 @kbditem{g, sly-update-connection-list}
   1446 Update the connection list in the buffer.
   1447 
   1448 @kbditem{q, sly-temp-buffer-quit}
   1449 Quit the connection list (kill buffer, restore window configuration).
   1450 
   1451 @kbditem{R, sly-restart-connection-at-point}
   1452 Restart the Lisp process for the connection at point.
   1453 
   1454 @cmditem{sly-connect}
   1455 Connect to a running Slynk server. With prefix argument, asks if all
   1456 connections should be closed first.
   1457 
   1458 @cmditem{sly-disconnect}
   1459 Disconnect all connections.
   1460 
   1461 @cmditem{sly-abort-connection}
   1462 Abort the current attempt to connect.
   1463 
   1464 @end table
   1465 
   1466 @node Disassembly
   1467 @section Disassembly commands
   1468 
   1469 @table @kbd
   1470 
   1471 @kbditem{C-c M-d, sly-disassemble-symbol}
   1472 Disassemble the function definition of the symbol at point.
   1473 
   1474 @kbditem{C-c C-t, sly-toggle-trace-fdefinition}
   1475 Toggle tracing of the function at point.  If invoked with a prefix
   1476 argument, read additional information, like which particular method
   1477 should be traced.
   1478 
   1479 @cmditem{sly-untrace-all}
   1480 Untrace all functions.
   1481 
   1482 @end table
   1483 
   1484 @node Recovery
   1485 @section Abort/Recovery commands
   1486 
   1487 @table @kbd
   1488 @kbditem{C-c C-b, sly-interrupt}
   1489 Interrupt Lisp (send @code{SIGINT}).
   1490 
   1491 @cmditem{sly-restart-inferior-lisp}
   1492 Restart the @code{inferior-lisp} process.
   1493 
   1494 @kbditem{C-c ~, sly-mrepl-sync}
   1495 Synchronize the current package and working directory from Emacs to
   1496 Lisp.
   1497 
   1498 @cmditem{sly-cd}
   1499 Set the current directory of the Lisp process.  This also
   1500 changes the current directory of the REPL buffer.
   1501 
   1502 @cmditem{sly-pwd}
   1503 Print the current directory of the Lisp process.
   1504 
   1505 @end table
   1506 
   1507 @node Temporary buffers
   1508 @section Temporary buffers
   1509 
   1510 Some @SLY{} commands create temporary buffers to display their
   1511 results. Although these buffers usually have their own special-purpose
   1512 major-modes, certain conventions are observed throughout.
   1513 
   1514 Temporary buffers can be dismissed by pressing @kbd{q}. This kills the
   1515 buffer and restores the window configuration as it was before the
   1516 buffer was displayed. Temporary buffers can also be killed with the
   1517 usual commands like @code{kill-buffer}, in which case the previous
   1518 window configuration won't be restored.
   1519 
   1520 Pressing @kbd{RET} is supposed to ``do the most obvious useful
   1521 thing.'' For instance, in an apropos buffer this prints a full
   1522 description of the symbol at point, and in an @acronym{XREF} buffer it
   1523 displays the source code for the reference at point. This convention
   1524 is inherited from Emacs's own buffers for apropos listings,
   1525 compilation results, etc.
   1526 
   1527 Temporary buffers containing Lisp symbols use @code{sly-mode} in
   1528 addition to any special mode of their own. This makes the usual
   1529 @SLY{} commands available for describing symbols, looking up
   1530 function definitions, and so on.
   1531 
   1532 Initial focus of those ``description'' buffers depends on the variable
   1533 @code{sly-description-autofocus}. If @code{nil} (the default),
   1534 description buffers do not receive focus automatically, and vice
   1535 versa.
   1536 
   1537 @node Multi-threading
   1538 @section Multi-threading
   1539 
   1540 If the Lisp system supports multi-threading, SLY spawns a new thread
   1541 for each request, e.g., @kbd{C-x C-e} creates a new thread to evaluate
   1542 the expression.  An exception to this rule are requests from the
   1543 @REPL{}: all commands entered in the @REPL{} buffer are evaluated in a
   1544 dedicated @REPL{} thread.
   1545 
   1546 You can see a listing of the threads for the current connection with
   1547 the command @code{M-x sly-list-threads}, or @code{C-c C-x t}. This
   1548 pops open a @code{*sly-threads*} buffer, where some keybindings to
   1549 control threads are active, if you know what you are doing. The most
   1550 useful is probably @kbd{k} to kill a thread, but type @kbd{C-h m} in
   1551 that buffer to get a full listing.
   1552 
   1553 Some complications arise with multi-threading and special variables.
   1554 Non-global special bindings are thread-local, e.g., changing the value
   1555 of a let bound special variable in one thread has no effect on the
   1556 binding of the variables with the same name in other threads.  This
   1557 makes it sometimes difficult to change the printer or reader behaviour
   1558 for new threads.  The variable
   1559 @code{slynk:*default-worker-thread-bindings*} was introduced for such
   1560 situations: instead of modifying the global value of a variable, add a
   1561 binding the @code{slynk:*default-worker-thread-bindings*}.  E.g., with
   1562 the following code, new threads will read floating point values as
   1563 doubles by default:
   1564 
   1565 @example
   1566 (push '(*read-default-float-format* . double-float)
   1567        slynk:*default-worker-thread-bindings*).
   1568 @end example
   1569 
   1570 @node SLY REPL and other special buffers
   1571 @chapter SLY REPL and other special buffers
   1572 
   1573 @menu
   1574 * REPL::
   1575 * Inspector::
   1576 * Debugger::
   1577 * Trace Dialog::
   1578 * Stickers::
   1579 @end menu
   1580 
   1581 @node REPL
   1582 @section SLY REPL: the ``top level''
   1583 
   1584 @cindex Listener
   1585 
   1586 @SLY{} uses a custom Read-Eval-Print Loop (@REPL{}, also known as a
   1587 ``top level'', or listener):
   1588 
   1589 @itemize @bullet
   1590 @item
   1591 Conditions signalled in @REPL{} expressions are debugged with the
   1592 integrated SLY debugger.
   1593 @item
   1594 Return values are interactive values (@pxref{Interactive objects})
   1595 distinguished from printed output by separate Emacs faces (colors).
   1596 @item
   1597 Output from the Lisp process is inserted in the right place, and
   1598 doesn't get mixed up with user input.
   1599 @item
   1600 Multiple @REPL{}s are possible in the same Lisp connection. This is
   1601 useful for performing quick one-off experiments in different packages
   1602 or directories without disturbing the state of an existing REPL.
   1603 @item
   1604 The REPL is a central hub for much of SLY's functionality, since
   1605 objects examined in the inspector (@pxref{Inspector}), debugger
   1606 (@pxref{Debugger}), and other extensions can be returned there.
   1607 @end itemize
   1608 
   1609 Switching to the @REPL{} from anywhere in a @SLY{} buffer is a very
   1610 common task. One way to do it is to find the @code{*sly-mrepl...*}
   1611 buffer in Emacs’s buffer list, but there are other ways to reach a
   1612 @REPL{}.
   1613 
   1614 @table @kbd
   1615 @kbditem{C-c C-z, sly-mrepl}
   1616 Start or select an existing main @REPL{} buffer.
   1617 
   1618 @cmditem{sly-mrepl-new}
   1619 Start a new secondary @REPL session, prompting for a nickname.
   1620 
   1621 @kbditem{C-c ~, sly-mrepl-sync}
   1622 Go to the REPL, switching package and default directory as
   1623 applicable. More precisely the Lisp variables @code{*package*} and
   1624 @code{*default-pathname-defaults*} are affected by the location
   1625 where the command was issued. In a specific position of a @code{.lisp}
   1626 file, for instance the current package and that file’s directory are
   1627 chosen.
   1628 @end table
   1629 
   1630 @menu
   1631 * REPL commands::
   1632 * REPL output::
   1633 * REPL backreferences::
   1634 @end menu
   1635 
   1636 @node REPL commands
   1637 @subsection REPL commands
   1638 
   1639 @table @kbd
   1640 
   1641 @kbditem{RET, sly-mrepl-return}
   1642 
   1643 Evaluate the expression at prompt and return the result.
   1644 
   1645 @kbditem{TAB, sly-mrepl-indent-and-complete-symbol}
   1646 
   1647 Indent the current line. If line already indented complete the symbol
   1648 at point (@pxref{Completion}). If there is not symbol at point show
   1649 the argument list of the most recently enclosed function or macro in
   1650 the minibuffer.
   1651 
   1652 @kbditem{M-p, sly-mrepl-previous-input-or-button}
   1653 
   1654 When at the current prompt, fetches previous input from the history,
   1655 otherwise jumps to the previous interactive value (@pxref{Interactive
   1656 objects}) representing a Lisp object.
   1657 
   1658 @kbditem{M-n, sly-mrepl-next-input-or-button}
   1659 
   1660 When at the current prompt, fetches next input from the history,
   1661 otherwise jumps to the previous interactive value representing a
   1662 Lisp object.
   1663 
   1664 @kbditem{C-r, isearch-backward}
   1665 
   1666 This regular Emacs keybinding, when invoked at the current @REPL{}
   1667 prompt, starts a special transient mode turning the prompt into the
   1668 string ``History-isearch backward''. While in this mode, the user can
   1669 compose a string used to search backwards through history, and reverse
   1670 the direction of search by pressing @kbd{C-s}. When invoked outside
   1671 the current @REPL{} prompt, does a normal text search through the
   1672 buffer contents.
   1673 
   1674 @kbditem{C-c C-b, sly-interrupt}
   1675 
   1676 Interrupts the current thread of the inferior-lisp process.
   1677 
   1678 For convenience this function is also bound to @kbd{C-c C-c}.
   1679 
   1680 @kbditem{C-M-p, sly-button-backward}
   1681 
   1682 Jump to the previous interactive value representing a Lisp object.
   1683 
   1684 @kbditem{C-M-n, sly-button-forward}
   1685 
   1686 Jump to the next interactive value representing a Lisp object.
   1687 
   1688 @kbditem{C-c C-o, sly-mrepl-clear-recent-output}
   1689 
   1690 Clear output between current and last REPL prompts, keeping results.
   1691 
   1692 @kbditem{C-c M-o, sly-mrepl-clear-repl}
   1693 
   1694 Clear the whole REPL of output and results.
   1695 
   1696 @end table
   1697 
   1698 @node REPL output
   1699 @subsection REPL output
   1700 
   1701 REPLs wouldn’t be much use if they just took user input and didn’t
   1702 print anything back. In @SLY{} the output printed to the REPL can
   1703 come from four different places:
   1704 
   1705 @itemize @bullet
   1706 
   1707 @item
   1708 A function’s return values. One line per return value is printed. Each
   1709 line of printed text, called a @REPL{} result, persists after more
   1710 expressions are evaluated, and is actually a button
   1711 (@pxref{Interactive objects}) presenting the Lisp-side object. You
   1712 can, for instance, inspect it (@pxref{Inspector}) or re-return it to
   1713 right before the current command prompt so that you may conjure it up
   1714 again, as usual in Lisp @REPL{}s, with the special variable @code{*}.
   1715 
   1716 In the @SLY{} @REPL{}, in addition to the @code{*}, @code{**}
   1717 and @code{***} special variables, return values can also be accessed
   1718 through a special backreference (@pxref{REPL backreferences}).
   1719 
   1720 @item
   1721 An object may be copied to the REPL from some other part in @SLY{},
   1722 such as the Inspector (@pxref{Inspector}), Debugger
   1723 (@pxref{Debugger}), etc. using the familiar @kbd{M-RET} binding, or by
   1724 selecting ``Copy to REPL'' from the context menu of an interactive
   1725 object. Aside from not having been produced by the evaluation of a
   1726 Lisp form in the @REPL{}, these objects behaves exactly like a @REPL{}
   1727 result.
   1728 
   1729 @item
   1730 The characters printed to the standard Lisp streams
   1731 @code{*standard-output*}, @code{*error-output*}
   1732 and @code{*trace-output*} as a @emph{synchronous} and direct result of
   1733 the evaluation of an expression in the @REPL{}.
   1734 
   1735 @item
   1736 The characters printed to the standard Lisp streams
   1737 @code{*standard-output*}, @code{*error-output*} and
   1738 @code{*trace-output*} printed, perhaps @emph{asynchronously},
   1739 from others threads, for instance. This feature is optional and
   1740 controlled by the variable @code{SLYNK:*GLOBALLY-REDIRECT-IO*}.
   1741 @end itemize
   1742 
   1743 @noindent
   1744 For advanced users, there are some Lisp-side Slynk variables affecting
   1745 the way Slynk transmits @REPL{} output to @SLY{}.
   1746 
   1747 @table @code
   1748 @item @code{SLYNK:*GLOBALLY-REDIRECT-IO*}
   1749 
   1750 This variable controls the global redirection of the the standard
   1751 streams (@code{*standard-output*}, etc) to the @REPL{} in Emacs. The
   1752 default value is @code{:started-from-emacs}, which means that
   1753 redirection should only take place upon @code{M-x sly} invocations.
   1754 When @code{t}, global redirection happens even for sessions started with
   1755 @code{M-x sly-connect}, meaning output may be diverted from wherever
   1756 you started the Lisp server originally.
   1757 
   1758 When @code{NIL} these streams are only temporarily redirected to Emacs
   1759 using dynamic bindings while handling requests, meaning you only see
   1760 output caused by the commands you issued to the REPL.
   1761 
   1762 Note that @code{*standard-input*} is currently never globally redirected
   1763 into Emacs, because it can interact badly with the Lisp's native @REPL{}
   1764 by having it try to read from the Emacs one.
   1765 
   1766 Also note that secondary @REPL{}s (those started with
   1767 @kbd{sly-mrepl-new}) don’t receive any redirected output.
   1768 
   1769 @item @code{SLYNK:*USE-DEDICATED-OUTPUT-STREAM*}
   1770 
   1771 This variable controls whether to use a separate socket solely for Lisp
   1772 to send printed output to Emacs through, which is more efficient than
   1773 sending the output in protocol messages to Emacs.
   1774 
   1775 The default value is @code{:started-from-emacs}, which means that the
   1776 socket should only be established upon @code{M-x sly} invocations.  When
   1777 @code{t}, it's established even for sessions started with @code{M-x
   1778 sly-connect}.  When @code{NIL} usual protocol messages are used for
   1779 sending input to the @REPL{}.
   1780 
   1781 Notice that using a dedicated output stream makes it more difficult to
   1782 communicate to a Lisp running on a remote host via SSH
   1783 (@pxref{Connecting to a remote Lisp}).  If you connect via @code{M-x
   1784 sly-connect}, the default @code{:started-from-emacs} value should ensure
   1785 this isn't a problem.
   1786 
   1787 @item @code{SLYNK:*DEDICATED-OUTPUT-STREAM-PORT*}
   1788 
   1789 When @code{*USE-DEDICATED-OUTPUT-STREAM*} is @code{t} the stream will
   1790 be opened on this port. The default value, @code{0}, means that the
   1791 stream will be opened on some random port.
   1792 
   1793 @item @code{SLYNK:*DEDICATED-OUTPUT-STREAM-BUFFERING*}
   1794 
   1795 For efficiency, some Lisps backends wait until a certain conditions
   1796 are met in a Lisp character stream before flushing that stream’s
   1797 contents, thus sending it to the @SLY{} @REPL{}. Be advised that this
   1798 sometimes works poorly on some implementations, so it’s probably best
   1799 to leave alone. Possible values are @code{nil} (no
   1800 buffering), @code{t} (enable buffering) or @code{:line} (enable
   1801 buffering on EOL)
   1802 @end table
   1803 
   1804 @node REPL backreferences
   1805 @subsection REPL backreferences
   1806 
   1807 In a regular Lisp REPL, the objects produced by evaluating expressions
   1808 at the command prompt can usually be referenced in future commands
   1809 using the special variables @code{*}, @code{**} and @code{***}. This
   1810 is also true of the @SLY{} @REPL{}, but it also provides a different
   1811 way to re-conjure these objects through a special Lisp reader macro
   1812 character available only in the REPL. The macro character, which
   1813 is @code{#v} by default takes, in a terse syntax, two indexes
   1814 specifying the precise objects in all of the @SLY{} @REPL{}’s recorded
   1815 history.
   1816 
   1817 Consider this fragment of a REPL session:
   1818 
   1819 @example
   1820 ; Cleared REPL history
   1821 CL-USER> (values 'a 'b 'c)
   1822 A
   1823 B
   1824 C
   1825 CL-USER> (list #v0)
   1826 (A)
   1827 CL-USER> (list #v0:1 #v0:2)
   1828 (B C)
   1829 CL-USER> (append #v1:0 #v2:0)
   1830 (A B C)
   1831 CL-USER>
   1832 @end example
   1833 
   1834 @noindent
   1835 Admittedly, while useful, this doesn’t seem terribly easy to use at
   1836 first sight. There are a couple of reasons, however, that should make
   1837 it worth considering:
   1838 
   1839 @itemize @bullet
   1840 @item
   1841 Backreference annotation and highlighting
   1842 
   1843 As soon as the @SLY{} @REPL{} detects that you have pressed @code{#v},
   1844 all the @REPL{} results that can possibly be referenced are
   1845 temporarily annotated on their left with two special numbers. These
   1846 numbers are in the syntax accepted by the @code{#v} macro-character,
   1847 namely @code{#vENTRY-IDX:VALUE-IDX}.
   1848 
   1849 Furthermore, as soon as you type a number for @code{ENTRY-IDX}, only
   1850 that entries values remain highlighted. Then, as you finish the entry
   1851 with @code{VALUE-IDX}, only that exact object remains highlighted. If
   1852 you make a mistake (say, by typing a letter or an invalid number)
   1853 while composing @code{#v} syntax, @SLY{} lets you know by painting the
   1854 backreference red.
   1855 
   1856 Highlighting also happens when you place the cursor over existing
   1857 valid @code{#v} expressions.
   1858 
   1859 @item
   1860 Returning functions calls
   1861 
   1862 An experimental feature in @SLY{} allows copying @emph{function calls}
   1863 to the @REPL{} from the Debugger (@pxref{Debugger}) and the Trace
   1864 Dialog (@pxref{Trace Dialog}). In those buffers, pressing
   1865 keybinding @kbd{M-S-RET} over objects that represent function calls
   1866 will copy the @emph{call}, and not the object, to the @REPL{}. This
   1867 works by first copying over the argument objects in order to the
   1868 @REPL{} results, and then composing an input line that includes the
   1869 called function's name and backreferences to those arguments
   1870 (@pxref{REPL backreferences}).
   1871 
   1872 Naturally, this call isn't @emph{exactly} the same because it doesn’t
   1873 evaluate in the same dynamic environment as the original one. But it's
   1874 a useful debug technique because backreferences are stable
   1875 @footnote{until you clear the @REPL{}’s output, that is}, so repeating
   1876 that very same function call with the very same arguments is just a
   1877 matter of textually copying the previous expression into the command
   1878 prompt, no matter how far ago it happened. And that, in turn,
   1879 is as easy as using @kbd{C-r} and some characters (@pxref{REPL
   1880 commands}) to arrive and repeat the desired @REPL{} history entry.
   1881 @end itemize
   1882 
   1883 @node Inspector
   1884 @section The Inspector
   1885 
   1886 The @SLY{} inspector is a Emacs-based alternative to the
   1887 standard @code{INSPECT} function. The inspector presents objects in
   1888 Emacs buffers using a combination of plain text, hyperlinks to related
   1889 objects.
   1890 
   1891 The inspector can easily be specialized for the objects in your own
   1892 programs. For details see the @code{inspect-for-emacs} generic
   1893 function in @file{slynk-backend.lisp}.
   1894 
   1895 @table @kbd
   1896 
   1897 @kbditem{C-c I, sly-inspect}
   1898 Inspect the value of an expression entered in the minibuffer.
   1899 
   1900 @end table
   1901 
   1902 The standard commands available in the inspector are:
   1903 
   1904 @table @kbd
   1905 
   1906 @kbditem{RET, sly-inspector-operate-on-point}
   1907 If point is on a value then recursively call the inspector on that
   1908 value. If point is on an action then call that action.
   1909 
   1910 @kbditem{D, sly-inspector-describe-inspectee}
   1911 Describe the slot at point.
   1912 
   1913 @kbditem{e, sly-inspector-eval}
   1914 Evaluate an expression in the context of the inspected object. The
   1915 variable @code{*} will be bound to the inspected object.
   1916 
   1917 @kbditem{v, sly-inspector-toggle-verbose}
   1918 Toggle between verbose and terse mode. Default is determined by
   1919 `slynk:*inspector-verbose*'.
   1920 
   1921 @kbditem{l, sly-inspector-pop}
   1922 Go back to the previous object (return from @kbd{RET}).
   1923 
   1924 @kbditem{n, sly-inspector-next}
   1925 The inverse of @kbd{l}. Also bound to @kbd{SPC}.
   1926 
   1927 @kbditem{g, sly-inspector-reinspect}
   1928 Reinspect.
   1929 
   1930 @kbditem{h, sly-inspector-history}
   1931 Show the previously inspected objects.
   1932 
   1933 @kbditem{q, sly-inspector-quit}
   1934 Dismiss the inspector buffer.
   1935 
   1936 @kbditem{>, sly-inspector-fetch-all}
   1937 Fetch all inspector contents and go to the end.
   1938 
   1939 @kbditem{M-RET, sly-mrepl-copy-part-to-repl}
   1940 Store the value under point in the variable `*'.  This can
   1941 then be used to access the object in the REPL.
   1942 
   1943 @kbditempair{TAB, S-TAB, forward-button, backward-button}
   1944 
   1945 Jump to the next and previous inspectable object respectively.
   1946 
   1947 @end table
   1948 
   1949 @node Debugger
   1950 @section The SLY-DB Debugger
   1951 
   1952 @cindex Debugger
   1953 
   1954 @SLY{} has a custom Emacs-based debugger called @SLY-DB{}. Conditions
   1955 signalled in the Lisp system invoke @SLY-DB{} in Emacs by way of the
   1956 Lisp @code{*DEBUGGER-HOOK*}.
   1957 
   1958 @SLY-DB{} pops up a buffer when a condition is signalled. The buffer
   1959 displays a description of the condition, a list of restarts, and a
   1960 backtrace. Commands are offered for invoking restarts, examining the
   1961 backtrace, and poking around in stack frames.
   1962 
   1963 @menu
   1964 * Examining frames::
   1965 * Restarts::
   1966 * Frame Navigation::
   1967 * Miscellaneous::
   1968 @end menu
   1969 
   1970 @node Examining frames
   1971 @subsection Examining frames
   1972 
   1973 Commands for examining the stack frame at point.
   1974 
   1975 @table @kbd
   1976 @kbditem{t, sly-db-toggle-details}
   1977 Toggle display of local variables and @code{CATCH} tags.
   1978 
   1979 @kbditem{v, sly-db-show-frame-source}
   1980 View the frame's current source expression. The expression is
   1981 presented in the Lisp source file's buffer.
   1982 
   1983 @kbditem{e, sly-db-eval-in-frame}
   1984 Evaluate an expression in the frame. The expression can refer to the
   1985 available local variables in the frame.
   1986 
   1987 @kbditem{d, sly-db-pprint-eval-in-frame}
   1988 Evaluate an expression in the frame and pretty-print the result in a
   1989 temporary buffer.
   1990 
   1991 @kbditem{D, sly-db-disassemble}
   1992 Disassemble the frame's function. Includes information such as the
   1993 instruction pointer within the frame.
   1994 
   1995 @kbditem{i, sly-db-inspect-in-frame}
   1996 Inspect the result of evaluating an expression in the frame.
   1997 
   1998 @kbditem{C-c C-c, sly-db-recompile-frame-source}
   1999 Recompile frame. @kbd{C-u C-c C-c} for recompiling with maximum debug settings.
   2000 
   2001 @end table
   2002 
   2003 @node Restarts
   2004 @subsection Invoking restarts
   2005 
   2006 @table @kbd
   2007 @kbditem{a, sly-db-abort}
   2008 Invoke the @code{ABORT} restart.
   2009 
   2010 @anchor{sly-db-quit}
   2011 @kbditem{q, sly-db-quit}
   2012 ``Quit'' -- For @SLY{} evaluation requests, invoke a restart which
   2013 restores to a known program state. For errors in other threads,
   2014 @xref{*SLY-DB-QUIT-RESTART*}.
   2015 
   2016 @kbditem{c, sly-db-continue}
   2017 Invoke the @code{CONTINUE} restart.
   2018 
   2019 @kbditem{0 ... 9, sly-db-invoke-restart-n}
   2020 Invoke a restart by number.
   2021 @end table
   2022 
   2023 Restarts can also be invoked by pressing @kbd{RET} or @kbd{Mouse-2} on
   2024 them in the buffer.
   2025 
   2026 @node Frame Navigation
   2027 @subsection Navigating between frames
   2028 
   2029 @table @kbd
   2030 @kbditempair{n,p,sly-db-down,sly-db-up}
   2031 Move between frames.
   2032 
   2033 @kbditempair{M-n, M-p, sly-db-details-down, sly-db-details-up}
   2034 Move between frames ``with sugar'': hide the details of the original
   2035 frame and display the details and source code of the next. Sugared
   2036 motion makes you see the details and source code for the current frame
   2037 only.
   2038 
   2039 @kbditem{>, sly-db-end-of-backtrace}
   2040 Fetch the entire backtrace and go to the last frame.
   2041 
   2042 @kbditem{<, sly-db-beginning-of-backtrace}
   2043 Go to the first frame.
   2044 
   2045 @end table
   2046 
   2047 @node Miscellaneous
   2048 @subsection Miscellaneous Commands
   2049 
   2050 @table @kbd
   2051 @kbditem{r, sly-db-restart-frame}
   2052 Restart execution of the frame with the same arguments it was
   2053 originally called with. (This command is not available in all
   2054 implementations.)
   2055 
   2056 @kbditem{R, sly-db-return-from-frame}
   2057 Return from the frame with a value entered in the minibuffer. (This
   2058 command is not available in all implementations.)
   2059 
   2060 
   2061 @kbditem{B, sly-db-break-with-default-debugger}
   2062 Exit @SLY-DB{} and debug the condition using the Lisp system's default
   2063 debugger.
   2064 
   2065 @kbditem{C, sly-db-inspect-condition}
   2066 Inspect the condition currently being debugged.
   2067 
   2068 @kbditem{:, sly-interactive-eval}
   2069 Evaluate an expression entered in the minibuffer.
   2070 @kbditem{A, sly-db-break-with-system-debugger}
   2071 Attach debugger (e.g. gdb) to the current lisp process.
   2072 
   2073 @end table
   2074 
   2075 @node Trace Dialog
   2076 @section Trace Dialog
   2077 
   2078 The @SLY{} Trace Dialog, in package @code{sly-trace-dialog}, is a
   2079 tracing facility, similar to Common Lisp's @code{trace}, but
   2080 interactive rather than purely textual.
   2081 
   2082 You use it just like you would regular @code{trace}: after tracing a
   2083 function, calling it causes interesting information about that
   2084 particular call to be reported.
   2085 
   2086 However, instead of printing the trace results to the
   2087 the @code{*trace-output*} stream (usually the REPL), the @SLY{} Trace
   2088 Dialog collects and stores them in your Lisp environment until, on
   2089 user's request, they are fetched into Emacs and displayed in a
   2090 dialog-like interactive view.
   2091 
   2092 After starting up @SLY{}, @SLY{}'s Trace Dialog installs
   2093 a @emph{Trace} menu in the menu-bar of any @code{sly-mode} buffer and
   2094 adds two new commands, with respective key-bindings:
   2095 
   2096 @table @kbd
   2097 @kbditem{C-c C-t, sly-trace-dialog-toggle-trace}
   2098 If point is on a symbol name, toggle tracing of its function
   2099 definition. If point is not on a symbol, prompt user for a function.
   2100 
   2101 With a @kbd{C-u} prefix argument, and if your lisp implementation
   2102 allows it, attempt to decipher lambdas, methods and other complicated
   2103 function signatures.
   2104 
   2105 The function is traced for the @SLY{} Trace Dialog only, i.e. it is
   2106 not found in the list returned by Common Lisp's @code{trace}.
   2107 
   2108 @kbditem{C-c T, sly-trace-dialog}
   2109 Pop to the interactive Trace Dialog buffer associated with the
   2110 current connection (@pxref{Multiple connections}).
   2111 @end table
   2112 
   2113 @page
   2114 Consider the (useless) program:
   2115 
   2116 @example
   2117 (defun foo (n) (if (plusp n) (* n (bar (1- n))) 1))
   2118 (defun bar (n) (if (plusp n) (* n (foo (1- n))) 1))
   2119 @end example
   2120 
   2121 After tracing both @code{foo} and @code{bar} with @kbd{C-c M-t},
   2122 calling call @code{(foo 2)} and moving to the trace dialog with
   2123 @kbd{C-c T}, we are presented with this buffer.
   2124 
   2125 @example
   2126 Traced specs (2)                                  [refresh]
   2127                                                   [untrace all]
   2128   [untrace] common-lisp-user::bar
   2129   [untrace] common-lisp-user::foo
   2130 
   2131 Trace collection status (3/3)                     [refresh]
   2132                                                   [clear]
   2133 
   2134    0 - common-lisp-user::foo
   2135      | > 2
   2136      | < 2
   2137    1 `--- common-lisp-user::bar
   2138         | > 1
   2139         | < 1
   2140    2    `-- common-lisp-user::foo
   2141              > 0
   2142              < 1
   2143 @end example
   2144 
   2145 The dialog is divided into sections displaying the functions already
   2146 traced, the trace collection progress and the actual trace tree that
   2147 follow your program's logic. The most important key-bindings in this
   2148 buffer are:
   2149 
   2150 @table @kbd
   2151 @kbditem{g, sly-trace-dialog-fetch-status}
   2152 Update information on the trace collection and traced specs.
   2153 @kbditem{G, sly-trace-dialog-fetch-traces}
   2154 Fetch the next batch of outstanding (not fetched yet) traces. With a
   2155 @kbd{C-u} prefix argument, repeat until no more outstanding traces.
   2156 @kbditem{C-k, sly-trace-dialog-clear-fetched-traces}
   2157 Prompt for confirmation, then clear all traces, both fetched and
   2158 outstanding.
   2159 @end table
   2160 
   2161 The arguments and return values below each entry are interactive
   2162 buttons. Clicking them opens the inspector
   2163 (@pxref{Inspector}). Invoking @kbd{M-RET}
   2164 (@code{sly-trace-dialog-copy-down-to-repl}) returns them to the REPL
   2165 for manipulation (@pxref{REPL}). The number left of each entry
   2166 indicates its absolute position in the calling order, which might
   2167 differ from display order in case multiple threads call the same
   2168 traced function.
   2169 
   2170 @code{sly-trace-dialog-hide-details-mode} hides arguments and return
   2171 values so you can concentrate on the calling logic. Additionally,
   2172 @code{sly-trace-dialog-autofollow-mode} will automatically
   2173 display additional detail about an entry when the cursor moves over
   2174 it.
   2175 
   2176 @node Stickers
   2177 @section Stickers
   2178 
   2179 @SLY{} Stickers, implemented as the @code{sly-stickers} contrib
   2180 (@pxref{Extensions}), is a tool for ``live'' code annotations. It's an
   2181 alternative to the @code{print} or @code{break} statements you add to
   2182 your code when debugging.
   2183 
   2184 Contrary to these techniques, ``stickers'' are non-intrusive, meaning
   2185 that saving your file doesn't save your debug code along with it.
   2186 
   2187 Here's the general workflow:
   2188 
   2189 @itemize @bullet
   2190 @item
   2191 In Lisp source files, using @kbd{C-c C-s C-s} or @code{M-x
   2192 sly-stickers-dwim} places a sticker on any Lisp form. Stickers can
   2193 exist inside other stickers.
   2194 
   2195 @*@image{images/stickers-1-placed-stickers,350pt}@*
   2196 
   2197 @item
   2198 Stickers are ``armed'' when a definition or a file is compiled with the
   2199 familiar @kbd{C-c C-c} (@code{M-x sly-compile-defun}) or @kbd{C-c C-k}
   2200 (@code{M-x sly-compile-file}) commands. An armed sticker changes color from
   2201 the default grey background to a blue background.
   2202 
   2203 @*@image{images/stickers-2-armed-stickers,350pt}@*
   2204 
   2205 @end itemize
   2206 
   2207 From this point on, when the Lisp code is executed, the results of
   2208 evaluating the underlying forms are captured in the Lisp
   2209 side. Stickers help you examine your program's behaviour in three
   2210 ways:
   2211 @enumerate
   2212 @item
   2213 @kbd{C-c C-s C-r}
   2214 (or @code{M-x sly-stickers-replay}) interactively walks the user
   2215 through recordings in the order that they occurred. In the
   2216 created @code{*sly-stickers-replay*} buffer, type @kbd{h} for a list
   2217 of keybindings active in that buffer.
   2218 
   2219 @*@image{images/stickers-3-replay-stickers,350pt}@*
   2220 
   2221 @item
   2222 To step through stickers as your code is executed, ensure that
   2223 ``breaking stickers'' are enabled via @code{M-x
   2224 sly-stickers-toggle-break-on-stickers}.  Whenever a sticker-covered
   2225 expression is reached, the debugger comes up with useful restarts and
   2226 interactive for the values produced.  You can tweak this behaviour by
   2227 setting the Lisp-side variable
   2228 @code{SLYNK-STICKERS:*BREAK-ON-STICKERS*} to a list with the
   2229 elements @code{:before} and @code{:after}, making @SLY{} break before a
   2230 sticker, after it, or both.
   2231 
   2232 @*@image{images/stickers-4-breaking-stickers,350pt}@*
   2233 
   2234 @item
   2235 @kbd{C-c C-s S} (@code{M-x sly-stickers-fetch}) populates the sticker
   2236 overlay with the latest captured results, called ``recordings''. If a sticker
   2237 has captured any recordings, it will turn green, otherwise it will turn
   2238 red. A sticker whose Lisp expression has caused a non-local exit, will
   2239 be also be marked with a special face.
   2240 
   2241 @*@image{images/stickers-5-fetch-recordings,350pt}@*
   2242 
   2243 @end enumerate
   2244 
   2245 At any point, stickers can be removed with the
   2246 same @code{sly-stickers-dwim} keybinding, by placing the cursor at the
   2247 beginning of a sticker. Additionally adding prefix arguments
   2248 to @code{sly-stickers-dwim} increase its scope, so @kbd{C-u C-c C-s
   2249 C-s} will remove all stickers from the current function and @kbd{C-u
   2250 C-u C-c C-s C-s} will remove all stickers from the current file.
   2251 
   2252 Stickers can be nested inside other stickers, so it is possible to
   2253 record the value of an expression inside another expression which is
   2254 also annotated.
   2255 
   2256 Stickers are interactive parts just like any other part in @SLY{} that
   2257 represents Lisp-side objects, so they can be inspected and returned to
   2258 the REPL, for example. To move through the stickers with the keyboard
   2259 use the existing keybindings to move through compilation
   2260 notes (@kbd{M-p} and @kbd{M-n}) or use @kbd{C-c C-s p} and @kbd{C-c C-s
   2261 n} (@code{sly-stickers-prev-sticker} and
   2262 @code{sly-stickers-next-sticker}).
   2263 
   2264 There are some caveats when using @SLY{} Stickers:
   2265 
   2266 @itemize
   2267 @item
   2268 Stickers on unevaluated forms (such as @code{let} variable bindings, or
   2269 other constructs) are rejected, though the function is still compiled as
   2270 usual. To let the user know about this, these stickers remain grey, and are
   2271 marked as ``disarmed''. A message also appears in the echo area.
   2272 @item
   2273 Stickers placed on expressions inside backquoted expressions in macros
   2274 are always armed, even though they may come to provoke a runtime error
   2275 when the macro's expansion is run. Think of this when setting a sticker
   2276 inside a macro definition.
   2277 @end itemize
   2278 
   2279 @node Customization
   2280 @chapter Customization
   2281 
   2282 @menu
   2283 * Emacs-side::
   2284 * Lisp-side customization::
   2285 @end menu
   2286 
   2287 @node Emacs-side
   2288 @section Emacs-side
   2289 
   2290 @menu
   2291 * Keybindings::
   2292 * Keymaps::
   2293 * Defcustom variables::
   2294 * Hooks::
   2295 @end menu
   2296 
   2297 @node Keybindings
   2298 @subsection Keybindings
   2299 
   2300 In general we try to make our key bindings fit with the overall Emacs
   2301 style.
   2302 
   2303 We never bind @kbd{C-h} anywhere in a key sequence.  This is because
   2304 Emacs has a built-in default so that typing a prefix followed
   2305 by @kbd{C-h} will display all bindings starting with that prefix,
   2306 so @kbd{C-c C-d C-h} will actually list the bindings for all
   2307 documentation commands.  This feature is just a bit too useful to
   2308 clobber!
   2309 
   2310 @quotation
   2311 @i{``Are you deliberately spiting Emacs's brilliant online help facilities? The gods will be angry!''}
   2312 @end quotation
   2313 
   2314 @noindent This is a brilliant piece of advice. The Emacs online help facilities
   2315 are your most immediate, up-to-date and complete resource for keybinding
   2316 information. They are your friends:
   2317 
   2318 @table @kbd
   2319 @kbdanchorc{C-h k <key>, describe-key, ``What does this key do?''}
   2320 Describes current function bound to @kbd{<key>} for focus buffer.
   2321 
   2322 @kbdanchorc{C-h b, describe-bindings, ``Exactly what bindings are available?''}
   2323 Lists the current key-bindings for the focus buffer.
   2324 
   2325 @kbdanchorc{C-h m, describe-mode, ``Tell me all about this mode''}
   2326 Shows all the available major mode keys, then the minor mode keys, for
   2327 the modes of the focus buffer.
   2328 
   2329 @kbdanchorc{C-h l, view-lossage, ``Woah@comma{} what key chord did I just do?''}
   2330 Shows you the literal sequence of keys you've pressed in order.
   2331 
   2332 @c <key> is breaks links PDF, despite that it's not l it's C-h
   2333 @c @kbdanchorc{ <key> l, , ``What starts with?''}
   2334 @c Lists all keybindings that begin with @code{<key>} for the focus buffer mode.
   2335 
   2336 
   2337 @end table
   2338 
   2339 @anchor{Emacs Init File}
   2340 For example, you can add one of the following to your Emacs init file
   2341 (usually @file{~/.emacs} or @file{~/.emacs.d/init.el}, but @pxref{Init
   2342 File,Init File, Emacs Init File, emacs, The Emacs Manual}).
   2343 
   2344 @example
   2345 (eval-after-load 'sly
   2346   `(define-key sly-prefix-map (kbd "M-h") 'sly-documentation-lookup))
   2347 @end example
   2348 
   2349 @SLY{} comes bundled with many extensions (called ``contribs'' for
   2350 historical reasons, @pxref{Extensions}) which you can customize just
   2351 like @SLY{}'s code. To make @kbd{C-c C-c} clear the last REPL prompt's
   2352 output, for example, use
   2353 
   2354 @example
   2355 (eval-after-load 'sly-mrepl
   2356    `(define-key sly-mrepl-mode-map (kbd "C-c C-k")
   2357                 'sly-mrepl-clear-recent-output))
   2358 @end example
   2359 
   2360 @node Keymaps
   2361 @subsection Keymaps
   2362 
   2363 Emacs’s keybindings ``live'' in keymap variables. To customize a
   2364 particular binding and keep it from trampling on other important keys
   2365 you should do it in one of @SLY{}'s keymaps. The following
   2366 non-exhaustive list of @SLY{}-related keymaps is just a reference: the
   2367 manual will go over each associated functionality in detail.
   2368 
   2369 @table @code
   2370 
   2371 @item sly-doc-map
   2372 
   2373 Keymap for documentation commands (@pxref{Documentation}) in
   2374 @SLY{}-related buffers, accessible by the @kbd{C-c C-d} prefix.
   2375 
   2376 @item sly-who-map
   2377 
   2378 Keymap for cross-referencing (``who-calls'') commands
   2379 (@pxref{Cross-referencing}) in @SLY{}-related buffers, accessible by
   2380 the @kbd{C-c C-w} prefix.
   2381 
   2382 @item sly-selector-map
   2383 
   2384 A keymap for @SLY{}-related functionality that should be available in
   2385 globally in all Emacs buffers (not just @SLY{}-related buffers).
   2386 
   2387 @item sly-mode-map
   2388 
   2389 A keymap for functionality available in all @SLY{}-related buffers.
   2390 
   2391 @item sly-editing-mode-map
   2392 
   2393 A keymap for @SLY{} functionality available in Lisp source files.
   2394 
   2395 @item sly-popup-buffer-mode-map
   2396 
   2397 A keymap for functionality available in the temporary ``popup''
   2398 buffers that @SLY{} displays (@pxref{Temporary buffers})
   2399 
   2400 @item sly-apropos-mode-map
   2401 
   2402 A keymap for functionality available in the temporary @SLY{}
   2403 ``apropos'' buffers (@pxref{Documentation}).
   2404 
   2405 @item sly-xref-mode-map
   2406 
   2407 A keymap for functionality available in the temporary @code{xref}
   2408 buffers used by cross-referencing commands
   2409 (@pxref{Cross-referencing}).
   2410 
   2411 @item sly-macroexpansion-minor-mode-map
   2412 
   2413 A keymap for functionality available in the temporary buffers used for
   2414 macroexpansion presentation (@pxref{Macro-expansion}).
   2415 
   2416 @item sly-db-mode-map
   2417 
   2418 A keymap for functionality available in the debugger buffers used to
   2419 debug errors in the Lisp process (@pxref{Debugger}).
   2420 
   2421 @item sly-thread-control-mode-map
   2422 
   2423 A keymap for functionality available in the @SLY{} buffers dedicated
   2424 to controlling Lisp threads (@pxref{Multi-threading}).
   2425 
   2426 @item sly-connection-list-mode-map
   2427 
   2428 A keymap for functionality available in the @SLY{} buffers dedicated
   2429 to managing multiple Lisp connections (@pxref{Multiple connections}).
   2430 
   2431 @item sly-inspector-mode-map
   2432 
   2433 A keymap for functionality available in the @SLY{} buffers dedicated
   2434 to inspecting Lisp objects (@pxref{Inspector}).
   2435 
   2436 @item sly-mrepl-mode-map
   2437 
   2438 A keymap for functionality available in @SLY{}’s REPL buffers
   2439 (@pxref{REPL}).
   2440 
   2441 @item sly-trace-dialog-mode-map
   2442 
   2443 A keymap for functionality available in @SLY{}’s ``Trace Dialog''
   2444 buffers (@pxref{Trace Dialog}).
   2445 
   2446 @end table
   2447 
   2448 
   2449 @node Defcustom variables
   2450 @subsection Defcustom variables
   2451 
   2452 The Emacs part of @SLY{} can be configured with the Emacs
   2453 @code{customize} system, just use @kbd{M-x customize-group sly
   2454 RET}. Because the customize system is self-describing, we only cover a
   2455 few important or obscure configuration options here in the manual.
   2456 
   2457 @table @code
   2458 
   2459 @item sly-truncate-lines
   2460 The value to use for @code{truncate-lines} in line-by-line summary
   2461 buffers popped up by @SLY{}. This is @code{t} by default, which
   2462 ensures that lines do not wrap in backtraces, apropos listings, and so
   2463 on. It can however cause information to spill off the screen.
   2464 
   2465 @anchor{sly-complete-symbol-function}
   2466 @item sly-complete-symbol-function
   2467 The function to use for completion of Lisp symbols. Two completion
   2468 styles are available: @code{sly-simple-completions}
   2469 and @code{sly-flex-completions} (@pxref{Completion}).
   2470 
   2471 @item sly-filename-translations
   2472 This variable controls filename translation between Emacs and the Lisp
   2473 system. It is useful if you run Emacs and Lisp on separate machines
   2474 which don't share a common file system or if they share the filesystem
   2475 but have different layouts, as is the case with @acronym{SMB}-based
   2476 file sharing.
   2477 
   2478 @anchor{sly-net-coding-system}
   2479 @cindex Unicode
   2480 @cindex UTF-8
   2481 @cindex ASCII
   2482 @cindex LATIN-1
   2483 @cindex Character Encoding
   2484 @item sly-net-coding-system
   2485 If you want to transmit Unicode characters between Emacs and the Lisp
   2486 system, you should customize this variable.  E.g., if you use SBCL, you
   2487 can set:
   2488 @example
   2489 (setq sly-net-coding-system 'utf-8-unix)
   2490 @end example
   2491 To actually display Unicode characters you also need appropriate
   2492 fonts, otherwise the characters will be rendered as hollow boxes.  If
   2493 you are using Allegro CL and GNU Emacs, you can also
   2494 use @code{emacs-mule-unix} as coding system.  GNU Emacs has often
   2495 nicer fonts for the latter encoding.  (Different encodings can be used
   2496 for different Lisps, see @ref{Multiple Lisps}.)
   2497 
   2498 @item sly-keep-buffers-on-connection-close
   2499 This variable holds a list of keywords indicating @SLY{} buffer types
   2500 that should be kept around when a connection closes.  For example, if
   2501 the variable's value includes @code{:mrepl} (which is the default),
   2502 @REPL{} buffer is kept around while all other stale buffers (debugger,
   2503 inspector, etc..) are automatically killed.
   2504 
   2505 @end table
   2506 
   2507 @node Hooks
   2508 @subsection Hooks
   2509 
   2510 @table @code
   2511 
   2512 @item sly-mode-hook
   2513 This hook is run each time a buffer enters @code{sly-mode}. It is
   2514 most useful for setting buffer-local configuration in your Lisp source
   2515 buffers. An example use is to enable @code{sly-autodoc-mode}
   2516 (@pxref{Autodoc}).
   2517 
   2518 @anchor{sly-connected-hook}
   2519 @item sly-connected-hook
   2520 This hook is run when @SLY{} establishes a connection to a Lisp
   2521 server. An example use is to pop to a new @REPL{}.
   2522 
   2523 @item sly-db-hook
   2524 This hook is run after @SLY-DB{} is invoked. The hook functions are
   2525 called from the @SLY-DB{} buffer after it is initialized. An example use
   2526 is to add @code{sly-db-print-condition} to this hook, which makes all
   2527 conditions debugged with @SLY-DB{} be recorded in the @REPL{} buffer.
   2528 
   2529 @end table
   2530 
   2531 @node Lisp-side customization
   2532 @section Lisp-side (Slynk)
   2533 
   2534 The Lisp server side of @SLY{} (known as ``Slynk'') offers several
   2535 variables to configure. The initialization file @file{~/.slynk.lisp}
   2536 is automatically evaluated at startup and can be used to set these
   2537 variables.
   2538 
   2539 @menu
   2540 * Communication style::
   2541 * Other configurables::
   2542 @end menu
   2543 
   2544 @node Communication style
   2545 @subsection Communication style
   2546 
   2547 The most important configurable is @code{SLYNK:*COMMUNICATION-STYLE*},
   2548 which specifies the mechanism by which Lisp reads and processes
   2549 protocol messages from Emacs. The choice of communication style has a
   2550 global influence on @SLY{}'s operation.
   2551 
   2552 The available communication styles are:
   2553 
   2554 @table @code
   2555 @item NIL
   2556 This style simply loops reading input from the communication socket
   2557 and serves @SLY{} protocol events as they arise. The simplicity
   2558 means that the Lisp cannot do any other processing while under
   2559 @SLY{}'s control.
   2560 
   2561 @item :FD-HANDLER
   2562 This style uses the classical Unix-style ``@code{select()}-loop.''
   2563 Slynk registers the communication socket with an event-dispatching
   2564 framework (such as @code{SERVE-EVENT} in @acronym{CMUCL} and
   2565 @acronym{SBCL}) and receives a callback when data is available. In
   2566 this style requests from Emacs are only detected and processed when
   2567 Lisp enters the event-loop. This style is simple and predictable.
   2568 
   2569 @item :SIGIO
   2570 This style uses @dfn{signal-driven I/O} with a @code{SIGIO} signal
   2571 handler. Lisp receives requests from Emacs along with a signal,
   2572 causing it to interrupt whatever it is doing to serve the
   2573 request. This style has the advantage of responsiveness, since Emacs
   2574 can perform operations in Lisp even while it is busy doing other
   2575 things. It also allows Emacs to issue requests concurrently, e.g. to
   2576 send one long-running request (like compilation) and then interrupt
   2577 that with several short requests before it completes. The
   2578 disadvantages are that it may conflict with other uses of @code{SIGIO}
   2579 by Lisp code, and it may cause untold havoc by interrupting Lisp at an
   2580 awkward moment.
   2581 
   2582 @item :SPAWN
   2583 This style uses multiprocessing support in the Lisp system to execute
   2584 each request in a separate thread. This style has similar properties
   2585 to @code{:SIGIO}, but it does not use signals and all requests issued
   2586 by Emacs can be executed in parallel.
   2587 
   2588 @end table
   2589 
   2590 The default request handling style is chosen according to the
   2591 capabilities of your Lisp system. The general order of preference is
   2592 @code{:SPAWN}, then @code{:SIGIO}, then @code{:FD-HANDLER}, with
   2593 @code{NIL} as a last resort. You can check the default style by
   2594 calling @code{SLYNK-BACKEND::PREFERRED-COMMUNICATION-STYLE}. You can
   2595 also override the default by setting
   2596 @code{SLYNK:*COMMUNICATION-STYLE*} in your Slynk init file (@pxref{Lisp-side customization}).
   2597 
   2598 @node Other configurables
   2599 @subsection Other configurables
   2600 
   2601 These Lisp variables can be configured via your @file{~/.slynk.lisp}
   2602 file:
   2603 
   2604 @table @code
   2605 
   2606 @item SLYNK:*CONFIGURE-EMACS-INDENTATION*
   2607 This variable controls whether indentation styles for
   2608 @code{&body}-arguments in macros are discovered and sent to Emacs. It
   2609 is enabled by default.
   2610 
   2611 @item SLYNK:*GLOBAL-DEBUGGER*
   2612 When true (the default) this causes @code{*DEBUGGER-HOOK*} to be
   2613 globally set to @code{SLYNK:SLYNK-DEBUGGER-HOOK} and thus for @SLY{}
   2614 to handle all debugging in the Lisp image. This is for debugging
   2615 multithreaded and callback-driven applications.
   2616 
   2617 @anchor{*SLY-DB-QUIT-RESTART*}
   2618 @item SLYNK:*SLY-DB-QUIT-RESTART*
   2619 This variable names the restart that is invoked when pressing @kbd{q}
   2620 (@pxref{sly-db-quit}) in @SLY-DB{}. For @SLY{} evaluation requests this
   2621 is @emph{unconditionally} bound to a restart that returns to a safe
   2622 point. This variable is supposed to customize what @kbd{q} does if an
   2623 application's thread lands into the debugger (see
   2624 @code{SLYNK:*GLOBAL-DEBUGGER*}).
   2625 @example
   2626 (setf slynk:*sly-db-quit-restart* 'sb-thread:terminate-thread)
   2627 @end example
   2628 
   2629 @item SLYNK:*BACKTRACE-PRINTER-BINDINGS*
   2630 @itemx SLYNK:*MACROEXPAND-PRINTER-BINDINGS*
   2631 @itemx SLYNK:*SLY-DB-PRINTER-BINDINGS*
   2632 @itemx SLYNK:*SLYNK-PPRINT-BINDINGS*
   2633 These variables can be used to customize the printer in various
   2634 situations.  The values of the variables are association lists of
   2635 printer variable names with the corresponding value.  E.g., to enable
   2636 the pretty printer for formatting backtraces in @SLY-DB{}, you can use:
   2637 
   2638 @example
   2639 (push '(*print-pretty* . t) slynk:*sly-db-printer-bindings*).
   2640 @end example
   2641 
   2642 The fact that most @SLY{} output (in the @REPL{} for instance,
   2643 @pxref{REPL}) uses @code{SLYNK:*SLYNK-PPRINT-BINDINGS*} may surprise you
   2644 if you expected it to use a global setting for, say,
   2645 @code{*PRINT-LENGTH*}.  The rationale for this decision is that output
   2646 is a very basic feature of @SLY{}, and it should keep operating normally
   2647 even if you (mistakenly) set absurd values for some @code{*PRINT-...*}
   2648 variable.  You, of course, override this protection:
   2649 
   2650 @example
   2651 (setq slynk:*slynk-pprint-bindings*
   2652       (delete '*print-length*
   2653               slynk:*slynk-pprint-bindings* :key #'car))
   2654 @end example
   2655 
   2656 @item SLYNK:*STRING-ELISION-LENGTH*
   2657 @itemx SLYNK:*STRING-ELISION-LENGTH*
   2658 
   2659 This variable controls the maximum length of strings before their pretty
   2660 printed representation in the Inspector, Debugger, @REPL, etc is elided.
   2661 Don't set this variable directly, create a binding for this variable
   2662 in @code{SLYNK:*SLYNK-PPRINT-BINDINGS*} instead.
   2663 
   2664 @item SLYNK:*ECHO-NUMBER-ALIST*
   2665 @itemx SLYNK:*PRESENT-NUMBER-ALIST*
   2666 These variables hold function designators used for displaying numbers
   2667 when SLY presents them in its interface.
   2668 
   2669 The difference between the two functions is that
   2670 @code{*PRESENT-NUMBER-ALIST*}, if non-nil,
   2671 overrides @code{*ECHO-NUMBER-ALIST*} in the context of the @REPL{}, Trace
   2672 Dialog and Stickers (see @ref{REPL}, @ref{Trace Dialog} and
   2673 @ref{Stickers}), while the latter is used for commands like @kbd{C-x
   2674 C-e} or the inspector (see @ref{Evaluation}, @ref{Inspector}).
   2675 
   2676 If in doubt, use @code{*ECHO-NUMBER-ALIST*}.
   2677 
   2678 Both variables have the same structure: each element in the alist takes
   2679 the form @code{(TYPE . FUNCTIONS)}, where @code{TYPE} is a type designator
   2680 and @code{FUNCTIONS} is a list of function designators for displaying
   2681 that number in SLY. Each function takes the number as a single argument
   2682 and returns a string, or nil, if that particular representation is to be
   2683 disregarded.
   2684 
   2685 Additionally if a given function chooses to return @code{t} as its
   2686 optional second value, then all the remaining functions following it
   2687 in the list are disregarded.
   2688 
   2689 For integer numbers, the default value of this variable holds function
   2690 designators that echo an integer number in its binary, hexadecimal and
   2691 octal representation. However, if your application is using integers
   2692 to represent
   2693 @uref{https://en.wikipedia.org/wiki/Unix_time,,Unix Epoch Times} you
   2694 can use this function to display a human-readable time
   2695 whenever you evaluate an integer.
   2696 
   2697 @example
   2698 (defparameter *day-names* '("Monday" "Tuesday" "Wednesday"
   2699                             "Thursday" "Friday" "Saturday"
   2700                             "Sunday"))
   2701 
   2702 (defun fancy-unix-epoch-time (integer)
   2703   "Format INTEGER as a Unix Epoch Time if within 10 years from now."
   2704   (let ((now (get-universal-time))
   2705         (tenyears (encode-universal-time 0 0 0 1 1 1910 0))
   2706         (unix-to-universal
   2707           (+ integer
   2708              (encode-universal-time 0 0 0 1 1 1970 0))))
   2709     (when (< (- now tenyears) unix-to-universal (+ now tenyears))
   2710       (multiple-value-bind
   2711             (second minute hour date month year day-of-week dst-p tz)
   2712           (decode-universal-time unix-to-universal)
   2713         (declare (ignore dst-p))
   2714         (format nil "~2,'0d:~2,'0d:~2,'0d on ~a, ~d/~2,'0d/~d (GMT~@@d)"
   2715                 hour minute second (nth day-of-week *day-names*)
   2716                 month date year (- tz))))))
   2717 
   2718 (pushnew 'fancy-unix-epoch-time
   2719          (cdr (assoc 'integer slynk:*echo-number-alist*)))
   2720 
   2721 42 ; => 42 (6 bits, #x2A, #o52, #b101010)
   2722 1451404675 ; => 1451404675 (15:57:55 on Tuesday, 12/29/2015 (GMT+0), 31 bits, #x5682AD83)
   2723 @end example
   2724 
   2725 @item SLYNK-APROPOS:*PREFERRED-APROPOS-MATCHER*
   2726 This variable holds a function used for performing apropos searches. It
   2727 defaults to @code{SLYNK-APROPOS:MAKE-FLEX-MATCHER}, but can also be set
   2728 to @code{SLYNK-APROPOS:MAKE-CL-PPCRE-MATCHER} (to use a regex-able
   2729 matcher) or @code{SLYNK-APROPOS:MAKE-PLAIN-MATCHER}, for example.
   2730 
   2731 @item SLYNK:*LOG-EVENTS*
   2732 Setting this variable to @code{t} causes all protocol messages
   2733 exchanged with Emacs to be printed to @code{*TERMINAL-IO*}. This is
   2734 useful for low-level debugging and for observing how @SLY{} works
   2735 ``on the wire.'' The output of @code{*TERMINAL-IO*} can be found in
   2736 your Lisp system's own listener, usually in the buffer
   2737 @code{*inferior-lisp*}.
   2738 
   2739 @end table
   2740 
   2741 @node Tips and Tricks
   2742 @chapter Tips and Tricks
   2743 
   2744 @menu
   2745 * Connecting to a remote Lisp::
   2746 * Loading Slynk faster::
   2747 * Auto-SLY::
   2748 * REPLs and game loops::
   2749 * Controlling SLY from outside Emacs::
   2750 @end menu
   2751 
   2752 @node Connecting to a remote Lisp
   2753 @section Connecting to a remote Lisp
   2754 
   2755 One of the advantages of the way @SLY{} is implemented is that we can
   2756 easily run the Emacs side (@code{sly.el} and friends) on one machine
   2757 and the Lisp backend (Slynk) on another. The basic idea is to start up
   2758 Lisp on the remote machine, load Slynk and wait for incoming @SLY{}
   2759 connections. On the local machine we start up Emacs and tell @SLY{} to
   2760 connect to the remote machine. The details are a bit messier but the
   2761 underlying idea is that simple.
   2762 
   2763 @menu
   2764 * Setting up the Lisp image::
   2765 * Setting up Emacs::
   2766 * Setting up pathname translations::
   2767 @end menu
   2768 
   2769 @node Setting up the Lisp image
   2770 @subsection Setting up the Lisp image
   2771 
   2772 The easiest way to load Slynk ``standalone'' (i.e. without
   2773 having @code{M-x sly} start a Lisp that is subsidiary to a particular
   2774 Emacs), is to load the ASDF system definition for Slynk.
   2775 
   2776 Make sure the path to the directory containing Slynk's @code{.asd}
   2777 file is in @code{ASDF:*CENTRAL-REGISTRY*}. This file lives in
   2778 the @code{slynk} subdirectory of @SLY{}. Type:
   2779 
   2780 @example
   2781 (push #p"/path/to/sly/slynk/" ASDF:*CENTRAL-REGISTRY*)
   2782 (asdf:require-system :slynk)
   2783 @end example
   2784 
   2785 inside a running Lisp image@footnote{@SLY{} also SLIME's old-style
   2786 @code{slynk-loader.lisp} loader which does the same thing, but ASDF is preferred}.
   2787 
   2788 Now all we need to do is startup our Slynk server. A working example
   2789 uses the default settings:
   2790 
   2791 @example
   2792 (slynk:create-server)
   2793 @end example
   2794 
   2795 This creates a ``one-connection-only'' server on port 4005 using the
   2796 preferred communication style for your Lisp system. The following
   2797 parameters to @code{slynk:create-server} can be used to change that
   2798 behaviour:
   2799 
   2800 @table @code
   2801 @item :PORT
   2802 Port number for the server to listen on (default: 4005).
   2803 @item :DONT-CLOSE
   2804 Boolean indicating if the server will continue to accept connections
   2805 after the first one (default: @code{NIL}). For ``long-running'' Lisp processes
   2806 to which you want to be able to connect from time to time,
   2807 specify @code{:dont-close t}
   2808 @item :STYLE
   2809 See @xref{Communication style}.
   2810 @end table
   2811 
   2812 So a more complete example will be
   2813 @example
   2814 (slynk:create-server :port 4006  :dont-close t)
   2815 @end example
   2816 
   2817 Finally, since section we're going to be tunneling our connection via
   2818 @acronym{SSH}@footnote{there is a way to connect without an SSH
   2819 tunnel, but it has the side-effect of giving the entire world access
   2820 to your Lisp image, so we're not going to talk about it} we'll only
   2821 have one port open we must tell Slynk's REPL contrib (see @REPL{}) to
   2822 not use an extra connection for output, which it will do by default.
   2823 
   2824 @example
   2825 (setf slynk:*use-dedicated-output-stream* nil)
   2826 @end example
   2827 
   2828 @footnote{Alternatively, a separate tunnel for the port set in
   2829 @code{slynk:*dedicated-output-stream-port*} can also be used if a dedicated output
   2830 is essential.}
   2831 
   2832 @node Setting up Emacs
   2833 @subsection Setting up Emacs
   2834 
   2835 Now we need to create the tunnel between the local machine and the
   2836 remote machine. Assuming a @acronym{UNIX} command-line, this can be
   2837 done with:
   2838 
   2839 @example
   2840 ssh -L4005:localhost:4005 youruser@@remote.example.com
   2841 @end example
   2842 
   2843 This incantation creates a SSH tunnel between the port 4005 on our
   2844 local machine and the port 4005 on the remote machine,
   2845 where @code{youruser} is expected to have an account.  @footnote{By
   2846 default Slynk listens for incoming connections on port 4005, had we
   2847 passed a @code{:port} parameter to @code{slynk:create-server} we'd be
   2848 using that port number instead}.
   2849 
   2850 Finally we start @SLY{} with @code{sly-connect} instead of the usual
   2851 @code{sly}:
   2852 
   2853 @example
   2854 M-x sly-connect RET RET
   2855 @end example
   2856 
   2857 The @kbd{RET RET} sequence just means that we want to use the default
   2858 host (@code{localhost}) and the default port (@code{4005}). Even
   2859 though we're connecting to a remote machine the SSH tunnel fools Emacs
   2860 into thinking it's actually @code{localhost}.
   2861 
   2862 @node Setting up pathname translations
   2863 @subsection Setting up pathname translations
   2864 
   2865 One of the main problems with running slynk remotely is that Emacs
   2866 assumes the files can be found using normal filenames. if we want
   2867 things like @code{sly-compile-and-load-file} (@kbd{C-c C-k}) and
   2868 @code{sly-edit-definition} (@kbd{M-.}) to work correctly we need to
   2869 find a way to let our local Emacs refer to remote files.
   2870 
   2871 There are, mainly, two ways to do this. The first is to mount, using
   2872 NFS or similar, the remote machine's hard disk on the local machine's
   2873 file system in such a fashion that a filename like
   2874 @file{/opt/project/source.lisp} refers to the same file on both
   2875 machines. Unfortunately NFS is usually slow, often buggy, and not
   2876 always feasible. Fortunately we have an ssh connection and Emacs'
   2877 @code{tramp-mode} can do the rest.
   2878 (See @inforef{Top, TRAMP User Manual,tramp}.)
   2879 
   2880 What we do is teach Emacs how to take a filename on the remote machine
   2881 and translate it into something that tramp can understand and access
   2882 (and vice versa). Assuming the remote machine's host name is
   2883 @code{remote.example.com}, @code{cl:machine-instance} returns
   2884 ``remote'' and we login as the user ``user'' we can use @code{sly-tramp}
   2885 contrib to setup the proper translations by simply doing:
   2886 
   2887 @example
   2888 (add-to-list 'sly-filename-translations
   2889              (sly-create-filename-translator
   2890               :machine-instance "remote"
   2891               :remote-host "remote.example.com"
   2892               :username "user"))
   2893 @end example
   2894 
   2895 @node Loading Slynk faster
   2896 @section Loading Slynk faster
   2897 
   2898 In this section, a technique to load Slynk faster on South Bank Common
   2899 Lisp (SBCL) is presented.  Similar setups should also work for other
   2900 Lisp implementations.
   2901 
   2902 A pre-canned solution that automates this technique was developed by
   2903 @uref{https://gitlab.com/ambrevar/lisp-repl-core-dumper,Pierre
   2904 Neidhardt}.
   2905 
   2906 For SBCL, we recommend that you create a custom core file with socket
   2907 support and @acronym{POSIX} bindings included because those modules
   2908 take the most time to load.  To create such a core, execute the
   2909 following steps:
   2910 
   2911 @example
   2912 shell$ sbcl
   2913 * (mapc 'require '(sb-bsd-sockets sb-posix sb-introspect sb-cltl2 asdf))
   2914 * (save-lisp-and-die "sbcl.core-for-sly")
   2915 @end example
   2916 
   2917 After that, add something like this to your @file{~/.emacs} or
   2918 @file{~/.emacs.d/init.el} (@pxref{Emacs Init File}):
   2919 
   2920 @lisp
   2921 (setq sly-lisp-implementations '((sbcl ("sbcl" "--core"
   2922       "sbcl.core-for-sly"))))
   2923 @end lisp
   2924 
   2925 For maximum startup speed you can include the Slynk server directly in
   2926 a core file.  The disadvantage of this approach is that the setup is a
   2927 bit more involved and that you need to create a new core file when you
   2928 want to update @SLY{} or @acronym{SBCL}.  The steps to execute are:
   2929 
   2930 @example
   2931 shell$ sbcl
   2932 * (load ".../sly/slynk-loader.lisp")
   2933 * (slynk-loader:dump-image "sbcl.core-with-slynk")
   2934 @end example
   2935 
   2936 @noindent
   2937 Then add this to the Emacs initializion file:
   2938 
   2939 @anchor{init-example}
   2940 @lisp
   2941 (setq sly-lisp-implementations
   2942       '((sbcl ("sbcl" "--core" "sbcl.core-with-slynk")
   2943               :init (lambda (port-file _)
   2944                       (format "(slynk:start-server %S)\n" port-file)))))
   2945 @end lisp
   2946 
   2947 @node Auto-SLY
   2948 @section Connecting to SLY automatically
   2949 
   2950 To make @SLY{} connect to your lisp whenever you open a lisp file
   2951 just add this to your @file{~/.emacs} or
   2952 @file{~/.emacs.d/init.el} (@pxref{Emacs Init File}):
   2953 
   2954 @example
   2955 (add-hook 'sly-mode-hook
   2956           (lambda ()
   2957             (unless (sly-connected-p)
   2958               (save-excursion (sly)))))
   2959 @end example
   2960 
   2961 @node REPLs and game loops
   2962 @section REPLs and ``Game Loops''
   2963 
   2964 When developing Common Lisp video games or graphical applications, a
   2965 REPL (@pxref{REPL}) is just as useful as anywhere else.  But it is often
   2966 the case that one needs to control exactly the timing of REPL requests
   2967 and ensure they do not interfere with the ``game loop''.  In other
   2968 situations, the choice of communication style (@pxref{Communication
   2969 style}) to the Slynk server may invalidate simultaneous multi-threaded
   2970 operation of REPL and game loop.
   2971 
   2972 Instead of giving up on the REPL or using a complicated solution, SLY's
   2973 REPL can be built into your game loop by using a couple of Slynk Common
   2974 Lisp functions, @code{SLYNK-MREPL:SEND-PROMPT} and
   2975 @code{SLYNK:PROCESS-REQUESTS}.
   2976 
   2977 @example
   2978 (defun my-repl-aware-game-loop ()
   2979   (loop initially
   2980           (princ "Starting our game")
   2981           (slynk-mrepl:send-prompt)
   2982         for i from 0
   2983         do (with-simple-restart (abort "Skip rest of this game loop iteration")
   2984              (when (zerop (mod i 10))
   2985                (fresh-line)
   2986                (princ "doing high-priority 3D game loop stuff"))
   2987              (sleep 0.1)
   2988              ;; When you're ready to serve a potential waiting 
   2989              ;; REPL request, just do this non-blocking thing:
   2990              (with-simple-restart (abort "Abort this game REPL evaluation")
   2991                (slynk:process-requests t)))))
   2992 @end example
   2993 
   2994 Note that this function is to be called @emph{from the REPL}, and will
   2995 enter kind of ``sub-REPL'' inside it.  It'll likely ``just work'' in
   2996 this situation.  However, if you need you need to call this from
   2997 anywhere else (like, say, another thread), you must additionally arrange
   2998 for the variable @code{SLYNK-API:*CHANNEL*} to be bound to the value it
   2999 is bound to in whatever SLY REPL you wish to interact with your game.
   3000 
   3001 @node Controlling SLY from outside Emacs
   3002 @section Controlling SLY from outside Emacs
   3003 
   3004 If your application has a non-SLY, non-Emacs user interface (graphical
   3005 or otherwise), you can use it to exert some control over SLY
   3006 functionality, such as its REPL (@pxref{REPL}) and inspector
   3007 (@pxref{Inspector}).  This requires that you first set, in Emacs,
   3008 variable @code{sly-enable-evaluate-in-emacs} to non-nil.  As the name
   3009 suggests, it lets outside Slynk servers evaluate code in your Elisp
   3010 runtime.  It is set to @code{nil} by default for security purposes.
   3011 
   3012 Once you've done that, you can
   3013 call @code{SLYNK-MREPL:COPY-TO-REPL-IN-EMACS} from your CL code with
   3014 some objects you'd like to manipulate in the REPL.  Then you can have
   3015 this code run from some UI event handler:
   3016 
   3017 @example
   3018 (lambda ()
   3019   (slynk-mrepl:copy-to-repl-in-emacs
   3020      (list 42 'foo)
   3021      :blurb "Just a forty-two and a foo"))
   3022 @end example
   3023 
   3024 And see those objects pop up in your REPL for inspection and
   3025 manipulation.
   3026 
   3027 You can also use the functions @code{SLYNK:INSPECT-IN-EMACS},
   3028 @code{SLYNK:ED-IN-EMACS}, and in general, any exported function ending
   3029 in @code{IN-EMACS}.  See their docstrings for details.
   3030 
   3031 @node Extensions
   3032 @chapter Extensions
   3033 
   3034 @menu
   3035 * Loading and unloading::       More contribs::
   3036 * More contribs::
   3037 @end menu
   3038 
   3039 @cindex Contribs
   3040 @cindex Contributions
   3041 @cindex Plugins
   3042 @cindex Extensions
   3043 
   3044 Extensions, also known as ``contribs'' are Emacs packages that extend
   3045 @SLY{}’s functionality. Contrasting with its ancestor @SLIME{}
   3046 (@pxref{Introduction}), most contribs bundled with @SLY{} are active
   3047 by default, since they are a decent way to split @SLY{} into pluggable
   3048 modules. The auto-documentation (@pxref{Autodoc}), trace (@pxref{Trace
   3049 Dialog}) and Stickers (@pxref{Stickers}) are contribs enabled by
   3050 default, for example.
   3051 
   3052 Usually, contribs differ from regular Emacs plugins in that they are
   3053 partly written in Emacs-lisp and partly in Common Lisp. The former is
   3054 usually the UI that queries the latter for information and then
   3055 presents it to the user. @SLIME{} used to load all the contribs’
   3056 Common Lisp code upfront, but @SLY{} takes care to loading these two
   3057 parts at the correct time. In this way, developers can write
   3058 third-party contribs that live independently of @SLY{} perhaps even in
   3059 different code repositories. The @code{sly-macrostep} contrib
   3060 (@uref{https://github.com/joaotavora/sly-macrostep}) is one such
   3061 example.
   3062 
   3063 A special @code{sly-fancy} contrib package is the only one loaded by
   3064 default. You might never want to fiddle with it (it is the one that
   3065 contains the default extensions), but if you find that you don't like
   3066 some package or you are having trouble with a package, you can modify
   3067 your setup a bit.  Generally, you set the variable @code{sly-contribs}
   3068 with the list of package-names that you want to use.  For example, a
   3069 setup to load only the @code{sly-scratch} and @code{sly-mrepl}
   3070 packages looks like:
   3071 
   3072 @example
   3073 ;; @emph{Setup load-path and autoloads}
   3074 (add-to-list 'load-path "~/dir/to/cloned/sly")
   3075 (require 'sly-autoloads)
   3076 
   3077 ;; @emph{Set your lisp system and some contribs}
   3078 (setq inferior-lisp-program "/opt/sbcl/bin/sbcl")
   3079 (setq sly-contribs '(sly-scratch sly-mrepl))
   3080 @end example
   3081 
   3082 After starting @SLY{}, the commands of both packages should be
   3083 available.
   3084 
   3085 @node Loading and unloading
   3086 @section Loading and unloading ``on the fly''
   3087 
   3088 We recommend that you setup the @code{sly-contribs}
   3089 variable @emph{before} starting @SLY{} via @kbd{M-x sly}, but if you
   3090 want to enable more contribs @emph{after} you that, you can set
   3091 new @code{sly-contribs} variable to another value and call @code{M-x
   3092 sly-setup} or @code{M-x sly-enable-contrib}. Note this though:
   3093 
   3094 @itemize @bullet
   3095 @item
   3096 If you've removed contribs from the list they won't be unloaded
   3097 automatically.
   3098 @item
   3099 If you have more than one @SLY{} connection currently active, you must
   3100 manually repeat the @code{sly-setup} step for each of them.
   3101 @end itemize
   3102 
   3103 Short of restarting Emacs, a reasonable way of unloading contribs is
   3104 by calling an Emacs Lisp function whose name is obtained by
   3105 adding @code{-unload} to the contrib's name, for every contrib you
   3106 wish to unload. So, to remove @code{sly-mrepl}, you must call
   3107 @code{sly-mrepl-unload}. Because the unload function will only, if
   3108 ever, unload the Emacs Lisp side of the contrib, you may also need to
   3109 restart your lisps.
   3110 
   3111 @node More contribs
   3112 @section More contribs
   3113 
   3114 @menu
   3115 * TRAMP Support::
   3116 * Scratch Buffer::
   3117 @end menu
   3118 
   3119 @node TRAMP Support
   3120 @subsection TRAMP
   3121 
   3122 @cindex TRAMP
   3123 
   3124 The package @code{sly-tramp} provides some functions to set up
   3125 filename translations for TRAMP. (@pxref{Setting up pathname
   3126 translations})
   3127 
   3128 @node Scratch Buffer
   3129 @subsection Scratch Buffer
   3130 
   3131 @anchor{sly-scratch}
   3132 The @SLY{} scratch buffer, in contrib package @code{sly-scratch},
   3133 imitates Emacs' usual @code{*scratch*} buffer.
   3134 If @code{sly-scratch-file} is set, it is used to back the scratch
   3135 buffer, making it persistent. The buffer is like any other Lisp
   3136 buffer, except for the command bound to @kbd{C-j}.
   3137 
   3138 @table @kbd
   3139 
   3140 @kbditem{C-j, sly-eval-print-last-expression}
   3141 Evaluate the expression sexp before point and insert a printed
   3142 representation of the return values into the current buffer.
   3143 
   3144 @cmditem{sly-scratch}
   3145 Create a @file{*sly-scratch*} buffer. In this
   3146 buffer you can enter Lisp expressions and evaluate them with
   3147 @kbd{C-j}, like in Emacs's @file{*scratch*} buffer.
   3148 
   3149 @end table
   3150 
   3151 
   3152 @node Credits
   3153 @chapter Credits
   3154 
   3155 @emph{The soppy ending...}
   3156 
   3157 @unnumberedsec Hackers of the good hack
   3158 
   3159 @SLY{} is a fork of SLIME which is itself an Extension
   3160 of @acronym{SLIM} by Eric Marsden. At the time of writing, the authors
   3161 and code-contributors of @SLY{} are:
   3162 
   3163 @include contributors.texi
   3164 
   3165 ... not counting the bundled code from @file{hyperspec.el},
   3166 @cite{CLOCC}, and the @cite{CMU AI Repository}.
   3167 
   3168 Many people on the @code{sly-devel} mailing list have made non-code
   3169 contributions to @SLY{}. Life is hard though: you gotta send code to
   3170 get your name in the manual. @code{:-)}
   3171 
   3172 @unnumberedsec Thanks!
   3173 
   3174 We're indebted to the good people of @code{common-lisp.net} for their
   3175 hosting and help, and for rescuing us from ``Sourceforge hell.''
   3176 
   3177 Implementors of the Lisps that we support have been a great help. We'd
   3178 like to thank the @acronym{CMUCL} maintainers for their helpful
   3179 answers, Craig Norvell and Kevin Layer at Franz providing Allegro CL
   3180 licenses for @SLY{} development, and Peter Graves for his help to
   3181 get @SLY{} running with @acronym{ABCL}.
   3182 
   3183 Most of all we're happy to be working with the Lisp implementors
   3184 who've joined in the @SLY{} development: Dan Barlow and Christophe
   3185 Rhodes of @acronym{SBCL}, Gary Byers of OpenMCL, and Martin Simmons of
   3186 LispWorks. Thanks also to Alain Picard and Memetrics for funding
   3187 Martin's initial work on the LispWorks backend!
   3188 
   3189 @node Key Index
   3190 @unnumbered Key (Character) Index
   3191 @printindex ky
   3192 
   3193 @node Command Index
   3194 @unnumbered Command and Function Index
   3195 @printindex fn
   3196 
   3197 @node Variable Index
   3198 @unnumbered Variable and Concept Index
   3199 @printindex vr
   3200 
   3201 @bye
   3202 Local Variables:
   3203 paragraph-start: "@[a-zA-Z]+\\({[^}]+}\\)?[ \n]\\|[ ]*$"
   3204 paragraph-separate: "@[a-zA-Z]+\\({[^}]+}\\)?[ \n]\\|[ ]*$"
   3205 End:
   3206 
   3207 @c  LocalWords:  RET backreferences defun Autodoc autodoc minibuffer
   3208 @c  LocalWords:  backreference