robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
55bd54e526
master
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" ) 11finish 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" ) 26finish 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 () 34let paragraph_mark_start = getpos ( "'{" )[ 1 ] 35return getline ( paragraph_mark_start ) =~ 36 \'\S' ? paragraph_mark_start : paragraph_mark_start + 1 37endfunction 38 39function GetRSTIndent () 40let lnum = prevnonblank ( v: lnum - 1 ) 41if lnum == 0 42return 0 43endif 44 45let ind = indent ( lnum ) 46let line = getline ( lnum ) 47 48let psnum = s: get_paragraph_start () 49if psnum != 0 50if getline ( psnum ) =~ s: note_pattern 51let ind = max ([ 3 , ind ]) 52endif 53endif 54 55if line =~ s: itemization_pattern 56let ind += 2 57elseif line =~ s: enumeration_pattern 58let ind += matchend ( line , s: enumeration_pattern ) 59endif 60 61let 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. 65if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$' 66return matchend ( line , '^:.\{-1,}:\s\+' ) 67endif 68 69if line =~ '^\s*$' 70execute lnum 71call search ( '^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)' , 'bW' ) 72let line = getline ( '.' ) 73if line =~ s: itemization_pattern 74let ind -= 2 75elseif line =~ s: enumeration_pattern 76let ind -= matchend ( line , s: enumeration_pattern ) 77elseif line =~ '^\s*\.\.' 78let ind -= 3 79endif 80endif 81 82return ind 83endfunction 84 85" Restore 'cpoptions' 86let & cpo = s: save_cpo 87unlet s: save_cpo