Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans : Auto Format : prevent it for a section of my code

I use Netbeans auto format (ctrl+alt+f) a lot. It's a very nice function!.

But I use StringBuffer.append() to generate some xml. I indent the .append parameter to represente the node structure of my xml.

    msg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    msg.append(  "<root>");
    msg.append(    "<subNode/>");

my problem : the autoformat move all my parameters to the same column.

    msg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    msg.append("<root>");
    msg.append("<subNode/>");

My question : How can I prevent the auto format to to modify my code on a section of my file. I'm hoping to found something similar to "editor-fold".

    //<editor-noAutoFormatting>" 
    msg.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    msg.append(  "<root>");
    msg.append(    "<subNode/>");
like image 792
Loda Avatar asked Mar 26 '12 10:03

Loda


1 Answers

The question has already been ask :

  • Netbeans: Auto Format - Prevent Space Formatting on Variable Assignment
  • Netbeans auto format issue with method parameter indention
  • editing the NetBeans source formatting standard

There is unfortunately no answer for that. The idea of annotation is not implemented for formatting (or I don't find it).

So from now the only way to avoid this, is to select the text you want to format, without your xml part and then use format.

EDIT :

The only things I found to avoid autoformat to delete spaces is to use comments /* */.The spaces between them will not be trim by Netbeans formatter.

Example :

msg.append(/* */"<subNode/>");.
like image 171
alain.janinm Avatar answered Sep 28 '22 22:09

alain.janinm