CLion inconsistent auto indentation for line comment - c++

There are some weird auto indentation going on in CLion that I don't understand why. Here is an example
int i1(5); // some comments, then I hit Enter
// auto indentation goes here. I hit Enter again
// It goes here
float f = 5; // some comments, then I hit Enter
// then auto indentation goes here. I hit Enter again
// It then goes here.
float f2 = 6;
// If I don't comment on the previous line, there is no weird indentation
It seems like whenever I use = to initialize an variable, and then add comment at the end of the line, it will give me extra indentation on the next line. But in all other instance, it will not give me extra indentation.
I recently installed CLion and it was using default code style. It seems like the the extra indentation is controlled by the continuation indent setting, but I only want this continuation indent setting be application to codes, not comments. Where can I change me setting to disable the continuation indentation for comment when using = for assignment?

This bug has been fixed in CLion 2018.2 EAP (https://www.jetbrains.com/clion/nextversion/ ).
I personally uninstalled CLion 2018.1 because of this bug, since the EAP was stable enough.

Related

IntelliSense bug c; changing to continue;

I am using VScode with intelliSense for programming in c++. When I type a line ending with c; for example
int a=b+c;
Intellisense still offers me option continue;, so when I hit Enter to go to the next line, it changes c; to continue;, what I obviously don't like and don't want.
In general I would expect it wouldn't offer any options after semicolon. Can I somehow change this setting?

Eclipse / CDT auto-indent on new line only incorrect for structs?

Using new Eclipse and CDT versions built into STM32CubeIDE. I have the built in formatter options adjusted and use clang-format as my main beautifier. Everywhere I can see in the Window >> Preferences menus I have indent turned to 2 spaces-only.
Next line indent works correctly with everything but structs which the indentation seems to be doubled.
It doesn't seem to be indenting 2 units twice, because pressing tab moves me 4 spaces while inside a struct block. Clang-Format with CTRL + SHIFT + F does fix the incorrect formatting, but I'd rather a proper solution.
Either it's a bug, or somewhere this is yet another setting for "4 space indent but only while inside a struct block"?
See examples:
typedef struct
{
//New lines created inside the block start here, indented at 4 and not 2
//I get here if I press tab from the start column
//This is where it should intent to, manually pressed spaced twice
} some_new_t;
void foo()
{
//Correct
}
if (something)
{
//Correct
}
while(1)
{
//Correct
}
#ifdef TEST
//Doesn't indent, that's fine
#endif
EDIT: Applies to unions as well
Figured it out. This was not a 2 spaces vs 4 spaces issue, rather double indent when you only wanted one.
For some reason CDT has a lot more references to C++ and still Java than C and this was labeled under something misleading.
Under Window, Preferences, C/C++, Code Style, Formatter >> Edit >> Indentation >> Indent there are two options that can be checked.
'public', 'protected', 'private' within class body
and
Declarations relative to 'public' 'private'
You can check ONLY ONE of these for C structures and unions to indent at your chosen width. For whatever non-C reason, each one counts as including one indent width.

Debugging big input in eclipse

Unfortunately a program I wrote in C++ has a bug (or bugs), yet I can't deduce what it is since only a single output line doesn't match the expected output (the input file has 3K lines of input). I know which input line is the problematic, yet it's over 2K lines into the input file so debugging it manually isn't very efficient.
Is there any way to let the debugger run "alone" with the first 2K lines and stop exactly before trying to execute the problematic input line? I use Windows and eclipse but don't mind switching the IDE or switch to Linux if necessary.
Thanks in advance!
Don't reinvent the wheel!
Eclipse has powerfull feature Enable condition for breakpoint.
Set breakpoint in your code
Right-click on breakpoint - "Breakpoint properties"
Check "Conditional"
Write your condition when breakpoint should be stopped (you have access to scope and global variables)
Here is Eclipse help page. Breakpoint Enable Condition
(with screenshot)
Well, eclipse may well have advanced debugging features, and to tell the truth I do not know the first thing about eclipse, but FWIW you can easily simulate what you want.
What you have is:
for(i = 0; i < lineCount; ++i)
process one line
Add a condition to check the line number and place a breakpoint inside it!:
for(i = 0; i < lineCount; ++i)
if(i == 2000)
{
int x = i*i; //random line, just add your breakpoint here!
}
process one line
Since you know exactly what line is problematic, just a dummy if statement which would check the contents of the line, and if mathces your problem line, do nothing - and put a breakoint at this line.

Kate (text editor) indentation, c++

I use the kate text editor for writing c++ code. I really like the editor except for its indentation behavior which drives me mad. I have the following problem: If I want to write code like
if( true )
{
//code
}
the indentation messes everything up initially: instead of inserting a tab and jumping to the position marked "//code" when hitting enter, kate just inserts a single blank space. So to describe it more in detail: You start from
if( true )
{//your cursor is here
}
and on pressing enter, kate produces something like
if( true )
{
[ ]//your cursor is here
}
where '[ ]' stands for a single blank space. But instead, I want kate to insert a tabulator to give the result indicated at the start. Or, to repeat it more verbosely, I want that kate gives me
if( true )
{
<tabulator>//your cursor is here
}
on hitting enter. I have played around with all settings and can not make it work. It drives me crazy. I selected "default identation mode normal", "Ident using tabulators" (8 characters). Does anybody know how to customize this behavior? I looked up the katerc file but couldn't find any options that would help me...
edit: I should add that it would be ok if kate would just give me
if( true )
{
//your cursor is here
}
on pressing enter. But this additional blank space is absolutely annoying.
Ok, I tried for half an hour, I don't know why I found out how to do it right AFTER posting the question :). So in case anybody has the same issue, here is the "solution": I missed that kate seems to have a global setting for the indentation mode as well as a local one for every file. In my case - for some reason - my file had special indentation options set. You can alter them via the menu bar by chosing "Tools -> Indentation". This local option overrides the global one! Or the global one is just the default for the local options, I don't know exactly...
You can create a config file .kateconfig and add the variables kate: replace-tabs off; tab-indents: true;
More on this in the manual.

Debugging C++ in an Eclipse-based IDE - is there something like "step over loop/cycle"?

At the moment I'm using an eclipse-like IDE and the corresponding debug perspective, that most of you are probably familiar with. While debugging code I quite often find myself stepping through many lines of code and observing variables and double checking if everything is as it is supposed to be.
But suppose there is something like this:
1. important line, e.g. generating a new object;
2. another important line, e.g. some tricky class method;
3. for (int i = 0; i < some_limit; ++i)
4. some_array[i]++;
5. more important stuff;
Obviously I'm interested in what happens in lines 1,2 and 5 (I know this is a poor example, but please bear with me for a little while longer) but I don't want to step through all hundreds (or even thousands) of iterations of lines 3/4.
So, finally, my question: Is there some way to step directly over the for-cycle? What I do right now is set a new breakpoint at line 5 and let the program run as soon as I hit line 3 and I believe this is not an optimal solution.
edit: The eclipse implementation of what ks1322 proposed is called "Run to line" and is mapped to ctrl-r
Use until command instead of next.
From gdb documentation:
Continue running until a source line past the current line, in the
current stack frame, is reached. This command is used to avoid single
stepping through a loop more than once.
If you will use until instead of next, gdb will step over loops only once, which almost exactly what you want.