Mercurial > vim
changeset 36554:d8231da22aa0 draft
runtime(sh): better function support for bash/zsh in indent script
Commit: https://github.com/vim/vim/commit/0acd3abfadf54a97a3cad999791603aa6a8b2248
Author: Lukas Zapletal <lzap+git@redhat.com>
Date: Thu Nov 14 21:50:15 2024 +0100
runtime(sh): better function support for bash/zsh in indent script
closes: https://github.com/vim/vim/issues/16052
Signed-off-by: Lukas Zapletal <lzap+git@redhat.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 14 Nov 2024 22:00:04 +0100 |
parents | 02b122f33c10 |
children | facb5fcbda75 |
files | runtime/indent/sh.vim runtime/indent/testdir/bash.in runtime/indent/testdir/bash.ok |
diffstat | 3 files changed, 49 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/indent/sh.vim +++ b/runtime/indent/sh.vim @@ -7,6 +7,8 @@ " License: Vim (see :h license) " Repository: https://github.com/chrisbra/vim-sh-indent " Changelog: +" 20241411 - Detect dash character in function keyword for +" bash mode (issue #16049) " 20190726 - Correctly skip if keywords in syntax comments " (issue #17) " 20190603 - Do not indent in zsh filetypes with an `if` in comments @@ -195,7 +197,9 @@ endfunction function! s:is_function_definition(line) return a:line =~ '^\s*\<\k\+\>\s*()\s*{' || \ a:line =~ '^\s*{' || - \ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{' + \ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{' || + \ ((&ft is# 'zsh' || s:is_bash()) && + \ a:line =~ '^\s*function\s*\S\+\s*\%(()\)\?\s*{' ) endfunction function! s:is_array(line)
new file mode 100644 --- /dev/null +++ b/runtime/indent/testdir/bash.in @@ -0,0 +1,22 @@ +#!/bin/bash +# vim: set ft=bash sw=2 noet: + +# START_INDENT +a = 10 +b = 20 + +function add() { +c = $((a + b)) +} + +function print { +# do nothing +} + +if [[ $c -ge 15 ]]; +then +print("ok") +else +print("not ok") +fi +# END_INDENT
new file mode 100644 --- /dev/null +++ b/runtime/indent/testdir/bash.ok @@ -0,0 +1,22 @@ +#!/bin/bash +# vim: set ft=bash sw=2 noet: + +# START_INDENT +a = 10 +b = 20 + +function add() { + c = $((a + b)) +} + +function print { + # do nothing +} + +if [[ $c -ge 15 ]]; +then + print("ok") +else + print("not ok") +fi +# END_INDENT