runtime(sh): update sh indent script
Commit:
https://github.com/vim/vim/commit/711f4a07f356cbe6f1d6d67994519f0b36a100f2
Author: Christian Brabandt <[email protected]>
Date: Tue Mar 18 22:36:28 2025 +0100
runtime(sh): update sh indent script
fixes: https://github.com/vim/vim/issues/16930
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index 184e82987..cc433ba5f 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -7,6 +7,7 @@
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-sh-indent
" Changelog:
+" 20250318 - Detect local arrays in functions
" 20241411 - Detect dash character in function keyword for
" bash mode (issue #16049)
" 20190726 - Correctly skip if keywords in syntax comments
@@ -73,6 +74,8 @@ function! s:indent_value(option)
endfunction
function! GetShIndent()
+ let mode = mode()
+
let curline = getline(v:lnum)
let lnum = prevnonblank(v:lnum - 1)
if lnum == 0
@@ -86,8 +89,11 @@ function! GetShIndent()
" Check contents of previous lines
" should not apply to e.g. commented lines
- if line =~
'^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>'
||
- \ (&ft is# 'zsh' && line =~
'^\s*\<\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>')
+
+ if s:start_block(line)
+ let ind += s:indent_value('default')
+ elseif line =~
'^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>\($\|\s\)'
||
+ \ (&ft is# 'zsh' && line =~
'^\s*\<\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>\($\|\s\)')
if !s:is_end_expression(line)
let ind += s:indent_value('default')
endif
@@ -111,7 +117,7 @@ function! GetShIndent()
let ind += s:indent_value('continuation-line')
endif
elseif s:end_block(line) && !s:start_block(line)
- let ind = indent(lnum)
+ let ind -= s:indent_value('default')
elseif pnum != 0 &&
\ s:is_continuation_line(pline) &&
\ !s:end_block(curline) &&
@@ -122,7 +128,7 @@ function! GetShIndent()
while !s:is_empty(getline(i)) && i > pnum
let i -= 1
endw
- if i == pnum
+ if i == pnum && (s:is_continuation_line(line) || pline =~ '{\s*\(#.*\)\=$')
let ind += ind2
else
let ind = ind2
@@ -136,7 +142,11 @@ function! GetShIndent()
" TODO: should we do the same for other "end" lines?
if curline =~ '^\s*\%(fi\);\?\s*\%(#.*\)\=$'
let ind = indent(v:lnum)
- let previous_line = searchpair('\<if\>', '', '\<fi\>\zs', 'bnW',
'synIDattr(synID(line("."),col("."), 1),"name") =~? "comment\|quote"')
+ " in insert mode, try to place the cursor after the fi statement
+ let endp = '\<fi\>' .. (mode ==? 'i' ? '\zs' : '')
+ let startp = '^\s*\<if\>'
+ let previous_line = searchpair(startp, '', endp , 'bnW',
+ \ 'synIDattr(synID(line("."),col("."), 1),"name") =~?
"comment\|quote\|option"')
if previous_line > 0
let ind = indent(previous_line)
endif
@@ -167,7 +177,13 @@ function! GetShIndent()
elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1tuekD-001IBi-DL%40256bit.org.