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

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

Attached: v2 of this patch

This patch marks only the following characters as
punctuation: !%^~:,

I removed . because it is commonly used in command names
(e.g., mkfs.ext4).

(Excluding '.' not only covers the majority of command and
function names but also prevents using ,!%^~: as
symbol constituents, resulting in more accurate
variable symbols.)

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

On 2025-04-13 05:45, Eli Zaretskii wrote:
>> Date: Fri, 11 Apr 2025 10:55:02 -0400
>> From: James Cherti <[email-masked]>
>>
>> In sh and Bash, the characters !%^~:.,= and are not valid in variable or
>> function names.
>>
>> Assigning them the "_" syntax causes Emacs to treat them as word
>> constituents, disrupting navigation and completion
>> (e.g. dabbrev-expand, forward-word, etc.).
>>
>> The attached patch updates the syntax table in sh-mode to mark
>> these characters as punctuation, correcting the issue.
> 
> Thanks.
> 
> TBH, such a change sounds scary, as it could cause all kinds of
> unintended changes in behavior.
> 
> I've added a couple of people who might know this mode better than I
> do, in the hope that they will have comments or opinions.
From 4d9e0830e8ea7b90381cace37591043b91787020 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 sh and Bash, the characters !%^~:, and are not valid in variable
names. Assigning them the "_" syntax causes Emacs to treat them
as symbol constituents.

* 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 | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 94061e2ecb5..ea3cf3bd4ca 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