[vim/vim] runtime(sh): Improve the matching of function definitions (PR #19638)

3 views
Skip to first unread message

Aliaksei Budavei

unread,
Mar 11, 2026, 3:11:39 PM (22 hours ago) Mar 11
to vim/vim, Subscribed
  • Drop the remaining undefined shFunctionStart references
    (gone in v7.2b.000, c236c16).
  • 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.
  • 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.

Resolves: #19619

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
http://www.mirbsd.org/htman/i386/man1/mksh.htm


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/19638

Commit Summary

  • 35a63ed runtime(sh): Improve the matching of function definitions

File Changes

(22 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19638@github.com>

Aliaksei Budavei

unread,
Mar 11, 2026, 3:17:38 PM (22 hours ago) Mar 11
to vim/vim, Subscribed
zzzyxwvut left a comment (vim/vim#19638)

@JohnoKing, you seem to know your way around a garden
variety of Korn shells. Can you please take a look at the
proposed changes?

The new submitted tests aim to showcase working code only;
however, I don't have access to neither ksh2020 nor ksh88.
I resorted to blindly re-using composed mksh test cases for
both, which I could verify locally, hoping for current POSIX
compliance otherwise. Let me know if any tests contain
broken code.

Does any Korn shell support id_4 (sub-shelling) syntax?

id_1() { echo $1; }
id_2() ( echo $1; )
function id_3() { echo $1; }
function id_4() ( echo $1; )


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19638/c4041569337@github.com>

Johnothan King

unread,
Mar 11, 2026, 4:30:08 PM (21 hours ago) Mar 11
to vim/vim, Subscribed
JohnoKing left a comment (vim/vim#19638)

Does any Korn shell support id_4 (sub-shelling) syntax?

id_4 is invalid for all ksh implementations, whereas id_1 and id_2 are valid. id_3 is only valid for mksh; for other Korn shells the post-name () are invalid if the function keyword is used. Sub-shelling is only supported via id_2's syntax.

The syntax for the mksh and ksh88 scripts is valid (the ksh88 script fails to run, but that's because ksh88 requires $n be declared with typeset prior to ((...)), which is unrelated to syntax).

The syntax for the ksh2020 script is invalid (my previous PR was somewhat lax about discipline function syntax to avoid making the regex overly convoluted). In ksh93 and ksh2020 functions with a dot in their name are classified as discipline functions. These are used with variables to run code when a variable is expanded or altered (e.g., a kshrc script could have a PS1.get() { or function .sh.tilde.set {, or a regular script might use .sh.pid.unset() {).

The ksh2020 script has functions with the names .a. and ...(). The first one is invalid because function names can't end with a . (although they can start with a .). The second one technically isn't considered an actual name because ksh expects the discipline function to correspond to a variable, which ... doesn't specify. Double dots with no letters between them is also invalid, so foo..append() is invalid syntax, but parent.foo.append() is valid syntax. The valid discipline function types that ought follow the final dot are get, getn, set, append, and unset; other names past the last dot are invalid.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19638/c4042003597@github.com>

Aliaksei Budavei

unread,
Mar 11, 2026, 7:45:18 PM (17 hours ago) Mar 11
to vim/vim, Push

@zzzyxwvut pushed 1 commit.

  • 5307e49 runtime(sh): Improve the matching of function definitions


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19638/before/35a63ed744a2eaab0d178b526d158ad6134a6a85/after/5307e4996dbff7d341cd259389773a2cb2ef55b1@github.com>

Aliaksei Budavei

unread,
Mar 11, 2026, 7:46:08 PM (17 hours ago) Mar 11
to vim/vim, Subscribed
zzzyxwvut left a comment (vim/vim#19638)

Thank you for the detailed explanation.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19638/c4042932982@github.com>

Aliaksei Budavei

unread,
Mar 11, 2026, 8:01:10 PM (17 hours ago) Mar 11
to vim/vim, Push

@zzzyxwvut pushed 1 commit.

  • a3d7603 runtime(sh): Improve the matching of function definitions

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19638/before/5307e4996dbff7d341cd259389773a2cb2ef55b1/after/a3d7603c3b04099164a8166e5f42adf9b8ac1c46@github.com>

Reply all
Reply to author
Forward
0 new messages