<glimmer-definition>
   <settings>
      <language>Perl</language>
      <compiler></compiler>
      <debugger>%term% perl -d %1/%2</debugger>
      <execution>%term% perl %1/%2</execution>
      <auto-indent>1</auto-indent>
      <use-spaces>0</use-spaces>
      <tab-stop>5</tab-stop>
   </settings>

   <mime-types>
      <extension>pl</extension>
      <extension>pm</extension>
      <extension>cgi</extension>
   </mime-types>

   <syntax-items>
      <syntax-item>
         <name>string1</name>
         <start-regex>&quot;</start-regex>
         <end-regex>\(&quot;\|\n\)</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>string2</name>
         <start-regex>&apos;</start-regex>
         <end-regex>\(&apos;\|\n\)</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>string3</name>
         <start-regex>`</start-regex>
         <end-regex>\(`\|\n\)</end-regex>
         <style>string</style>
      </syntax-item>
      <syntax-item>
         <name>arraylim</name>
         <start-regex>$#</start-regex>
         <end-regex>\( \|\t\|\n\)</end-regex>
         <style>variable</style>
      </syntax-item>
      <syntax-item>
         <name>comment</name>
         <start-regex>\s*#</start-regex>
         <end-regex>\n</end-regex>
         <style>comment</style>
      </syntax-item>
   </syntax-items>

   <pattern-items>
      <pattern-item>
         <name>vars</name>
         <regex>\$[a-zA-Z_][a-zA-Z0-9_]*</regex>
         <style>variable</style>
      </pattern-item>
      <pattern-item>
         <name>reference</name>
         <regex>[\$\@\%]\$[a-zA-Z_][a-zA-Z0-9_]*</regex>
         <style>variable</style>
      </pattern-item>
      <pattern-item>
         <name>deref</name>
         <regex>-&gt;</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>array</name>
         <regex>@[a-zA-Z_][a-zA-Z0-9_]*</regex>
         <style>variable</style>
      </pattern-item>
      <pattern-item>
         <name>hash</name>
         <regex>%[a-zA-Z_][a-zA-Z0-9_]*</regex>
         <style>variable</style>
      </pattern-item>
      <pattern-item>
         <name>function_calls</name>
         <regex>\&amp;[a-zA-Z_][a-zA-Z0-9_]*</regex>
         <style>function</style>
      </pattern-item>
      <pattern-item>
         <name>keywords1</name>
         <regex>\b\(eq\|ne\|not\|or\|read\|keys\|chomp\|if\|else\|unless\|open\|close\|split\|for\|while\|foreach\|exit\|sub\|print\|use\|require\|elseif\|continue\|until\|do\|last\|next\|redo\|goto\|chop\|chr\|crypt\|hex\|index\|lc\|lcfirst\|length\|oct\|ord\|reverse\|rindex\|printf\|sprintf\|substr\|uc\|ucfirst\|pos\|quotemeta\|study\|abs\|atan2\|cos\|exp\|int\|log\|rand\|sin\|sqrt\|srand\|pop\|push\|shift\|splice\|unshift\|grep\|join\|map\|sort\|unpack\|pack\|delete\|each\|exists\|values\|binmode\|closedir\|dbmclose\|dbmopen\|die\|eof\|fileno\|flock\|format\|getc\|readdir\|rewinddir\|seek\|seekdir\|select\|syscall\|sysread\|sysseek\|syswrite\|tell\|telldir\|truncate\|warn\|write\|vec\|chdir\|chmod\|chown\|chroot\|fcntl\|glob\|ioctl\|link\|lstat\|mkdir\|opendir\|readlink\|rename\|rmdir\|stat\|symlink\|umask\|unlink\|utime\|caller\|dump\|eval\|return\|wantarray\|import\|local\|my\|package\|defined\|formline\|prototype\|reset\|scalar\|undef\|alarm\|exec\|fork\|getpgrp\|getppid\|getpriority\|kill\|pipe\|setpgrp\|setpriority\|sleep\|system\|times\|wait\|waitpid\|no\|bless\|ref\|tie\|tied\|untie\|accept\|bind\|connect\|getpeername\|getsockname\|getsockopt\|listen\|recv\|send\|setsockopt\|shutdown\|socket\|socketpair\|msgctl\|msgget\|msgrcv\|msgsnd\|semctl\|semget\|semop\|shmctl\|shmget\|shmread\|shmwrite\|endgrent\|endhostent\|endnetent\|endpwent\|getgrent\|getgrgid\|getgrnam\|getlogin\|getpwent\|getpwnam\|getpwuid\|setgrent\|setpwent\|endprotoent\|endservent\|gethostbyaddr\|gethostbyname\|gethostent\|getnetbyaddr\|getnetbyname\)\b</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>keywords2</name>
         <regex>\b\(getnetent\|getprotobyname\|getprotobynumber\|getprotoent\|getservbyname\|getservbyport\|getservent\|sethostent\|setnetent\|setprotoent\|setservent\|gmtime\|localtime\|time\)\b</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>hex</name>
         <regex>#[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]</regex>
         <style>hexidecimal</style>
      </pattern-item>
      <pattern-item>
         <name>macros</name>
         <regex>\b[A-Z][A-Z_][A-Z0-9_\-]+\b</regex>
         <style>macro</style>
      </pattern-item>
      <pattern-item>
         <name>operators</name>
         <regex>\(%\|&amp;\|+\|-\|=\|==\|&gt;=\|&lt;=\|@\|\*\|\\\\\|/\|\\.\|&lt;&lt;\|&gt;&gt;\|!\|~\|||\|&amp;&amp;\)</regex>
         <style>operator</style>
      </pattern-item>
      <pattern-item>
         <name>tags1</name>
         <regex>&lt;/?\(html\|ol\|ul\|li\|frameset\|frame\|head\|title\|body\|table\|tr\|td\|th\|img\|center\|div\|br\|b\|font\|a\|script\|hr\|input\|textarea\|form\|i\|p\|h[1-6]\|pre\|blockquote\)</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>tags2</name>
         <regex>&lt;/?\(HTML\|OL\|UL\|LI\|FRAMESET\|FRAME\|HEAD\|TITLE\|BODY\|TABLE\|TR\|TD\|TH\|IMG\|CENTER\|DIV\|BR\|B\|FONT\|A\|SCRIPT\|HR\|INPUT\|TEXTAREA\|FORM\|I\|P\|H[1-6]\|PRE\|BLOCKQUOTE\)</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>open</name>
         <regex>&lt;</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>close</name>
         <regex>&gt;</regex>
         <style>keyword</style>
      </pattern-item>
      <pattern-item>
         <name>numbers</name>
         <regex>\b[0-9][dh0-9\.]*\b</regex>
         <style>decimal</style>
      </pattern-item>
   </pattern-items>

   <embedded-items>
      <embedded-item>
         <name>keywords1</name>
         <outside-regex>&lt;.+&gt;?</outside-regex>
         <inside-regex>\b\(address\|strong\|frameborder\|framespacing\|text\|links\|vlinks\|hidden\|method\|action\|password\|button\|value\|colspan\|rowspan\|cols\|rows\|background\|src\|border\|cellpadding\|cellspacing\|color\|vspace\|hspace\|height\|width\|marginheight\|marginwidth\|bgcolor\|size\|target\|href\|select\|option\|name\|type\|align\|valign\)\b</inside-regex>
         <style>data_type</style>
      </embedded-item>
      <embedded-item>
         <name>keywords2</name>
         <outside-regex>&lt;.+&gt;?</outside-regex>
         <inside-regex>\b\(ADDRESS\|STRONG\|FRAMEBORDER\|FRAMESPACING\|TEXT\|LINKS\|VLINKS\|HIDDEN\|METHOD\|ACTION\|PASSWORD\|BUTTON\|VALUE\|COLSPAN\|ROWSPAN\|COLS\|ROWS\|BACKGROUND\|SRC\|BORDER\|CELLPADDING\|CELLSPACING\|COLOR\|VSPACE\|HSPACE\|HEIGHT\|WIDTH\|MARGINHEIGHT\|MARGINWIDTH\|BGCOLOR\|SIZE\|TARGET\|HREF\|SELECT\|OPTION\|NAME\|TYPE\|ALIGN\|VALIGN\)\b</inside-regex>
         <style>data_type</style>
      </embedded-item>
   </embedded-items>
</glimmer-definition>

<python-definition>
import glimmer

def perl_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", perl_enter_callback)

def perl_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", perl_tab_callback)

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

