Next: , Previous: Fancy Inspector, Up: Contributed Packages


8.12 Presentations

A “presentation”1 in SLIME is a region of text associated with a Lisp object. Right-clicking on the text brings up a menu with operations for the particular object. Some operations, like inspecting, are available for all objects, but the object may also have specialized operations. For instance, pathnames have a dired operation.

More importantly, it is possible to cut and paste presentations (i.e., Lisp objects, not just their printed presentation), using all standard Emacs commands. This way it is possible to cut and paste the results of previous computations in the REPL. This is of particular importance for unreadable objects.

The package slime-presentations installs presentations in the REPL, i.e. the results of evaluation commands become presentations. In this way, presentations generalize the use of the standard Common Lisp REPL history variables *, **, ***. Example:

     CL-USER> (find-class 'standard-class)
     #<STANDARD-CLASS STANDARD-CLASS>
     CL-USER>

Presentations appear in red color in the buffer. (In this manual, we indicate the presentations like this.) Using standard Emacs commands, the presentation can be copied to a new input in the REPL:

     CL-USER> (eql '#<STANDARD-CLASS STANDARD-CLASS>
                   '#<STANDARD-CLASS STANDARD-CLASS>)
     T

Note that standard evaluation and quoting rules still apply. So if a presentation is a list, it needs to be quoted in an evaluated context to avoid treating it as a function call:

     CL-USER> (list (find-class 'standard-class) 2 3 4)
     (#<STANDARD-CLASS STANDARD-CLASS> 2 3 4)
     CL-USER> (#<STANDARD-CLASS STANDARD-CLASS> 2 3 4)
     ; Funcall of #<STANDARD-CLASS STANDARD-CLASS> which is a non-function.
     ; Evaluation aborted.
     CL-USER> '(#<STANDARD-CLASS STANDARD-CLASS> 2 3 4)
     (#<STANDARD-CLASS STANDARD-CLASS> 2 3 4)

When you copy an incomplete presentation or edit the text within a presentation, the presentation changes to plain text, losing the association with a Lisp object. In the buffer, this is indicated by changing the color of the text from red to black. This can be undone.

Presentations are also available in the inspector (all inspectable parts are presentations) and the debugger (all local variables are presentations). This makes it possible to evaluate expressions in the REPL using objects that appear in local variables of some active debugger frame; this can be more convenient than using M-x sldb-eval-in-frame. Warning: The presentations that stem from the inspector and debugger are only valid as long as the corresponding buffers are open. Using them later can cause errors or confusing behavior.

For some Lisp implementations you can also install the package slime-presentation-streams, which enables presentations on the Lisp *standard-output* stream and similar streams. This means that not only results of computations, but also some objects that are printed to the standard output (as a side-effect of the computation) are associated with presentations. Currently, all unreadable objects and pathnames get printed as presentations.

     CL-USER> (describe (find-class 'standard-object))
     #<STANDARD-CLASS STANDARD-OBJECT> is an instance of
         #<STANDARD-CLASS STANDARD-CLASS>:
      The following slots have :INSTANCE allocation:
       PLIST                   NIL
       FLAGS                   1
       DIRECT-METHODS          ((#<STANDARD-METHOD
                                   SWANK::ALL-SLOTS-FOR-INSPECTOR
                                   (STANDARD-OBJECT T)>
       ...

Again, this makes it possible to inspect and copy-paste these objects.

In addition to the standard Emacs commands, there are several keyboard commands, a menu-bar menu, and a context menu to operate on presentations. We describe the keyboard commands below; they are also shown in the menu-bar menu.

C-c C-v SPC
M-x slime-mark-presentation
If point is within a presentation, move point to the beginning of the presentation and mark to the end of the presentation. This makes it possible to copy the presentation.
C-c C-v w
M-x slime-copy-presentation-at-point-to-kill-ring
If point is within a presentation, copy the surrounding presentation to the kill ring.
C-c C-v r
M-x slime-copy-presentation-at-point-to-repl
If point is within a presentation, copy the surrounding presentation to the REPL.
C-c C-v d
M-x slime-describe-presentation-at-point
If point is within a presentation, describe the associated object.
C-c C-v i
M-x slime-inspect-presentation-at-point
If point is within a presentation, inspect the associated object with the SLIME inspector.
C-c C-v n
M-x slime-next-presentation
Move point to the next presentation in the buffer.
C-c C-v p
M-x slime-previous-presentation
Move point to the previous presentation in the buffer.
Similar operations are also possible from the context menu of every presentation. Using mouse-3 on a presentation, the context menu opens and offers various commands. For some objects, specialized commands are also offered. Users can define additional specialized commands by defining a method for swank::menu-choices-for-presentation.

Warning: On Lisp implementations without weak hash tables, all objects associated with presentations are protected from garbage collection. If your Lisp image grows too large because of that, use C-c C-v M-o (slime-clear-presentations) to remove these associations. You can also use the command C-c M-o (slime-repl-clear-buffer), which both clears the REPL buffer and removes all associations of objects with presentations.

Warning: Presentations can confuse new users.

     CL-USER> (cons 1 2)
     (1 . 2)
     CL-USER> (eq '(1 . 2) '(1 . 2))
     T

One could have expected NIL here, because it looks like two fresh cons cells are compared regarding object identity. However, in the example the presentation (1 . 2) was copied twice to the REPL. Thus EQ is really invoked with the same object, namely the cons cell that was returned by the first form entered in the REPL.


Footnotes

[1] Presentations are a feature originating from the Lisp machines. It was possible to define present methods specialized to various devices, e.g. to draw an object to bitmapped screen or to write some text to a character stream.