Subject: [PATCH] sh-mode: Fix incorrect word syntax for punctuation in sh-mode
From: James Cherti <[email-masked]>
To: [email-masked]
Date: Fri, 11 Apr 2025 10:55:02 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

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.

--
James Cherti
GitHub: https://github.com/jamescherti
Website: https://www.jamescherti.com/
From b87d1cdd585bd3a0723d996cefbae8814df5fd7e 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 word constituents

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.).

* 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 bd2178167ee..522916cf506 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -404,17 +404,17 @@ sh-mode-syntax-table
 	?\` "\"`"
 	;; ?$ might also have a ". p" syntax. Both "'" and ". p" seem
 	;; to work fine. This is needed so that dabbrev-expand
 	;; $VARNAME works.
 	?$ "'"
-	?! "_"
-	?% "_"
-	?: "_"
-	?. "_"
-	?^ "_"
-	?~ "_"
-	?, "_"
+	?! "."
+	?% "."
+	?: "."
+	?. "."
+	?^ "."
+	?~ "."
+	?, "."
 	?= "."
         ?/ "."
 	?\; "."
 	?| "."
 	?& "."
--
2.49.0