Last Nick & Channel Name Tab Completion

By TheImrac on Aug 15, 2011

Snippet to append the last users nickname to your edit box by hitting tab at the beginning or after a space. Also, if the last word is the last users nickname, it will be changed to the channel name.

Examples: "" >> [TAB] >> "LastUsersNick" "Hi " >> [TAB] >> "Hi LastUsersNick" "Hi LastUsersNick" >> [TAB] >> "Hi #CurrentChannel"

Very nice when answering questions in a busy channel.

on *:TABCOMP:#:{
  var %lastnick = $hget(lastnick,$cid $+ $chan)
  if (($regex(edit,$editbox($active),/(^|^.* )( $+ $chan $+ $chr(124) $+ %lastnick $+ )?$/)) && ($1- == $regsubex($editbox($active),/(^ +| +$)/g,)))  { 
    if ($regml(edit,2) == %lastnick) editbox -a $regml(edit,1) $+ $chan
    else editbox -a $regml(edit,1) $+ $iif(%lastnick, $v1, $chan)
    halt
  }
}
on *:TEXT:*:#:{ hadd -m lastnick $cid $+ $chan $nick }
on *:ACTION:*:#:{ hadd -m lastnick $cid $+ $chan $nick }
on *:NOTICE:*:#:{ hadd -m lastnick $cid $+ $chan $nick }

Comments

Sign in to comment.
Jethro   -  Aug 16, 2011

Matcou, who are you to this Wiz126 character? I wasn't accusing him of being a liar, was I? Let's give it a rest already.

More
 Respond  
Jethro   -  Aug 16, 2011

Pardon me for hijacking your thread for something off-topic, Thelmrac.

Matcou, I meant other people but didn't aim for a perticular individual. :p

As we begin to learn more about MSL, we'll gradually have more clearer understanding and distinction toward what other people have to say and judge if he or she gives us a factual, senseful answer. Oftentimes beginners and novice users alike don't have a clue and can easily be ill-informed or misinformed. Then before we know it, it passes down from another new user to the other...the consequence is going to be dire.

More
 Respond  
TheImrac   -  Aug 16, 2011

mSLDev I am guessing. http://msldev.zigwap.com/

More
 Respond  
Matcou   -  Aug 16, 2011

@Jethro_ jaytea can confirm that Wiz126 is a msl wiz :). You can talk to him about it #msl@irc.swiftirc.net. Wiz126 has a msl code editor in the making. If i find the link i will post. Sorry for being off topic.

More
 Respond  
Jethro   -  Aug 15, 2011

:P Matcou, don't easily believe what other people say. They can give you BS.

Listen to people like jaytea, as they've been involved with MSL for the longest time, which have consequently developed extensive know-how over the years of their lives. They have to know what they're talking about.

More
 Respond  
Matcou   -  Aug 15, 2011

Sorry jaytea that is what Wiz126 told me :)

More
 Respond  
jaytea   -  Aug 15, 2011

Tabcomp is very buggy.

how so? the syntax is not very intuitive, and certain compromises have had to be made, but i can't find any reason to suggest it's buggy :P

More
 Respond  
Matcou   -  Aug 15, 2011

Tabcomp is very buggy. I would not be surprised if this snippet failed every once in a while.

More
 Respond  
Veritas   -  Aug 15, 2011

Nice, I love it, 8/10 +like

More
 Respond  
Noutrious   -  Aug 15, 2011

Short and nice, the way it should be. :)

More
 Respond  
jaytea   -  Aug 15, 2011

I got it working (for the most part), without needing to use the dirty variable hack.

ah, quite right, since the first condition implies the second.

It still takes out any extra spaces in the edit box string

yes, that's very unfortunate and entirely unavoidable without a DLL. a while ago i abandoned a sophisticated identifier completion script i was making because of it :( bear in mind you can add a single trailing space to the editbox with /editbox's -p switch.

More
 Respond  
TheImrac   -  Aug 15, 2011

I got it working (for the most part), without needing to use the dirty variable hack. Basically I make sure $1- and the edit box are the same. If they are, that means TAB isn't trying to auto complete. The Downfalls: It still takes out any extra spaces in the edit box string If you are use the normal auto complete on a nickname and its the only auto complete match, and its the last nickname seen, it will toggle between that nickname and the channel if you hit tab again. (not a huge deal)

But now you can tab through multiple normal auto completes and it won't change to the channel name if one of the nicks is the last nickname seen.

More
 Respond  
Aha2Y   -  Aug 15, 2011

Very nice script!

More
 Respond  
jaytea   -  Aug 15, 2011

good point

you can compare $1- to $editbox($active):

on *:tabcomp:#:{
  if (!%tabcomp) || ($1- == $gettok($editbox($active), 1-, 32)) {

    ; your script

  }
  unset %tabcomp
}

now, it's still possible for the two to be equal if, for example, i type 'j' then press tab to get 'jaytea' and tab again. if there's no other 'j*' nicks in the channel, your script will fire. the only way to prevent this is by storing data over successive calls to on TABCOMP, since there is no way to access the history of completions ;(

More
 Respond  
TheImrac   -  Aug 15, 2011

Err wait there is... $1-

Aight.. gotta think about this for a bit.

More
 Respond  
TheImrac   -  Aug 15, 2011

Very interesting stuff. Unfortunately when my script appends a nick, if you hit tab again the ^tab gets activated. I wish there was an identifier that would return what will be completed.

More
 Respond  
jaytea   -  Aug 15, 2011

Actually, it seems to break with the added ^.

ah, that's interesting. apparently the difference between including the ^ prefix is that on ^TABCOMP will only trigger if there is a completion to be made. without the ^ prefix, it will trigger on any tab press, which is what this snippet relies on.

about preserving cycling, given that your script only concerns itself with instances where there is nothing to be completed, you can use the fact that on ^TABCOMP triggers only when there IS something to be completed:

on ^*:tabcomp:#:{ set %tabcomp 1 }

on *:tabcomp:#:{
  if (!%tabcomp) {

    ; your script

  }
  unset %tabcomp
}

a bit hacky but i can't think of a better way ;P

More
 Respond  
Jethro   -  Aug 15, 2011

To be, or not to be...that's the question. :(

More
 Respond  
TheImrac   -  Aug 15, 2011

Actually, it seems to break with the added ^.

An unfortunate side effect to this script is it breaks the tab cycling of names if one is the last nick, and breaks the channel cycling... I gotta figure away around it.

More
 Respond  
jaytea   -  Aug 15, 2011

it does work fine without it. /halt will always let you stop default nick completion, with or without the ^ prefix, all the prefix does is have the event trigger before identifier completion.

More
 Respond  
Jethro   -  Aug 15, 2011

Yup it can actually work without ^, so long as you have a halt or haltdef :P I suppose I'm orthodox-minded.

More
 Respond  
TheImrac   -  Aug 15, 2011

Seems to work fine without, but I will take your suggestion. Updated code.

More
 Respond  
Jethro   -  Aug 15, 2011

I think you missed the ^ prefix:

on ^*:TABCOMP:#:{

you want to halt the default and have the custom.

More
 Respond  
Jethro   -  Aug 15, 2011

Ok then now I see what you mean.

More
 Respond  
TheImrac   -  Aug 15, 2011

Agreed, no need to save the table as its only tracking the last message. If you restart, you don't know who the last message was from anyway. (It defaults to the channel name if there is no last message)

More
 Respond  
Jethro   -  Aug 15, 2011

Why not?

More
 Respond  
jaytea   -  Aug 15, 2011

But the only shortcoming I can see is that the hash table may not exist if you suffer a blackout or the client that runs the code get exited or closed.

why would it need to?

More
 Respond  
Jethro   -  Aug 15, 2011

This snippet is very useful indeed. But the only shortcoming I can see is that the hash table may not exist if you suffer a power outage or the client that runs the code get exited or closed. Also, a notice event may add a bonus addition.

More
 Respond  
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.