blob: 73c8b04611851cfcb8c8f497356ef24ad0e0b44d [file] [log] [blame]
Bram Moolenaardb6ea062014-07-10 22:01:47 +02001" Vim indent file
2" Language: Rrst
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" 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: 2023 Feb 25
7" 2024 Feb 19 by Vim Project (announce adoption)
Bram Moolenaardb6ea062014-07-10 22:01:47 +02008
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=GetRrstIndent()
20
Bram Moolenaardd60c362023-02-27 15:49:53 +000021let b:undo_indent = "setl inde< indk<"
22
Bram Moolenaardb6ea062014-07-10 22:01:47 +020023if exists("*GetRrstIndent")
24 finish
25endif
26
27function GetRstIndent()
28 let pline = getline(v:lnum - 1)
29 let cline = getline(v:lnum)
30 if prevnonblank(v:lnum - 1) < v:lnum - 1 || cline =~ '^\s*[-\+\*]\s' || cline =~ '^\s*\d\+\.\s\+'
31 return indent(v:lnum)
32 elseif pline =~ '^\s*[-\+\*]\s'
33 return indent(v:lnum - 1) + 2
34 elseif pline =~ '^\s*\d\+\.\s\+'
35 return indent(v:lnum - 1) + 3
36 endif
37 return indent(prevnonblank(v:lnum - 1))
38endfunction
39
40function GetRrstIndent()
41 if getline(".") =~ '^\.\. {r .*}$' || getline(".") =~ '^\.\. \.\.$'
42 return 0
43 endif
44 if search('^\.\. {r', "bncW") > search('^\.\. \.\.$', "bncW")
45 return s:RIndent()
46 else
47 return GetRstIndent()
48 endif
49endfunction
50
51" vim: sw=2