500dchess · 2022-07-06 03:12
I need to edit some C++ code where the original author didn't care about extremely long lines. As nice as it would be to clean up the formatting, right now I'm just trying to get it to work, and it messes up my workflow to have tons of newlines added every time I add a closing bracket. Here's a gif of what I'm talking about:
https://i.redd.it/xai1fe7c7v991.gif
How can I disable this behavior?
​
Edit: further testing seems to indicate that this is caused by the language server (ccls). If I disable lsp-managed-mode, the behavior stops. Also, if I leave lsp-managed-mode enabled and wrap the statement in #if false ... #endif, the line breaks aren't added either. Still not sure if there's a way to disable just this function without disabling the language server altogether.
xtifr · 2022-07-06 05:08
I have no idea. I have never seen Emacs do that! That is definitely not its normal behavior! I just tried it myself to make sure, and nothing like that happens here!
If you are using a pre-packaged version of Emacs like Doom, you should probably inquire of the vendor. Otherwise, you should look through your configuration and see if you can determine what you did that's causing this behavior!
Hlorri · 2022-07-06 05:29
That's *probably* electric mode. `C-c C-a` to toggle.
500dchess · 2022-07-06 13:35
Unfortunately not, but I did go one by one through every minor mode to figure out the issue is actually caused by lsp-managed mode. Does that mean it's caused by the language server? I'm using ccls.
sr105 · 2022-07-06 14:00
I had this same issue. The lsp server recommends code "actions," and lsp-mode is configured out-of-the-box to automatically perform them all. I had to dig into the lsp-mode docs to find the variables to disable the actions. I no longer remember what these do, but I have them set in my custom file. Maybe this will help you.
'(lsp-auto-execute-action nil)
'(lsp-before-save-edits nil)
'(lsp-completion-enable-additional-text-edit nil)
'(lsp-enable-indentation nil)
geza42 · 2022-07-06 22:04
I think you can disable this with:
`(setq lsp-enable-on-type-formatting nil)`
If you do want to have on-type formatting, but you don't want to have automatic line breaks, then increase line length limit in clang-format's config file. This way clang-format will still format your code, but won't insert line breaks.