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 / runtime / indent / rst.vim < prev    next >
Encoding:
Text File  |  2012-05-31  |  1.4 KB  |  60 lines

  1. " Vim indent file
  2. " Language:         reStructuredText Documentation Format
  3. " Maintainer:       Nikolai Weibull <now@bitwi.se>
  4. " Latest Revision:  2011-08-03
  5.  
  6. if exists("b:did_indent")
  7.   finish
  8. endif
  9. let b:did_indent = 1
  10.  
  11. setlocal indentexpr=GetRSTIndent()
  12. setlocal indentkeys=!^F,o,O
  13. setlocal nosmartindent
  14.  
  15. if exists("*GetRSTIndent")
  16.   finish
  17. endif
  18.  
  19. let s:itemization_pattern = '^\s*[-*+]\s'
  20. let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
  21.  
  22. function GetRSTIndent()
  23.   let lnum = prevnonblank(v:lnum - 1)
  24.   if lnum == 0
  25.     return 0
  26.   endif
  27.  
  28.   let ind = indent(lnum)
  29.   let line = getline(lnum)
  30.  
  31.   if line =~ s:itemization_pattern
  32.     let ind += 2
  33.   elseif line =~ s:enumeration_pattern
  34.     let ind += matchend(line, s:enumeration_pattern)
  35.   endif
  36.  
  37.   let line = getline(v:lnum - 1)
  38.  
  39.   " Indent :FIELD: lines.  DonΓÇÖt match if there is no text after the field or
  40.   " if the text ends with a sent-ender.
  41.    if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$'
  42.      return matchend(line, '^:.\{-1,}:\s\+')
  43.    endif
  44.  
  45.   if line =~ '^\s*$'
  46.     execute lnum
  47.     call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
  48.     let line = getline('.')
  49.     if line =~ s:itemization_pattern
  50.       let ind -= 2
  51.     elseif line =~ s:enumeration_pattern
  52.       let ind -= matchend(line, s:enumeration_pattern)
  53.     elseif line =~ '^\s*\.\.'
  54.       let ind -= 3
  55.     endif
  56.   endif
  57.  
  58.   return ind
  59. endfunction
  60.