home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim60.zip / vim60rt2.zip / vim / vim60 / indent / sh.vim < prev    next >
Text File  |  2001-09-26  |  2KB  |  55 lines

  1. "  vim: set sw=4 sts=4:
  2. "  Maintainer    : Nikolai 'pcp' Weibull <da.box@home.se>
  3. "  URL        : http://www.pcppopper.org/
  4. "  Revised on    : Sun, 23 Sep 2001 16:26:03 +0200
  5. "  Language    : Shell Script
  6.  
  7. " Only load this indent file when no other was loaded.
  8. if exists("b:did_indent")
  9.     finish
  10. endif
  11.  
  12. let b:did_indent = 1
  13.  
  14. setlocal indentexpr=GetShIndent()
  15. setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done indentkeys-=:,0#
  16.  
  17. " Only define the function once.
  18. if exists("*GetShIndent")
  19.     finish
  20. endif
  21.  
  22. set cpoptions-=C
  23.  
  24. function GetShIndent()
  25.     " Find a non-blank line above the current line.
  26.     let lnum = prevnonblank(v:lnum - 1)
  27.  
  28.     " Hit the start of the file, use zero indent.
  29.     if lnum == 0
  30.     return 0
  31.     endif
  32.  
  33.     " Add a 'shiftwidth' after if, while, else, case, until, for, function()
  34.     " Skip if the line also contains the closure for the above
  35.     let ind = indent(lnum)
  36.     let line = getline(lnum)
  37.     if line =~ '^\s*\(if\|then\|do\|else\|elif\|case\|while\|until\|for\)\>'
  38.         \ || line =~ '^\s*\<\h\w*\>\s*()\s*{'
  39.         \ || line =~ '^\s*{'
  40.     if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$'
  41.         let ind = ind + &sw
  42.     endif
  43.     endif
  44.  
  45.     " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done
  46.     " Retain the indentation level if line matches fin (for find)
  47.     let line = getline(v:lnum)
  48.     if (line =~ '^\s*\(then\|do\|else\|elif\|esac\|fi\|done\)\>' || line =~ '^\s*}')
  49.         \ && line !~ '^\s*fi[ln]\>'
  50.     let ind = ind - &sw
  51.     endif
  52.  
  53.     return ind
  54. endfunction
  55.