add nadict to the system without replacing adict adict users: comments / changes please. i'd like to replace adict with nadict. Reference: /n/atom/patch/applied/nadict Date: Fri Feb 28 12:39:04 CET 2014 Signed-off-by: quanstro@quanstro.net --- /acme/bin/nadict Thu Jan 1 00:00:00 1970 +++ /acme/bin/nadict Fri Feb 28 12:38:29 2014 @@ -0,0 +1,133 @@ +#!/bin/rc + +fn newwindow { + winctl=`{read /mnt/acme/new/ctl} + winid=$winctl(1) + winctl noscroll +} + +fn winctl { + echo $* > /mnt/acme/$winid/ctl +} + +fn winread { + cat /mnt/acme/$winid/$1 +} + +fn winwrite { + cat > /mnt/acme/$winid/$1 +} + +fn windump { + if(! ~ $1 - '') + winctl dumpdir $1 + if(! ~ $2 - '') + winctl dump $2 +} + +fn winname { + winctl name $1 +} + +fn wintag { + winctl tag $1 +} + +fn winwriteevent { + echo $1$2$3 $4 | winwrite event +} + +fn windel { + if(~ $1 sure) + winctl delete + if not + winctl del +} + +fn wineventloop { + . <{winread event >[2]/dev/null | acmeevent} +} + +fn event { + # $1 - c1 origin of event + # $2 - c2 type of action + # $3 - q0 beginning of selection + # $4 - q1 end of selection + # $5 - eq0 beginning of expanded selection + # $6 - eq1 end of expanded selection + # $7 - flag + # $8 - nr number of runes in $9 + # $9 - text + # $10 - chorded argument + # $11 - origin of chorded argument + + switch($1$2){ + case E* # write to body or tag + case F* # generated by ourselves; ignore + case K* # type away we do not care + case Mi # mouse: text inserted in tag + case MI # mouse: text inserted in body + case Md # mouse: text deleted from tag + case MD # mouse: text deleted from body + + case Mx MX # button 2 in tag or body + winwriteevent $* + + case Ml ML # button 3 in tag or body + { + if(~ $dict NONE) + dictwin /nadict/$9/ $9 + if not + dictwin /nadict/$dict/$9 $dict $9 + } & + } +} + +fn dictwin { + newwindow + winname $1 + switch($#*){ + case 1 + dict -d '?' >[2=1] | sed 1d | winwrite body + case 2 + dict=$2 + case 3 + dict=$2 + dict -d $dict $3 >[2=1] | winwrite body + } + winctl clean + wineventloop +} + +dict=NONE +if(~ $1 -d){ + shift + dict=$1 + shift +} +if(~ $1 -d*){ + dict=`{echo $1 | sed 's/-d//'} + shift +} +if(~ $1 -*){ + echo 'usage: adict [-d dict] [word...]' >[1=2] + exit usage +} + +switch($#*){ +case 0 + if(~ $dict NONE) + dictwin /nadict/ + if not + dictwin /nadict/$dict/ $dict +case * + if(~ $dict NONE){ + dict=`{dict -d'?' | sed -n 's/^ ([^\[ ]+).*/\1/p' | sed 1q} + if(~ $#dict 0){ + echo 'no dictionaries present on this system' >[1=2] + exit nodict + } + } + for(i) + dictwin /nadict/$dict/$i $dict $i +}