C 模式下的 Emacs 注释区
在GNU Emacs中,有没有一个好的方法可以将C模式下的comment-region命令从更改
/* 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)
,但这没有帮助。 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. */
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 Emacs 21 开始,出现了一个名为 的模块
'newcomment
,它具有不同的注释样式(请参阅变量'comment-styles
。此设置接近您想要的:(注意:您可能应该在
'c-mode-hook
中进行该设置)但是,没有任何设置使注释看起来像您想要的那样。
我看到获得您想要的内容的最简单方法是添加此技巧:
comment-style
的当前设置总是在注释行前加上“ * ”(如果不是整个“ /* ”),如果您没有 Emacs 21,我想您可以简单地下载 < a href="http://cvs.savannah.gnu.org/viewvc/*checkout*/emacs/lisp/newcomment.el?root=emacs" rel="noreferrer">
newcomment.el
我不知道它在早期版本的 Emacs 中是否能正常工作,但可能值得一试,尽管升级 Emacs 会是一个更好的解决方案。我的黑客破坏了
'uncomment-region
。正确的修复方法是更改'comment-padright
。这需要更多的研究,以免破坏其他东西。上述 hack 仅更改'c-mode
中的行为(根据您的喜好调整条件)。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:(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:
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).我能找到的最接近内置注释支持的方法是将
comment-style
设置为multi-line
,这将产生以下结果:如果这还不够接近,查看
newcomment.el
并根据需要定义您自己的注释函数。Closest I could find with the built-in commenting support is if you set
comment-style
tomulti-line
, which will produce this:If that isn't close enough, take a look at
newcomment.el
and define your own commenting functions as appropriate.