reddit / emacs

auto indent does not match tab stop size

IcePhoneX_ · 2022-08-06 15:40
when I press RET in, say a struct (in C) it will indent next line with 2 spaces instead of a 4 spaces tab, so I have to unindent it then reindent it with a tab each time, sorry if this is simple to solve and thanks in advance
xtifr · 2022-08-06 20:51
You need to set your coding style. The default is "gnu", which makes sense, since Emacs is a Gnu project, but is also quite annoying since the gnu style is so quirky! A quick fix is to customize `c-default-style` and change "gnu" to "stroustrup" or "k&r". (Using customize is the easiest option since `c-default-style` is an alist.) Customizing a single option can be done via `M-x customize-option` or via the menu with Options->Customize Emacs->Specific Option. In either case, you will then be prompted for the option to customize, and can enter `c-default-style RET`. Eventually, you may want to create your own style, possibly inheriting from one of the existing ones, but that's an exercise for later.
IcePhoneX_ · 2022-08-07 11:25
actually I found it at `M-x c-set-style` but it's the same thing, thanks for your help, now auto-indent works the way I want c: