SLIME Tips and Techniques - Part 2
Sunday, January 21, 2007
Luke Gorrie (Lisp and Erlang hacker extraordinaire) sent me a SLIME tip which I hadn't known about. I knew that you could use both slime-close-parens-at-point and slime-close-all-sexp to close all parens; however, I just assumed that they did basically the same thing. Well, it turns out that slime-close-parens-at-point can be used to close parens inside a top level form (not just at the end like slime-close-all-sexp does) - pretty nifty! Here's Luke's tip (slightly edited):
My possibly-little-known tip would be:Note that if you had used C-c C-] (`slime-close-all-sexp') at the same point, it would have inserted enough parens to close the top-level form - which is not wanted in this case:
`C-c C-q' - slime-close-parens-at-point: Closes parentheses at point to complete the top-level-form by inserting ')' characters until `(save-excursion (beginning-of-defun) (end-of-defun))' executes without errors, or `slime-close-parens-limit' is exceeded.
Consider code like this (where | is the point):(defun foo (x) (let ((*y* (zonk x| (bar x)))Here we had a working function but we've hacked on the middle line and unbalanced the parens in the process. Now we have to insert the right number of ')' characters to make them balance again.
`C-c C-q' automatically inserts the right number of )'s at point:(defun foo (x) (let ((*y* (zonk x)))| (bar x)))This only works if the top-level-form can be made well-formed by inserting )'s at point. Otherwise it has no effect.
I'm not sure if this exists in other editing modes. I added it to SLIME based on my misunderstanding of a request for the similar feature `C-]' (`slime-close-all-sexp') which I've never gotten the hang of.
(defun foo (x) (let ((*y* (zonk x)))))| (bar x)))So, it's good to know the difference in the two SLIME functions. Since slime-close-parens-at-point always "does the right thing", I'll start using that instead of slime-close-all-sexp from now on.
Keep those cards and letters (with SLIME tips) coming in! ;-)