<glimmer-definition>
   <settings>
      <language>C++</language>
      <compiler>glimmerout g++ -g %2 -o %3 2&gt;&amp;1</compiler>
      <debugger>%term% gdb %3</debugger>
      <execution>%term% %1/%3</execution>
      <auto-indent>1</auto-indent>
      <use-spaces>0</use-spaces>
      <tab-stop>4</tab-stop>
   </settings>

   <mime-types>
      <extension>H</extension>
      <extension>hpp</extension>
      <extension>hxx</extension>
      <extension>hh</extension>
      <extension>HH</extension>
      <extension>C</extension>
      <extension>cpp</extension>
      <extension>cxx</extension>
      <extension>cc</extension>
      <extension>CC</extension>
   </mime-types>

   <syntax-items>
      <syntax-item>
         <name>defs_full</name>
         <start-regex>^#\ *\t*\(include\|pragma\)</start-regex>
         <end-regex>\(\n\)</end-regex>
         <style>preprocessor</style>
      </syntax-item>
      <syntax-item>
         <name>cpp-comment</name>
         <start-regex>//</start-regex>
         <end-regex>\n</end-regex>
         <style>comment</style>
      </syntax-item>
      <syntax-item>
         <name>c-comment</name>
         <start-regex>/\*</start-regex>
         <end-regex>\*/</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>define_comment</name>
         <start-regex>^#if 0</start-regex>
         <end-regex>^#endif</end-regex>
         <style>comment</style>
      </syntax-item>
   </syntax-items>
   
   <pattern-items>
      <pattern-item>
         <name>chars</name>
         <regex>&apos;\\?[a-zA-Z0-9_\\()#@!$%^&amp;*-=+&quot;{}&lt;&gt;]&apos;</regex>
         <style>char_string</style>
      </pattern-item>
      <pattern-item>
         <name>defs</name>
         <regex>^#\ *\t*\(if\|ifdef\|ifndef\|else\|elif\|define\|endif\|undef\)\b</regex>
         <style>preprocessor</style>
      </pattern-item>
      <pattern-item>
         <name>typedefs</name>
         <regex>\b\(bool\|char\|float\|double\|short\|int\|long\|signed\|unsigned\|register\|void\)\b</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>keywords</name>
         <regex>\b\(asm\|auto\|break\|case\|const\|continue\|default\|do\|else\|enum\|extern\|for\|goto\|if\|return\|sizeof\|static\|struct\|switch\|typedef\|union\|volotile\|while\)\b</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>cpp</name>
         <regex>\b\(and\|and_eq\|bitend\|bitor\|catch\|class\|compl\|const_cast\|delete\|dynamic_cast\|explicit\|export\|false\|friend\|inline\|mutable\|namespace\|new\|not\|not_eq\|operator\|or\|or_eq\|private\|protected\|public\|reinterpret_cast\|static_cast\|template\|this\|throw\|true\|try\|typeid\|typename\|using\|virtual\|volatile\|wchar_t\|xor\|xor_eq\)\b</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>glib</name>
         <regex>\b\(gint\|gfloat\|gdouble\|gboolean\|gchar\|gpointer\|guint\|guchar\|GList\|GSList\|GHash\|GString\|GModule\|GTable\|GTree\)\b</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>macros</name>
         <regex>\b[A-Z_][A-Z0-9_\-]+\b</regex>
         <style>macro</style>
      </pattern-item>
      <pattern-item>
         <name>gnu-types</name>
         <regex>\b\(Gtk\|Gds\|Gdk\|Gnome\)[a-zA-Z0-9_]+</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>gnu-funcs</name>
         <regex>\b\(gtk\|gdk\|g\|gnome\|gds\)_[a-zA-Z0-9_]+</regex>
         <style>function</style>
      </pattern-item>
      <pattern-item>
         <name>class-members</name>
         <regex>^[a-zA-Z_][a-zA-Z0-9_]*::</regex>
         <style>data_type</style>
      </pattern-item>
      <pattern-item>
         <name>labels</name>
         <regex>^[a-zA-Z_][a-zA-Z_]*:</regex>
         <style>function</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>operators</name>
         <regex>\(\*\|\*\*\|-&gt;\|::\|&gt;&gt;\|&lt;&lt;\|&gt;\|&lt;\|=\|==\|!=\|&lt;=\|&gt;=\|++\|--\|%\|+\|-\|||\|&amp;&amp;\|!\|+=\|-=\|\*=\|/=\|%=\|~\)</regex>
         <style>operator</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 cpp_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", cpp_enter_callback)

def cpp_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", cpp_tab_callback)

def insert_c_comment():
    glimmer.freeze()
    if glimmer.has_selection():
        start = glimmer.selection_start()
        end = glimmer.selection_end()
        file = glimmer.get_file_number()
        glimmer.move(0)
        glimmer.insert_in(file, start, "/* ")
        glimmer.insert_in(file, end+3, " */")
        glimmer.move_to(end+6)
    else:
        glimmer.insert("/*\n *\n*/")
        glimmer.move(-3)
    glimmer.thaw()

def insert_cpp_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()

def open_cpp_header():
    import string
    file = 0
    fname = ""
    file = glimmer.get_file_number()
    fname = glimmer.get_filename(file)
    path = ""
    noext = ""
    fullfile = ""
    openfile = 0
    if string.count(fname, ".C"):
        openfile = 1
        path = glimmer.get_path(file)
        noext = glimmer.get_file(file)
        fullfile = path + "/" + noext + ".H"
    elif string.count(fname, ".h"):
        openfile = 1
        path = glimmer.get_path(file)
        noext = glimmer.get_file(file)
        fullfile = path + "/" + noext + ".cxx"
    elif string.count(fname, ".H"):
        openfile = 1
        path = glimmer.get_path(file)
        noext = glimmer.get_file(file)
        fullfile = path + "/" + noext + ".C"
    elif string.count(fname, ".cxx"):
        openfile = 1
        path = glimmer.get_path(file)
        noext = glimmer.get_file(file)
        fullfile = path + "/" + noext + ".h"
    if openfile:
        openedfile = open(fullfile)
        if openedfile:
            del openedfile
            glimmer.open_file(fullfile)

glimmer.add_sub_to_menu("_Insert/", "C++", -1)
glimmer.add_item_to_menu("_Insert/C++/", "Comment (C)", "", "", -1, insert_c_comment)
glimmer.add_item_to_menu("_Insert/C++/", "Comment (C++)", "", "", -1, insert_cpp_comment)
glimmer.add_item_to_popup_menu("Open Reverse", -1, open_cpp_header)
glimmer.add_item_to_popup_menu("Comment (C)", -1, insert_c_comment)
glimmer.add_item_to_popup_menu("Comment (C++)", -1, insert_cpp_comment)

</python-definition>
