home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
editor
/
me_cd.arc
/
PMATCH.MUT
< prev
next >
Wrap
Text File
|
1988-09-14
|
2KB
|
71 lines
; pmatch.mut : paren matcher. Works on (){}
; put the cursor at a paren, execute p-match. The cursor is
; moved to the matching paren, sits there for a while so you
; can see the matching paren and then curor is restored. The
; mark is left at the matching paren so you can
; (exchange-dot-and-mark) at your convience.
; C Durland
(const DELAY 2300) ; the bigger the number the longer the delay
(defun
p-match-forward (open-paren close-paren) HIDDEN
{
(string m 10)(int c)(c 1)
(next-character)(m (concat "[" open-paren close-paren "]"))
(while (!= c 0)
{
; (if (key-waiting) {(get-key)(FALSE)(done)}) ; let user interrupt
(if (re-search-forward m) () { FALSE (done) })
(switch (get-matched "&")
open-paren (+= c 1)
close-paren (c (- c 1))
)
; (update) ; these are fun to watch
})
(previous-character)
TRUE
}
p-match-backward (open-paren close-paren) HIDDEN
{
(string m 10)(int c)(c 1)
(m (concat "[" open-paren close-paren "]"))
(while (!= c 0)
{
(if (re-search-reverse m) () { FALSE (done) })
(switch (get-matched "&")
open-paren (+= c 1)
close-paren (c (- c 1))
)
(update) ; these are fun to watch
})
TRUE
}
p-match
{
(string op 5)(int c)
(if (looking-at ".") () { (msg "Can't match that!")(done) })
(set-mark)(msg "Looking ...")
(switch (op (get-matched "&"))
"(" (p-match-forward "(" ")")
"{" (p-match-forward "{" "}")
"}" (p-match-backward "}" "{")
")" (p-match-backward ")" "(")
default { (msg "Can't match that!")(done) }
)
(if ()
{
(msg "Heres the matching paren")
(update)
(c 0)(while (!= c DELAY) (+= c 1)) ; delay loop
(msg "mark is at matching paren")
}
(msg "Unbalanced \"" op "\"")
)
(exchange-dot-and-mark)
}
)