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

Indentation of esac is off #39

Closed
telemachus opened this issue Sep 11, 2013 · 4 comments
Closed

Indentation of esac is off #39

telemachus opened this issue Sep 11, 2013 · 4 comments

Comments

@telemachus
Copy link
Contributor

With vim-endwise installed, the indentation of case...esac structures in shell scripts is off.

The result is something like this:

case "$1" in                                                               
     foo)                                                                
         echo hello                                                    
         ;;                                                                   
     esac

An earlier comment suggests that this is a known problem. However, @tangledhelix seems to say there that the problem occurs with or without vim-endwise. That's not the case, I don't think. I only have this problem with vim-endwise installed.

@tpope
Copy link
Owner

tpope commented Sep 11, 2013

You will see the same issue without endwise if you try to create an empty case statement. Not a lot I can do about that.

@tpope tpope closed this as completed Sep 11, 2013
@telemachus
Copy link
Contributor Author

@tpope No, that's exactly what I'm saying: If I uninstall endwise, I don't get the same behavior. If endwise isn't present, the indentation is correct by default.

Ah, now I see: the issue is an empty case statement. Duh, sorry. In that case, honestly, it seems better for vim-endwise not to do case...esac in shell scripts. But at least now I get the issue.

@tangledhelix
Copy link
Contributor

A comment from @telemachus I received by email earlier notes that Super Shell Indent was in use and that it fixed the esac indent problem -- is that still in use even when vim-endwise is not installed, @telemachus? Perhaps that could explain why the indentation works (for you) without vim-endwise, when @tpope and I are not able to reproduce that behavior (I just tested again).

@telemachus
Copy link
Contributor Author

@tangledhelix Yes and no. @tpope was right, and I was confused. If you create an empty case...esac statement, then the indentation is off whether or not I have vim-endwise. This is what I didn't see at first.

case
    esac

case "$1" in
    foo)
        echo hello
        ;;
esac

But that said, if I add Super Shell Indent, then everything works -- whether or not I have vim-endwise, including empty case statements.

So I now understand that the real problem is in Vim's indentation file for shell. Having said that, unless that gets fixed, I wonder whether it isn't better to remove case...esac handling from vim-endwise. Just my two cents.

For what it's worth, a very small edit to the built-in shell indentation seems to fix things:

$ diff old-sh.vim sh.vim
79a80,81
>   elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1))
>     let ind -= s:indent_value('default')
156a159,166
> function! s:is_case_empty(line)
>     if a:line =~ '^\s*$' || a:line =~ '^\s*#'
>         return s:is_case_empty(getline(v:lnum - 1))
>     else
>         return a:line =~ '^\s*case\>'
>     endif
> endfunction
> 

Unfortunately, I'm a complete rookie at Vimscript, so I'm not sure how much to trust this. Essentially though, I'm just testing for an "empty case" by checking if the previous line is case or empty (and if it's empty retrying with the line before that until we hit a non-empty line).

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

3 participants