Menu

#521 Request tri-state auto format options

open
nobody
None
5
2011-02-21
2011-02-20
J D
No

I would like to request that the auto-format options (Pydev|Editor|Code Style|Code Format) be made tri-state.

As it is now, if one performs an auto-format (either by Ctrl+Shift+F or implicitly on save by selecting "auto-format editor contents before saving,") then for each of the spacing options, spacing is added per the option if it is checked, but removed if the option is un-checked. This behavior can break code, in particular the "use space before and after operators" option. If this option is checked, then lines where a literal E-format floating point number is used are corrupted, e.g. "h = 6.626E-34" becomes "h = 6.626E - 34", which is illegal syntax. If the option is un-checked, E-literals are not affected, but all other math expressions throughout the file are collapsed, which makes them hard to read.

I would like to use "auto-format on save" to trim spaces at the ends of lines, since they are hard to see and create noise in the revision control system, but the above issue makes auto-format unusable.

My request is to make the spacing options tri-state. When an auto-format is performed, options that are "checked" and "un-checked" would behave as they do now, but a grayed checkbox would mean "leave it alone."

Obviously this applies only to the spacing options; the first checkbox in the dialog, which enables auto-formatting on save, must remain a binary selection.

Discussion

  • J D

    J D - 2011-02-20

    I forgot to mention, implementing this idea would also at least partly resolve the similar issue mentioned by burdell2k in 3182889.

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-02-20

    Wouldn't solve the 'bugs' be enough (i.e.: that formatting error with a number should be fixed regardless).

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-02-20
    • status: open --> pending
     
  • J D

    J D - 2011-02-21

    Thank you for the response!

    > Wouldn't solve the 'bugs' be enough

    Well, I guess so, but my thoughts were:

    1) adding a no-action option seems like it should be less work than trying to anticipate every possible formatting contingency. (there might be more than the ones that burdell2k and I have found). Also it gives users a workaround and reduces the urgency of bugs - one could simply turn off a buggy option, and still take advantage of the ones that work.

    and,

    2) the auto-formatting I really want is to leave the code alone, just trim end-of-line spaces from every line in the file, and make sure there is a blank line at the end. But this means you need a way to turn off the other formatting options. For the four options that begin "Use space...", the way they work now is that if the option is "set", then spaces get added, and if the option is "unset" then spaces get removed - they always do *something*, one way or the other. I want to be able to set them to "do nothing."

    BTW I sort of figured out how to do what I want with a script, using "Scripting Pydev" and hooking the "onSave" command. But I don't really understand how to work with the Eclipse API, and although my script does have the effect I want (strips the lines, using RemoveTrailingWhitespaceOperation), it generates voluminous complaints in the error log that I don't have a clue how to fix. It also sometimes confuses the insertion caret about where it is supposed to be. (Quite likely related to those errors.) So it's not ideal.

     
  • J D

    J D - 2011-02-21
    • status: pending --> open