home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / mutt / pmatch.mut < prev    next >
Text File  |  1988-09-14  |  2KB  |  71 lines

  1.     ; pmatch.mut : paren matcher.  Works on (){}
  2.     ; put the cursor at a paren, execute p-match.  The cursor is
  3.     ;   moved to the matching paren, sits there for a while so you
  4.     ;   can see the matching paren and then curor is restored.  The
  5.     ;   mark is left at the matching paren so you can
  6.     ;   (exchange-dot-and-mark) at your convience.
  7.     ; C Durland
  8.  
  9. (const DELAY 2300)    ; the bigger the number the longer the delay
  10.  
  11. (defun
  12.   p-match-forward (open-paren close-paren) HIDDEN
  13.   {
  14.     (string m 10)(int c)(c 1)
  15.  
  16.     (next-character)(m (concat "[" open-paren close-paren "]"))
  17.     (while (!= c 0)
  18.     {
  19. ;      (if (key-waiting) {(get-key)(FALSE)(done)})    ; let user interrupt
  20.       (if (re-search-forward m) () { FALSE (done) })
  21.       (switch (get-matched "&")
  22.     open-paren (+= c 1)
  23.     close-paren (c (- c 1))
  24.       )
  25. ;      (update)    ; these are fun to watch
  26.     })
  27.     (previous-character)
  28.     TRUE
  29.   }
  30.   p-match-backward (open-paren close-paren) HIDDEN
  31.   {
  32.     (string m 10)(int c)(c 1)
  33.  
  34.     (m (concat "[" open-paren close-paren "]"))
  35.     (while (!= c 0)
  36.     {
  37.       (if (re-search-reverse m) () { FALSE (done) })
  38.       (switch (get-matched "&")
  39.     open-paren (+= c 1)
  40.     close-paren (c (- c 1))
  41.       )
  42.       (update)    ; these are fun to watch
  43.     })
  44.     TRUE
  45.   }
  46.   p-match
  47.   {
  48.     (string op 5)(int c)
  49.  
  50.     (if (looking-at ".") () { (msg "Can't match that!")(done) })
  51.     (set-mark)(msg "Looking ...")
  52.     (switch (op (get-matched "&"))
  53.       "(" (p-match-forward  "(" ")")
  54.       "{" (p-match-forward  "{" "}")
  55.       "}" (p-match-backward "}" "{")
  56.       ")" (p-match-backward ")" "(")
  57.       default { (msg "Can't match that!")(done) }
  58.     )
  59.     (if ()
  60.       {
  61.     (msg "Heres the matching paren")
  62.     (update)
  63.     (c 0)(while (!= c DELAY) (+= c 1))    ; delay loop
  64.     (msg "mark is at matching paren")
  65.       }
  66.       (msg "Unbalanced \"" op "\"")
  67.     )
  68.     (exchange-dot-and-mark)
  69.   }
  70. )
  71.