Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KDevelop automatically inserts a space after # in #include <file.h>

Tags:

c++

kdevelop

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.

like image 824
debrandt Avatar asked May 10 '16 18:05

debrandt


3 Answers

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?

like image 86
j4x Avatar answered Nov 13 '22 18:11

j4x


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.

like image 26
Ryan.Shi Avatar answered Nov 13 '22 19:11

Ryan.Shi


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.

like image 31
oliver Avatar answered Nov 13 '22 18:11

oliver