October 2011
15 posts
Reloading Slime without restarting Emacs
After updating Slime it’s usually needed to restart Emacs so that the changes take effect, but restarting Emacs is quite inconvenient. After adding the following code into .emacs, M-x slime-reload will reload all the Emacs Lisp parts (CL side should be restarted with ,restart short-cut in the REPL).
(defun load-slime ()
;; here should be placed all the usual configuration code.
;; like...
Failed FASLs
When doing C-c C-k and COMPILE-FILE returns failure-p, slime asks whether to load the resulting fasl, although the compilation process failed. The default action can be controlled by slime-load-failed-fasl variable, it accepts the following values: never don’t load the fasl always load the fasl ask ask the user (default).
I have it set to always.
Keeping FASLs away
C-c C-k by default puts FASLs in the same directory as the .lisp file, which may be not very nice.
(setq slime-compile-file-options '(:fasl-directory "/tmp/slime-fasls/"))
will place fasls into “/tmp/slime-fasls/”. I also have
(make-directory "/tmp/slime-fasls/" t)
in my .emacs to make sure the directory exists (/tmp gets cleaned on each reboot).
Compilation policies
C-u C-c C-c and C-u C-c C-k will compile code with DEBUG optimization set to 3. M–– C-c C-c and M–– C-c C-k will compile code with SPEED set to 3.
Monitoring and controlling threads
M-x slime-list-threads (you can also access it through slime-selector shortcut t) will list running threads by their names, and their statuses.
The thread on the current line can be killed with k, or if there’s a lot of threads to kill, several lines can be selected and k will kill all the threads in the selected region.
g will update the thread list, but when you have a lot of threads...
Inspector navigation
A couple of inspector commands: l go back to the previous inspected object. n go forward. g reinspect current object (g is generally used for updating things throughout Emacs).
Disassembling and inspecting things
While things can be inspected and disassembled by their name with slime-inspect (C-c I) and slime-disassemble-symbol (C-c M-d), it’s often easier to do that through their definitions.
slime-inspect-definition inspects the object defined by the definition at point (e.g. defun or defpackage), works on functions, variables, macros, packages, classes. slime-disassemble-definition disassemble...
Cross referencing
Slime has a nice cross referencing facility, for example, you can see what calls a particular function or expands a macro. It presents a list of places which reference a particular entity, from there you can recompile the thing which references by pressing C-c C-c on that line. C-c C-k will recompile all the references. This is useful when modifying macros, inline functions, or constants....
Expanding format strings
M-x slime-format-string-expand: expands the format control string at point.
”~a, ~a.” on SBCL yields
#'(LAMBDA
(STREAM
&OPTIONAL
(#:FORMAT-ARG1502
(ERROR 'SB-FORMAT:FORMAT-ERROR :COMPLAINT "required argument missing"
:CONTROL-STRING "~a, ~a." :OFFSET 1))
(#:FORMAT-ARG1503
(ERROR 'SB-FORMAT:FORMAT-ERROR :COMPLAINT "required...
REPL history customization
There are two useful features which are turned off by default slime-repl-history-remove-duplicates, when set to T removes duplicate entries. slime-repl-history-trim-whitespaces, when set to T strips whitespace characters from the beginning and the end.
Clearing REPL
C-c M-o clears everything, only leaves a new prompt. C-c C-o clears output of the previous command, for example, after evaluting (make-array 10000) there’ll be a large array printed, and C-c C-o will only remove that array, leaving all previous command outputs untouched.
Update: C-c M-o also clears presentations and *, **, ***, etc. variables (the latter feature was added just today), so...
Documentation look up
C-c C-d h looks up documentation in CLHS. But it works only on symbols, so there are two more bindings: C-c C-d # for reader macros C-c C-d ~ for format directives Other bindings which may be useful: C-c C-d d describes a symbol using DESCRIBE C-c C-d f describes a function using DESCRIBE
slime-selector
Slime has many buffers, and sometimes it’s not easy navigating between them, slime-selector simplifies this task. It’s not bound to any key by default, I bind it globally to C-z
(global-set-key "\C-z" 'slime-selector)
Then it allows you to select a buffer by a letter. Some of the most useful shortcuts are listed here, the full list can be seen by pressing “?”.
r ...
Synchronizing packages
C-c ~ (slime-sync-package-and-default-directory): When run in a buffer with a lisp file it will change the current package of the REPL to the package of that file and also set current directory of the REPL to the parent directory of the file. On success it will display
package: NEW-PACKAGE-NAME directory: ~/
in the minibuffer, or
package: CURRENT-REPL-PACKAGE (package :foo doesn't exist) ...
Viewing large arglists
Arglists of some functions are quite long and they may not fit on the screen in one line, there are two ways to display them. First
(setq slime-autodoc-use-multiline-p t)
that’ll make the minbuffer change its height automatically to accommodate several lines of text. But I find it annoying when the minibuffer jumps up and down, especially when I don’t really want to read the whole...
September 2011
2 posts
Calling code
C-c C-y (slime-call-defun): When the point is inside a defun and C-c C-y is pressed, (I’ll use [] as an indication where the cursor is)
(defun foo ()
nil[])
then “(foo [])” will be inserted into the REPL, so that you can write additional arguments and run it.
If FOO was in a different package than the package of the REPL, (package:foo ) or (package::foo ) will be inserted....