home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / mutt / builtin / pmatch.mut < prev    next >
Text File  |  1995-01-14  |  2KB  |  73 lines

  1. ;; pmatch.mut : paren matcher.  Works on (){}
  2. ;; Put the cursor at a paren, execute p-match.  The cursor is moved to the
  3. ;;   matching paren, sits there for a while so you can see the matching
  4. ;;   paren and then curor is restored.  The mark is left at the matching
  5. ;;   paren so you can (exchange-dot-and-mark) at your convience.
  6. ;; C Durland    Public Domain
  7.  
  8. (const DELAY 3)    ; Number of seconds to show the matching paren
  9.  
  10. (defun
  11.   p-match-forward (open-paren close-paren) HIDDEN
  12.   {
  13.     (string m)(int c)
  14.  
  15.     (c 1)
  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)(int c)
  33.  
  34.     (c 1)
  35.     (m (concat "[" open-paren close-paren "]"))
  36.     (while (!= c 0)
  37.     {
  38.       (if (key-waiting) {(get-key)(FALSE)(done)})    ; let user interrupt
  39.       (if (re-search-reverse m) () { FALSE (done) })
  40.       (switch (get-matched "&")
  41.     open-paren  (+= c 1)
  42.     close-paren (c (- c 1))
  43.       )
  44.       (update)    ; these are fun to watch
  45.     })
  46.     TRUE
  47.   }
  48.   p-match
  49.   {
  50.     (string op)(int c)
  51.  
  52.     (if (looking-at ".") () { (msg "Can't match that!")(done) })
  53.     (set-mark)(msg "Looking ...")
  54.     (switch (op (get-matched "&"))
  55.       "(" (p-match-forward  "(" ")")
  56.       "{" (p-match-forward  "{" "}")
  57.       "}" (p-match-backward "}" "{")
  58.       ")" (p-match-backward ")" "(")
  59.       default { (msg "Can't match that!")(done) }
  60.     )
  61.     (if ()
  62.       {
  63.     (msg "Here's the matching paren")
  64.     (update)                ; show matching paren
  65.     (key-waiting DELAY)            ; wait a little bit
  66.     (msg "Mark is at matching paren")
  67.       }
  68.       (msg "Unbalanced \"" op "\"")
  69.     )
  70.     (swap-marks)
  71.   }
  72. )
  73.