Sonntag, Januar 25, 2015

Use .kateconfig for setting per-project indentation and tab settings in Kate

Everybody who has ever worked with source code knows: proper indentation is vital to keeping your sanity.

However, people cannot seem to agree on whether to use tabs or spaces (and if the latter, how many spaces) to use for indentation. This is unfortunate, because the obviously correct way of doing it is with tabs. The only reason why many people believe spaces are superior is because
  1. they want their indentation to look shorter than 8 fixed-width characters, the tab-width was not configurable back in the computing stone age, and people in general are incredibly conservative; and
  2. they fundamentally misunderstand the difference between indentation and alignment, and generally overuse alignment.
Having contributed my part to the eternal flame war, even more important than using tabs for indentation is having a consistent style within each project.

So what is a user of the Kate editor (like myself, who uses it as part of KDevelop) to do when faced with working in different projects with different styles? I recently discovered a feature of Kate that is not documented widely enough: It will search the full hierarchy of parent directories for a file named .kateconfig. So just put a .kateconfig file in the root directory of each project you're working on, containing a single line like the following:
kate: space-indent off; indent-width 4; replace-tabs off; tab-width 4; indent-mode cstyle;
And voilà, you're good to go!

Keine Kommentare: