Mercurial > vim
annotate runtime/indent/rst.vim @ 34655:a63ac82f6e7f
runtime(json5): add basic indent support (#14298)
Commit: https://github.com/vim/vim/commit/63833bb0217fbfd5556a77103bd6c1ce78cfd996
Author: Rocco Mao <dapeng.mao@qq.com>
Date: Wed Mar 27 02:02:44 2024 +0800
runtime(json5): add basic indent support (https://github.com/vim/vim/issues/14298)
Signed-off-by: Rocco Mao <dapeng.mao@qq.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 26 Mar 2024 19:15:03 +0100 |
parents | 5c220cf30f1f |
children |
rev | line source |
---|---|
7 | 1 " Vim indent file |
19968 | 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 | |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
19968
diff
changeset
|
7 " 2023 Aug 28 by Vim Project (undo_indent) |
7 | 8 |
9 if exists("b:did_indent") | |
10 finish | |
11 endif | |
12 let b:did_indent = 1 | |
13 | |
14 setlocal indentexpr=GetRSTIndent() | |
375 | 15 setlocal indentkeys=!^F,o,O |
1216 | 16 setlocal nosmartindent |
7 | 17 |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
19968
diff
changeset
|
18 let b:undo_indent = "setlocal indentexpr< indentkeys< smartindent<" |
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
19968
diff
changeset
|
19 |
7 | 20 if exists("*GetRSTIndent") |
21 finish | |
22 endif | |
23 | |
3082 | 24 let s:itemization_pattern = '^\s*[-*+]\s' |
25 let s:enumeration_pattern = '^\s*\%(\d\+\|#\)\.\s\+' | |
19968 | 26 let s:note_pattern = '^\.\. ' |
27 | |
28 function! s:get_paragraph_start() | |
29 let paragraph_mark_start = getpos("'{")[1] | |
30 return getline(paragraph_mark_start) =~ '\S' ? paragraph_mark_start : paragraph_mark_start + 1 | |
31 endfunction | |
3082 | 32 |
7 | 33 function GetRSTIndent() |
34 let lnum = prevnonblank(v:lnum - 1) | |
35 if lnum == 0 | |
36 return 0 | |
37 endif | |
38 | |
39 let ind = indent(lnum) | |
40 let line = getline(lnum) | |
41 | |
19968 | 42 let psnum = s:get_paragraph_start() |
43 if psnum != 0 | |
44 if getline(psnum) =~ s:note_pattern | |
45 let ind = 3 | |
46 endif | |
47 endif | |
48 | |
3082 | 49 if line =~ s:itemization_pattern |
50 let ind += 2 | |
51 elseif line =~ s:enumeration_pattern | |
52 let ind += matchend(line, s:enumeration_pattern) | |
7 | 53 endif |
54 | |
55 let line = getline(v:lnum - 1) | |
56 | |
3082 | 57 " Indent :FIELD: lines. Don’t match if there is no text after the field or |
58 " if the text ends with a sent-ender. | |
59 if line =~ '^:.\+:\s\{-1,\}\S.\+[^.!?:]$' | |
60 return matchend(line, '^:.\{-1,}:\s\+') | |
61 endif | |
62 | |
7 | 63 if line =~ '^\s*$' |
64 execute lnum | |
3082 | 65 call search('^\s*\%([-*+]\s\|\%(\d\+\|#\)\.\s\|\.\.\|$\)', 'bW') |
7 | 66 let line = getline('.') |
3082 | 67 if line =~ s:itemization_pattern |
68 let ind -= 2 | |
69 elseif line =~ s:enumeration_pattern | |
70 let ind -= matchend(line, s:enumeration_pattern) | |
7 | 71 elseif line =~ '^\s*\.\.' |
3082 | 72 let ind -= 3 |
7 | 73 endif |
74 endif | |
75 | |
76 return ind | |
77 endfunction |