Skip to content

Commit 955c02d

Browse files
zzzyxwvutchrisbra
authored andcommitted
runtime(sh): Distinguish parts of function definitions
- Highlight keywords "function" and "namespace" with the "Keyword" group ("shFunctionKey"). - Highlight function body delimiters "{" and "}" with the "Delimiter" group ("shFunctionExprRegion"). - Highlight function body delimiters "(" and ")" with the "Operator" group ("shFunctionSubShRegion"). - Also, follow one style in folding all supported variants of function bodies for grouping commands too by enclosing a delimited function body, e.g. "{" and "}", in a fold and leaving its function header, e.g. "function f()", out of it when the header is written on a separate line. To restore previous colouring, add to "after/syntax/sh.vim": ------------------------------------------------------------ hi link shFunctionKey Function hi link shFunctionExprRegion Function hi link shFunctionSubShRegion Function ------------------------------------------------------------ fixes: vim/vim#19638 (comment) closes: #19638 Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 9c0d057 commit 955c02d

52 files changed

Lines changed: 258 additions & 250 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

runtime/syntax/sh.vim

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -660,40 +660,43 @@ if !exists("b:is_posix")
660660
syn keyword shFunctionKey function skipwhite skipnl nextgroup=shDoError,shIfError,shFunctionTwo,shFunctionFour,shFunctionCmdTwo
661661
endif
662662

663+
ShFoldFunctions syn region shFunctionExpr matchgroup=shFunctionExprRegion start="{" end="}" contains=@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
664+
ShFoldFunctions syn region shFunctionSubSh matchgroup=shFunctionSubShRegion start="(" end=")" contains=@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
665+
663666
if exists("b:is_bash")
664667
syn keyword shFunctionKey coproc
665668
syn match shFunctionCmdOne "^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds
666669
syn match shFunctionCmdTwo "\%(\<\k\+\>\|[^()<>|&$;\t ]\+\)\+\ze\s*\%(()\ze\)\=\_s*\%(\<\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" contained skipwhite skipnl nextgroup=@shFunctionCmds
667-
ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
668-
ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
669-
ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\_s*((\@!" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
670-
ShFoldFunctions syn region shFunctionFour matchgroup=shFunction start="\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*\%(\%(()\)\=\)\@>\_s*((\@!" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
670+
syn match shFunctionOne "^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr
671+
syn match shFunctionTwo "\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\ze\s*\%(()\ze\)\=\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
672+
syn match shFunctionThree "^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh
673+
syn match shFunctionFour "\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\ze\s*\%(\%(()\ze\)\=\)\@>\_s*((\@!" contained skipwhite skipnl nextgroup=shFunctionSubSh
671674
elseif exists("b:is_ksh88")
672675
" AT&T ksh88
673676
syn match shFunctionCmdOne "^\s*\zs\h\w*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds
674-
ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\zs\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
675-
ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\<\h\w*\>\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
676-
ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\zs\h\w*\s*()\_s*((\@!" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
677+
syn match shFunctionOne "^\s*\zs\h\w*\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr
678+
syn match shFunctionTwo "\<\h\w*\>\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
679+
syn match shFunctionThree "^\s*\zs\h\w*\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh
677680
elseif exists("b:is_mksh")
678681
" MirBSD ksh is the wild west of absurd and abstruse function names...
679682
syn match shFunctionCmdOne "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds
680-
ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
681-
ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\%([@!+.%,:-]\+\|\<\w\+\)*[-A-Za-z_.%,0-9:]\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
682-
ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\_s*((\@!" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
683+
syn match shFunctionOne "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr
684+
syn match shFunctionTwo "\%([@!+.%,:-]\+\|\<\w\+\)*[-A-Za-z_.%,0-9:]\ze\s*\%(()\ze\)\=\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
685+
syn match shFunctionThree "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh
683686
elseif exists("b:is_kornshell")
684687
" ksh93
685688
syn match shFunctionCmdOne "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds
686-
ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
687-
ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\%(\.\|\<\h\+\)[A-Za-z_.0-9]*\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
688-
ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\_s*((\@!" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
689-
ShFoldFunctions syn region shNamespaceOne matchgroup=shFunction start="\<\h\w*\>\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
689+
syn match shFunctionOne "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr
690+
syn match shFunctionTwo "\%(\.\|\<\h\+\)[A-Za-z_.0-9]*\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
691+
syn match shFunctionThree "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*((\@!" skipwhite skipnl nextgroup=shFunctionSubSh
692+
syn match shNamespaceOne "\<\h\w*\>\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
690693
else
691694
syn match shFunctionCmdOne "^\s*\zs\h\w*\s*()\ze\_s*\%(for\|case\|if\|while\|until\)\>" skipwhite skipnl nextgroup=@shFunctionCmds
692695
syn match shFunctionCmdTwo "\<\h\w*\s*()\ze\_s*\%(for\|case\|if\|while\|until\)\>" contained skipwhite skipnl nextgroup=@shFunctionCmds
693-
ShFoldFunctions syn region shFunctionOne matchgroup=shFunction start="^\s*\zs\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
694-
ShFoldFunctions syn region shFunctionTwo matchgroup=shFunction start="\<\h\w*\>\s*()\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
695-
ShFoldFunctions syn region shFunctionThree matchgroup=shFunction start="^\s*\zs\h\w*\s*()\_s*(" end=")" contains=@shFunctionList skipwhite skipnl nextgroup=shQuickComment
696-
ShFoldFunctions syn region shFunctionFour matchgroup=shFunction start="\<\h\w*\>\s*()\_s*(" end=")" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shQuickComment
696+
syn match shFunctionOne "^\s*\zs\h\w*\s*()\ze\_s*{" skipwhite skipnl nextgroup=shFunctionExpr
697+
syn match shFunctionTwo "\<\h\w*\>\s*()\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
698+
syn match shFunctionThree "^\s*\zs\h\w*\s*()\ze\_s*(" skipwhite skipnl nextgroup=shFunctionSubSh
699+
syn match shFunctionFour "\<\h\w*\>\s*()\ze\_s*(" contained skipwhite skipnl nextgroup=shFunctionSubSh
697700
endif
698701

699702
if !exists("g:sh_no_error")
@@ -902,9 +905,6 @@ if !exists("skip_sh_syntax_inits")
902905
hi def link shEchoDelim shOperator
903906
hi def link shEchoQuote shString
904907
hi def link shForPP shLoop
905-
hi def link shFunction Function
906-
hi def link shFunctionCmdOne shFunction
907-
hi def link shFunctionCmdTwo shFunction
908908
hi def link shEmbeddedEcho shString
909909
hi def link shEscape shCommandSub
910910
hi def link shExDoubleQuote shDoubleQuote
@@ -982,8 +982,16 @@ if !exists("skip_sh_syntax_inits")
982982
hi def link shConditional Conditional
983983
hi def link shCtrlSeq Special
984984
hi def link shExprRegion Delimiter
985-
hi def link shFunctionKey Function
986-
hi def link shFunctionName Function
985+
hi def link shFunctionKey Keyword
986+
hi def link shFunctionOne Function
987+
hi def link shFunctionTwo shFunctionOne
988+
hi def link shFunctionThree shFunctionOne
989+
hi def link shFunctionFour shFunctionOne
990+
hi def link shFunctionCmdOne shFunctionOne
991+
hi def link shFunctionCmdTwo shFunctionOne
992+
hi def link shFunctionExprRegion shExprRegion
993+
hi def link shFunctionSubShRegion shSubShRegion
994+
hi def link shNamespaceOne Function
987995
hi def link shNumber Number
988996
hi def link shOperator Operator
989997
hi def link shRepeat Repeat

runtime/syntax/testdir/dumps/sh_06_00.dump

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_06_01.dump

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_06_02.dump

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_06_03.dump

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_07_00.dump

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_07_01.dump

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_07_02.dump

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_07_03.dump

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/syntax/testdir/dumps/sh_07_04.dump

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)