1
0
Fork 0
mirror of https://github.com/vim/vim synced 2025-03-19 16:25:11 +01:00
vim/runtime/indent/rst.vim

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
1.9 KiB
VimL
Raw Permalink Normal View History

2004-06-13 20:20:40 +00:00
" Vim indent file
2020-04-10 22:10:56 +02:00
" Vim reST indent file
" Language: reStructuredText Documentation Format
" Maintainer: Marshall Ward <marshall.ward@gmail.com>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2020-03-31
" 2023 Aug 28 by Vim Project (undo_indent)
2004-06-13 20:20:40 +00:00
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetRSTIndent()
2005-06-29 22:40:58 +00:00
setlocal indentkeys=!^F,o,O
2007-05-10 18:32:52 +00:00
setlocal nosmartindent
2004-06-13 20:20:40 +00:00
let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<"
2004-06-13 20:20:40 +00:00
if exists("*GetRSTIndent")
finish
endif
2011-09-14 17:55:08 +02:00
let s:itemization_pattern = '^\s*[-*+]\s'
let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+'
2020-04-10 22:10:56 +02:00
let s:note_pattern = '^\.\. '
function! s:get_paragraph_start()
let paragraph_mark_start = getpos("'{")[1]
return getline(paragraph_mark_start) =~ '\S' ? paragraph_mark_start : paragraph_mark_start + 1
endfunction
2011-09-14 17:55:08 +02:00
2004-06-13 20:20:40 +00:00
function GetRSTIndent()
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
return 0
endif
let ind = indent(lnum)
let line = getline(lnum)
2020-04-10 22:10:56 +02:00
let psnum = s:get_paragraph_start()
if psnum != 0
if getline(psnum) =~ s:note_pattern
let ind = 3
endif
endif
2011-09-14 17:55:08 +02:00
if line =~ s:itemization_pattern
let ind += 2
elseif line =~ s:enumeration_pattern
let ind += matchend(line, s:enumeration_pattern)
2004-06-13 20:20:40 +00:00
endif
let line = getline(v:lnum - 1)
2011-09-14 17:55:08 +02:00
" Indent :FIELD: lines. Dont match if there is no text after the field or
" if the text ends with a sent-ender.
if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$'
return matchend(line, '^:.\{-1,}:\s\+')
endif
2004-06-13 20:20:40 +00:00
if line =~ '^\s*$'
execute lnum
2011-09-14 17:55:08 +02:00
call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW')
2004-06-13 20:20:40 +00:00
let line = getline('.')
2011-09-14 17:55:08 +02:00
if line =~ s:itemization_pattern
let ind -= 2
elseif line =~ s:enumeration_pattern
let ind -= matchend(line, s:enumeration_pattern)
2004-06-13 20:20:40 +00:00
elseif line =~ '^\s*\.\.'
2011-09-14 17:55:08 +02:00
let ind -= 3
2004-06-13 20:20:40 +00:00
endif
endif
return ind
endfunction