By default Emacs uses tab instead of spaces for indentation, so I changed these 2 variables to change this behavior,
(setq-default indent-tabs-mode nil) ;; Disable indent with tabs
(setq default-tab-width 4) ;; Set default indent width
It did change the indent mode from tab to space, but if I press RET
, when I am in a programming buffer C++
for example, to enter a new line, I get 2 spaces of indentation instead of 4. How do I set this indentation level to 4 be default globally.
Also when when I am editing a line for example, it auto shift the line back to 2 space of indentation, for some reason, and also re-formats how I wrote the code, for example, I usually write like this,
if (true)
{
// 4 spaces for indentation.
}
If I try to edit or add something, it pushes the lines back to 2 spaces of indentation and also sometimes re-formats the brackets position,
if (true) {
// 2 spaces for indentation.
}
I am constantly fighting with this thing, and it gets annoying very quickly sometimes. As far as I know, I did not install any formatting package.
emacs -Q
and confirm the standard behaviour. Assuming it's your own config, you can use the recursive bisection technique to quickly narrow down which piece of your config is responsible. – phils Nov 16 '21 at 14:14c-default-style
is set to"gnu"
which indents the braces, as stated here - EmacsWiki I have now switched tolinux
style, but I don't see any difference. At this point I am mostly manually editing brace position every time. I like howdoom-emacs
has the perfectc-style
that I prefer, wish they had a package to set it up. – apoorv569 Nov 17 '21 at 22:53RET
. BTW I found thedoom-emacs
c-style
here is the link. Now the question is how do I see what package is causing this. I don't have any package that formats the code. I only haveLSP
andccls
forc/c++
. I do have a lot of other packages as well. Here is myemacs
config. – apoorv569 Nov 18 '21 at 05:51*Message*
buffer I saw these messages when the reformatting happens,LSP :: Applying 3 edits to 'MainFrame.cpp' ... Applying 3 edits to 'MainFrame.cpp' ...done
I think its
– apoorv569 Nov 18 '21 at 06:04LSP
that is re formatting the code.lsp-enable-on-type-formatting
tonil
and it worked. It no longer formats the code. Thedoom c-style
is kind of working, but not exactly as it does in doom. When I type for examplevoid func()
and pressRET
to go to next line and create{}
and my cursor is between the 2 braces i.e{|}
and I pressRET
indoom
it automatically create new line, indents 4 spaces and take the closing brace to new line. I want to achieve that same behavior. – apoorv569 Nov 18 '21 at 06:45