home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / indent / config.vim < prev    next >
Encoding:
Text File  |  2002-02-28  |  2.1 KB  |  84 lines

  1. " Maintainer    : Nikolai 'pcp' Weibull <da.box@home.se>
  2. " URL        : http://www.pcppopper.org/
  3. " Revised on    : Wed, 27 Feb 2002 03:54:50 +0100
  4. " Language    : Autoconf configure.{ac,in} file
  5. " TODO        : how about nested [()]'s in one line
  6. "          what's wrong with '\\\@!'?
  7.  
  8. " Only load this indent file when no other was loaded.
  9. if exists("b:did_indent")
  10.     finish
  11. endif
  12.  
  13. source <sfile>:p:h/sh.vim    " will set b:did_indent
  14.  
  15. setlocal indentexpr=GetConfigIndent()
  16. setlocal indentkeys=!^F,o,O,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done
  17.  
  18. " Only define the function once.
  19. if exists("*GetConfigIndent")
  20.     finish
  21. endif
  22.  
  23. " get the offset (indent) of the end of the match of 'regexp' in 'line'
  24. function s:GetOffsetOf(line, regexp)
  25.     let end = matchend(a:line, a:regexp)
  26.     let width = 0
  27.     let i = 0
  28.     while i < end
  29.     if a:line[i] != "\t"
  30.         let width = width + 1
  31.     else
  32.         let width = width + &ts - (width % &ts)
  33.     endif
  34.     let i = i + 1
  35.     endwhile
  36.     return width
  37. endfunction
  38.  
  39. function GetConfigIndent()
  40.     " Find a non-blank line above the current line.
  41.     let lnum = prevnonblank(v:lnum - 1)
  42.  
  43.     " Hit the start of the file, use zero indent.
  44.     if lnum == 0
  45.     return 0
  46.     endif
  47.  
  48.     " where to put this
  49.     let ind = GetShIndent()
  50.     let line = getline(lnum)
  51.  
  52.     " if previous line has unmatched, unescaped opening parentheses,
  53.     " indent to its position. TODO: not failsafe if multiple ('s
  54.     if line =~ '\\\@<!([^)]*$'
  55.     let ind = s:GetOffsetOf(line, '\\\@!(')
  56.     endif
  57.  
  58.     " if previous line has unmatched opening bracket,
  59.     " indent to its position. TODO: same as above
  60.     if line =~ '\[[^]]*$'
  61.     let ind = s:GetOffsetOf(line, '\[')
  62.     endif
  63.  
  64.     " if previous line had an unmatched closing parantheses,
  65.     " indent to the matching opening parantheses
  66.     if line =~ '[^(]*\\\@<!)$'
  67.     call search(')', 'bW')
  68.     let lnum = searchpair('\\\@<!(', '', ')', 'bWn')
  69.     let ind = indent(lnum)
  70.     endif
  71.  
  72.     " if previous line had an unmatched closing bracket,
  73.     " indent to the matching opening bracket
  74.     if line =~ '[^[]*]$'
  75.     call search(']', 'bW')
  76.     let lnum = searchpair('\[', '', ']', 'bWn')
  77.     let ind = indent(lnum)
  78.     endif
  79.  
  80.     return ind
  81. endfunction
  82.  
  83. " vim: set sw=4 sts=4:
  84.