Surround with identifier

By FelicianoX on Sep 25, 2011

Simple and can be useful sometimes.

Say you had "//echo -a $uptime(system)" in your editbox, but you would like to make it "//echo $duration($uptime(system))" you can highlight it and press CTRL+F2 and type $duration into the input dialog and it does it for you :P

/*
* 100% by FelicianoX (#mSL @ irc.swiftirc.net)
* You can change cF2 to cF3 or F3 or whatever you want.
*/

alias cF2 {
  if ($editbox($active).selstart != $editbox($active).selend) {
    var %id = $input(Surround with identifier:, eyv, Identifier Surrounder ;P), %v1 = $v1, %v2 = $v2
    set -nu %eb $editbox($active)
    if (%id) {
      editbox -a $mid($+($mid($(#,) $+ %eb, 1, %v1),%id,$chr(40),$mid(%eb, %v1, $calc(%v2 -%v1)), $chr(41), $mid(%eb, %v2)), 2)
    }
  }
}

Comments

Sign in to comment.
jaytea   -  Sep 29, 2011

that is, in fact, the very reason for -n's existence :P

 Respond  
FelicianoX   -  Sep 28, 2011

Yeah I didn't think it was gonna work at first but then I tried it and it did :O

 Respond  
Wims   -  Sep 28, 2011

As far as I know -n does not prevent any calc evaluation

edit: hu I just tried, it works even on 6.35, not sure why i felt like it wasn't working

 Respond  
FelicianoX   -  Sep 27, 2011

Dean fixed it by using /set -n to treat it as normal text :P Thanks.

 Respond  
_Dean_   -  Sep 27, 2011

nice idea, but if i put "2 + 5" and then put $calc it will return $calc(7) and not $calc(2 + 5)
8/10

 Respond  
raccoon   -  Sep 26, 2011

Pretty nifty. :)

 Respond  
Jordyk19   -  Sep 26, 2011

Good idea, works perfect. :)

 Respond  
jaytea   -  Sep 26, 2011

interesting idea. here's another: you move your mouse to the front and type $duration( then press 'tab' and the script adds the ')' in the appropriate position. or you can type '$more($than($one($identifier(' and it adds '))))' ;P all perfectly possible with on TABCOMP and a bit of calculation.

 Respond  
Frenetic   -  Sep 25, 2011

Nice work could come in handy.

 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.