GithubHelp home page GithubHelp logo

Indentation of `esac` is off about vim-endwise HOT 4 CLOSED

tpope avatar tpope commented on September 3, 2024
Indentation of `esac` is off

from vim-endwise.

Comments (4)

tpope avatar tpope commented on September 3, 2024

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.

from vim-endwise.

telemachus avatar telemachus commented on September 3, 2024

@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.

from vim-endwise.

tangledhelix avatar tangledhelix commented on September 3, 2024

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).

from vim-endwise.

telemachus avatar telemachus commented on September 3, 2024

@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).

from vim-endwise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.