Files
org-vim/runtime/syntax/testdir/input/sh_functions_bash.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
695 B
Bash
Raw Normal View History

runtime(sh): Improve the matching of function definitions - Drop the remaining undefined "shFunctionStart" references (gone in v7.2b.000, c236c16d0). - Revise nestable contexts where function definitions are supported: * Stop looking for function definitions in arithmetic expressions. * Recognise function definitions enclosing other function definitions. - In addition to grouping commands "{}" and "()", also match other compound commands (e.g. "if"; see "shFunctionCmd*") whenever these commands are supported as complete function bodies. - Balance body delimiters "(" and ")" for "shFunctionFour" in Bash; match such function bodies whenever the use of the function parameter list "()" token is optional, i.e. when the "function" reserved word is present. - Enable the use of "shFunctionFour" definitions. - Do not claim optional leading whitespace characters before a matched function definition. - Prefer patterns with ASCII atoms (e.g. "\h") to equivalent collections (e.g. "[A-Za-z_]") for speed. - Accommodate word-boundary assertions in function name patterns to names that may start and/or end with supported non-word characters, e.g. "@test:". - Match more valid function names in Bash: non-ASCII names, non-word names. - Allow for function names with "do", "done", etc. prefixes; confine these name checks to "shDoError" and "shIfError". fixes: #19619 related: #19638 References: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_09_04 https://gitweb.git.savannah.gnu.org/gitweb/?p=bash.git;a=blob_plain;f=doc/bash.html;hb=637f5c8696a6adc9b4519f1cd74aa78492266b7f https://web.archive.org/web/20151105130220/http://www.research.att.com/sw/download/man/man1/ksh88.html https://web.archive.org/web/20151025145158/http://www2.research.att.com/sw/download/man/man1/ksh.html http://www.mirbsd.org/htman/i386/man1/mksh.htm Co-authored-by: Johnothan King <johnothanking@protonmail.com> Co-authored-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
2026-03-24 20:34:15 +00:00
#!/bin/bash
# VIM_TEST_SETUP setlocal fen fdc=2 fdl=8 fdm=syntax
# VIM_TEST_SETUP let g:sh_fold_enabled = 1 + 2 + 4
typeset -i n=0
doosie() ((n+=1)); doosie
donee() [[ -n $# ]]; donee
thence()
until :
do
:
done
thence
whiles() while false; do :; done; whiles
elsewhere() if :
then :; fi; elsewhere
selector() select x in 1 2; do
break
done
selector 0</dev/null 2>/dev/null || :
cased() case "$#" in *) :;; esac; cased
fore()
for x in 1 2
do
:
done
fore
iffy() for ((;;))
do
break
done
iffy
if :; then
function !?#()
(
function @α! {
echo "$1"
}
@α! "$1"
)
eval !?\# "$1"
fi
namespace ()
{ echo $#;
}; namespace $@