6

I simply want to include a C++ header file in KDevelop by writing

#include <file.h>

However, KDevelop automatically corrects the above statement to

# include <file.h>

I have not been able to figure out where I can change this. I want the first version, such that my files are similar to the other files in the project I am working on.

The file is type set correctly as a C++ file. I think the reason for the extra space is that KDevelop wants to indent the line because it is inside a conditional, i.e. a include guard as given below:

#ifndef THIS_FILE_H
#define THIS_FILE_H

// THIS_FILE_H
#endif

KDevelop also wants to indent the #define THIS_FILE_H line.

I have tried created my own indentation style by going to the Settings -> Customize KDevelop menu item, and then clicking on Source Formatter on the left. When defining the formatting style, I have disabled the indentation of preprocessor directives, nevertheless, it has no effect on the indentation of the #include and #define inside the include guard.

debrandt
  • 61
  • 3
  • 1
    Well, it shouldn't matter at least. – πάντα ῥεῖ May 10 '16 at 19:01
  • 1
    It matters enough to break the SO code highlighting. I have no idea how this could happen and go unnoticed tbh. KDevelop is not that small from what I heard. – Baum mit Augen May 10 '16 at 19:03
  • That's right, but it has been annoying me for quite some time now, so figured somebody might know how to prevent this behaviour. – debrandt May 10 '16 at 19:03
  • Is the file type set correctly? Maybe KDevelop thinks you're writing in a language that uses the `#` character as a start of a comment in the code (e.g. Python, Perl, shell). – Paulo1205 May 10 '16 at 19:13
  • Maybe it is using a C style indenting rules, since the ".h" usually indicates a C language header. – Thomas Matthews May 10 '16 at 19:16
  • I believe I figured out what is causing it, but still cannot change the behaviour. See edited question above. – debrandt May 10 '16 at 19:18
  • 1
    This should have something to do with Kate part of KDevelop. Play around with options in `Configure Editor` menu, because i don't see this behavior. – arrowd May 24 '16 at 15:06
  • I use KDevelop 4.7.3 every day and haven't ever seen this. – Nicolas Holthaus Jun 16 '16 at 22:08
  • @BaummitAugen I think they follow certain code styling where common directives would have one or more spaces and ` #if #else #endif` having none at start (but can be idented). SO it's more of misfeature because "developer thought it should be default" – Swift - Friday Pie Feb 19 '20 at 09:57

3 Answers3

1

I know this is quite old but here is my advice, for future reference.

Go to Settings -> Configure KDevelop -> Code Formatter.

There you'll be able to see a dropdown the language you want KDevelop to format (C, C++, C#, Java, and whatever), the formatter ("Artistic Style" or "Custom Script Formatter") and a list of possible predefined styles plus buttons to customise your own.

Check whether you have selected one suitable predefined and try a few ones to see what happens.

KDevelop should stop adding the extra space after # include after this.

Question: does your KDevelop also adds a space after a #define as well?

j4x
  • 3,595
  • 3
  • 33
  • 64
1

Same Problem. So, I uninstall kate, then remove all config files in home directory whose name contains kate. Then I opened kdevelop and found nothing change. At last, Kdevelop->Settings->Open/Save->Modes&Filetypes, select Sources/C++ and Sources/C, change it to None, restart kdevelop. OMG, finally, the world is peace.

To conclude, the Sources Modes&Filetypes occur the problem.

Ryan.Shi
  • 31
  • 3
1

The automatic spaces appear to be caused by the indentation mode, which (in KDevelop 4.7.1) you can switch for the current file via Editor -> Tools -> Indentation. If indentation is set to C++/boost Style, you'll get those weird automatic spaces while typing; while in mode Normal you only get the usual indentation at beginning of line.

The default indentation mode can be set in Settings -> Configure Editor -> Open/Save -> Modes & Filetypes. For each Filetype (eg. Sources/C, Sources/C++, Sources/C++11, Sources/C++11/Qt4) the Indentation Mode can be set independently.

KDevelop appears to remember the setting for files you have opened once; so for these files the new configuration settings have no effect. I don't know how to make KDevelop forget these per-file settings.

oliver
  • 6,204
  • 9
  • 46
  • 50