Code::Blocks Forums
Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Alpha on March 01, 2013, 09:19:17 pm
-
I am working on providing the option for indentation style to be automatically detected and set. Probably the most logical method would be to call my detection routine from cbEditor::InternalSetEditorStyleAfterFileOpen() (similar to how DetectLineEnds(cbStyledTextCtrl* control) is called). There is a problem, however. I want to call GetLineIndentString(), but cannot because it is not a static method.
Program design question: would it be preferred that I convert GetLineIndentString() to a static method? Or add a static counterpart? Or move it to cbStyledTextCtrl? Or something else?
-
Program design question: would it be preferred that I convert GetLineIndentString() to a static method? Or add a static counterpart? Or move it to cbStyledTextCtrl? Or something else?
If it doesn't access and class data, I'd vote for external/global function :)
-
It does not access class data (well not from cbEditor, it does use from cbStyledTextCtrl). Of note, I believe the SmartIndent plugins (and maybe Abbreviations) use this function.
-
Detecting tabs vs. spaces is easy, however, detecting 2-space indentation vs 4-space indentation (or any other arbitrary number of spaces) is a little more difficult.
I plan to create a threshold to determine the indentation style (and fall back to defaults if it is indeterminate). To tune this to greater accuracy, I need to collect statistics on samples of multiple styles of code.
If anyone could post samples/links to different styles of code, I can run this test on them.
If you have time to test yourself, apply the attached patch, and post the numbers printed in the Code::Blocks log (along with what the indentation style of the file(s) actually is).
-
If anyone could post samples/links to different styles of code, I can run this test on them.
Search github or code.google.com for examples, I suppose you can find all the possible styles know to man:)
-
Smart idea, thanks. (Sometimes, it seems, I miss that which should be obvious :-\...)
-
The attached patch should correctly identify (and set) the indentation style per editor, or, if identification is not strong enough, fallback to user defaults.
-
I see some source code which have both spaces and tabs in the same line. But I see that your patch handle either line begin with pure tabs or lines begin with pure spaces, right?
For example, the GDB's source code
a tab length = 8 space
but GDB's indent length = 2 space
I'm not sure your algorithm can detect this. :)
-
I'm not sure your algorithm can detect this. :)
Correct. During my testing, I had no idea what the correct settings even would be in this situation. I decided that in the case of mixed spaces/tabs, just allow the tab key to emit actual tabs, letting the programmer decide when/where they want to use tabs and spaces.
-
My idea is:
1, firstly, guess the tab's length
2, secondly, guess the indent's length
I'm not thinking details. ;)
-
Alpha:
Why this option is on by default?
I suppose many users will be annoyed if the function guesses wrong?
-
I would prefer for all such changesm that the former behaviour is not changed by default.
Even if some users will not notice the new functions immediately.
-
I wrote the function to fail fast, so if it is not very certain, the default values are used. That is why I put it on by default. However, I can go turn it off.