robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:f9ca139e3aa1 (#27554)9bb046d1be

master
2.4 KiB90 linesraw
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")
12  finish
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")
24  finish
25endif
26
27let s:cpo_save = &cpo
28set cpo&vim
29
30" Simple Python indentation algorithm
31function s:GetPyIndent()
32  let plnum = prevnonblank(v:lnum - 1)
33  let pline = getline(plnum)
34  let cline = getline(v:lnum)
35  if pline =~ '^s```\s*{\s*python '
36    return 0
37  elseif pline =~ ':$'
38    return indent(plnum) + &shiftwidth
39  elseif cline =~ 'else:$'
40    return indent(plnum) - &shiftwidth
41  endif
42  return indent(plnum)
43endfunction
44
45function s:GetMdIndent()
46  let pline = getline(v:lnum - 1)
47  let cline = getline(v:lnum)
48  if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
49    return indent(v:lnum)
50  elseif pline =~ '^\s*[-\+\*]\s'
51    return indent(v:lnum - 1) + 2
52  elseif pline =~ '^\s*\d\+\.\s\+'
53    return indent(v:lnum - 1) + 3
54  elseif pline =~ '^\[\^\S\+\]: '
55    return indent(v:lnum - 1) + shiftwidth()
56  endif
57  return indent(prevnonblank(v:lnum - 1))
58endfunction
59
60function s:GetYamlIndent()
61  let plnum = prevnonblank(v:lnum - 1)
62  let pline = getline(plnum)
63  if pline =~ ':\s*$'
64    return indent(plnum) + shiftwidth()
65  elseif pline =~ '^\s*- '
66    return indent(v:lnum) + 2
67  endif
68  return indent(plnum)
69endfunction
70
71function GetRmdIndent()
72  if getline(".") =~ '^[ \t]*```{r .*}$' || getline(".") =~ '^[ \t]*```$'
73    return 0
74  endif
75  if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
76    return s:RIndent()
77  elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
78        \ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
79    return s:GetYamlIndent()
80  elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
81    return s:GetPyIndent()
82  else
83    return s:GetMdIndent()
84  endif
85endfunction
86
87let &cpo = s:cpo_save
88unlet s:cpo_save
89
90" vim: sw=2