reddit / emacs

I'm in c mode, how can I achieve the below, any keybindings/functions I can invoke ?

Salaadas · 2022-06-24 06:38
xtifr · 2022-06-24 07:02
Standard Emacs should do that by default! If you're using some customized build like Doom, you may have to talk to the folks that made it. Otherwise, you may have to dig through your config to see what you did that disabled it! Try "emacs -q" (disables all config) and see what that does.
anaumann · 2022-06-24 07:02
Not exactly my area of expertise, but cc-mode has a number of formatting options described here: [https://www.emacswiki.org/emacs/IndentingC](https://www.emacswiki.org/emacs/IndentingC)
juanrgar · 2022-06-24 07:30
That's electric indent I think. But it should be enabled by default.
lrochfort · 2022-06-24 07:49
As others have said it should work out of the box. You could try looking at c-set-style. "linux" tends to be a sane default.
Lefantom55 · 2022-06-24 08:27
Check the `newline-indent` function,.it does exactly what you want. I have personnaly remapped it
PetriciaKerman · 2022-06-24 13:27
I use clang format + ccls + a .clangformat I stole from the kernel
tech_addictede · 2022-06-24 21:42
You could also mark the region and run `M-x` `align`.
ShakesTheClown23 · 2022-06-25 02:50
Not 100 on this, but putting the point where you think should be indented and hiding "C-c o" puts you into this kick ass mode where it tells you what arcane c-mode context you're in and lets you enter the new indent for it. Like "+" is to use 1 "c-basic-offset", and maybe there's more codes I forget. Others may have helped you more but I remember loving this feature.
Salaadas · 2022-06-25 04:01
EDIT: I managed to find the line in the config where it was disable, it works now guys. Thank you very much
Salaadas · 2022-06-25 04:03
I also tried this and it works! Thank you!