source formatting: what is supposed to be automatic now?

David Nolden david.nolden.kdevelop at art-master.de
Sat Nov 26 14:40:56 UTC 2011


2011/11/26 Milian Wolff <mail at milianw.de>:
> Hey all, esp. David.
>
> I saw all these commits recently regarding source formatting, and wonder what
> is supposed to be improved now? I thought that the settings between editor and
> formatter are now synchronized somehow?
>
> But when I open e.g. sourceformattercontroller.h and override a method in the
> class, just for the fun of it, like e.g. this one:
>
> "virtual QAction* action (const QDomElement& element) const;"
>
> I get it indented by four spaces, even though the rest uses two tabs.
>
> Same if I e.g. implement a method, I alwasy get indentation by four spaces,
> even in files that only use two spaces.
>
> Is this because I use astyle? Is all this not implemented there?

You get the indentation which you have configured in your
source-formatter. If you use astyle, then you get the indentation
which you have configured in astyle.

If you want "proper" formatting, eg. based on the per-directory rules
defined in the "format_sources" files, then you need to select "Custom
Script Formatter", and then "kdev_format_sources.sh".

Then you will get the editor settings matching the format_sources
files (if you have uncrustify installed).

However, until now, I have defined 2-space indentation for most of my
code, and 4-space indentation for the rest, so you will still get
4-space indentation in sourceformattercontroller.h. This has to be
made consistent by either reformatting the code, or adapting the
rules.

And regarding the configuration, in future we should detect whether
there are "format_sources" files in the project-tree, and if yes, use
the "Custom Script -> kdev_format_sources.sh" formatter by default
instead of astyle, so that no manual configuration is required. Then
everything would work perfectly out-of-the-box (given that uncrustify
is installed and format_sources rules are consistent with the code).

Greetings, David




More information about the KDevelop-devel mailing list