]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(sh): Keep function name patterns engine neutral
authorAliaksei Budavei <0x000c70@gmail.com>
Thu, 2 Apr 2026 16:59:28 +0000 (16:59 +0000)
committerChristian Brabandt <cb@256bit.org>
Thu, 2 Apr 2026 16:59:28 +0000 (16:59 +0000)
Request less backtracking to function-name candidates for
nonlinear patterns with any regexp engine BUT force using
the old engine with these patterns to avoid incurring an
additional penalty, according to ":syntime report", when the
new regexp engine is preferred.

fixes:  #19847
closes: #19849

Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/syntax/sh.vim

index f9aaa932a4e454c8aa0eb838e9849db0b7c1829d..05eb488d534a8b0b85cf953101b9d28f1cd5473d 100644 (file)
@@ -23,6 +23,7 @@
 "              2026 Feb 11 improve support for KornShell function names and variables
 "              2026 Feb 15 improve comment handling #19414
 "              2026 Mar 23 improve matching of function definitions #19638
+"              2026 Apr 02 improve matching of function definitions #19849
 " }}}
 " Version:             208
 " Former URL:          http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH
@@ -665,12 +666,12 @@ ShFoldFunctions syn region shFunctionSubSh        matchgroup=shFunctionSubShRegion star
 
 if exists("b:is_bash")
     syn keyword shFunctionKey coproc
-    syn match shFunctionCmdOne "^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)" skipwhite skipnl nextgroup=@shFunctionCmds
-    syn match shFunctionCmdTwo "\%(\<\k\+\>\|[^()<>|&$;\t ]\+\)\+\ze\s*\%(()\ze\)\=\_s*\%(\<\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"  contained skipwhite skipnl nextgroup=@shFunctionCmds
-    syn match shFunctionOne    "^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\ze\_s*{"   skipwhite skipnl nextgroup=shFunctionExpr
-    syn match shFunctionTwo    "\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\ze\s*\%(()\ze\)\=\_s*{"        contained skipwhite skipnl nextgroup=shFunctionExpr
-    syn match shFunctionThree  "^\s*\zs\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\s*()\ze\_s*((\@!"       skipwhite skipnl nextgroup=shFunctionSubSh
-    syn match shFunctionFour   "\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\ze\s*\%(\%(()\ze\)\=\)\@>\_s*((\@!"    contained skipwhite skipnl nextgroup=shFunctionSubSh
+    syn match shFunctionCmdOne "\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"    skipwhite skipnl nextgroup=@shFunctionCmds
+    syn match shFunctionCmdTwo "\%#=1\%(\%(\<\k\+\>\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\s*\%(()\ze\)\=\_s*\%(\<\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"     contained skipwhite skipnl nextgroup=@shFunctionCmds
+    syn match shFunctionOne    "\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*{"      skipwhite skipnl nextgroup=shFunctionExpr
+    syn match shFunctionTwo    "\%#=1\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\s*\%(()\ze\)\=\_s*{"   contained skipwhite skipnl nextgroup=shFunctionExpr
+    syn match shFunctionThree  "\%#=1^\s*\zs\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\s*()\ze\_s*((\@!"  skipwhite skipnl nextgroup=shFunctionSubSh
+    syn match shFunctionFour   "\%#=1\%(\%(\<\k\+\|[^()<>|&$;\t ]\+\)\+\)\@>\ze\s*\%(\%(()\ze\)\=\)\@>\_s*((\@!"       contained skipwhite skipnl nextgroup=shFunctionSubSh
 elseif exists("b:is_ksh88")
     " AT&T ksh88
     syn match shFunctionCmdOne "^\s*\zs\h\w*\s*()\ze\_s*\%(\%(for\|case\|select\|if\|while\|until\)\>\|\[\[\s\|((\)"   skipwhite skipnl nextgroup=@shFunctionCmds
@@ -681,13 +682,13 @@ elseif exists("b:is_mksh")
     " MirBSD ksh is the wild west of absurd and abstruse function names...
     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
     syn match shFunctionOne    "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*{"    skipwhite skipnl nextgroup=shFunctionExpr
-    syn match shFunctionTwo    "\%([@!+.%,:-]\+\|\<\w\+\)*[-A-Za-z_.%,0-9:]\ze\s*\%(()\ze\)\=\_s*{"    contained skipwhite skipnl nextgroup=shFunctionExpr
+    syn match shFunctionTwo    "\%#=1\%(\%(\<\w\+\|[@!+.%,:-]\+\)*[-A-Za-z_.%,0-9:]\)\@>\ze\s*\%(()\ze\)\=\_s*{"       contained skipwhite skipnl nextgroup=shFunctionExpr
     syn match shFunctionThree  "^\s*\zs[-A-Za-z_@!+.%,0-9:]*[-A-Za-z_.%,0-9:]\s*()\ze\_s*((\@!"        skipwhite skipnl nextgroup=shFunctionSubSh
 elseif exists("b:is_kornshell")
     " ksh93
     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
     syn match shFunctionOne    "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*{"  skipwhite skipnl nextgroup=shFunctionExpr
-    syn match shFunctionTwo    "\%(\.\|\<\h\+\)[A-Za-z_.0-9]*\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
+    syn match shFunctionTwo    "\%(\<\h\+\|\.\)[A-Za-z_.0-9]*\ze\_s*{" contained skipwhite skipnl nextgroup=shFunctionExpr
     syn match shFunctionThree  "^\s*\zs[A-Za-z_.][A-Za-z_.0-9]*\s*()\ze\_s*((\@!"      skipwhite skipnl nextgroup=shFunctionSubSh
     syn match shNamespaceOne   "\<\h\w*\>\ze\_s*{"     contained skipwhite skipnl nextgroup=shFunctionExpr
 else