home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
contrib
/
autparen.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
3KB
|
80 lines
; autparen.mut -- Show matching open parens while typing
;
; Author: Tim Brengle
; largely derived from pmatch.mut by Craig Durland
;
; This rebinds the ")", "}", and "]" keys so that typing one of them causes
; the corresponding opening delimiter to be shown briefly. If there is no
; matching instance, you will hear a beep (if the sysvar (beeper) is non-zero)
; or see a message. The DELAY const has been chosen empirically so that I can
; keep typing at my normal speed on my PC-AT clone and just listen for the
; beep. Your mileage may vary. There should be no impact as long as you have
; sufficient type-ahead capacity.
;
; Problems and gotchas:
; In order for the regular expression to work properly with square brackets
; ("[" and "]"), the right bracket must appear first. Since it makes no
; difference for the others, I made it that way for all.
;
; Instances of the delimiters appearing as parts of strings are not handled
; any differently. Try removing and replacing the last ")" in this file.
; At least GNU Emacs doesn't handle it any better...
;
; Adding new matching delimiter pairs should be obvious, but they must be
; different characters; this won't work on strings, for instance.
(const DELAY 1) ; Number of seconds to delay
(defun
insert-and-match (open-paren close-paren) HIDDEN
{
(string m)(int c mark)
(m (concat '[' close-paren open-paren ']')) ;form regular expression
(insert-text close-paren) ;insert delimiter
(previous-character) ;so match won't end too soon
(set-mark (mark (create-mark)))
(c 1)
(while (!= c 0) ;while not-balanced
{
(if (re-search-reverse m) ;find either open- or close-?
(switch (get-matched '&') ;yes: update balance count
close-paren (+= c 1)
open-paren (c (- c 1))
)
{ ;no: must be unbalanced
(if (== (beep -1) 0)
(msg 'No matching "' open-paren '"')
(beep)
)
(goto-mark mark) ;back to insertion point
(next-character)
FALSE
(done) ;quit
}
)
})
(update) ;all balanced so show
(key-waiting DELAY)
(goto-mark mark) ;back to insertion point
(next-character)
(msg "")
TRUE
}
)
(defun
insert-close-paren
{ (insert-and-match '(' ')') }
insert-close-brace
{ (insert-and-match '{' '}') }
insert-close-bracket
{ (insert-and-match '[' ']') }
MAIN
{
(bind-to-key 'insert-close-paren' ')')
(bind-to-key 'insert-close-brace' '}')
(bind-to-key 'insert-close-bracket' ']')
}
)