Subject: bug#77746: [PATCH] sh-mode: Fix incorrect word syntax for punctuation in sh-mode

From: Stefan Kangas <[email-masked]>
Date: Sun, 13 Apr 2025 22:13:04 -0700

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

>>> In sh and Bash, the characters !%^~:.,= and are not valid in variable or
>>> function names.
>
> I'm not positive about all of them, but at least some of those can
> appear in the names of commands.
>
>>> Assigning them the "_" syntax causes Emacs to treat them as word
>>> constituents,
>
> Not quite: it makes them appear as "symbol constituents".
>
>>> disrupting navigation and completion (e.g. dabbrev-expand,
>>> forward-word, etc.).
>
> `forward-word` for example shouldn't be affected (unless you enable
> `superword-mode`).  `dabbrev-expand` OTOH is affected, indeed.
>
>>> The attached patch updates the syntax table in sh-mode to mark
>>> these characters as punctuation, correcting the issue.
>> TBH, such a change sounds scary, as it could cause all kinds of
>> unintended changes in behavior.
>
> It's indeed risky/delicate.

Yes, this one does not look straightforward.

IMO, risky changes like this one should really come with a reasonably
comprehensive set of unit tests too, to give us better confidence that
we have considered a reasonable amount of use cases.

Sadly, our unit tests in this area do not have very good coverage as it
stands, so this would take some work.

> Rather than go straight to changing the syntax-table, I suggest you
> start by providing some concrete examples of behaviors you consider
> incorrect with the current code.  Maybe changing the main syntax-table
> of that mode will be the better option, but if so, it'll probably
> require changing other code to keep using the current
> syntax-table there.

This is probably the best way forward here.