Emacs注释区域在C模式 [英] Emacs comment-region in C mode
问题描述
/ *这是一个很好的方法来改变C模式的注释区域命令是一个注释,它扩展了* /
/ *,超过了C中的一行以上。* /
to
/ *这是一个扩展
超过一行在C. * /
?我试过
(setq comment-multi-line t)
但这没有帮助。在Emacs手册中有一个多行评论部分,但是它并没有提到任何东西。
由于Emacs 21,有一个名为 'newcomment
,它具有不同的注释样式(参见变量'comment-styles
。此设置接近您想要的:
(setq comment-style'multi-line)
(注意:您应该在 c-mode-hook
中进行设置。
但是,没有一个设置使评论看起来像你想要的。
我看到的最简单的方法是添加这个hack: p>
(defadvice comment-region-internal(之前co
覆盖第四个参数为空格
(when(eq major-mode'c-mode);这里有一些条件
(let((arg-ad-arg 4)))
(当arg
(ad-set-arg 4(make-string(length arg) \\))))))
comment-style
总是在注释行前加上*(如果不是整个/ *)。
如果没有Emacs 21,我想你可以下载 newcomment.el
。我不知道它在早期版本的Emacs中是否正常工作,但可能值得一提,尽管升级Emacs将是一个更好的解决方案。
我的破解'取消注释区域
。一个适当的修复将是更改'comment-padright
。这将需要更多的研究,以免打破其他事情。以上黑客只会在'c-mode
(根据您的喜好调整条件)中更改行为。
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. */
to
/* This is a comment which extends
over more than one line in C. */
? I have tried
(setq comment-multi-line t)
but this does not help. There is a section on multi-line comments in the Emacs manual, but it does not mention anything.
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)
(Note: you should probably make that setting in 'c-mode-hook
).
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) ?\ ))))))
The current settings for comment-style
always prefix the comment lines with " * " (if not the whole " /* ").
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.
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).
这篇关于Emacs注释区域在C模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!