<glimmer-definition>
   <settings>
      <language>Glimmer Language Definition</language>
      <compiler>null</compiler>
      <debugger>null</debugger>
      <execution>null</execution>
      <auto-indent>1</auto-indent>
      <use-spaces>1</use-spaces>
      <tab-stop>3</tab-stop>
      <over-ride>1</over-ride>
   </settings>

   <mime-types>
      <extension>lang</extension>
   </mime-types>

   <syntax-items>
      <syntax-item>
         <name>comment</name>
         <start-regex>^&lt;!--</start-regex>
         <end-regex>--&gt;</end-regex>
         <style>comment</style>
      </syntax-item>
      <syntax-item>
         <name>string</name>
         <start-regex>&quot;</start-regex>
         <end-regex>\(&quot;\|\n\)</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>rstring</name>
         <start-regex>r&apos;</start-regex>
         <end-regex>&apos;</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>singlestring</name>
         <start-regex>&apos;</start-regex>
         <end-regex>\(&apos;\|\n\)</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>multiline-string</name>
         <start-regex>&quot;&quot;&quot;</start-regex>
         <end-regex>&quot;&quot;&quot;</end-regex>
         <style>string</style>
      </syntax-item>
   </syntax-items>

   <pattern-items>
      <pattern-item>
         <name>python</name>
         <regex>\(glimmer\|glimmer\.[a-z_]+\)</regex>
         <style>function</style>
      </pattern-item>
      <pattern-item>
         <name>tags</name>
         <regex>&lt;/?\(glimmer-definition\|python-definition\|settings\|language\|compiler\|debugger\|execution\|auto-indent\|use-spaces\|tab-stop\|over-ride\|mime-types\|extension\|mime-type\|syntax-items\|syntax-item\|pattern-items\|pattern-item\|embedded-items\|embedded-item\|name\|start-regex\|end-regex\|regex\|outside-regex\|inside-regex\|style\)&gt;</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>entities</name>
         <regex>\(\&amp;\|\%\)[a-zA-Z0-9#]*;</regex>
         <style>variable</style>
      </pattern-item>
      <pattern-item>
         <name>regex-chars</name>
         <regex>\(\\(\|\\)\|\\b\|\\t\|\\n\|(\|)\|\\|\|\[\|\]\|{\|}\)</regex>
         <style>symbol</style>
      </pattern-item>
      <pattern-item>
         <name>modules</name>
         <regex>\b\(import\|from\)\b</regex>
         <style>preprocessor</style>
      </pattern-item>
      <pattern-item>
         <name>func-class</name>
         <regex>\b\(def\|class\|return\)\b</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>keywords</name>
         <regex>\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</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>operators</name>
         <regex>\(\?\|\%\|\*\|\*\*\|-\|&gt;\|::\|:\|&gt;&gt;\|&lt;&lt;\|&gt;\|&lt;\|=\|==\|!=\|&lt;=\|&gt;=\|++\|--\|%\|+\|-\|||\|&amp;&amp;\|!\|+=\|-=\|\*=\|/=\|%=\|~\|\.\|,\|;\)</regex>
         <style>operator</style>
      </pattern-item>
   </pattern-items>
</glimmer-definition>

<python-definition>
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()

glimmer.add_sub_to_menu("_Insert/", "Language Definition", -1)
glimmer.add_item_to_menu("_Insert/Language Definition/", "Comment (#)", "", "", -1, insert_lang_comment)
glimmer.add_item_to_popup_menu("Comment (#)", -1, insert_lang_comment)
</python-definition>
