Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wwalker opened this issue Apr 6, 2021 · 2 comments

Comments

@wwalker
Copy link
Contributor

wwalker commented Apr 6, 2021

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 wwalker changed the title functions in curly brace scope do not indent properly inside a curly brace scope, lines following a function def become, incorrectly, unindented Apr 30, 2021
@wwalker
Copy link
Contributor Author

wwalker commented Apr 30, 2021

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

@chrisbra
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants