fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
368 stars 73 forks source link

Can comments starting in column 1 be indented? #143

Open Pmoloney3415 opened 1 year ago

Pmoloney3415 commented 1 year ago

Is it possible to add an option to do this within the programme? Thanks for the great project!

ghost commented 5 months ago

This would be a really useful feature for a project I'm working on!

nbehrnd commented 5 months ago

For the time till then, you might search and replace the occurrences with e.g., AWK.

It works fine in AWK as implemented as GNU Awk 5.2.1. Or put it in a script e.g.,

#!/usr/bin/gawk -f

# name   : indent.awk
# purpose: indent comment lines starting on column 1 by three additional leading spaces

# either run the script by
#
# ```
# $ awk -f ./indent.awk my_code.f90
# $ ./indent.awk my_code.f90  # after provision of the executable bit to the script
# ```

{ if ($0 ~ /^!/) print "   "$0; else print $0}