<settings>
language=Perl
compiler=
debugger=%term% perl -d %1/%2
execution=%term% perl %1/%2
auto_indent=1
use_spaces=0
tab_stop=5
</settings>

<extensions>
 <item name="Perl" ext="pl">
 <item name="Perl Module" ext="pm">
 <item name="Perl/CGI" ext="cgi">
</extensions>

<syntax>
 <item name="string1" start="\"" end="\(\"\|\n\)" color="string">
 <item name="string2" start="'" end="\('\|\n\)" color="string">
 <item name="string3" start="`" end="\(`\|\n\)" color="string">
 <item name="comment" start="#" end="\n" color="comment">
</syntax>

<pattern>
 <item name="vars" words="\$[a-zA-Z_][a-zA-Z0-9_]*" color="variable">
 <item name="array" words="@[a-zA-Z_][a-zA-Z0-9_]*" color="variable">
 <item name="hash" words="%[a-zA-Z_][a-zA-Z0-9_]*" color="variable">
 <item name="function_calls" words="\&[a-zA-Z_][a-zA-Z0-9_]*" color="function">
 <item name="keywords1" words="\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" color="keyword">
 <item name="keywords2" words="\b\(getnetent\|getprotobyname\|getprotobynumber\|getprotoent\|getservbyname\|getservbyport\|getservent\|sethostent\|setnetent\|setprotoent\|setservent\|gmtime\|localtime\|time\)\b" color="keyword">
 <item name="hex" words="#[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]" color="hexidecimal">
 <item name="macros" words="\b[A-Z][A-Z_][A-Z0-9_\-]+\b" color="macro">
 <item name="operators" words="\(%\|&\|+\|-\|=\|==\|>=\|<=\|@\|\*\|\\\\\|/\|\\.\|<<\|>>\|!\|~\|||\|&&\)" color="operator">
 <item name="tags1" words="</?\(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\)" color="keyword">
 <item name="tags2" words="</?\(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\)" color="keyword">
 <item name="open" words="<" color="keyword">
 <item name="close" words=">" color="keyword">
 <item name="numbers" words="\b[0-9][dh0-9\.]*\b" color="decimal">
</pattern>

<embedded>
 <item name="keywords1" start="<" words="\b\(frameborder\|framespacing\|text\|links\|vlinks\|hidded\|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" end=">" color="data_type">
 <item name="keywords2" start="<" words="\b\(FRAMEBORDER\|FRAMESPACING\|TEXT\|LINKS\|VLINKS\|HIDDED\|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" end=">" color="data_type">
</embedded>

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

i = glimmer.add_sub_to_insert_menu("Perl", -1)
glimmer.add_item_to_insert_menu("Comment (#)", i, insert_perl_comment)
glimmer.add_item_to_popup_menu("Comment (#)", -1, insert_perl_comment)
</python>
