dparkins / language-fortran

Syntax highlighting for FORTRAN for atom
MIT License
35 stars 16 forks source link

auto-indent gets wrong if a line contains the word "function" #64

Closed maxlevesque closed 9 years ago

maxlevesque commented 9 years ago

Hello, It's been a while I'm having trouble with auto-indent in a very long module. I didn't take the time to track back the bug in language-fortran's auto-indent. Here it is! :)

Let's type this in my favorite Atom editor:

program toto
    implicit none
    real :: x
    real :: y ! no problem
    real :: z ! this line contains the word "function" in the comment.
    real :: q ! <= this is sufficient to mess the auto-indent
    real :: messy
end program toto

Now, let's apply Edit > Lines > Auto-Indent ...

program toto
    implicit none
    real :: x
    real :: y ! no problem
    real :: z ! this line contains the word "function" in the comment.
        real :: q ! <= this is sufficient to mess the auto-indent
        real :: messy
    end program toto

Now let's replace function in the declaration of z by anything else and apply again Auto-Indent ...

program toto
    implicit none
    real :: x
    real :: y ! no problem
    real :: z ! this line contains the word "anything else" in the comment.
    real :: q ! <= this is sufficient to mess the auto-indent
    real :: messy
end program toto

Conclusion

When the word function is found in a line, even if it is in a comment, then auto-indent gets wrong.

maxlevesque commented 9 years ago

That's not a comment-only bug:

program toto
    print*, "this is a function I like"
        print*, "ok"
    end program toto
maxlevesque commented 9 years ago

Of course, word subroutine produces same effects:

program toto
    print*, "this is a subroutine I like"
        print*, "ok"
    end program toto
tomedunn commented 9 years ago

Thanks for posting! The auto indent regex is set to trigger any time subroutine or function occur and aren't immediately preceded by end. I'll see if I can make some simple tweaks to it so it won't trigger when those words are in comments or in strings.

maxlevesque commented 9 years ago

Hi @tomedunn , I greatly appreciate all your work. I hope my reports help to improve the life of all the poor-fortran-developpers ;) nearby and do not only bring more work to you!

tomedunn commented 9 years ago

The reports are hugely helpful @maxlevesque . I'm rarely able to use Atom for writing Fortran programs since I'm typically programming remotely via the terminal using Vim. So while it's relatively easy for me to test changes against the host of static Fortran files I have, it takes quite a bit of effort to check dynamic behaviors such as auto-indenting.