##
##  ~/.irc/rse -- ircII run-commands for RSE settings
##  Copyright (c) 1998-2005 Ralf S. Engelschall <rse@engelschall.com>
##

#   Banner
^set display off
echo *** Loading ircII configuration: rse (Ralf S. Engelschall)

#   Allow certain levels of customization
set novice off
load functions

#   Use 8-bit ISO-Latin-1 character set
#   (requires "stty -istrip cs8")
set translation LATIN_1
set eight_bit_characters on

#   Bash-style command line editing
set history_file ~/.irc_history
set history 100
bind meta1-[  meta2
bind meta1-O  meta2
bind meta2-A  backward_history
bind meta2-B  forward_history
bind meta2-C  forward_character
bind meta2-D  backward_character
bind ^W       delete_previous_word
bind ^R       parse /!$"Search: "

#   Vim-style window management (part-size screens)
bind ^Y       meta6_character
bind meta6-c  parse_command window new
bind meta6-^c parse_command window new
bind meta6-k  parse_command window kill
bind meta6-l  parse_command window list
bind meta6-<  previous_window
bind meta6-p  previous_window
bind meta6-n  next_window
bind meta6->  next_window
bind meta6-^` next_window
bind meta6-=  parse window balance
bind meta6-+  parse window grow   4
bind meta6--  parse window shrink 4

#   Screen-style window management (full-size screens)
alias win.newwin window new hide;window swap last
bind ^A       meta7_character
bind meta7-c  parse_command win.newwin
bind meta7-^c parse_command win.newwin
bind meta7-k  parse_command window killswap
bind meta7-l  parse_command window list
bind meta7-a  beginning_of_line # alternative: parse_command window swap last
bind meta7-^a parse_command window swap last
bind meta7-p  swap_previous_window
bind meta7-n  swap_next_window
bind meta7-^` swap_next_window # notice: actually a space, for unknown reasons
bind meta7-1  parse_command window swap 1
bind meta7-2  parse_command window swap 2
bind meta7-3  parse_command window swap 3
bind meta7-4  parse_command window swap 4
bind meta7-5  parse_command window swap 5
bind meta7-6  parse_command window swap 6
bind meta7-7  parse_command window swap 7
bind meta7-8  parse_command window swap 8
bind meta7-9  parse_command window swap 9
bind meta7-0  parse_command window swap 10
bind meta7-C  parse_command clear all

#   Convenience Keystrokes
bind ^X       meta8_character
bind meta8-q  parse_command quit
bind meta8-w  parse_command who -here *
bind meta8-W  parse_command who
bind meta8-l  parse_command list -users *
bind meta8-L  parse_command list -wide -name
bind meta8-n  parse_command names *
bind meta8-N  parse_command names

#   Emotions Commands
bind ^B parse_command blink
bind ^G parse_command grin
bind ^T parse_command hmmm
bind ^F parse_command freeze
alias blink me winks. \;-)
alias grin me grins. :-)
alias hmmm me thinks, hmmm... :-|
alias freeze me freezes! :-\(

#   Convenience Commands
alias h+ ^set hold_mode on
alias h- ^set hold_mode off
alias shutup ignore $0 all
alias unset set -$0
alias unalias alias -$0
alias ! exec $*
alias who {
    if ([$C] == []) {
        echo *** You still haven't joined a channel!
    } {
        //who $C
    }
}

#   Convenience Private Messaging
alias talkto window new name $0;query $0
alias reply talkto $* $,
alias . msg .
alias , msg ,
alias oops {
    ^assign alias.oops $B
    msg $. Oops, sorry! That wasn't meant for you.
    msg $0 $alias.oops
}

#   Convenience Attention Checking
set exec_protection off
^assign alias.attention.mode off
^assign alias.attention.event echo *** ATTENTION, PLEASE! ***
alias attention {
    if ([$0] == [on]) {
        ^assign alias.attention.mode on
    }
    if ([$0] == [off]) {
        ^assign alias.attention.mode off
    }
    if ([$0] == [event]) {
        ^assign alias.attention.event $1-
    }
    echo *** Attention: mode ${alias.attention.mode}, event ${alias.attention.event}
}
alias __attention_check {
    if ([$alias.attention.mode] == [on]) {
        if (   [$0] == [${N}:]          \
            || match(${N}    $*) != [0] \
            || match(${N},   $*) != [0] \
            || match(${N};   $*) != [0] \
            || match(${N}.   $*) != [0] \
            || match(${N}:   $*) != [0] \
            || match(${N}!   $*) != [0] \
            || match(${N}\\? $*) != [0] ) {
            $alias.attention.event
            ^assign alias.attention.mode off
            timer 10 ^assign alias.attention.mode on
        }
    }
}

#   Display Formatting
set lastlog 1000
set input_prompt >\ 
on ^send_public   * echo $lformat(8 $N:) $1-
on ^public        * echo $lformat(8 $0:) $2-;__attention_check $2-
on ^send_msg      * echo ${N} -> $0: $1-
on ^public_other  * echo $1 <- $0: $2-;__attention_check $2-
on ^public_msg    * echo $1 <- $0: $2-;__attention_check $2-
on ^msg           * echo $N <- $0: $1-
on ^msg_group     * echo $1 <- $0: $2-
on ^send_notice   * echo ${N} ~> $0: $1-
on ^public_notice * echo $1 <~ $0: $2-
on ^notice        * echo $1 <~ $0: $2-
alias __set_continued_line_prefix {
    ^assign alias.prefix $lformat(10 \ )
    set continued_line $alias.prefix
    ^assign -alias.prefix
}   
__set_continued_line_prefix
set beep off
set beep_on_msg msg notice

#   Server Auto-Reconnect
on ^disconnect * timer 10 server 0

#   Away Handling
alias away {
    if ([$0] == []) {
        if ([$alias.away] == [yes]) {
            //^away
            ^assign alias.away no
        }
    } {
        //^away $*
        ^assign alias.away yes
    }
}
on ^idle 5  away I've just wandered off...
on ^idle 10 away I'm still not back? Hmmm... but perhaps I'm coming back soon.
on ^idle 20 away Well, I must be long gone. Don't keep waiting for me.
bind ^B parse_command away
set input_protection off
on -input * away
on ^306 "*You have been marked as being away*"
on ^305 "*You are no longer marked as being away*"
set beep_when_away yes
set show_away_once no

#   Convenience Tab-Expansion for /msg
load tabkey

#   Convenience Logging Support
on ^exec thing assign thing $1
on ^exec_exit thing
alias _log ^set logfile ~/.irc_log.$thing
alias log.process {
    exec -name thing date '+%Y%m%dT%H%M%S'
    wait %thing
    _log
}
alias log {
    if ([$0] == [on]) {
        if ([$1] > 0) {
            set logfile $1
        }{
            ^log.process
        }
    }
    set log $0
}

#   Convenience LEO dictionary interface (via the "leo" CLI)
/alias leo exec leo -n '$*' | sed -e '1,2d' -e '30,$$d' -e 's/^/::: LEO: /'

#   End of Configuration
^set display on

