/*
 * ``TC'' - Tabscript Clone
 * (C) 1995 Jeremy Nelson
 * Originally written for Daveman's Tooblox, also packaged with TG's Superpak 
 * Please distribute this script like crazy!  (and use it too! ;-)
 */

#
# (note from jfn)  The original allowed you to save up to 10 nicks to 
# by cycled through by pressing <tab> or <esc>.  I totaly rewrote the file
# and added the ability to set the number of nicks to save, and also made 
# it a full tabkey clone.  This file is a lot easier to figure out, too.
# 
# What it does:
#     save an arbitrary number of nicks in a list (settable by you)
#     cycle through the list by pressing <tab>
#     cycle backwards through the list by pressing <^R>
#     remove nicks from the list (^X^X)
#

bind ^I parse_command ^get_msg_nick
bind ^R parse_command ^get_msg_nick_backward
bind ^X^X parse_command eval echo *** Nickname $pop(msglist) removed

# maximum number of nicks you want to keep track of...
@ max_nicks = 6

#
# add a word to a list -- makes sure the list doesnt get longer then
# the number allowed in max_nicks.
#
alias add_to_list {
	if (where = match($1 $($0)))
	{
		@ kludge = notw(${where-1} $($0))
		if (kludge)
			{^assign $0 $kludge}
			{^assign -$0}
		^assign -kludge
	}
	assign $0 $1 $rightw($max_nicks $($0))
}

#
# Takes the last word in a string and puts it at the front.
# Pretty straightforward
#
alias rotate unshift $0 $pop($0)
alias roll push $0 $shift($0)

#
# do the obvious thing
#
alias get_msg_nick {
	roll msglist
	type ^U/msg $rightw(1 $msglist) 
}
alias get_msg_nick_backward {
	rotate msglist
	type ^U/msg $rightw(1 $msglist) 
}
alias addnick fe ($*) an {add_to_list msglist $an}

on #-msg 111 * add_to_list msglist $0
on #-send_msg 111 * add_to_list msglist $0 

on #-dcc_chat 111 * add_to_list msglist =$0
on #-send_dcc_chat 111 * add_to_list msglist =$0

ALIAS M if ([$($0)]){msg $($0) $1-}{msg $0 $1-}
