text-editorkate

How do I configure Kate to automatically detect spaces/tabs indentation?


I mess with software written by completely unrelated groups of people, and it all uses completely different indentation standards. I'm okay with having to set the indentation width, but there's nothing more annoying than opening up a file with tabs, making some changes, and finding that my changes used spaces for indentation instead.

All the software I write uses four-space indentation. Then I go to make a Quake 3 mod and the entire codebase uses tabs. When I make changes I have to be incredibly careful to set my indentation settings first or I'm going to have to manually rewrite the indentation before committing, every single time.

I went through the settings and couldn't find anything. The tabs-and-spaces mode literally doesn't do anything special and just sets it to tabs mode instead (after a reset). I went through google and all I found was this extremely unhelpful mailing list message. Detecting consistent indentation isn't that difficult, other text editors manage it fine, it doesn't have to be perfect, it just has to work most of the time.

If Kate has a setting for this, where is it, and if it doesn't, when is it going to get such a setting? If I can't make Kate do this I'm going to have to switch off of it. I already went through Notepad++ and Geany, but they both have serious problems with doing regexes on extremely large files (say, tens of megabytes of text) or with rendering monospace non-european text.


Solution

  • Unfortunately, kate does not support this right now. There is a bug report for this from 2005, but noone implemented that yet (yes, 13 years ago).

    What Kate does support though are Kate modeline (also called document variables). For instance, you can write in your text document e.g.:

    // kate: replace-tabs on; indent-width 4;
    

    And then the document containing this comment will automatically use 4 spaces and use spaces to indent.

    Instead of writing these kind of comments into files, you can also write this into files called .kateconfig. You can find more information about .kateconfig files and modelines in this article.