dparkins / language-fortran

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

Problematic auto indent of preprocessor directives #99

Open packet0 opened 7 years ago

packet0 commented 7 years ago

Currently auto indent makes preprocessor directives also indented. Unfortunately the de facto standard fpp preprocessor doesn't allow white characters before #, so it's a problem if this happens.

current, not ok:

do i=0, 10
    #ifdef MPI
    write (*,*) "test"
    #ifndef USE_MPI_IN_PLACE
    write (*,*) "test"
    #endif
    write (*,*) "test"
    #endif
end do

ok:

do i=0, 10
#ifdef MPI
    write (*,*) "test"
#ifndef USE_MPI_IN_PLACE
    write (*,*) "test"
#endif
    write (*,*) "test"
#endif
end do

On the other hand, it's allowed to have white characters after #, so something like below is also fine. alternative?:

do i=0, 10
#   ifdef MPI
        write (*,*) "test"
#       ifndef USE_MPI_IN_PLACE
            write (*,*) "test"
#       endif
        write (*,*) "test"
#   endif
end do

I've seen both the "OK" and "Alternative" versions (in the same file...), and I don't really mind either. Its best if there could be an option for it...

Some resources: Fortran Wiki GFortran Doc ICC Doc

tomedunn commented 7 years ago

Thanks for posting. I'll check to see if anything has change with the way Atom handles indenting, but last I checked this kind of tabbing behavior isn't possible in Atom. Atom doesn't really store the tab level of each line the same way an editor like Vim does. So it can't choose to ignore the current indenting level for one line and then pick back up where it left off with the next. It just knows if it should increase the tab by one, decrease it by one, or keep it the same.

That said, if you find any languages that manage to accomplish this in Atom, please let us know and we can try to incorporate this kind of behavior.

packet0 commented 7 years ago

OK, so it's due to atom's inflexible treatment of line properties. I could find various issues related to auto indent on Atom's repo (back from 2015...), and I couldn't find any language grammer that accomplishes anyting similar. I guess I'll have to live with it or find/write some addon for the meantime. Thanks for responding and helping out.

tomedunn commented 7 years ago

There is a good writeup on the issue and a possible solution here. I'm not sure what, if any, kind of progress has been made to implement anything along these lines but I know I would definitely like to see more options for indenting languages. Fortran is pretty poorly served by the current system (as it has been in both Textmate and Sublime Text as well).