| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | " Vim indent file | 
					
						
							| 
									
										
										
										
											2017-03-05 17:04:09 +01:00
										 |  |  |  | " Language:             reStructuredText Documentation Format | 
					
						
							|  |  |  |  | " Previous Maintainer:  Nikolai Weibull <now@bitwi.se> | 
					
						
							|  |  |  |  | " Latest Revision:      2011-08-03 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |  |   finish | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | setlocal indentexpr=GetRSTIndent() | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | setlocal indentkeys=!^F,o,O | 
					
						
							| 
									
										
										
										
											2007-05-10 18:32:52 +00:00
										 |  |  |  | setlocal nosmartindent | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | if exists("*GetRSTIndent") | 
					
						
							|  |  |  |  |   finish | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 17:55:08 +02:00
										 |  |  |  | let s:itemization_pattern = '^\s*[-*+]\s' | 
					
						
							|  |  |  |  | let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+' | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | function GetRSTIndent() | 
					
						
							|  |  |  |  |   let lnum = prevnonblank(v:lnum - 1) | 
					
						
							|  |  |  |  |   if lnum == 0 | 
					
						
							|  |  |  |  |     return 0 | 
					
						
							|  |  |  |  |   endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   let ind = indent(lnum) | 
					
						
							|  |  |  |  |   let line = getline(lnum) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 17:55:08 +02:00
										 |  |  |  |   if line =~ s:itemization_pattern | 
					
						
							|  |  |  |  |     let ind += 2 | 
					
						
							|  |  |  |  |   elseif line =~ s:enumeration_pattern | 
					
						
							|  |  |  |  |     let ind += matchend(line, s:enumeration_pattern) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |   endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   let line = getline(v:lnum - 1) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 17:55:08 +02:00
										 |  |  |  |   " Indent :FIELD: lines.  Don’t match if there is no text after the field or | 
					
						
							|  |  |  |  |   " if the text ends with a sent-ender. | 
					
						
							|  |  |  |  |    if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$' | 
					
						
							|  |  |  |  |      return matchend(line, '^:.\{-1,}:\s\+') | 
					
						
							|  |  |  |  |    endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |   if line =~ '^\s*$' | 
					
						
							|  |  |  |  |     execute lnum | 
					
						
							| 
									
										
										
										
											2011-09-14 17:55:08 +02:00
										 |  |  |  |     call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW') | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |     let line = getline('.') | 
					
						
							| 
									
										
										
										
											2011-09-14 17:55:08 +02:00
										 |  |  |  |     if line =~ s:itemization_pattern | 
					
						
							|  |  |  |  |       let ind -= 2 | 
					
						
							|  |  |  |  |     elseif line =~ s:enumeration_pattern | 
					
						
							|  |  |  |  |       let ind -= matchend(line, s:enumeration_pattern) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |     elseif line =~ '^\s*\.\.' | 
					
						
							| 
									
										
										
										
											2011-09-14 17:55:08 +02:00
										 |  |  |  |       let ind -= 3 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |     endif | 
					
						
							|  |  |  |  |   endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return ind | 
					
						
							|  |  |  |  | endfunction |