Skip to content

Commit 64c8105

Browse files
marshallwardchrisbra
authored andcommitted
runtime(rst): Preserve indentation of directives
This patch preserves indentation in comments. It work by removing the explicit 3-space indentation and replaces with with an expression which uses the current value with a minimum of three spaces. Discussed in the mailing list: https://groups.google.com/g/vim_dev/c/rn8ZLDrCbYU Thanks to Friedrich Romstedt for reporting and Christian Brabandt for investigating the issue. closes: #18566 Signed-off-by: Marshall Ward <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 5ffb23c commit 64c8105

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

runtime/indent/rst.vim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
" Maintainer: Marshall Ward <[email protected]>
55
" Previous Maintainer: Nikolai Weibull <[email protected]>
66
" Latest Revision: 2020-03-31
7-
" 2023 Aug 28 by Vim Project (undo_indent)
7+
" 2023 Aug 28 by Vim Project (undo_indent)
8+
" 2025 Oct 13 by Vim project: preserve indentation #18566
89

910
if exists("b:did_indent")
1011
finish
1112
endif
1213
let b:did_indent = 1
1314

15+
" Save and modify cpoptions
16+
let s:save_cpo = &cpo
17+
set cpo&vim
18+
1419
setlocal indentexpr=GetRSTIndent()
1520
setlocal indentkeys=!^F,o,O
1621
setlocal nosmartindent
@@ -27,7 +32,8 @@ let s:note_pattern = '^\.\. '
2732

2833
function! s:get_paragraph_start()
2934
let paragraph_mark_start = getpos("'{")[1]
30-
return getline(paragraph_mark_start) =~ '\S' ? paragraph_mark_start : paragraph_mark_start + 1
35+
return getline(paragraph_mark_start) =~
36+
\ '\S' ? paragraph_mark_start : paragraph_mark_start + 1
3137
endfunction
3238

3339
function GetRSTIndent()
@@ -42,7 +48,7 @@ function GetRSTIndent()
4248
let psnum = s:get_paragraph_start()
4349
if psnum != 0
4450
if getline(psnum) =~ s:note_pattern
45-
let ind = 3
51+
let ind = max([3, ind])
4652
endif
4753
endif
4854

@@ -75,3 +81,7 @@ function GetRSTIndent()
7581

7682
return ind
7783
endfunction
84+
85+
" Restore 'cpoptions'
86+
let &cpo = s:save_cpo
87+
unlet s:save_cpo

0 commit comments

Comments
 (0)