在C模式下Emacs的评论区 [英] Emacs comment-region in C mode
问题描述
在GNU Emacs的,有没有从
In GNU Emacs, is there a good way to change the comment-region command in C mode from
/* This is a comment which extends */
/* over more than one line in C. */
到
/* This is a comment which extends
over more than one line in C. */
?我曾尝试
(setq comment-multi-line t)
但这并没有帮助。有一个<一href=\"http://www.gnu.org/software/emacs/manual/html%5Fmono/emacs.html#Multi%5F002dLine-Comments\">section多行注释在Emacs手册,但它并没有提到任何东西。
but this does not help. There is a section on multi-line comments in the Emacs manual, but it does not mention anything.
推荐答案
由于Emacs的21,还有的是一个名为模块<一个href=\"http://cvs.savannah.gnu.org/viewvc/%2Acheckout%2A/emacs/lisp/newcomment.el?root=emacs\"><$c$c>'newcomment$c$c>,它有不同的注释风格(见变量注释的风格
此设置得接近你想要什么:
Since Emacs 21, there's been a module named 'newcomment
, which has different comment styles (see the variable 'comment-styles
. This setting gets close to what you want:
(setq comment-style 'multi-line)
(注意:你可能应该在该设置'C型钩
)。
然而,没有任何的设置,使意见看起来像你想要的东西。
However, none of the settings make the comments look like what you want.
我看到了得到你想要的最简单的方法是添加这个技巧:
The easiest way I saw to get what you want is to add this hack:
(defadvice comment-region-internal (before comment-region-internal-hack-ccs activate)
"override 4th argument to be just spaces"
(when (eq major-mode 'c-mode) ; some condition here
(let ((arg (ad-get-arg 4)))
(when arg
(ad-set-arg 4 (make-string (length arg) ?\ ))))))
为注释风格的当前设置
总是preFIX注释行用*(如果不是全部的/ *)。
The current settings for comment-style
always prefix the comment lines with " * " (if not the whole " /* ").
如果你没有的Emacs 21,我想你可以简单地下载<一个href=\"http://cvs.savannah.gnu.org/viewvc/%2Acheckout%2A/emacs/lisp/newcomment.el?root=emacs\"><$c$c>newcomment.el$c$c>从资源库中。我不知道,如果它的工作原理,是在早期版本的Emacs,但它可能是值得一试,虽然升级Emacs的将是一个更好的解决方案。
If you don't have Emacs 21, I suppose you could simply download newcomment.el
from the repository. I don't know if it works as-is in earlier versions of Emacs, but it might be worth a shot, though upgrading Emacs would be a better solution.
我的黑客打破了取消注释区域
。一个适当的解决将是改变注释的padright
。这将需要多一点研究,以免破坏其他的东西。以上只是黑客行为的变化在'C模式
(调整状态,以自己的喜好)。
My hack breaks the 'uncomment-region
. A proper fix would be to change 'comment-padright
. That would take a little more research so as not to break other things. The above hack only changes behavior in 'c-mode
(adjust the condition to your liking).
这篇关于在C模式下Emacs的评论区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!