QuBiT / cucumber-netbeans-plugin

Plugin / Module which allow Syntax Highlighting and many more in NetBeans with .feature Files
MIT License
50 stars 19 forks source link

Feature request: auto format for tables #18

Closed fgalli closed 14 years ago

fgalli commented 14 years ago

Hi, I saw from a webcast a nice feature from another editor. The ability to autoformat tables like this:

| name | price | | Milk | 2.99 | | Puzzle | 8.99 |

Into a nicer way like (hope it doesn't mess up the spaces...btw it's all aligned):

| name | price | | Milk | 2.99 | | Puzzle | 8.99 |

I really hope to see this little feature added to this great nb module

fgalli commented 14 years ago

It messed up... this is the correct one: http://pastebin.com/f43c84938

kbaum commented 14 years ago

I agree. It would be great if we could autoformat tables in netbeans.

aslakhellesoy commented 14 years ago

Here is how TextMate does it: http://github.com/bmabey/cucumber-tmbundle/blob/master/Support/lib/cucumber/mate/table_aligner.rb#L34

(Watch out for UTF-8).

Should be easy to port to Java.

aslakhellesoy commented 14 years ago

You may also want to take a look at a java implementation for aligning tables, in Gherkin:

http://github.com/aslakhellesoy/gherkin/blob/master/java/src/gherkin/formatter/PrettyFormatter.java

Thinking about it - maybe you could use the entire formatter to format the entire feature of the current editor! See the main class for an example:

http://github.com/aslakhellesoy/gherkin/blob/master/java/src/gherkin/Main.java

aslakhellesoy commented 14 years ago

I have now made binary releases (jar) of Gherkin available in this Maven repo: http://cukes.info/maven

This should give you what you need to start using Gherkin's autoformat. Again - see the Main class. It has moved to http://github.com/aslakhellesoy/gherkin/blob/master/java/src/main/java/gherkin/Main.java

aslakhellesoy commented 14 years ago

If you find any bugs in the PrettyFormatter, please file a bug in the Gherkin project, adding a link to a gist with a feature that isn't properly reformatted.

QuBiT commented 14 years ago

Thanks to Aslak, the new Version 1.6.5 is ready for download, so try it out.

To Format a File you have 2 possibilities:

or

jorahood commented 14 years ago

Just wanted to note that for me, formatting does not normalize the widths of tables. Was this an intended outcome?

aslakhellesoy commented 14 years ago

Tables should be formatted too. Can you paste your feature to http://gist.github.com and give us a link? I'll look into it.

QuBiT commented 14 years ago

Tested it with NetBeans 6.9M1 and NetBeans 6.8 with Version 1.6.7 and different Features (en, de) and all worked well.

Did you upgrade from a Version below 1.6.5? yes -> check if there are two modules installed, uninstall the old one. yes, and I uninstalled it, and I still get this error -> if you can try to delete your .netbeans/ folder, "maybe" this helps.

jorahood commented 14 years ago

Must have been a pbkm, works fine now. Kudos!