fprettify icon indicating copy to clipboard operation
fprettify copied to clipboard

[Feature request] Support formatting options as modules

Open marmistrz opened this issue 8 years ago • 1 comments
trafficstars

I've seen a code which mixes .gt. and > - awful! Thought about contributing this... but stumbled across the longish __init__.py.

It's very difficult to find out where such a thing should be added. What I thought about was: plugins.

If there were a directory plugins, then adding a new formatting option would be as simple as:

  1. Write the needed code in plugins/mynewplugin.py, matching a predefined interface (inheriting an ABC [1] ?)
  2. Register that in __init__.py, possibly binding that to command line options (there may be dependencies between plugins)

For example, replacing .gt. with > could be as simple as a find-and-replace. This would make the code much clearer and much easier to contribute to.

[1] https://pymotw.com/3/abc/

marmistrz avatar Feb 03 '17 13:02 marmistrz

It is an ongoing effort to decouple dependencies and I hope I will eventually come up with a more modular and organised code.

I did not yet think about extensibility of fprettify and my work was focused on whitespace changes only (other features are planned). Replacing the old .gt., ... with the more modern >, ... would be a very useful feature indeed.

I will think about what interface could be provided for plugins / new features. Probably the base class should provide functions get_fortran_line and set_fortran_line and some basic Fortran parsing utilities, mainly to separate comments and strings from Fortran statements.

pseewald avatar Feb 07 '17 17:02 pseewald