| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | " Vim indent file | 
					
						
							|  |  |  | " Language:	Rmd | 
					
						
							| 
									
										
										
										
											2024-02-19 20:37:11 +01:00
										 |  |  | " Maintainer: This runtime file is looking for a new maintainer. | 
					
						
							|  |  |  | " Former Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com> | 
					
						
							|  |  |  | " Former Repository: https://github.com/jalvesaq/R-Vim-runtime | 
					
						
							|  |  |  | " Last Change:	2022 Nov 09  09:44PM | 
					
						
							|  |  |  | "		2024 Feb 19 by Vim Project (announce adoption) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  | setlocal indentkeys=0{,0},<:>,!^F,o,O,e | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | setlocal indentexpr=GetRmdIndent() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-27 15:49:53 +00:00
										 |  |  | let b:undo_indent = "setl inde< indk<" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | if exists("*GetRmdIndent") | 
					
						
							|  |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  | let s:cpo_save = &cpo | 
					
						
							|  |  |  | set cpo&vim | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  | " Simple Python indentation algorithm | 
					
						
							|  |  |  | function s:GetPyIndent() | 
					
						
							|  |  |  |   let plnum = prevnonblank(v:lnum - 1) | 
					
						
							|  |  |  |   let pline = getline(plnum) | 
					
						
							|  |  |  |   let cline = getline(v:lnum) | 
					
						
							|  |  |  |   if pline =~ '^s```\s*{\s*python ' | 
					
						
							|  |  |  |     return 0 | 
					
						
							|  |  |  |   elseif pline =~ ':$' | 
					
						
							|  |  |  |     return indent(plnum) + &shiftwidth | 
					
						
							|  |  |  |   elseif cline =~ 'else:$' | 
					
						
							|  |  |  |     return indent(plnum) - &shiftwidth | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   return indent(plnum) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  | function s:GetMdIndent() | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2023-02-27 15:49:53 +00:00
										 |  |  |   elseif pline =~ '^\[\^\S\+\]: ' | 
					
						
							|  |  |  |     return indent(v:lnum - 1) + shiftwidth() | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  |   endif | 
					
						
							|  |  |  |   return indent(prevnonblank(v:lnum - 1)) | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  | function s:GetYamlIndent() | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  |   let plnum = prevnonblank(v:lnum - 1) | 
					
						
							|  |  |  |   let pline = getline(plnum) | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  |   if pline =~ ':\s*$' | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  |     return indent(plnum) + shiftwidth() | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  |   elseif pline =~ '^\s*- ' | 
					
						
							|  |  |  |     return indent(v:lnum) + 2 | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  |   return indent(plnum) | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | 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() | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  |   elseif v:lnum > 1 && (search('^---$', "bnW") == 1 && | 
					
						
							|  |  |  |         \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum)) | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  |     return s:GetYamlIndent() | 
					
						
							| 
									
										
										
										
											2021-04-21 18:09:37 +02:00
										 |  |  |   elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW") | 
					
						
							|  |  |  |     return s:GetPyIndent() | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  |     return s:GetMdIndent() | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  |   endif | 
					
						
							|  |  |  | endfunction | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 22:58:02 +02:00
										 |  |  | let &cpo = s:cpo_save | 
					
						
							|  |  |  | unlet s:cpo_save | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-10 22:01:47 +02:00
										 |  |  | " vim: sw=2 |