开发者

Does SLIME have a shortcut key to comment a block of Lisp code in slime-mode?

I开发者_运维百科'd rather not have to manually add semicolons to every line.

Specs:

Aquamacs 2.1 (Emacs 23.2)

SLIME 2010-11-16

MacPorts CLISP 2.49

Mac OS X 10.6.4

MacBook Pro 5,1


If the block of the code is a Lisp form and you would like to comment this form out, you can use slime-insert-balanced-comments (I use M-x s-i-b-c and SLIME expands the command automatically). To uncomment it use slime-remove-balanced-comments (M-x s-r-b-c).

I found these commands very useful.

Also I put the following block in my .emacs file:

;; Comment function
(defun comment-or-uncomment-this (&optional lines)
   (interactive "P")
   (if mark-active
      (if (< (mark) (point))
         (comment-or-uncomment-region (mark) (point))
         (comment-or-uncomment-region (point) (mark)))
      (comment-or-uncomment-region
         (line-beginning-position)
         (line-end-position lines))))

(global-set-key (kbd "C-;") 'comment-or-uncomment-this)

I guess, it was from here.

UPD: I forgot to mention that despite the fact that slime-insert/remove-balanced-comments works just fine with paredit, the C-; command can be a big pain to use on lines that have uneven number of parentheses on them. In case of lines like

((blah|-blah)))))))

(where | means the point), I first press ) as many times as necessary to break the line in the correct place and to detach outer closing parentheses from this line (in this case it would be two times). Paredit helps here: it reorganizes the s-exp so that closing parentheses are split in two parts and thus you can comment the line out without breaking outer s-exps. In the last example the line turns into:

  ((blah-blah))
|)))))

and the first line can be safely commented out with C-;.


Look here:

  • http://wwwx.cs.unc.edu/~sud/tips/Emacs_Tips.html

It's M-x comment-region, but there's no default key binding for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜