SLIME Tips and Techniques - Part 3
Monday, January 22, 2007
There are a pair of functions in SLIME that have no key
bindings, aren't documented in the SLIME manual, and which I seem to use a lot but nobody else does! The functions
are slime-insert-balanced-comments and it's complement
slime-remove-balanced-comments. I normally bind the first command to
"C-c ;" and the second one to "C-c M-;". The command
slime-insert-balanced-comments inserts a set of balanced comments around the s-expression
containing the point. If this command is invoked repeatedly
(without any other command occurring between invocations), the
comment progressively moves outward over enclosing expressions.
If invoked with a positive prefix argument, the s-expression arg
expressions out is enclosed in a set of balanced comments.
I find these commands really useful when I'm testing code and want to disable certain "chunks" of the existing logic. For example, say you have the following code snippet (with the point located immediately after the '(print "none")' sexp):
(if a (print "a") (if b (print "b") (if c (print "c") (if d (print "d") (print "none")))))If I press "C-c ;", the last "if" form is commented out:
(if a (print "a") (if b (print "b") (if c (print "c") #|(if d (print "d") (print "none"))|#)))If I press "C-c ;" again (without moving the point), the comment is "moved up" and the enclosing "(if c ..." sexp is commented out:
(if a (print "a") (if b (print "b") #|(if c (print "c") (if d (print "d") (print "none")))|#))Or, alternatively, I could have just used a prefix command to comment out that form directly (e.g. - "C-2 C-c ;").
When I want to remove the comment, I just press "C-c M-;" with the point anywhere inside the comment.