robin/laufey

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

zeertzjqMerge pull request #36174 from zeertzjq/vim-094046555bd54e526

master
2.1 KiB87 linesraw
1" Vim indent file
2" Vim reST indent file
3" Language: reStructuredText Documentation Format
4" Maintainer: Marshall Ward <marshall.ward@gmail.com>
5" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
6" Latest Revision: 2020-03-31
7" 2023 Aug 28 by Vim Project (undo_indent)
8" 2025 Oct 13 by Vim project: preserve indentation #18566
9
10if exists("b:did_indent")
11  finish
12endif
13let b:did_indent = 1
14
15" Save and modify cpoptions
16let s:save_cpo = &cpo
17set cpo&vim
18
19setlocal indentexpr=GetRSTIndent()
20setlocal indentkeys=!^F,o,O
21setlocal nosmartindent
22
23let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
24
25if exists("*GetRSTIndent")
26  finish
27endif
28
29let s:itemization_pattern = '^\s*[-*+]\s'
30let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
31let s:note_pattern = '^\.\. '
32
33function! s:get_paragraph_start()
34    let paragraph_mark_start = getpos("'{")[1]
35    return getline(paragraph_mark_start) =~
36        \ '\S' ? paragraph_mark_start : paragraph_mark_start + 1
37endfunction
38
39function GetRSTIndent()
40  let lnum = prevnonblank(v:lnum - 1)
41  if lnum == 0
42    return 0
43  endif
44
45  let ind = indent(lnum)
46  let line = getline(lnum)
47
48  let psnum = s:get_paragraph_start()
49  if psnum != 0
50      if getline(psnum) =~ s:note_pattern
51          let ind = max([3, ind])
52      endif
53  endif
54
55  if line =~ s:itemization_pattern
56    let ind += 2
57  elseif line =~ s:enumeration_pattern
58    let ind += matchend(line, s:enumeration_pattern)
59  endif
60
61  let line = getline(v:lnum - 1)
62
63  " Indent :FIELD: lines.  Don’t match if there is no text after the field or
64  " if the text ends with a sent-ender.
65   if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$'
66     return matchend(line, '^:.\{-1,}:\s\+')
67   endif
68
69  if line =~ '^\s*$'
70    execute lnum
71    call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
72    let line = getline('.')
73    if line =~ s:itemization_pattern
74      let ind -= 2
75    elseif line =~ s:enumeration_pattern
76      let ind -= matchend(line, s:enumeration_pattern)
77    elseif line =~ '^\s*\.\.'
78      let ind -= 3
79    endif
80  endif
81
82  return ind
83endfunction
84
85" Restore 'cpoptions'
86let &cpo = s:save_cpo
87unlet s:save_cpo