<settings>
language=Ada
compiler=glimmerout gnatmake %1/%2 2>&1
debugger=%term% -e gnatgdb %1/%2
execution=%1/%3
auto_indent=1
use_spaces=1
tab_stop=3
</settings>

<extensions>
 <item name="Ada Source" ext="ada">
 <item name="Ada Package" ext="adb">
 <item name="Ada Package" ext="ads">
</extensions>

<syntax>
 <item name="string1" start="\"" end="\(\"\|\n\)" color="string">
 <item name="comment" start="--" end="\n" color="comment">
</syntax>

<pattern>
 <item name="char-string" words="'\\?[a-zA-Z0-9_\\()#@!$%^&*-=+\"{}<)]'" color="char_string">
 <item name="preprocessor1" words="\b\(PACKAGE\|PRAGMA\|USE\|WITH\)" color="preprocessor">
 <item name="preprocessor2" words="\b\(Package\|Pragma\|Use\|With\)" color="preprocessor">
 <item name="preprocessor3" words="\b\(package\|pragma\|use\|with\)" color="preprocessor">
 <item name="function1" words="\b\(FUNCTION\|PROCEDURE\|RETURN\)" color="function">
 <item name="function2" words="\b\(Function\|Procedure\|Return\)" color="function">
 <item name="function3" words="\b\(function\|procedure\|return\)" color="function">
 <item name="keywords1" words="\b\(ABORT\|ABS\|ACCEPT\|ACCESS\|ALL\|AND\|ARRAY\|AT\|BEGIN\|BODY\|CASE\|CONSTANT\|DECLARE\|DELAY\|DELTA\|DIGITS\|DO\|ELSE\|ELSIF\|END\|ENTRY\|EXCEPTION\|EXIT\|FOR\|GENERIC\|GOTO\|IF\|IN\|IS\|LIMITED\|LOOP\|MOD\|NEW\|NOT\|NULL\|OF\|OR\|OTHERS\|OUT\|PRIVATE\|RAISE\|RANGE\|RECORD\|REM\|RENAMES\|REVERSE\|SELECT\|SEPARATE\|SUBTYPE\|TASK\|TERMINATE\|THEN\|TYPE\|WHEN\|WHILE\|XOR\)\b" color="keyword">
 <item name="keywords2" words="\b\(Abort\|Abs\|Accept\|Access\|All\|And\|Array\|At\|Begin\|Body\|Case\|Constant\|Declare\|Delay\|Delta\|Digits\|Do\|Else\|Elsif\|End\|Entry\|Exception\|Exit\|For\|Generic\|Goto\|If\|In\|Is\|Limited\|Loop\|Mod\|New\|Not\|Null\|Of\|Or\|Others\|Out\|Private\|Raise\|Range\|Record\|Rem\|Renames\|Reverse\|Select\|Separate\|Subtype\|Task\|Terminate\|Then\|Type\|When\|While\|Xor\)\b" color="keyword">
 <item name="keywords3" words="\b\(abort\|abs\|accept\|access\|all\|and\|array\|at\|begin\|body\|case\|constant\|declare\|delay\|delta\|digits\|do\|else\|elsif\|end\|entry\|exception\|exit\|for\|generic\|goto\|if\|in\|is\|limited\|loop\|mod\|new\|not\|null\|of\|or\|others\|out\|private\|raise\|range\|record\|rem\|renames\|reverse\|select\|separate\|subtype\|task\|terminate\|then\|type\|when\|while\|xor\)\b" color="keyword">
 <item name="types1" words="\b\(BOOLEAN\|CHARACTER\|COUNT\|DURATION\|FLOAT\|INTEGER\|LONG_FLOAT\|LONG_INTEGER\|PRIORITY\|SHORT_FLOAT\|SHORT_INTEGER\|STRING\)\b" color="data_type">
 <item name="types2" words="\b\(Boolean\|Character\|Count\|Duration\|Float\|Integer\|Long_Float\|Long_Integer\|Priority\|Short_Float\|Short_Integer\|String\)\b" color="data_type">
 <item name="types3" words="\b\(boolean\|character\|count\|duration\|float\|integer\|long_float\|long_integer\|priority\|short_float\|short_integer\|string\)\b" color="data_type">
 <item name="numbers" words="\b[0-9][0-9\.]*\b" color="decimal">
 <item name="tnf" words="\b\(TRUE\|FALSE\|True\|False\|true\|false\)\b" color="macro">
 <item name="operators" words="\(:\|;\|,\|+\|-\|\*\|>=\|<=\|>\|<\|/=\|:=\|=\|&\|\.\|'\|\*\*\|/\|(\|)\)" color="operator">
</pattern>

<python>
import glimmer
import re

def ada_enter_callback():
    insert = "\n"
    extralen = 0
    slen = 0
    file = glimmer.get_file_number()
    tstart = glimmer.line_start()
    tend = glimmer.current_position()
    if (tend-tstart) > 0:
        chars = glimmer.get_text(tstart, tend)
        slen = len(chars)
        if slen > 0:
            index = 0
            while index < slen:
                c = chars[index]
                if c == '\t' or c == ' ':
                    insert = insert + chars[index]
                    index = index+1
                else:
                    break
            output = re.search("(begin|declare|else|exception|generic|loop|or|private|select|is|do|then abort|then)$", chars, re.I)
            if not(output):
               output = re.search("(when|of)", chars, re.I)
            if output:
                extralen = glimmer.get_file_tab_width(file)
                if glimmer.get_file_use_spaces(file):
                    while extralen > 0:
                        insert = insert + " "
                        extralen = extralen-1
                else:
                    insert = insert + '\t'
    glimmer.insert(insert)

glimmer.register_signal_hook("enter-pressed", ada_enter_callback)

def ada_tab_callback():
   tablen = 0
   insertchars = ""
   file = glimmer.get_file_number()
   if glimmer.get_file_use_spaces(file):
      tablen = glimmer.get_file_tab_width(file)
      pos = glimmer.current_position()
      lstart = glimmer.line_start()
      if pos - lstart > 0:
         str1 = glimmer.get_text(lstart, pos)
      else:
         str1 = ""
      if glimmer.get_tab_stops():
         str1 = string.expandtabs(str1, tablen)
         len1 = len(str1)
         del str1
         tablen = tablen - (len1 % tablen)
      while tablen > 0:
         insertchars = insertchars + " "
         tablen = tablen-1
   else:
      insertchars = insertchars + "\t"
   glimmer.insert(insertchars)

glimmer.register_signal_hook("tab-pressed", ada_tab_callback)

def insert_ada_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("--")
           cur = cur+2
        glimmer.move_to(end+((line2-line1)+1)*2)
    else:
        glimmer.insert("--")
    glimmer.thaw()

i = glimmer.add_sub_to_insert_menu("Ada", -1)
glimmer.add_item_to_insert_menu("Comment (--)", i, insert_ada_comment)
glimmer.add_item_to_popup_menu("Comment (--)", -1, insert_ada_comment)
</python>
