Skip to content

Commit 0acd3ab

Browse files
lzapchrisbra
authored andcommitted
runtime(sh): better function support for bash/zsh in indent script
closes: #16052 Signed-off-by: Lukas Zapletal <lzap+git@redhat.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 460799d commit 0acd3ab

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

runtime/indent/sh.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
" License: Vim (see :h license)
88
" Repository: https://github.com/chrisbra/vim-sh-indent
99
" Changelog:
10+
" 20241411 - Detect dash character in function keyword for
11+
" bash mode (issue #16049)
1012
" 20190726 - Correctly skip if keywords in syntax comments
1113
" (issue #17)
1214
" 20190603 - Do not indent in zsh filetypes with an `if` in comments
@@ -195,7 +197,9 @@ endfunction
195197
function! s:is_function_definition(line)
196198
return a:line =~ '^\s*\<\k\+\>\s*()\s*{' ||
197199
\ a:line =~ '^\s*{' ||
198-
\ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{'
200+
\ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{' ||
201+
\ ((&ft is# 'zsh' || s:is_bash()) &&
202+
\ a:line =~ '^\s*function\s*\S\+\s*\%(()\)\?\s*{' )
199203
endfunction
200204

201205
function! s:is_array(line)

runtime/indent/testdir/bash.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# vim: set ft=bash sw=2 noet:
3+
4+
# START_INDENT
5+
a = 10
6+
b = 20
7+
8+
function add() {
9+
c = $((a + b))
10+
}
11+
12+
function print {
13+
# do nothing
14+
}
15+
16+
if [[ $c -ge 15 ]];
17+
then
18+
print("ok")
19+
else
20+
print("not ok")
21+
fi
22+
# END_INDENT

runtime/indent/testdir/bash.ok

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# vim: set ft=bash sw=2 noet:
3+
4+
# START_INDENT
5+
a = 10
6+
b = 20
7+
8+
function add() {
9+
c = $((a + b))
10+
}
11+
12+
function print {
13+
# do nothing
14+
}
15+
16+
if [[ $c -ge 15 ]];
17+
then
18+
print("ok")
19+
else
20+
print("not ok")
21+
fi
22+
# END_INDENT

0 commit comments

Comments
 (0)