| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:	Rmd | 
					
						
							|  |  |  | " Author:	Jakson Alves de Aquino <jalvesaq@gmail.com> | 
					
						
							| 
									
										
										
										
											2015-06-19 13:27:23 +02:00
										 |  |  | " Last Change:	Thu Jul 10, 2014  07:11PM | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " Only load this indent file when no other was loaded. | 
					
						
							|  |  |  | if exists("b:did_indent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | runtime indent/r.vim | 
					
						
							|  |  |  | let s:RIndent = function(substitute(&indentexpr, "()", "", "")) | 
					
						
							|  |  |  | let b:did_indent = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | setlocal indentkeys=0{,0},:,!^F,o,O,e | 
					
						
							|  |  |  | setlocal indentexpr=GetRmdIndent() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if exists("*GetRmdIndent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetMdIndent() | 
					
						
							|  |  |  |   let pline = getline(v:lnum - 1) | 
					
						
							|  |  |  |   let cline = getline(v:lnum) | 
					
						
							|  |  |  |   if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' | 
					
						
							|  |  |  |     return indent(v:lnum) | 
					
						
							|  |  |  |   elseif pline =~ '^\s*[-\+\*]\s' | 
					
						
							|  |  |  |     return indent(v:lnum - 1) + 2 | 
					
						
							|  |  |  |   elseif pline =~ '^\s*\d\+\.\s\+' | 
					
						
							|  |  |  |     return indent(v:lnum - 1) + 3 | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   return indent(prevnonblank(v:lnum - 1)) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function GetRmdIndent() | 
					
						
							| 
									
										
										
										
											2015-06-19 13:27:23 +02:00
										 |  |  |   if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$' | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  |     return 0 | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2015-06-19 13:27:23 +02:00
										 |  |  |   if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW") | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  |     return s:RIndent() | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return GetMdIndent() | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " vim: sw=2 |