Discussion:
source formatting for .h files: C or C++?
René J.V. Bertin
2017-08-24 19:34:43 UTC
Permalink
Hi,

Is it correct that the source formatting choice for .h files is taken from the C formatting choice, even if the header is clearly a C++ one?

R.
Aleix Pol
2017-09-04 11:35:20 UTC
Permalink
Post by René J.V. Bertin
Hi,
Is it correct that the source formatting choice for .h files is taken from the C formatting choice, even if the header is clearly a C++ one?
It's clearly not correct.

Aleix
René J.V. Bertin
2017-09-04 12:48:55 UTC
Permalink
Post by Aleix Pol
Post by René J.V. Bertin
Is it correct that the source formatting choice for .h files is taken from the C formatting choice, even if the header is clearly a C++ one?
It's clearly not correct.
No, but am I right this is what happens (or can happen, one could imagine an order effect here)?

Not sure if there's an easy fix if file type is determined from the extension, nor even how you'd do a reliable C++ detection from syntax that doesn't check for every C++-specific idiom. And then there's ObjC and ObjC++...

R.
Aleix Pol
2017-09-04 14:40:18 UTC
Permalink
Post by René J.V. Bertin
Post by Aleix Pol
Post by René J.V. Bertin
Is it correct that the source formatting choice for .h files is taken from the C formatting choice, even if the header is clearly a C++ one?
It's clearly not correct.
No, but am I right this is what happens (or can happen, one could imagine an order effect here)?
Not sure if there's an easy fix if file type is determined from the extension, nor even how you'd do a reliable C++ detection from syntax that doesn't check for every C++-specific idiom. And then there's ObjC and ObjC++...
R.
I think that we're just checking the mimetype so that's why:
$ kmimetypefinder5 kcategorizedview.h
text/x-chdr

Maybe you can look at the code how the language is inferred.

Aleix
René J.V. Bertin
2017-09-04 15:18:18 UTC
Permalink
Post by Aleix Pol
$ kmimetypefinder5 kcategorizedview.h
text/x-chdr
Maybe you can look at the code how the language is inferred.
kmimetypefinder5 simply calls QMimeDatabase::mimeTypeForFile(). You can invoke the app with `-c` in which case the returned mimetype will be determined from the file contents only. Not a win: for the above file it returns text/x-csrc ...

I don't think it'd be a good idea to try and do better than QMimeDatabase, at least I'm not going to claim I can.

KDevelop might tune the response based on what it knows about in which files a given .h file is included but even that remains tricky. How to you classify and format a headerfile that contains both C and C++ code?

Is the formatting handled purely inside KDevelop code, or does it in fact rely on KTextEditor or KSyntaxHighlighting? If purely in-house it might be possible to couple it to the known value of __cplusplus (and __OBJC__)?

And it would probably be a good idea anyway to make it possible to couple the formatting for all C dialects. How often does it happen that you want different formatting for the C and C++ files in a given session which does NOT coincide with different formatting for different projects in that session? IOW, why can C/C++ formatting be different but is it not possible to have one project say using tabs for indentation and another using spaces? (That happens much more often for me...)

R.

Loading...