home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 March / PCWELT_3_2006.ISO / base / 05_common.mo / usr / share / elvis-2.2_0 / scripts / match.ex < prev    next >
Encoding:
Text File  |  2004-02-22  |  1.8 KB  |  70 lines

  1. " Defines a "match" alias, which moves the cursor to a matching word.  The
  2. " lists of matching words can be easily changed.
  3. " Contributed by Ian Utley (iu@apertus.uk.com)
  4.  
  5. alias match {
  6.     "Move to the line where the pairing keyword is located
  7.     local a b d x y i nowrapscan magic magicchar=^$.[* noignorecase
  8.     "x and y are lists of matching words -- we'll seek forward from x words
  9.     "and backward from y words.  The words listed here are appropriate for
  10.     "Unix shell scripts.
  11.     set x="if/then/case/do/begin/repeat" y="fi/else/esac/done/end/until"
  12.     let a=current("word")
  13.     if (a == "")
  14.     then error Cursor is not on a word
  15.     set b=""
  16.     while b=="" && x!="."
  17.     do {
  18.     if a==dirfile(x)
  19.     then {
  20.         let b=dirfile(y)
  21.         set d=forward
  22.     }
  23.     if a==dirfile(y)
  24.     then {
  25.         let b=dirfile(x)
  26.         set d=backward
  27.     }
  28.     let x=dirdir(x)
  29.     let y=dirdir(y)
  30.     }
  31.     if ( b=="" )
  32.     then error (a) is not a matchable keyword 
  33.     mark c
  34.     set i=1
  35.     if (d=="forward")
  36.     then {
  37.         while ( i != 0 )
  38.         do {
  39.             set i=0
  40.             try eval /\<(b)\>
  41.             else {
  42.                 " Failed to locate a match
  43.                 'c
  44.                 error No matching (b) located
  45.             }
  46.             mark d
  47.             eval 'c,'d global /\<(a)\>/ let i=i+1
  48.             eval 'c,'d global /\<(b)\>/ let i=i-1
  49.         }
  50.     }
  51.     if (d=="backward") 
  52.     then {
  53.         while ( i != 0 )
  54.         do {
  55.             set i=0
  56.             try eval ?\<(b)\>
  57.             else {
  58.                 " Failed to find a match
  59.                 'c
  60.                 error No matching (b) located
  61.             }
  62.             mark d
  63.             eval 'd,'c global /\<(a)\>/ let i=i+1
  64.             eval 'd,'c global /\<(b)\>/ let i=i-1
  65.             " global command has moved cursor back to 'c
  66.             'd
  67.         }
  68.     }
  69. }
  70.