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

From: Stefan Monnier <[email-masked]>
Date: Tue, 15 Apr 2025 16:46:32 -0400

> In my view, variables and functions are the two most
> significant types of symbols when developing shell scripts.

I know.  But the fact is, we don't really have any maintainer for
that code.  I'm probably one of those most familiar with it (from back
when I implemented the SMIE-based indentation code), and I'm not sure
what kind of impact your change could have, so I'm uneasy accepting
your patch.

I added Dmitry to the Cc because AFAICT he's the last one to have
changed that syntax-table and he seems to have changed it for the same
kind of reasons as you:

    commit f6277911eb2c520aec8f0efd80c91999226e3322
    Author: Dmitry Gutov <[email-masked]>
    Date:   Fri Oct 2 07:11:56 2020 +0200
    
        Make xref work better on variables in shell-script-mode
        
        * lisp/progmodes/sh-script.el (sh-mode-syntax-table): Classify "/"
        as punctuation so that `M-.' on $foo/bar works on the $foo part
        (bug#25585).
    
    diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
    --- a/lisp/progmodes/sh-script.el
    +++ b/lisp/progmodes/sh-script.el
    @@ -370,26 +370,27 @@
     (defvar sh-mode-syntax-table
    [...]
             ?= "."
    +        ?/ "."
             ?\; "."
             ?| "."

Apparently this change hasn't brought any trouble over the last 5 years,
so that's encouraging.

AFAICT the chars you want to change have had the symbol-constituent
syntax "forever", i.e. since the first commit:

    commit ac59aed83fbdfd298f58a1a7e638264b0c3b0caa
    Author: Richard M. Stallman <[email-masked]>
    Date:   Tue Mar 22 05:43:25 1994 +0000
    
        entered into RCS
    
    diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
    --- /dev/null
    +++ b/lisp/progmodes/sh-script.el
    [...]
    +(defvar sh-mode-syntax-table
    +  (let ((table (copy-syntax-table)))
    +    (modify-syntax-entry ?\# "<" table)
    +    (modify-syntax-entry ?\^l ">#" table)
    +    (modify-syntax-entry ?\n ">#" table)
    +    (modify-syntax-entry ?\" "\"\"" table)
    +    (modify-syntax-entry ?\' "\"'" table)
    +    (modify-syntax-entry ?\` "$`" table)
    +    (modify-syntax-entry ?$ "_" table)
    +    (modify-syntax-entry ?! "_" table)
    +    (modify-syntax-entry ?% "_" table)
    +    (modify-syntax-entry ?: "_" table)
    +    (modify-syntax-entry ?. "_" table)
    +    (modify-syntax-entry ?^ "_" table)
    +    (modify-syntax-entry ?~ "_" table)
    +    table)
    +  "Syntax table in use in Shell-Script mode.")

That can be taken to mean that we have 30 years of experience with that
setting as being "the right one".  Of course it can also be taken to
mean that it was just an accident that simply bites rarely enough that
nobody bothered to fix it yet.

        Stefan