문제

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:

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top