Can you please create an issue at my repository?
https://github.com/chrisbra/vim-sh-indent/

I'll have a look then.

Best,
Christian

On Do, 07 Feb 2019, Michael Jarvis wrote:

> It seems that a recent commit (314dd79ca) has broken shell-script indention. 
> This is using Vim 8.1.877.
> 
> To reproduce, try creating a simple shell script with several if-then-else 
> statements. Then edit the script with Vim, and try re-indenting the file with 
> gg=G, and you will see that the indention is not what is expected. 
> 
> At first I suspected it might be something in my configuration, but I get the 
> same problem when running without a vimrc ("vim -u NONE") and manually 
> entering ":filetype plugin indent on" and "set filetype=sh". 
> 
> For instance, consider this script. Note that the "if" and "then" are 
> represented with both styles, where if and then are on the same line, and 
> also where they are on separate lines. Both styles are valid, and a matter of 
> preference. 
> 
> #!/bin/bash
> # Use gg=G to re-indent whole file
> if [[ /bin/true ]]; then
>     echo "hello true"
> else
>     if [[ /bin/false ]]; then
>         echo "hello false"
>     else
>         echo "true"
>     fi
> fi
> if [[ /bin/true ]]
> then
>     echo "hello true"
> else
>     if [[ /bin/false ]]
>     then
>         echo "hello false"
>     else
>         echo "true"
>     fi
> fi
> 
> This gets reformatted by Vim 8.1.877 to be:
> 
> #!/bin/bash
> # Use gg=G to re-indent whole file
> 
> if [[ /bin/true ]]; then
>         echo "hello true"
> else
>         if [[ /bin/false ]]; then
>                 echo "hello false"
>         else
>                 echo "true"
>         fi
>         fi
> 
>         if [[ /bin/true ]]
>         then
>                 echo "hello true"
>         else
>                 if [[ /bin/false ]]
>                 then
>                         echo "hello false"
>                 else
>                         echo "true"
>         fi
>         fi
> 
> It appears that the author was trying to improve the indention for shell 
> scripts, but it seems to have made things worse. :-/ 
> 
> Here's a patch that I made locally that seems to fix it. I am sure there is a 
> better way to do this, but I was in a rush. 
> 
> diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
> index c93be3195..028dcf275 100644
> --- a/runtime/indent/sh.vim
> +++ b/runtime/indent/sh.vim
> @@ -114,12 +114,13 @@ function! GetShIndent()
>    let line = curline
>    " Current line is a endif line, so get indent from start of "if condition" 
> line
>    " TODO: should we do the same for other "end" lines?
> -  if curline =~ '^\s*\%(fi\)\s*\%(#.*\)\=$'
> -    let previous_line = search('if.\{-\};\s*then\s*\%(#.*\)\=$', 'bnW')
> -    if previous_line > 0
> -      let ind = indent(previous_line)
> -    endif
> -  elseif line =~ '^\s*\%(then\|do\|else\|elif\|done\|end\)\>' || 
> s:end_block(line)
> +" if curline =~ '^\s*\%(fi\)\s*\%(#.*\)\=$'
> +"   let previous_line = search('if.\{-\};\s*then\s*\%(#.*\)\=$', 'bnW')
> +"   if previous_line > 0
> +"     let ind = indent(previous_line)
> +"   endif
> +" elseif line =~ '^\s*\%(then\|do\|else\|elif\|done\|end\)\>' || 
> s:end_block(line)
> +  if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || 
> s:end_block(line)
>      let ind -= s:indent_value('default')
>    elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1))
>      let ind -= s:indent_value('default')
> 


Mit freundlichen Grüßen
Christian
-- 
Dem Storch gegenüber haben die Frösche eine beschränkte Souveränität.
                -- David Frost

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui