Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can comments starting in column 1 be indented? #143

Open
Pmoloney3415 opened this issue Feb 10, 2023 · 2 comments
Open

Can comments starting in column 1 be indented? #143

Pmoloney3415 opened this issue Feb 10, 2023 · 2 comments

Comments

@Pmoloney3415
Copy link

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

@ghost
Copy link

ghost commented Mar 20, 2024

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

@nbehrnd
Copy link

nbehrnd commented Mar 21, 2024

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

  • for comments starting in column 1:

    $ awk '{ if ($0 ~ /^!/) print "   "$0; else print $0}' my_file.f90
  • for comment lines starting with some white space then followed by a comment

    $ awk '{ if ($0 ~ /^\s!/) print "   "$0; else print $0}' my_file.f90
  • to apply both conditions simultaneously, either use awk's logical or

    $ awk '{if (($0 ~ /^!/) || ($0 ~ /\s!/)) print "   "$0; else print $0}' my_file.f90

    or a regex clause for zero, or any number of white spaces

    $ awk '{ if ($0 ~ /^\s*!/) print "   "$0; else print $0}' my_file.f90

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants