C++ emacs 中的样式:默认括号自动缩进行为的大于 80 列例外
我有一个很长的 C++ 函数声明,我正在 emacs 中编写它。带括号的缩进行为对于 80 列也不例外,看起来像:
std::vector<std::vector<double> > doFooBarBlahBlah(const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg1,
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg2) {
Moving the argument to the next line and auto-indenting results in:
std::vector<std::vector<double> > doFooBarBlahBlah(
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg1,
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg2) {
The google C++ style Guide suggest:
std::vector<std::vector<double> > doFooBarBlahBlah(
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg1,
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg2) {
Is There an emacs extension toautomatic indentation in a way尊重这条规则?
I have a long function declaration in C++ that I'm writing up in emacs. The indentation behavior with parenthesis doesn't make an exception for 80 columns and looks like:
std::vector<std::vector<double> > doFooBarBlahBlah(const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg1,
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg2) {
Moving the argument to the next line and auto-indenting results in:
std::vector<std::vector<double> > doFooBarBlahBlah(
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg1,
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg2) {
The google C++ style guide suggests:
std::vector<std::vector<double> > doFooBarBlahBlah(
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg1,
const std::map<std::pair<unsigned, std::string>, FoobarType> fooArg2) {
Is there an emacs extension to automate indentation in a way that respects this rule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑以考虑列长度异常
这将为您解决问题:
找出需要为缩进设置哪些设置的方法是将光标移动到您想要以不同方式缩进的点,然后执行:
又名 Cc Co。在本例中,您希望将其设置为
'+
表示比当前级别多缩进一级。设置之一可以是返回偏移量的函数。缩进,包括如何自定义它(我在上面的示例中采用了简单的方法)。以及 c-offsets-alist 的文档。
Edited to account for column length exception
This will do the trick for you:
The way to find out what setting needs be set for indentation is to move your cursor to the point you want to indent differently and do:
aka C-c C-o. And in this case you want to set it to
'+
indicating to indent one more level than the current level. One of the settings can be a function which returns the offset.There's a ton of information available in the manual for cc-mode on indentation, including how to customize it (I took the easy way in the sample above). As well as the documentation for c-offsets-alist.