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

From: James Cherti <[email-masked]>
Date: Mon, 28 Apr 2025 15:28:24 -0400

Thank you for your prompt confirmation that the patch can be
merged, Stefan. This change will enhance the convenience of
editing bash and sh scripts.

While awaiting any objections, I am attaching v3 of the
patch, which includes all the characters we discussed. I am
sending it again in case the previous email was overlooked,
given the high volume of emails exchanged.

Attached: fix-sh-mode-syntax-table-v3.patch

--
James Cherti
GitHub: https://github.com/jamescherti
Website: https://www.jamescherti.com/

On 2025-04-28 13:41, Stefan Monnier via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
>> commit f6277911eb2c520aec8f0efd80c91999226e3322
>> Author: Dmitry Gutov <[email-masked]>
>> Date:   2020-10-02 07:11:56 +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).
>>
>> The above patch was accepted.
>>
>> @Stefan @Juri: Have you been able to perform any checks that
>> would allow this patch to be merged?
> 
> Yeah, based on my experimentation with `/`, I'm now thinking it might be
> safe enough to give punctuation syntax to those other characters.
> 
> Any remaining objection to pushing this to `master`?
> 
> 
>          Stefan
> 
> 
> 
> 
From 171139c76da34692863d36f1a237e1988d8f2f62 Mon Sep 17 00:00:00 2001
From: James Cherti <[email-masked]>
Date: Fri, 11 Apr 2025 10:18:19 -0400
Subject: [PATCH] Mark !%:.^~, as punctuation rather than symbol constituents

In Bash, the characters !%:.^~, are not valid in variable names. In sh,
they are not permitted in either function or variable names. Treating
them as punctuation is convenient, as they are rarely used in function
names and never in variable names. Even among commands, their usage is
uncommon. The only character among these that is commonly seen in
command names is '.', although it is rarely used in function names.

Marking these characters as punctuation, rather than symbol
constituents, enhances the accuracy of symbol detection.

* lisp/progmodes/sh-script.el: Mark !%:.^~, as punctuation in the
  sh-mode-syntax-table syntax table.

Copyright-paperwork-exempt: yes
---
 lisp/progmodes/sh-script.el | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 94061e2ecb5..dd10be7a20b 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -395,13 +395,13 @@ sh-mode-syntax-table
 	;; to work fine. This is needed so that dabbrev-expand
 	;; $VARNAME works.
 	?$ "'"
-	?! "_"
-	?% "_"
-	?: "_"
-	?. "_"
-	?^ "_"
-	?~ "_"
-	?, "_"
+	?! "."
+	?% "."
+	?: "."
+	?. "."
+	?^ "."
+	?~ "."
+	?, "."
 	?= "."
         ?/ "."
 	?\; "."
--
2.49.0