小编wto*_*tok的帖子

如何让Emacs正确缩进C99复合文字?

我正在写一个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)),
    };
}
Run Code Online (Sandbox Code Playgroud)

以下是我使用时的外观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)),
            };
}
Run Code Online (Sandbox Code Playgroud)

我的假设是,Emacs不承认大括号中的大括号,(type) { ... }因为它在大括号中type x = { ... }具有完全相同的内容,可以正常工作:

SDL_Point
random_point_within_rect(SDL_Rect r)
{
    SDL_Point p = {
        .x = (r.x + (rand() % r.w)), …
Run Code Online (Sandbox Code Playgroud)

c emacs formatting indentation c99

6
推荐指数
1
解决办法
118
查看次数

标签 统计

c ×1

c99 ×1

emacs ×1

formatting ×1

indentation ×1