1

These lines in my .emacs

(setq-default indent-tabs-mode nil)

(setq-default c-default-style "linux")
(setq-default c-basic-offset 4)

result in the following formatting of my c code (the c-basic-offset of 4 is respected by the style):

int main(
    int argc,
    char argv
    ) {
    if (1 == 1 &&
        2 == 2
        ) {
        return 42;
    }
    return 0;
}

At the same time, setting the style to "gnu", makes the offsets different (9 and 4 spaces):

int main(
         int argc,
         char argv
         ) {
    if (1 == 1 &&
        2 == 2
        ) {
        return 42;
    }
    return 0;
}

Why is the same setting treated differently by different styles? Bonus quesition: what do I set up to move the closing ) { of the function and the if blocks to the left like so:

int main(
    int argc,
    char argv
) {
    if (1 == 1 &&
        2 == 2
    ) {
        return 42;
    }
    return 0;
}
  • 2
    I think you'll find that they don't treat c-basic-offset differently. Read C-h v c-style-alist to acquire an understanding of what different styles can do. – phils Jul 3 '16 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.