[slime-devel] Some new functions
Bill_Clementson at peoplesoft.com
Bill_Clementson at peoplesoft.com
Sun Mar 7 20:22:00 UTC 2004
I am enclosing some functions that I use quite a bit in my Lisp
programming. They might be useful to include in SLIME. The first 2 are
based on functions originally written by Paul Foley. If you want to include
them, I would suggest binding insert-balanced-comments to "C-c C-;" and
remove-balanced-comments to "C-c C-:". The third function uses font-lock to
visually transform the word "lambda" to the Greek lambda character.
Someone who wants to use this function would typically add it in for the
specific mode. For example:
(add-hook 'lisp-mode-hook (lambda ()
(slime-mode t)
(pretty-lambdas)))
Here are the 3 functions:
(defun insert-balanced-comments (arg)
"Insert 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."
(interactive "*p")
(save-excursion
(when (eq last-command this-command)
(when (search-backward "#|" nil t)
(save-excursion
(delete-char 2)
(while (and (< (point) (point-max)) (not (looking-at " *|#")))
(forward-sexp))
(replace-match ""))))
(while (> arg 0)
(backward-char 1)
(cond ((looking-at ")") (incf arg))
((looking-at "(") (decf arg))))
(insert "#|")
(forward-sexp)
(insert "|#")))
(defun remove-balanced-comments ()
"Remove a set of balanced comments enclosing point."
(interactive "*")
(save-excursion
(when (search-backward "#|" nil t)
(delete-char 2)
(while (and (< (point) (point-max)) (not (looking-at " *|#")))
(forward-sexp))
(replace-match ""))))
(defun pretty-lambdas ()
(font-lock-add-keywords
nil `(("(\\(lambda\\>\\)"
(0 (progn (compose-region (match-beginning 1) (match-end 1)
,(make-char 'greek-iso8859-7 107))
nil))))))
More information about the slime-devel
mailing list