[TxMt] formatting f77 code

Donna Calhoun donna.calhoun at gmail.com
Wed Oct 14 16:24:44 UTC 2009


I wrote recently regarding the f77 capabilities in TextMate.  I  
recently downloaded the demo version of TM, and found it to very  
useful in many ways.  But I found its f77 indenting rules less than  
satisfactory.   I really want to be able to use TM and would gladly  
purchase a copy, but I've come to rely heavily on automatic indenting  
and formatting for checking syntax errors, making the code readable  
and so on.   I am afraid that a lack of proper indenting rules
is a showstopper for me.

I apologize in advance for comparing TM with Emacs, but below is a  
list of indenting rules for f77 ("punchcard Fortran") that I've come  
to expect from Emacs.  Is there any way to get these features in TM?

1.  All lines should start in column 7, with two exceptions :
       * Lines whose first character is 'c' or 'C' (the comment  
character).  Emacs also leaves 'd' and
        'D' in the first column although this could (happily) be  
dropped.  See comments below.

       * line continuation characters.  Continuations are indicated by  
any character in column 6.
         The customary continuation character is '&'.

       * Line numbers. Used mainly for 'format' statements, but also  
for 'goto', and if one is really
         old school, do/continue statements.  The format/continue/goto  
should always start in column
         7, but the line number should be right justified, with final  
character in column 5.

2.  Characters beyond column 72 should be identified, either with a  
different color or different font.

3.  Comments should be properly indented.   The comments character  
should remain in column 1, but all
     remaining text should align given current context.  In emacs,  
comments are also properly wrapped, with
     a comment character put in column 1, and the comment continuing  
at its proper indentation level.

4.  Fixed tabbing beyond column 7.  Emacs appears to use 3-spaces per  
tab (by default), which is fine, although it
     would be nice to allow for customized tabs beyond column 7.

5.  Ideally, lines which are longer than 72 characters would  
automatically be split, with
     a default continuation character added in line 6 on new line.

I think I got most of the important items.  Here is a sample of  
"properly" (at least in
my opinion - I'd be curious to hear what others think) formatted f77  
code (formatted in Aquamacs).  All
formatting rules are applied by hitting "tab" in Aquamacs when the  
cursor is anywhere on the the line to be formatted.

       subroutine assign_src(mx,my,meqn,q0,lap0,t,rhs)
       implicit none

       integer mx, my, meqn
       double precision t
       integer m

       double precision q0(0:mx+1,0:my+1,meqn)
       double precision lap0(0:mx+1,0:my+1,meqn)
       double precision rhs(0:mx+1,0:my+1,meqn)
       integer i,j
       double precision lap_u,at,dadt
       double precision long_line

       call qval_time(t,at,dadt)

       do m = 1,meqn
          do j = 1,my
             do i = 1,mx
c              # Comments are properly indented after the comment  
character in
c              # line 1, and are correctly wrapped they exceed column  
72.
c              # (The '#' marks are mine)
                lap_u = rhs(i,j,m)
                rhs(i,j,m) = lap_u - at*lap0(i,j,1) + dadt*q0(i,j,1)

c              # A really long line with a continuation character in  
column 6
                long_line = (rhs(i+1,j,m) + rhs(i-1,j,m) + rhs(i,j 
+1,m) + rhs(i
      &               ,j-1,m) - 4*rhs(i,j,m))

c              # Note line number in format statement in column < 7  
and right
c              justified.  Also, this comment is also wrapped.
                write(6,100) 'rhs',rhs(i,j,m)
   100          format(A10,E16.8)
             enddo
          enddo

       enddo

       end

       subroutine old_school()
       implicit none

       integer i
       double precision x

c     # example of line numbers in a do loop.
       x = 0
       do 110 i = 1,20
          x = x + 1
   110 continue

       end


Aquamacs/Emacs isn't perfect.   Since 'd' and 'D' is also comment  
characters, AM will assume that
a statement beginning with 'double precision' should leave the 'd' in  
column 1 and
split the rest to column 7, which would likely lead to a compile  
error.  The same thing happens with
'call' statements starting in column 1.  Applying automatic  
indentation to

call quad()

results in

c     all quad()

which will also result in a compiler error.

But aside from those few glitches (features?)  I would be happy to see  
an Emacs style indenting in TM.

Also, I would be happy to hear if I am missing anything major in TM.   
Are there easy ways to get the above into the Fortran bundle?





More information about the textmate mailing list