Tab completion

By Pass on Jan 16, 2008

I originally made this for a blacklist script, but made a more 'universal' version that can be used by multiple scripts. One such usage may be for a quick nickname completor.

The example provided is only a window with the basic tab-completion functions - you must fill the hash table for yourself using the /_tab -a command. Open the example window with /tabwin.

; ======================
; = Tab-completion script by Pass
; ----------------------
; - Usage: /_tab -admcs <text> <data>
; - /_tab : creates/loads the hashtable
; - /_tab -a <item> : Adds an item to the tab list
; - /_tab -d <item/N> : Deletes an item from the tab list
; - /_tab -m <window> <string> : Matches a string to the list
; - /_tab -c : Clears the tab list
; - /_tab -s : Saves the tab hashtable
; ----------------------
; = Do not edit below this line
; ======================

; --------------
; Example code
; --------------
on *:tabcomp:@tab:{
  if ($1-) {
    var %match = $gettok($1-,$numtok($1-,32),32)
    if (%tab.match.@tab == $null) set -u2 %tab.match.@tab %match
    _tab -m @tab $$1-
  }
}

alias tabwin {
  if ($window(@tab)) window -c @tab
  window -daCek0w1 +fts @tab -1 -1 300 200
  titlebar @tab - /tabwin
  _tab
}
; --------------
; End of example
; --------------

alias _tab {
  if ($left($1,1) == -) {
    var %s = $right($1,-1)
    if (a isincs %s) hadd tab $2 $true
    if (d isincs %s) {
      if ($hget(tab,$2).item) var %item = $v1
      if (%item) hdel tab %item
    }
    if (c isincs %s) { hfree tab | hmake tab }
    if (s isincs %s) hsave -o tab tab.hsh
    elseif (m === %s) {
      var %new.match = $($+(%,tab.match.,$2),2) $+ *
      if ( $($+(%,tab.,$2),2) >= $hfind(tab,%new.match,0,w) ) set -u2 $+(%,tab.,$2) 0
      inc -u2 $+(%,tab.,$2) 1
      var %win = $($+(%,tab.,$2),2)
      if ($hfind(tab,%new.match,%win,w)) {
        var %v1 = $v1,%num = $calc($numtok($3-,32) - 1),%nums = $+(1-,%num)
        editbox $2 $iif(%num > 0,$gettok($3-,%nums,32)) %v1
      }
    }
    elseif (l === %s) {
      var %n = 1,%list
      while ($hget(tab,%n).item) {
        var %list = %list $v1
        inc %n
      }
      return %list
    }
  }
  else {
    if ($hget(tab)) hfree tab
    hmake tab
    if ($isfile(tab.hsh)) hload tab tab.hsh
  }
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.