Right now the standard emacs indentation works like the following:
现在标准的emacs缩进的工作原理如下:
switch (cond) {
case 0: {
command;
}
break;
}
I want the break; to line up with case.
我想休息一下;与案件排队。
Also, is there a list of the c-set-offset commands somewhere?
另外,某处有c-set-offset命令列表吗?
2 个解决方案
#1
22
The biggest help (I've found) in customizing indentation is figuring out what cc-mode uses to indent the current line. That's what C-c C-o aka M-x c-set-offset can do - it'll allow you to customize the offset for a syntactic element, and it shows you what element was used for the current line!
自定义缩进的最大帮助(我发现)是弄清楚cc模式用于缩进当前行的内容。这就是C-c C-o又名M-x c-set-offset所能做到的 - 它允许你自定义语法元素的偏移量,它会显示当前行使用的元素!
Here's how you can customize it. Move your cursor to the break;
line.
以下是您可以自定义的方法。将光标移动到休息处;线。
C-c C-o RET 0 RET
At which point, your code will be indented like:
此时,您的代码将缩进为:
switch (cond) {
case 0: {
command;
}
break;
}
For documentation on the offsets, check out the docstring for the variable 'c-offsets-alist
有关偏移的文档,请查看变量'c-offsets-alist的docstring
C-h v c-offsets-alist RET
Similarly, you can add this to your .emacs:
同样,您可以将其添加到.emacs:
(setq c-offsets-alist '((statement-case-intro . 0)))
The documentation for customizing indention is here and is worth reading. There are tons of ways to do it, so reading the manual is worth the time (if you want non-default indentation). And here's a pointer to all the syntactic symbols used in cc-mode.
自定义缩进的文档在这里,值得一读。有很多方法可以做到这一点,因此阅读手册是值得的(如果你想要非默认缩进)。这里是指向cc模式中使用的所有语法符号的指针。
#2
0
For me, getting php-mode switch statements to indent correctly requires:
对我来说,让php模式switch语句正确缩进需要:
(c-set-offset (quote brace-list-entry) 2 nil)
(c-set-offset (quote case-label) 2 nil)
But as others have mentioned, C-c C-o is your friend.....
但正如其他人所说,C-c C-o是你的朋友......
#1
22
The biggest help (I've found) in customizing indentation is figuring out what cc-mode uses to indent the current line. That's what C-c C-o aka M-x c-set-offset can do - it'll allow you to customize the offset for a syntactic element, and it shows you what element was used for the current line!
自定义缩进的最大帮助(我发现)是弄清楚cc模式用于缩进当前行的内容。这就是C-c C-o又名M-x c-set-offset所能做到的 - 它允许你自定义语法元素的偏移量,它会显示当前行使用的元素!
Here's how you can customize it. Move your cursor to the break;
line.
以下是您可以自定义的方法。将光标移动到休息处;线。
C-c C-o RET 0 RET
At which point, your code will be indented like:
此时,您的代码将缩进为:
switch (cond) {
case 0: {
command;
}
break;
}
For documentation on the offsets, check out the docstring for the variable 'c-offsets-alist
有关偏移的文档,请查看变量'c-offsets-alist的docstring
C-h v c-offsets-alist RET
Similarly, you can add this to your .emacs:
同样,您可以将其添加到.emacs:
(setq c-offsets-alist '((statement-case-intro . 0)))
The documentation for customizing indention is here and is worth reading. There are tons of ways to do it, so reading the manual is worth the time (if you want non-default indentation). And here's a pointer to all the syntactic symbols used in cc-mode.
自定义缩进的文档在这里,值得一读。有很多方法可以做到这一点,因此阅读手册是值得的(如果你想要非默认缩进)。这里是指向cc模式中使用的所有语法符号的指针。
#2
0
For me, getting php-mode switch statements to indent correctly requires:
对我来说,让php模式switch语句正确缩进需要:
(c-set-offset (quote brace-list-entry) 2 nil)
(c-set-offset (quote case-label) 2 nil)
But as others have mentioned, C-c C-o is your friend.....
但正如其他人所说,C-c C-o是你的朋友......