mIRC Home    About    Download    Register    News    Help

Print Thread
Autocomplete with ", " added + cycling? #238202 07/07/12 03:54 PM
Joined: Jul 2012
Posts: 6
N
NorxMAL Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Jul 2012
Posts: 6
This is the code I wrote
Code:
on *:TABCOMP:#: {
  if ( $nick($chan,$1) != $null ) || ( $nick($chan,$left($1,$calc($len($1)-1))) != $null ) { 
    if ( $right($1,1) == $chr(44) ) { 
      /editbox -a left($1,1)
    }
    else {
      /editbox -ap $1 $+ $chr(44)
    }
    haltdef
  }
}


Problem is that I can't retrieve what was typed before TAB was pressed in the ON TABCOMP, and to cycle nicks one need to double tap TAB for the next one to show.

Re: Autocomplete with ", " added + cycling? [Re: NorxMAL] #238203 07/07/12 04:30 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
FYI this belongs in "Scripts & Popups"

Originally Posted By: NorxMAL
Problem is that I can't retrieve what was typed before TAB


Sure you can, just use $editbox().selstart to get the position of the caret in the $editbox() line.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Autocomplete with ", " added + cycling? [Re: NorxMAL] #238204 07/07/12 04:35 PM
Joined: Jul 2012
Posts: 6
N
NorxMAL Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Jul 2012
Posts: 6
I ask a moderator to move it now smile

Thanks for the tip smile

Re: Autocomplete with ", " added + cycling? [Re: NorxMAL] #238215 07/07/12 08:53 PM
Joined: Jul 2012
Posts: 6
N
NorxMAL Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Jul 2012
Posts: 6
I fixed it with this code smile
Code:
on *:TABCOMP:#: {
  if  ( $2 == $null ) {
    if ( %tabn != $left($1,$len(%tabn)) ) {  
      unset %tabm
      unset %tabn
    }
    if ( %tabm == $null ) { set %tabn $left($1,$calc($editbox($active).selstart -1)) }
    var %tabv 0
    :tab
    inc %tabv 1
    if ( %tabn == $left($nick($chan,%tabv),$len(%tabn)) ) { set %tabm $addtok(%tabm,$nick($chan,%tabv),58) }
    if ( $nick($chan,0) >= %tabv ) { goto tab }
    if ( %tabac >= $gettok(%tabm,0,58) ) { set %tabac 0 }
    inc %tabac 1
    /editbox -ap $gettok(%tabm,%tabac,58) $+ $chr(44)
    haltdef
  }
}


Edit : haltdef in the wrong place

Last edited by NorxMAL; 07/07/12 08:56 PM.
Re: Autocomplete with ", " added + cycling? [Re: NorxMAL] #238230 08/07/12 11:59 AM
Joined: Jul 2012
Posts: 6
N
NorxMAL Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Jul 2012
Posts: 6
Improvement on the script
Code:
on *:TABCOMP:#: {
  if  ( $2 == $null ) {
    if ( %tabn != $left($1,$len(%tabn)) ) {
      unset %tabm
      unset %tabn
    }
    set %tabedit $left($1,$calc($editbox($active).selstart -1))
    var %tablen $len($remove($left($1,$calc($editbox($active).selstart -1)),$chr(44)))
    if ( %tabedit != $left(%tabm,%tablen) ) && ( $right(%tabedit,1) != $chr(44) ) {
      unset %tabm
    }
    if ( %tabm == $null ) { set %tabn $left($1,$calc($editbox($active).selstart -1)) }
    var %tabv 0
    :tab
    inc %tabv 1
    if ( %tabn == $left($nick($chan,%tabv),$len(%tabn)) ) { set %tabm $addtok(%tabm,$nick($chan,%tabv),58) }
    if ( $nick($chan,0) >= %tabv ) { goto tab }
    if ( %tabac >= $gettok(%tabm,0,58) ) { set %tabac 0 }
    if ( %tabm == $null ) { halt }
    inc %tabac 1
    /editbox -ap $gettok(%tabm,%tabac,58) $+ $chr(44)
    haltdef
  }
}


edit : did a /set to /var instead
edit 2 : Further improvement

Last edited by NorxMAL; 08/07/12 12:08 PM.
Re: Autocomplete with ", " added + cycling? [Re: NorxMAL] #238232 08/07/12 03:29 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
You can improve it a tad further by using:
Code:
unset %tabm %tabn
Or to remove all of the variables starting with %tab:
Code:
unset %tab*
Your overall snippet can be shortened even more, but good job on that nevertheless.

Re: Autocomplete with ", " added + cycling? [Re: Tomao] #245271 14/04/14 09:50 PM
Joined: Apr 2014
Posts: 9
R
r0ot Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
R
Joined: Apr 2014
Posts: 9
This is an awesome script. Thank you.

I know I can make <nick> bold when it's first, but can't seem to figure out how I can do the same when <nick> is after or in the middle of a sentence.

Thanks!

Last edited by r0ot; 14/04/14 09:53 PM.
Re: Autocomplete with ", " added + cycling? [Re: r0ot] #245291 15/04/14 03:36 PM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Good snippet. Well done.

It can be improved not only for channel window. Also coloring, bold, etc. I will try if i have time.

Re: Autocomplete with ", " added + cycling? [Re: blessing] #245293 15/04/14 04:27 PM
Joined: Apr 2014
Posts: 9
R
r0ot Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
R
Joined: Apr 2014
Posts: 9
Thanks you blessing. Looking forward to it smile

Re: Autocomplete with ", " added + cycling? [Re: r0ot] #245358 17/04/14 04:33 PM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
This is what i have.

The script works on channel and chat window.
The nick can be customized and not only work on first word in editbox, but also anywhere after that.
You can put color, bold, underline on nick, or give some style to it like *nick* [~*<nick>*~] etc.

var %f1 is nick on first word in editbox
var %f2 is nick anywhere after %f1
You can edit it as you wish.

i hope it works as expected.

Code:
on *:tabcomp:*:{
  var %f1 nick:
  var %f2 *nick*
  
  var %t $target, %eb $1-, %nt $numtok(%eb,32), %f $iif(%nt > 1,%f2,%f1), %a 1
  while %a < $len(%f) {
    if $mid(%f,%a,4) == nick { dec %a | break }
    inc %a
  }
  var %aa $iif(%a,$mid(%f,1,%a)), %bb $mid(%f,$calc(%a + 5))
  var %et $gettok(%eb,1 - $calc(%nt - 1),32), %e $gettok(%eb,-1,32)
  var %ee $iif($remove(%e,%aa,%bb) == %nc.nick,%nc.nick,%e)
  var %p $iif($remove(%e,%aa,%bb) == %nc.nick,%nc.pos,$calc($editbox(%t).selstart - 1 - $iif(%nt > 1,$calc($len(%et) + 1),0))) 
  var %i $calc($nick(%t,%ee) + $iif($left(%nc.nick,%p) == $left(%ee,%p) && %nc.pos == %p,1,0))
  if %t ischan {
    var %n $nick(%t,$nc(%t,%i,%p,%ee))
    if !%n { var %n $nick(%t,$nc(%t,1,%p,%ee)) }
  }
  else { var %n $iif($+($mid(%ee,1,%p),*) iswm %t,%t) }
  if %n {
    haltdef
    var %lt $+(%aa,%n,%bb), %text $iif(%nt > 1,$+(%et,$chr(32),%lt),%lt)
    editbox -ap %text
    set -e %nc.pos %p
    set -e %nc.nick %n
  }    
}

alias -l nc {
  var %t $1, %i $2, %p $3, %ee $4, %b 1
  while $nick(%t,%i) {
    var %n $v1 
    if $+($mid(%ee,1,%p),*) iswm %n { var %b 0 | break }
    inc %i
  }
  return $calc(%i + %b) 
}

Re: Autocomplete with ", " added + cycling? [Re: blessing] #245363 17/04/14 08:43 PM
Joined: Apr 2014
Posts: 9
R
r0ot Offline
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
R
Joined: Apr 2014
Posts: 9
Dude...its beautiful!