Kate keeps autoformatting my code

So, at some point as I was configuring Kate, I realised that, for some reason, Kate is automatically formatting my C++ code, and I find it quite frustrating. Although it certainly does me some favours, I find that it can be counter-productive to my writing style in certain instances. I have tried quite a few things, but I can’t for my fucking life figure out what exactly is causing this, partly because Kate seems to behave in ways that are quite unexpected to me.

What I’ve tried so far is working with plugins. However, disabling every single one of them did not do the trick. At all. Strangely, though, if I change the status of any of them, be that turned on or off, the autoformatting is disabled for the remainder of the Kate session.

Please advise. I love using Kate, but this is nerve wrecking, I’ve been frustrated by this for days without being able to find a solution.

This stuff is good to know, so thank you for that, but unfortunately it didn’t solve my problem. Unless I did something wrong, creating a .clang-format file that contains exclusively DisableFormat: true does not seem to do anything.

I have no experience with Kate as Jetbrains tools does it for me.

It is tough to push back when standards are pushing you - I have come to appreciate certain standards and while it can be annoying - the standards is to make it easy for anyone following the code to tag along.

Also when you contribute to open source project - standards is a necessity - and if you are used to standards or accept them it is easier to contribute.

I know why standards exist, and, for my personal projects, I am trying to use my own standard I am happy with that I very strictly adhere to, and I continuously ask other people who also use C++ whether my code is looking fine or not. My issue isn’t with keeping some standard, although it does bother me that I don’t even know which standard whatever piece of software is trying to enforce here. Also, from what I’ve heard and read so far, I don’t think it’s quite wise for single-line comments to automatically be set to column 70.

Anyway, what’s the worst about this is that this automatic formatting happens while typing, which messes with my typing habits. This is really annoying, and, it seems to me, quite unnecessarily so. If it’d format on save, that’d still be annoying, but I could at least handle it. The fact that the automatic formatting happens while typing, however, is so much worse.

Can you explain what you mean by formatting? Are you referring to bracket placement and indenting or complete code formatting?

I’m not sure what exactly you mean, so I’ll give you a few examples:

  • when I write : outside a comment, the second : is being placed automatically and the cursor is moved past that
  • writing // for a comment automatically puts a bunch of spaces between the comment and whatever is before it so that the // characters are at column 67 and 68 with an additional whitespace so that the cursor is at column 70 (this doesn’t happen if the line in question contains no non-whitespace characters)
  • if there is any indentation at all, all preprocessor … operators(?), like #includes, are always completely unindented
  • additional whitespaces everywhere. I write if(, it gets corrected to if (. I write i=, it turns to i = . I write a comma, there is always a new whitespace, even in comments

I feel the need to mention that I do not think that all of these are bad, I’m just picking examples here that I know of.

Hmm…none of that happens for me in C++ with kate.

Do you have something like kite installed?

That’s actually not that bad, you should put space after if (because it is not a function call) and before and after = (except in Bash, where it is a syntax error, gotta love languages with significant whitespace). :slight_smile:

But my Kate does not do that for me, so it must be something else specific to your install.

I never heard of kite, and entering kite in the terminal yields a “command not found”. I do have clang installed, though, and do make intentional use of clangd, but that was initially unintentional and it took me a bit to figure out that what I was seeing was indeed from clangd and then I had to look up what it even actually is. I can only assume that clang-format is causing this, but I do not know. Certainly, it has to be something that got installed as a dependency, nothing I installed explicitly.

Two things:

  1. For my personal use, I 100% disagree. I see why this is useful, and I absolutely wish that my teacher would use such a feature, but this is one of those things that mess with my typing habits, something I mentioned earlier. I am already quite used to putting these spaces there manually, and by far not just from writing C++ code, so I end up with a ton of double spaces I have to retroactively fix because muscle memory gets me before I’m successfully getting the signal from my eyes that there already is a space there.

Yes, that I know. This is something that only happens with C++ code, for one. While editing the .bashrc, for example, I don’t see any of this happening. Also, as I said, disabling all plugins does not disable this behaviour. What I didn’t quite mention is that scouring through all settings, both of all plugins I use and also for everything not plugin related, I couldn’t find any setting that changes this behaviour either.

And, what I probably should’ve mentioned from the start, I am aware that I am using external tools (e.g. the above mentioned clangd), so @Root had a good idea with the link - frankly I’m quite surprised that my attempt at disabling this with a .clang-format file failed.

I have clang-format installed and clangd running. But I still am not seeing any of that behaviour that you are.

Please tell me there is a way to figure out which external tool is causing this …

You tell me…

If everything else fails, make a clean install in a VM and compare it with your install.

And yeah, I also have clangd and clang-format.

1 Like

Okay. Not gonna be too pleasant, but I guess this is better than opening up htop or ksysguard, looking at every process I can find, and trying to figure out whether whatever I see may be related to this. I actually have a laptop where I installed EndeavourOS from scratch today.

The only things I got around to install is KeePassXC, my VPN, and Timeshift, and I did barely any config - more importantly, I didn’t touch Kate at all yet. Testing rq, funnily enough apparently the preprocessor thing I mentioned is already built into Kate, but other than that I’m not seeing any of the behaviours I’ve mentioned.

So yeah, thanks for that idea, mine would’ve probably been a PITA. I’ll set up my system on my laptop now and I’ll keep a close eye on when I see things changing in a way I don’t want.

Yeah, preprocessor directives really ought to begin on column 0. While C and C++ standards allow whitespace before the # sign, it is not advisable.

And yes, Kate does that for you, you can disable it, though.

From your story, it feels you haven’t bothered opening the Tools menu, or Kate configuration settings. It’s all there.
Kate has a lot of configuration options on editing, auto-complete and such.
You can even set your document as No-Code-Language. Menu Tools-Functionality (or similar…).

I do not see at all how you could get that idea, especially after I’ve said:

I’ve looked everything once before this happened, because I like to configure my stuff exactly the way I want it to be, and I’ve looked at least once through all the “Configure Kate” since this happened. And when I say “all”, I mean all, with the exception of settings of plugins I don’t have active. I’ve been looking at everything and found nothing that helped. Hell, I even went as far as to disable spell-check.

The “Tools” menu I have neglected, but checking it now, I don’t see how anything there is relevant to this problem. And setting a document to not being code at all for Kate would be quite counterproductive - y’know, given that it disables syntax highlighting and clangd.

On another note, I am running out of options in diagnosing the root of the issue. Even though this is not the first time I’m experiencing this, I have no idea how to intentionally reproduce this on a new system. Looking at running processes also doesn’t seem to be helping me out a lot. I really don’t want to reinstall my system, I’ve spent days configuring it … :sob:

1 Like

Have you tried deleting your kate configuration altogether?

1 Like

Didn’t think of that one.
Tried it - didn’t work.

Update: Apparently, “deleting the Kate configuration” is not limited to katerc. Man, I love KDE, but the config files are just … *sigh*

Anyway, I now deleted .config/katerc, .config/katemetainfos, and .config/katemoderc. It seems as if this solved the problem, but I don’t want to mark this as the solution just yet, because this autoformat behaviour is incredibly fragile.

As I’ve said before, changing the state of any plugin breaks it for the remainder of the session, and I’ve even seen it somehow not work on some files at all, even across sessions, while still working on other files. So for now things are fine, but things might get not so fine again in the near future. I’ll see if I can test things more throughout the weekend and I’ll report back if anything changes.

For now: thank y’all a lot for the help thus far.