vim-sh-indent icon indicating copy to clipboard operation
vim-sh-indent copied to clipboard

inside a curly brace scope, lines following a function def become, incorrectly, unindented

Open wwalker opened this issue 4 years ago • 2 comments

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 "$@" )
}
}

wwalker avatar Apr 06 '21 01:04 wwalker

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 "$@" )
  }
}

wwalker avatar Apr 30 '21 16:04 wwalker

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.

chrisbra avatar Jun 23 '21 13:06 chrisbra