@ tabitem = [0]

alias addtab {
  if (([$0]==[/m]&&match(msg $tab_levels))||([$0]==[/wall]&&match(wall $tab_levels))||([$1]=~[=%]&&match(dmsg $tab_levels))||([$1]=~[-%]&&match(ftp $tab_levels))||([$0]!=[/m]&&[$0]!=[/wall]&&[$1]!~[=%]&&[$1]!~[-%]&&match(ar $tab_levels))) {
    if (matchitem(tabs $*) > -1) {
      @ delitem(tabs $matchitem(tabs $*))}
    @ setitem(tabs $numitems(tabs) $*)
    @ setitem(tabitem 0 ${numitems(tabs) - 1})}}

alias gettab {
  ^local aa $L
  if ((L =~ [/m %] || L =~ [/msg %]) && flag(a.tkncomp)) {
    ^local bb $_compnick($word(1 $aa))
    if (word(0 $bb)) {
      parsekey erase_line
      xtype -l $word(0 $aa) $word(1 $bb)${[ ]}}} else {
    if (getitem(tabitem 0) < 0) {
      @ setitem(tabitem 0 ${numitems(tabs) - 1})}
    parsekey erase_line
    xtype -l $getitem(tabs $getitem(tabitem 0))${[ ]}
    @ setitem(tabitem 0 ${getitem(tabitem 0)-1})}}

alias eraseline {
  @ setitem(tabitem 0 ${numitems(tabs) - 1})
  parsekey erase_line}

^bind ^U parse_command eraseline
^bind ^I parse_command gettab
