SLIME 是否有快捷键可以在 slime 模式下注释 Lisp 代码块?

发布于 2024-10-03 05:22:36 字数 175 浏览 1 评论 0原文

我宁愿不必手动向每一行添加分号。

规格:

Aquamacs 2.1 (Emacs 23.2)

SLIME 2010-11-16

MacPorts CLISP 2.49

Mac OS X 10.6.4

MacBook Pro 5,1

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌若浮生 2024-10-10 05:22:36

如果代码块是 Lisp 表单,并且您想注释掉该表单,则可以使用 slime-insert-balanced-comments (我使用 Mx sibc 和 SLIME 自动扩展命令)。
要取消注释,请使用 slime-remove-balanced-comments (Mx srbc)。

我发现这些命令非常有用。

另外,我将以下块放入我的 .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)

我猜,它来自此处

UPD:我忘了提及,尽管 slime-insert/remove-balanced-comments 与 paredit 配合得很好,C-; 命令在括号数量不均匀的行上使用可能会很痛苦。对于像这样的行

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

(其中 | 表示点),我首先根据需要多次按 ) 在正确的位置换行并分离外部右括号从这一行开始(在本例中将是两次)。 Paredit 在这里有帮助:它重新组织 s-exp,以便将右括号分成两部分,因此您可以注释掉该行,而不会破坏外部 s-exp。在最后一个示例中,该行变为:

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

并且可以使用 C-; 安全地注释掉第一行。

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-;.

思念绕指尖 2024-10-10 05:22:36

看这里:

它是 Mx comment-region,但没有默认的键绑定。

Look here:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文