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

indentation fails at multiple subroutine definitions in preprocessor directives #156

Open
LukasvdWiel opened this issue Aug 16, 2023 · 3 comments

Comments

@LukasvdWiel
Copy link

LukasvdWiel commented Aug 16, 2023

Let me have unformatted code:

#ifdef foo
subroutine bla(x)
#else
subroutine bla(x,y)
#endif

[do something]

end subroutine

subroutine bar

I would expect [do something] to be indented once, and both subroutine calls to be equally indented:

#ifdef foo
subroutine bla(x)
#else
subroutine bla(x,y)
#endif

    [do something]

end subroutine

subroutine bar

but what happens is that the second subroutine definition of bla is already indented.
Worse then that, all code below takes the extra indent level, and subsequent subroutines, such as bar in this example, is indented more than it should.

#ifdef foo
subroutine bla(x)
#else
    subroutine bla(x,y)
#endif

        [do something]

    end subroutine

    subroutine bar

I hope you could find time to fix this.

Have an excellent day!

Lukas

@nbehrnd
Copy link

nbehrnd commented Aug 16, 2023

@LukasvdWiel I would like to add a suggestion. It is unrelated to the content, but to the presentation of the content: If you would like to share a snippet of code in (Gruber's) Markdown, you either use four explicit spaces, or a tab of indentation. This is why [do something] above currently is displayed differently.

Alternatively, GitHub's flavour of Markdown additionally allows (optionally annotated) fenced blocks you likely aimed to use. Note however, this approach usually does not use single quotes (your post in the present form), but back ticks (known in French as accent grave) to enclose such a snippet. (Link to a compilation of hints about/around markdown.)

In addition to an easier copy-paste of such a snippet en bloc*, the annotation can enable syntax highlighting. Optional (mutually exclusive) keywords I know to be supported here on GitHub are python

for i in range(5):
    print(i)

awk

#!/usr/bin/awk -f
BEGIN{
string = "this is an example";

split(string, array)

for (i = 1; i<=length(array); i++){};
print array[i]}

or f90 / fortran

program test
  implicit none
  integer :: i

  do i = 1, 5
    write (*, "(2(I2, 1X))") i, i**2
  end do
end program test

* This copy-paste then equally preserves the indentation (useful if it is functionally relevant, e.g. for Python).

clip

@LukasvdWiel
Copy link
Author

LukasvdWiel commented Aug 16, 2023

@nbehrnd Thank you very much, I have applied your wisdom to my original message... It made the issue a lot prettier.

@nbehrnd
Copy link

nbehrnd commented Aug 20, 2023

@LukasvdWiel A revisit of your post, which is conceptual. That is to say, share of a specific minimal working example could illustrate, hence substantiate your point. If your observation could be replicated with source code in a single file, one option is to add an additional .txt extension; and while running an instance of GitHub in a browser, to attach it below one of the frames edited by you (an example below).

Else, if you already split your program into a main.f90 and a separate e.g. my_module.f90 about procedures or/and a minimal set of raw data, deposit within a .zip archive (because .zip equally is one of the file extensions permitted here) equally is at your hands.

Briefly (because of the leading number signs) I thought your examples could be an example of an accidental code-switching to Python. It is a term in natural languages (e.g. Franglais in lieu of French (Français), or English (Anglais)) when elements of one language enter an other without representing e.g. a loanword. This impression however can be an error on my side, too.

example.f90.txt
example.f90.txt.zip

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