您如何使用Paredit评论全部或部分Lisp s-exp? [英] How do you comment out all or part of a Lisp s-exp using Paredit?

查看:116
本文介绍了您如何使用Paredit评论全部或部分Lisp s-exp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编辑Lisp代码时,有时候可以完全注释顶级定义,如下所示:

When editing Lisp code, occasionally it's useful to entirely comment out a top-level definition, like this:

;(defun some-fn-which-is-broken (x)
;  ...)

...或注释掉s-e​​xpression的一部分,如下所示:

... or comment out only part of an s-expression, like this:

(foo x
;    y
     z)

...然后重新编译文件并在REPL中测试某些东西,等等。

... and then recompile the file and test something in the REPL, etc.

启用paredit模式后,这不起作用。以下是发生的情况,如果点正好在下面的第一个括号之前:

With paredit-mode enabled, this doesn't work. Here's what happens, if the point is right before the first paren below:

(defun some-fn (x)
  ...)

并输入一个分号,输入的是分号和换行符:

and you type a semicolon, what is entered is a semicolon and a newline:

;
(defun some-fn (x)
  ...)

注释掉s表达式的一部分:

Same with commenting out part of the s-expression:

(foo x
;    
     y
     z)

我认为,如果定义全部在一行,这样做:

I think that if the definition is all on one line, this works:

;(defparameter *foo* 10)

...但否则我无法找出如何做到这一点。 Paredit是伟大的,我真的很想继续使用它。有没有一个知道这个方法的Lispers,或者Emacs-wizards,可以鞭打一些Emacs Lisp绑定到像 paredit-comment-out-s-expr

... but otherwise I can't find out how to do this. Paredit is great, I would really like to keep using it. Are there any Lispers who know a way around this, or Emacs-wizards who can whip up a bit of Emacs Lisp to bind to something like paredit-comment-out-s-expr?

如果有更多的Lispy或Emacsy实现本质上相同的东西,注释出来的部分来源重新编译,请不要犹豫,建议他们

If there is a more Lispy or Emacsy way of accomplishing essentially the same thing, commenting out parts of source to recompile, please, don't hesitate to suggest them!

推荐答案

将点放在整个sexp的第一个字符上,用 CM-space标记整个sexp / kbd>,并发出 M - ; 来进行评论。如果需要这样做,您的源代码也将被重新格式化,以便只有您标记的sexp,而且同一行中的任何内容都不在同一行。

Position the point on the first character of the whole sexp, mark the whole sexp with C-M-space, and issue M-; to do the commenting. If it is necessary to do so, your source code will also be re-formatted so that only the sexp you marked, and nothing that was also on the same line, is in a comment.

你可以很容易地做一个简单的命令,甚至一个宏来做到这一点:

You can very easily make a simple command or even a macro to do that:


(defun comment-sexp ()
  "Comment out the sexp at point."
  (interactive)
  (save-excursion
    (mark-sexp)
    (paredit-comment-dwim)))

这篇关于您如何使用Paredit评论全部或部分Lisp s-exp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆