vim-sh-indent
vim-sh-indent copied to clipboard
inside a curly brace scope, lines following a function def become, incorrectly, unindented
Expected indention:
# process / ps stuff
# shellcheck disable=SC2046
{
pspg(){
ps -lf $( pgrep -f "$@" )
}
pspgt(){
ps -o lstart,cmd $( pgrep -f "$@" )
}
}
Actual indention:
# process / ps stuff
# shellcheck disable=SC2046
{
pspg(){
ps -lf $( pgrep -f "$@" )
}
pspgt(){
ps -o lstart,cmd $( pgrep -f "$@" )
}
}
New source to show that only after a function def does indention break.
# process / ps stuff
# shellcheck disable=SC2046
{
pspg() {
ps -lf $( pgrep -f "$@" )
}
pspgt() {
ps -o lstart,cmd $( pgrep -f "$@" )
}
}
{
just-a command not-a function
another command not-a function
}
# process / ps stuff
# shellcheck disable=SC2046
{
pspg(){
ps -lf $( pgrep -f "$@" )
}
just-a command not-a function
pspgt(){
ps -o lstart,cmd $( pgrep -f "$@" )
}
}
Assuming, the indentation should always start at the same level as the previous closing brace, this patch works:
diff --git a/indent/sh.vim b/indent/sh.vim
index d2fb1ba..aa47c6d 100644
--- a/indent/sh.vim
+++ b/indent/sh.vim
@@ -109,7 +109,7 @@ function! GetShIndent()
let ind += s:indent_value('continuation-line')
endif
elseif s:end_block(line) && !s:start_block(line)
- let ind -= s:indent_value('default')
+ let ind = indent(lnum)
elseif pnum != 0 &&
\ s:is_continuation_line(pline) &&
\ !s:end_block(curline) &&
However, test 01 starts to fail: https://gist.github.com/chrisbra/f143fe1ef1e4df7f7ed21818e9e2ebc0
I am not sure, if this is a good thing and the test should be changed or if the above change brakes other things slightly.