home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
text
/
editors
/
uedit-stuff
/
match
< prev
next >
Wrap
Text File
|
1991-01-10
|
4KB
|
83 lines
These two commands, which I threw together in about fifteen minutes, are for
letting you know how your parentheses and squiggle braces match up. When you
press a closing brace or a closing paren, the matching opening one gets
displayed as invert, if it is on the screen, until you type your next input.
It's a little slow if the one displayed is not on the same line, but it
doesn't slow down input because it abandons the search for the matching open
paren or open brace if you type another input. It will not restore what the
invert region was before the command. It does not check whether things are
inside quote marks or comments or anything like that. It trashes locA. NOTE
that while the invert region is displayed it is busy-waiting for you to type
something, so anything that waits for idle time won't work ... so it's best
not to leave it in that state unnecessarily.
Later on I added SC-0 [think of ctl-)] to toggle the matching feature on and
off. This version uses userGlobalA as the flag to control whether it's on or
off. By searching for occurrences of userGlobalA you can change it to use
some other flag, either global or local, or an n-variable (no checked menu
items in the latter case).
Display matching left paren as invert (if on screen) until next input
<shft-0: .. NORMAL-)
typechar(")")
if (eqnum(userglobalA, 0) | not thiskey) returntrue
updatedisplay
equatenum(n0, 0)
equateloc(curfile, loca, atcursor)
while (movecursor(curfile, schar) &
not geloc(curfile, spage, atcursor) &
not inputwaiting) {
if (is(curfile, ")")) incnum(n0)
else if (is(curfile, "(")) decnum(n0)
runkey(virtual-0)
}
movecursor(curfile, loca)
updatedisplay
>
Display matching left brace as invert (if on screen) until next input
<shft-]: .. NORMAL-}
typechar("}")
if (eqnum(userglobalA, 0) | not thiskey) returntrue
updatedisplay
equatenum(n0, 0)
equateloc(curfile, loca, atcursor)
while (movecursor(curfile, schar) &
not geloc(curfile, spage, atcursor) &
not inputwaiting) {
if (is(curfile, "}")) incnum(n0)
else if (is(curfile, "{")) decnum(n0)
runkey(virtual-0)
}
movecursor(curfile, loca)
updatedisplay
>
<virtual-0: if (eqnum(n0, 0)) {
equateloc(curfile, sinvert, atcursor)
movecursor(curfile, echar)
equateloc(curfile, einvert, atcursor)
updatedisplay
movecursor(curfile, loca)
updatedisplay
while (not inputwaiting) nothing
.. that nothing used to be delay(1) but the delay was often more like 10.
.. I had to make it spin to get quick response to resumption of typing
equateloc(curfile, einvert, sinvert)
movecursor(curfile, sinvert)
updatedisplay
} >
These wouldn't need nearly so many updatedisplays if the displayflag bits
were smarter...
Toggle whether ) and } show matching ( and {
<shftctl-0: if (eqnum(userglobalA, 0)) {
putmsg("turning On paren matching")
equatenum(userglobalA, 1)
} else {
putmsg("turning OFF paren matching")
equatenum(userglobalA, 0)
} >