Saturday, January 12, 2008

slime-close-parens-at-point

So I'm learning Lisp. I'm doing this by using Emacs and SLIME. That's cool, right? This combo is far and away the closest I've ever been to "interactive programming", and the experience is very, very cool. It's quite true when you hear somebody say that you need a Lisp-aware editor to truly experience Lisp. Things have mostly been going smoothly.

Except C-c C-q. This key chord supposedly triggers (slime-close-parens-at-point), which will insert just enough parentheses as necessary to make the whole surrounding expression valid. Before, I was using C-c C-], which dumps as many parentheses to finish all expressions before it, a different matter altogether. Sounds like a time-saver, right?

It would be, if not for the fact that the damn thing doesn't work. Terminal Emacs? Nope. GTK+ Emacs? Nope. In the SLIME REPL? Nope. In a Lisp buffer while SLIME is active? Nope. Why does this one thing not work? I can use other key chords just fine, like C-c C-c to incrementally run a function definition on the spot.

I'm going to do some Googling, but if anybody knows what the deal is, please leave a comment.

4 comments:

jfm3 said...

Do you have slime-editing-commands.el loaded?

tunginobi said...

I do now, thanks!

But it seems like that one function has been commented out anyway:

;; SLIME-CLOSE-PARENS-AT-POINT is obsolete:

;; It doesn't work correctly on the REPL, because there
;; BEGINNING-OF-DEFUN-FUNCTION and END-OF-DEFUN-FUNCTION is bound to
;; SLIME-REPL-MODE-BEGINNING-OF-DEFUN (and
;; SLIME-REPL-MODE-END-OF-DEFUN respectively) which compromises the
;; way how they're expect to work (i.e. END-OF-DEFUN does not signal
;; an UNBOUND-PARENTHESES error.)

;; Use SLIME-CLOSE-ALL-PARENS-IN-SEXP instead.

;; (defun slime-close-parens-at-point ()
;; "Close parenthesis at point to complete the top-level-form. Simply
;; inserts ')' characters at point until `beginning-of-defun' and
;; `end-of-defun' execute without errors, or `slime-close-parens-limit'
;; is exceeded."
;; (interactive)
;; (loop for i from 1 to slime-close-parens-limit
;; until (save-excursion
;; (slime-beginning-of-defun)
;; (ignore-errors (slime-end-of-defun) t))
;; do (insert ")")))

I tried uncommenting it, but C-c C-q still didn't work. I then tried adding the key binding to the bottom with the others, like this:

(defun slime-editing-commands-init ()
(define-key slime-mode-map "\M-\C-a" 'slime-beginning-of-defun)
(define-key slime-mode-map "\M-\C-e" 'slime-end-of-defun)
(define-key slime-mode-map "\C-c\M-q" 'slime-reindent-defun)
(define-key slime-mode-map "\C-c\C-q" 'slime-close-parens-at-point))

But, still nothing.

Anonymous said...

(global-set-key (kbd "C-c C-q") 'slime-close-all-parens-in-sexp ); Ctrl+c Ctrl+q

works here... but then again I only just started playing with lisp, dont know the expected behaviour.

/k

tunginobi said...

Paren-balancing isn't so much of an issue anymore now that I've gotten into using paredit, but thanks anyway.