Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop eclipse from removing whitespace when formatting

I am using eclipse to do some LWJGL programming and when I create arrays for holding the vertices, I tend to use a lot of whitespace to show what group of floats hold a vertex.

//Array for holding the vertices of a hexagon
float [ ] Vertices = {
    // Vertex 0
    -0.5f ,  1.0f , 0.0f ,
    // Vertex 1
    -1.0f ,  0.0f , 0.0f ,
    // Vertex 2
    -0.5f , -1.0f , 0.0f ,
    // Vertex 3
    0.5f , -1.0f , 0.0f ,
    // Vertex 4
    1.0f ,  0.0f , 0.0f ,
    // Vertex 5
    0.5f ,  1.0f , 0.0f ,
    // Center Vertex ( 6 )
    0.0f ,  0.0f , 0.0f

};

I should also note that I am using element array buffers so that is why there are only 7 vertices.

When I use the Format option in the Source tab of the menu bar, it strips all of this whitespace. How do I stop it from doing that? I cannot find an option in the preferences editor.

I am using Windows 8.1 and Eclipse Java Neon. And no, I won't use a different version of Eclipse as it took me about 5 hours customizing eclipse initially so... If there is a newer version that allows this to be done, I will not be changing the version. It would also take a while to install and stuff so... yeah.

like image 351
James Yeoman Avatar asked Oct 28 '25 09:10

James Yeoman


1 Answers

Disable the Eclipse formatter for the part of code where you want to ignore the formatter and re-enable it in this way :

//Array for holding the vertices of a hexagon
// @formatter:off
float [ ] Vertices = {
    // Vertex 0
    -0.5f ,  1.0f , 0.0f ,
    // Vertex 1
    -1.0f ,  0.0f , 0.0f ,
    // Vertex 2
    -0.5f , -1.0f , 0.0f ,
    // Vertex 3
    0.5f , -1.0f , 0.0f ,
    // Vertex 4
    1.0f ,  0.0f , 0.0f ,
    // Vertex 5
    0.5f ,  1.0f , 0.0f ,
    // Center Vertex ( 6 )
    0.0f ,  0.0f , 0.0f      
}; 
// @formatter:on

You must enable this feature if it is not already done.
Preferences->Java->Code Style->Formatter->Edit->Off/On Tags

like image 158
davidxxx Avatar answered Oct 30 '25 00:10

davidxxx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!