<glimmer-definition>
   <settings>
      <language>Python</language>
      <compiler></compiler>
      <debugger></debugger>
      <execution></execution>
      <auto-indent>1</auto-indent>
      <use-spaces>0</use-spaces>
      <tab-stop>4</tab-stop>
   </settings>

   <mime-types>
      <extension>py</extension>
   </mime-types>

   <syntax-items>
      <syntax-item>
         <name>multilinestring</name>
         <start-regex>&quot;&quot;&quot;</start-regex>
         <end-regex>&quot;&quot;&quot;</end-regex>
         <style>string</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>char_string</style>
      </syntax-item>
      <syntax-item>
         <name>singlestring</name>
         <start-regex>&apos;</start-regex>
         <end-regex>\(&apos;\|\n\)</end-regex>
         <style>char_string</style>
      </syntax-item>
      <syntax-item>
         <name>comment</name>
         <start-regex>#</start-regex>
         <end-regex>\n</end-regex>
         <style>comment</style>
      </syntax-item>
   </syntax-items>

   <pattern-items>
      <pattern-item>
         <name>modulhander</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>\(/\|\*\|&lt;&lt;\|&gt;&gt;\|&lt;\|&gt;\|=\|==\|!=\|&lt;=\|&gt;=\|%\|+\|-\||\|&amp;\)</regex>
         <style>operator</style>
      </pattern-item>
      <pattern-item>
         <name>whole_numbers1</name>
         <regex>\b[0-9]\b</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>whole_numbers2</name>
         <regex>\b[1-9][0-9]*\b</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>float_numbers1</name>
         <regex>\.\b[0-9]+\b</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>float_numbers2</name>
         <regex>\b[0-9]*\.\W</regex>
         <style>decimal</style>
      </pattern-item>
      <pattern-item>
         <name>hex_numbers</name>
         <regex>\b0x[0-9a-fA-F]+\b</regex>
         <style>hexidecimal</style>
      </pattern-item>
      <pattern-item>
         <name>oct_numbers</name>
         <regex>\b0[0-7]+\b</regex>
         <style>octal</style>
      </pattern-item>
      <pattern-item>
         <name>bin_numbers</name>
         <regex>\b0[01]+\b</regex>
         <style>octal</style>
      </pattern-item>
      <pattern-item>
         <name>self</name>
         <regex>\bself\b</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>punctuation</name>
         <regex>\((\|)\|\|:\|{\|}\|\[\|\]\|\.\)</regex>
         <style>punctuation</style>
      </pattern-item>
   </pattern-items>
</glimmer-definition>

<python-definition>
import glimmer
import string

def python_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", python_enter_callback)

def python_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", python_tab_callback)

def insert_python_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/", "Python", -1)
glimmer.add_item_to_menu("_Insert/Python/", "Comment (#)", "", "", -1, insert_python_comment)
glimmer.add_item_to_popup_menu("Comment (#)", -1, insert_python_comment)
</python-definition>
