<settings>
language=Glimmer Language Definition
compiler=
debugger=
execution=
over_ride=1
auto_indent=1
use_spaces=1
tab_stop=4
</settings>

<extensions>
 <item name="lang" ext="lang">
</extensions>

<syntax>
 <item name="multilinestring" start="\"\"\"" end="\"\"\"" color="string">
 <item name="string" start="\"" end="\(\"\|\n\)"color="string">
 <item name="rstring" start="r'" end="'" color="string">
 <item name="singlestring" start="'" end="\('\|\n\)" color="string">
 <item name="comment" start="\(#\|;\)" end="\n" color="comment">
</syntax>

<pattern>
 <item name="-python" words="\(glimmer\|glimmer\.[a-z_]+\)" color="function">
 <item name="-guile" words="add-\(syntax\|pattern\|embedded\|sub\|item\)-\(entry\|to-\)\(insert\|scripts\|popup\)?\(-menu\)?\b" color="function">
 <item name="tags" words="</?\(settings\|extensions\|syntax\|pattern\|embedded\|python\|guile\)>" color="keyword">
 <item name="items" words="\(<item\|name\|\bext\b\|\bstart\b\|words\|\bend\b\|color\|>\)" color="keyword">
 <item name="guile" words="\bdefine" color="keyword">
 <item name="modulhander" words="\b\(import\|from\)\b" color="preprocessor">
 <item name="func_class" words="\b\(def\|class\|return\)\b" color="keyword">
 <item name="keywords" words="\b\(and\|del\|for\|is\|raise\|assert\|elif\|from\|lambda\|break\|else\|global\|not\|try\|except\|if\|or\|while\|continue\|exec\|pass\|finally\|in\|print\)\b" color="keyword">
 <item name="chars" words="\((\|)\|{\|}\|\[\|\]\|:\)" color="keyword">
 <item name="operators" words="\(<>\|/\|\*\|<<\|>>\|>\|<\|=\|==\|!=\|<=\|>=\|%\|+\|-\||\|&\|\.\|,\)" color="operator">
</pattern>

<python>
import glimmer

def lang_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
         c = chars[slen-1]
         if c == ':':
            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", lang_enter_callback)

def lang_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", lang_tab_callback)

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

i = glimmer.add_sub_to_insert_menu("Language Definition", -1)
glimmer.add_item_to_insert_menu("Comment (#)", i, insert_lang_comment)
glimmer.add_item_to_popup_menu("Comment (#)", -1, insert_lang_comment)
</python>
