【发布时间】:2017-06-03 18:10:33
【问题描述】:
我正在编写一个 C99 程序并经常使用复合文字。但是,Emacs 似乎没有正确缩进它们。
例如,这里有一个简单的函数,手动缩进:
SDL_Point
random_point_within_rect(SDL_Rect r)
{
return (SDL_Point) {
.x = (r.x + (rand() % r.w)),
.y = (r.y + (rand() % r.h)),
};
}
这是我使用M-x indent-region时的样子:
SDL_Point
random_point_within_rect(SDL_Rect r)
{
return (SDL_Point) {
.x = (r.x + (rand() % r.w)),
.y = (r.y + (rand() % r.h)),
};
}
我的假设是 Emacs 无法将 (type) { ... } 中的大括号识别为与 type x = { ... } 中相同的东西,因为它在大括号中具有完全相同的内容,可以正常工作:
SDL_Point
random_point_within_rect(SDL_Rect r)
{
SDL_Point p = {
.x = (r.x + (rand() % r.w)),
.y = (r.y + (rand() % r.h)),
};
return p;
}
有没有一种方法可以让 Emacs 像结构文字一样处理复合文字,或者用其他方法来修复这里的缩进?
谢谢。
【问题讨论】:
-
看起来你的假设是对的,如果你 eval
(setq-local c-echo-syntactic-information-p t)你可以看到缩进规则
标签: c emacs formatting indentation c99