home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bx75p3.zip / doc / tabkey.stub < prev    next >
Text File  |  1999-02-23  |  3KB  |  113 lines

  1. /*
  2.  * Name: Tab key Handlers
  3.  * Originally by: Daemon
  4.  * Rewritten for EPIC by: wc & archon
  5.  * Modified for Drag0n by: CrackBaby
  6.  * Purpose: To cache a list of users who recently messaged you. You can scroll
  7.  * through the list by hitting the tab key.
  8.  */
  9.  
  10. @ int.tlim = 5
  11.  
  12. /* prefix takes a list of words and returns the string (if any) that begins
  13.  * all of them i.e. $prefix(blah123 blah456 blahlkwej blahfoo blahbar)
  14.  * returns "blah"  - archon */
  15.  
  16. alias prefix {
  17. /* find the longest word in the string */
  18.   fe ($*) pp {
  19.     @ lword = (strlen($pp) > strlen($lword)) ? pp : lword
  20.   }
  21.   @ wlen = strlen($lword)
  22.   @ cont = 1
  23.   @ nwords = numwords($*)
  24. /* go through the longest word to find the first 
  25.  * string that doesn't begin all the other strings */
  26.   fec ($lword) pp {
  27.     if (cont) {
  28.       if (numwords($pattern($pfix$pp* $*)) == nwords) {
  29.         @ pfix #= pp
  30.       }{
  31.         @ cont = []
  32.       }
  33.     }
  34.   }
  35.   @ function_return = pfix
  36.   @ lword = wlen = cont = nwords = pfix = []
  37. }
  38.  
  39. /* tabcomplete: when you hit tab, we look at your input line.  then we try
  40.  * to complete your command based on what you're doing.
  41.  */
  42.  
  43. /* I completely gutted this alias and rewrote it.  Now hitting tab with a
  44.    blank input line cycles through msgs and hitting it any other time
  45.    attempts to complete the word you're typing as a nick. - CB */
  46.  
  47. alias tabcomplete {
  48.   /* Note that the wildcard mask "/msg % *" allows you to cycle your
  49.      msg list or use the nick completer with /msg partial_nick. */
  50.   if (!L || L =~ [/msg % *]) {
  51.     getmsg 1
  52.   } else {
  53.     ^local fragment $rightw(1 $L)
  54.     ^local before $beforew($fragment $L)
  55.     type $^^{(before) ? [$before $getnick($fragment)] : getnick($fragment)}
  56.   }
  57. }
  58.  
  59. /* $getnick(<text fragment>)
  60.    Given a fragment of a nickname on the current channel, return the
  61.    full nick.  If multiple nicks match the fragment, return as many
  62.    letters as the nicks have in common ($prefix()). -CB */
  63.  
  64. alias getnick {
  65.   ^local completes
  66.   fe ($chanusers()) nick {
  67.     if (nick =~ [$0*]) {
  68.       @ completes = [$nick $completes]
  69.     }
  70.   }
  71.   @ function_return = prefix($completes)
  72. }
  73.  
  74. alias addmsg {
  75.   if (rmatch($0 $lst.tab)) {
  76.     @ lst.tab = remw($0 $lst.tab)
  77.     push lst.tab $0
  78.   }{
  79.     if (#lst.tab == int.tlim) {
  80.       shift lst.tab
  81.     }
  82.     push lst.tab $0
  83.   }
  84.   @ tmp.tptr = #lst.tab - 1
  85.   @ tmp.addn++
  86. }
  87.  
  88. alias getmsg {
  89.   if (!tmp.addn) {
  90.     if ([$0]) {
  91.       @ tmp.tptr = ((tmp.tptr - 1) < 0) ? #lst.tab - 1 : tmp.tptr - 1
  92.     }{
  93.       @ tmp.tptr = ((tmp.tptr + 1) >= #lst.tab) ? 0 : tmp.tptr + 1
  94.     }
  95.   }{
  96.     @ tmp.addn = 0
  97.   }
  98.   type $(K)msg $^\^^word($tmp.tptr $lst.tab) 
  99. }
  100.  
  101. alias getdes {
  102.   if (!tmp.addn) {
  103.     if ([$0]) {
  104.       @ tmp.tptr = ((tmp.tptr - 1) < 0) ? #lst.tab - 1 : tmp.tptr - 1
  105.     }{
  106.       @ tmp.tptr = ((tmp.tptr + 1) >= #lst.tab) ? 0 : tmp.tptr + 1
  107.     }
  108.   }{
  109.     @ tmp.addn = 0
  110.   }
  111.   type ${K}des $^\^^word($tmp.tptr $lst.tab) 
  112. }
  113.