# Author : Andrey Panov <panov@ifit.phys.dvgu.ru>

<settings>
language=FORTRAN
compiler=glimmerout g77 -g %2 -o %3 2>&1
debugger=%term% gdb %3
execution=%term% %1/%3
#over_ride=1
auto_indent=1
use_spaces=0
tab_stop=6
</settings>

<extensions>
 <item name="FORTRAN source file" ext="f">
 <item name="FORTRAN source file" ext="for">
 <item name="FORTRAN source file" ext="F">
 <item name="FORTRAN source file" ext="FOR">
 <item name="FORTRAN source file with preprocessor directives" ext="fpp">
</extensions>

<syntax>
 <item name="string" start="\"" end="\(\"\|\n\)"color="string">
 <item name="singlestring" start="'" end="\('\|\n\)" color="string">
 <item name="comment" start="\(^[Cc*]\|!\)" end="\n" color="comment">
 <item name="preprocessor" start="^#" end="\n" color="preprocessor">
 <item name="define_comment" start="^#if 0" end="^#endif" color="comment">
</syntax>

<pattern>
 <item name="function1" words="\(FUNCTION\|SUBROUTINE\|BLOCK\|BLOCKDATA\|PROGRAM\)" color="function">
 <item name="function2" words="\(function\|subroutine\|block\|blockdata\|program\)" color="function">
 <item name="types1" words="\(CHARACTER\|COMMON\|COMPLEX\|DIMENSION\|DOUBLE\|EQUIVALENCE\|EXTERNAL\|IMPLICIT\|INTEGER\|INTRINSIC\|KIND\|LOGICAL\|NAMELIST\|NONE\|PARAMETER\|PRECISION\|REAL\)" color="data_type">
 <item name="types2" words="\(character\|common\|complex\|dimension\|double\|equivalence\|external\|implicit\|integer\|intrinsic\|kind\|logical\|namelist\|none\|parameter\|precision\|real\)" color="data_type">
 <item name="keywords1" words="\b\(ASSIGN\|BACKSPACE\|CALL\|CASE\|CLOSE\|CYCLE\|DATA\|DO\|ELSE\|ELSEIF\|ENDFILE\|ENDDO\|ENDIF\|END\|EXIT\|FORMAT\|GOTO\|GO\|IF\|INCLUDE\|OPEN\|PAUSE\|READ\|RETURN\|REWIND\|SELECT\|SELECTCASE\|STOP\|THEN\|TO\|WHILE\|WRITE\|CONTINUE\|PRINT\)\b" color="keyword">
 <item name="keywords2" words="\b\(assign\|backspace\|call\|case\|close\|cycle\|data\|do\|else\|elseif\|endfile\|enddo\|endif\|end\|exit\|format\|goto\|go\|if\|include\|open\|pause\|read\|return\|rewind\|select\|selectcase\|stop\|then\|to\|while\|write\|continue\|print\)\b" color="keyword">
 <item name="intrinsic_functions1" words="\b\(ABS\|ACOS\|AIMAG\|AINT\|ASIN\|ATAN\|ATAN2\|BESJ0\|BESJ1\|BESJN\|BESY0\|BESY1\|BESYN\|CHAR\|CMPLX\|CONJG\|COS\|COSH\|DBLE\|DIM\|DPROD\|ERF\|ERFC\|EXP\|GETARG\|IACHAR\|IARGC\|ICHAR\|IMAG\|INDEX\|LEN\|LENTRIM\|LGE\|LGT\|LLE\|LLT\|LOC\|LOG\|LOG10\|MAX\|MIN\|MOD\|NINT\|RAND\|SIGN\|SIN\|SINH\|SQRT\|TAN\|TANH\|TIME\|XOR\)\b" color="function">
 <item name="intrinsic_functions2" words="\b\(abs\|acos\|aimag\|aint\|asin\|atan\|atan2\|besj0\|besj1\|besjn\|besy0\|besy1\|besyn\|char\|cmplx\|conjg\|cos\|cosh\|dble\|dim\|dprod\|erf\|erfc\|exp\|getarg\|iachar\|iargc\|ichar\|imag\|index\|len\|lentrim\|lge\|lgt\|lle\|llt\|loc\|log\|log10\|max\|min\|mod\|nint\|rand\|sign\|sin\|sinh\|sqrt\|tan\|tanh\|time\|xor\)\b" color="function">
 <item name="chars" words="\((\|)\|=\)" color="keyword">
 <item name="operators" words="\(\*\|\/\|>\|<\|==\|/=\|<=\|>=\|%\|+\|-\|,\|\:\)" color="operator">
 <item name="operators1" words="\(\.AND\.\|\.NOT\.\|\.OR\.\|\.GT\.\|\.LT\.\|\.GE\.\|\.LE\.\|\.EQ\.\|\.NE\.\|\.FALSE\.\|\.TRUE\.\)" color="operator">
 <item name="operators2" words="\(\.and\.\|\.not\.\|\.or\.\|\.gt\.\|\.lt\.\|\.ge\.\|\.le\.\|\.eq\.\|\.ne\.\)" color="operator">
 <item name="labels" words="\(^[0-9]+\b\|^ [0-9]+\b\)" color="macro">
# <item name="labels2" words="^[0-9]{1,5}" color="macro">
# <item name="numbers" words="\b[0-9\.][DEde0-9\.]*\b" color="decimal">
  <item name="hex_numbers" words="#\([0-9A-Fa-f]\)+\b" color="hexidecimal">
</pattern>

<python>
import glimmer

def insert_fortran_comment():
    glimmer.freeze()
    if glimmer.has_selection():
        start = glimmer.selection_start()
        end = glimmer.selection_end()
        file = glimmer.get_file_number()
        glimmer.move(0)
        line1 = glimmer.line_by_pos(start)
        line2 = glimmer.line_by_pos(end)
        cur = line1
        print start
        print end
        while cur <= line2:
           glimmer.move_to_col(0)
           glimmer.move_to_line(cur)
           glimmer.insert("C")
           cur = cur+1
        glimmer.move_to(end+((line2-line1)+1)*2)
    else:
        glimmer.move_to_col(0)
        glimmer.insert("C")
    glimmer.thaw()

i = glimmer.add_sub_to_insert_menu("FORTRAN", -1)
glimmer.add_item_to_insert_menu("Comment line", i, insert_fortran_comment)
glimmer.add_item_to_popup_menu("Comment line", -1, insert_fortran_comment)
</python>
