4coder » Forums » [Customisation] Auto-indents all over the place!
tienery
Luke
7 posts
#15193 [Customisation] Auto-indents all over the place!
4 months, 2 weeks ago Edited by Luke on May 9, 2018, 3:42 p.m. Reason: Initial post

Hello all,

I am attempting to implement the Haxe programming language into 4coder and I am exploring options on how to do syntax highlighting.

I have also noticed there was a bug in buildsuper.bat, which I have now fixed. See below:

1
if "%SRC%" == "" set SRC=%code_home%\4coder_default_bindings.cpp


Before, SRC was not prefixed with %code_home%. Adding it fixes the issue where 4_coder_default_bindings.cpp was not found.


I am currently experiencing a few issues with my custom implementation.

The first is when using an anonymous function like in the following scope:

1
2
3
4
5
frontFadeOut(function() 
                    {
                        Browser.document.getElementById("content").innerHTML = xml.responseText;
                        switchPage(url);
                                 });


The auto-indentation done by 4coder in the background seems to not pick up the fact that function can be a flow, but also a declaration. I'm not sure how 4coder can handle the function keyword being used in two different circumstances, one for actually declaring a function, and another for assigning an anonymous function without a name. In my custom implementation, I currently have function assigned to CPP_TOKEN_KEY_TYPE_DECLARATION. If JavaScript were to be implemented, I can foresee the same issue there.

Is there perhaps a better way to accomplish correct auto-indentation in this scenario?

Also, the '@' symbol is used in places for runtime and compile-time metadata or code generation respectively. In the below example, the use of the '@:' symbol is automatically indenting the next line.

1
2
@:noPublic
    var categories:Array<String>;


But it does not apply to the class which is declared as a CPP_TOKEN_KEY_TYPE_DECLARATION, which var is not.

1
2
@:build(StaticBuilder.build())
class News


However, there is some inconsistency with this behaviour. As mentioned previously, function is also declared as a TYPE_DECLARATION, but has the same effect as the first example:

1
2
@:makePublic
    function display(url:String)


Any thoughts on why this may be the case?

Many thanks for all your help in advance.
Mr4thDimention
Allen Webster
411 posts / 2 projects

Heyo

#15195 [Customisation] Auto-indents all over the place!
4 months, 2 weeks ago Edited by Allen Webster on May 9, 2018, 6:05 p.m.

1. Which type of keyword you assign won't make any difference to the built in auto-indent logic.

2. The built in auto indent is especially bad with lambdas because it does not expect to see braces inside of parentheses. Once it is inside parentheses it switches to a different layout mode and doesn't switch back when it sees a brace. I may take some time to upgrade all of that, since it is coming up more and more frequently.

3. By the way, are you talking about the text auto-indenter, or the virtual whitespace automatic code reflow stuff?
tienery
Luke
7 posts
#15197 [Customisation] Auto-indents all over the place!
4 months, 2 weeks ago

Hi,

Thanks for your reply. I'm not sure what you mean by 'virtual whitespace automatic code reflow stuff'. Is that perhaps where you have the illusion there is a huge number of spaces when code is wrapped onto the next line, but you can't actually remove them, or is that part of the auto-indenting mechanism? I suspect the latter.

I would be curious what the @ symbol does behind-the-scenes in 4coder, because if there is a way to disable the auto-indent, or virtual whitespace if that's what it's inserting, on the next line, that would be good.

Thanks.
Mr4thDimention
Allen Webster
411 posts / 2 projects

Heyo

#15202 [Customisation] Auto-indents all over the place!
4 months, 2 weeks ago

Virtual whitespace is the "illusion there is a huge number of spaces when code is wrapped onto the next line". When it is turned on the real whitespace is ignored and the code is just formatted to look "right" no matter what. Without it the individual spaces of indentation can be inserted and deleted manually, but the reflow doesn't happen automatically. This can be toggled in the config.4coder file. Virtual whitespace is totally separate from auto-indentation, and virtual whitespace cannot be customized at all, whereas auto-indent is fully implemented in the custom layer.

The @ symbol is probably just parsed as junk and who knows how that affects the auto-indent code, but I wrote a little objective C with 4coder, and the @ symbols weren't a problem then (if I remember correctly)... When I get a chance I'll take a look at your snippets to see what I can find.