robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
9bb046d1be
master
1" Vim indent file 2" Language: Rmd 3" Maintainer: This runtime file is looking for a new maintainer. 4" Former Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com> 5" Former Repository: https://github.com/jalvesaq/R-Vim-runtime 6" Last Change: 2022 Nov 09 09:44PM 7" 2024 Feb 19 by Vim Project (announce adoption) 8 9 10" Only load this indent file when no other was loaded. 11if exists ( "b:did_indent" ) 12finish 13endif 14runtime indent/r.vim 15let s: RIndent = function ( substitute ( & indentexpr , "()" , "" , "" )) 16let b: did_indent = 1 17 18setlocal indentkeys = 0{,0},<:>,!^F,o,O,e 19setlocal indentexpr = GetRmdIndent () 20 21let b: undo_indent = "setl inde< indk<" 22 23if exists ( "*GetRmdIndent" ) 24finish 25endif 26 27let s: cpo_save = & cpo 28set cpo & vim 29 30" Simple Python indentation algorithm 31function s: GetPyIndent () 32let plnum = prevnonblank ( v: lnum - 1 ) 33let pline = getline ( plnum ) 34let cline = getline ( v: lnum ) 35if pline =~ '^s```\s*{\s*python ' 36return 0 37elseif pline =~ ':$' 38return indent ( plnum ) + & shiftwidth 39elseif cline =~ 'else:$' 40return indent ( plnum ) - & shiftwidth 41endif 42return indent ( plnum ) 43endfunction 44 45function s: GetMdIndent () 46let pline = getline ( v: lnum - 1 ) 47let cline = getline ( v: lnum ) 48if prevnonblank ( v: lnum - 1 ) < v: lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+' 49return indent ( v: lnum ) 50elseif pline =~ '^\s*[-\+\*]\s' 51return indent ( v: lnum - 1 ) + 2 52elseif pline =~ '^\s*\d\+\.\s\+' 53return indent ( v: lnum - 1 ) + 3 54elseif pline =~ '^\[\^\S\+\]: ' 55return indent ( v: lnum - 1 ) + shiftwidth () 56endif 57return indent ( prevnonblank ( v: lnum - 1 )) 58endfunction 59 60function s: GetYamlIndent () 61let plnum = prevnonblank ( v: lnum - 1 ) 62let pline = getline ( plnum ) 63if pline =~ ':\s*$' 64return indent ( plnum ) + shiftwidth () 65elseif pline =~ '^\s*- ' 66return indent ( v: lnum ) + 2 67endif 68return indent ( plnum ) 69endfunction 70 71function GetRmdIndent () 72if getline ( "." ) =~ '^[ \t]*```{r .*}$' || getline ( "." ) =~ '^[ \t]*```$' 73return 0 74endif 75if search ( '^[ \t]*```{r' , "bncW" ) > search ( '^[ \t]*```$' , "bncW" ) 76return s: RIndent () 77elseif v: lnum > 1 && ( search ( '^---$' , "bnW" ) == 1 && 78 \( search ( '^---$' , "nW" ) > v: lnum || search ( '^\.\.\.$' , "nW" ) > v: lnum )) 79return s: GetYamlIndent () 80elseif search ( '^[ \t]*```{python' , "bncW" ) > search ( '^[ \t]*```$' , "bncW" ) 81return s: GetPyIndent () 82else 83return s: GetMdIndent () 84endif 85endfunction 86 87let & cpo = s: cpo_save 88unlet s: cpo_save 89 90" vim: sw=2