【发布时间】:2010-11-16 23:36:13
【问题描述】:
我宁愿不必手动为每一行添加分号。
规格:
Aquamacs 2.1 (Emacs 23.2)
史莱姆 2010-11-16
MacPorts CLISP 2.49
Mac OS X 10.6.4
MacBook Pro 5,1
【问题讨论】:
标签: emacs keyboard-shortcuts comments common-lisp slime
我宁愿不必手动为每一行添加分号。
规格:
Aquamacs 2.1 (Emacs 23.2)
史莱姆 2010-11-16
MacPorts CLISP 2.49
Mac OS X 10.6.4
MacBook Pro 5,1
【问题讨论】:
标签: emacs keyboard-shortcuts comments common-lisp slime
如果代码块是一个 Lisp 表单并且你想注释掉这个表单,你可以使用slime-insert-balanced-comments(我使用 M-x s-i-b-c 和 SLIME自动扩展命令)。
要取消注释,请使用 slime-remove-balanced-comments (M-x s-r-b-c)。
我发现这些命令非常有用。
我还将以下块放入我的 .emacs 文件中:
;; 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)
我猜,是来自here。
UPD:我忘了提到尽管slime-insert/remove-balanced-comments 与 paredit 配合得很好,但 C-; 命令可以在括号数奇数的行上使用会很痛苦。如果像
((blah|-blah)))))))
(其中| 表示点),我首先按需要多次按) 以在正确的位置换行并从该行中分离外部右括号(在这种情况下它将是两次)。 Paredit 在这里有帮助:它重新组织 s-exp,以便将右括号分成两部分,因此您可以在不破坏外部 s-exp 的情况下注释掉该行。在最后一个示例中,该行变为:
((blah-blah))
|)))))
第一行可以用 C-; 安全地注释掉。
【讨论】:
【讨论】:
comment-dwim在当前版本的Emacs中默认绑定到M-;。 (如果区域处于活动状态,这与comment-region 相同,否则它会在当前行的末尾添加注释。)