如何在 Emacs 中强制最大行长度?
在 Emacs 中,如何强制最大行长度为 80 个字符? 我希望它在我的代码中插入正确的换行符,就像文本的 fill-paragraph
一样,如果可能的话,正确插入该行的第二部分。
这里有一个小例子:
LongNameType<PrettyLong, AlsoLong> doSomethingWithLongFunctionName(int a, int b);
foo();
如果我实际上执行 fill-paragraph
它会变成:
LongNameType<PrettyLong, AlsoLong>
doSomethingWithLongFunctionName(int a, int b); foo();
而我更喜欢这样:
LongNameType<PrettyLong, AlsoLong>
doSomethingWithLongFunctionName(int a, int b);
foo();
In Emacs, how can I enforce a maximum line length of, say, 80 characters? I want it to insert proper line breaks in my code, much like fill-paragraph
for text, if possible, with the correct insertion of the second part of the line.
Here a little example:
LongNameType<PrettyLong, AlsoLong> doSomethingWithLongFunctionName(int a, int b);
foo();
If I actually do fill-paragraph
it becomes:
LongNameType<PrettyLong, AlsoLong>
doSomethingWithLongFunctionName(int a, int b); foo();
whereas I'd prefer this:
LongNameType<PrettyLong, AlsoLong>
doSomethingWithLongFunctionName(int a, int b);
foo();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
并不是真正的 emacser,但是如果您在 自动填充模式 中打开 < a href="http://www.emacswiki.org/emacs/CPlusPlusMode" rel="nofollow noreferrer">c++-模式?
C++ 模式应该为您提供自动缩进,自动填充模式为您提供换行......
Not really an emacser, but what happens if you turn on auto-fill-mode while in c++-mode?
C++ mode should give you auto-indent, and auto-fill-mode gives you line-wrapping....
我使用 modeline-posn 包。 如果模型行中的列号大于指定值,它会突出显示该列号。
I use modeline-posn package. It highlights column number in the modeline if it's greater than specified value.
您应该查看 Emacs 的众多“垂直线”库之一。 有些库始终在整个缓冲区上保持垂直突出显示线(不是您真正想要的),但其他库始终将垂直突出显示在固定列上,这不是您真正想要的,但您可以立即看到当你应该换行时。
You should check out one of the many "vertical line" libraries for Emacs. Some keep a vertical highlight line over the entire buffer at point at all times (not really what you want) but other libraries put the vertical highlight on a fix column at all times, which is not really what you want, but you can immediately see when you ought to be wrapping lines.
尝试
希望有帮助。
Try
Hope it helps.
您可以使用更高级的 clang-format 包。
(setq clang-format-style "file")
或添加到custom-set-variables
'(clang-format-style "文件”)
。这将使用 clang-format 工具强制列限制。
参考:
ClangFormatStyleOptions。
相关问题
You could use the more advanced clang-format package.
(setq clang-format-style "file")
or add tocustom-set-variables
'(clang-format-style "file")
.clang-format -style=gnu -dump-config > .clang-format
then place into your project's root.ColumnLimit: 120
to 80 or whatever value you want.That would force column limit using clang-format tool.
Reference:
ClangFormatStyleOptions.
Related question
有一些包警告您行长度限制。 就我个人而言,我使用 wide-column ,它根据当前列更改光标颜色。
There are a number of packages which warn you of line length limits. Personally, I use wide-column, which changes the cursor color depending on its current column.
fill-paragraph 和 auto-fill-mode 故意不换行代码。 有太多的方法可以做到这一点,而且很可能会出错。 他们会包装评论,但这对你没有帮助。
我这样做的唯一方法是明确地将文本放置在我想要文本中断的位置。 然后自动缩进应该将断线放在正确的位置。
您是否正在尝试重排大量现有代码? 或者尝试对您现在正在编写的代码进行自动填充工作?
fill-paragraph and auto-fill-mode deliberately don't wrap code. There are just too many ways to do it and it'd probably get it wrong. They will wrap comments, but that doesn't help you here.
The only way I've ever done it to to explicitly put the where I want the text to break. Then the auto-indent should put the broken line in the right place.
Are you trying to reflow a large body of existing code? Or trying to have auto-fill work on code you are writing now?