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

From: James Cherti <[email-masked]>
Date: Thu, 17 Apr 2025 09:01:31 -0400

Hello Eli,

Attached is v3 of this patch.

(I have updated the commit message to include more details
and reintroduced the '.' character.)

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

On 2025-04-15 07:47, James Cherti wrote:
> Hello Eli,
> 
> I just want to note that the second patch is not ideal, as
> it omits the '.' character. If you decide to merge this
> patch (or a variation of it), I recommend including '.' as
> well, since '.' is not allowed in variable names.
> 
> In the context of Bash development, it is uncommon to use
> characters like !%^~:. in function names. In my view, it is
> more practical to treat them as punctuation rather than
> symbol constituents by default, as what matters the most
> in Bash development is variable names and function names.
> 
> Maintaining some degree of backward compatibility might be
> beneficial in case other users prefer completing commands
> that contain characters like !%^~:,. (though in practice,
> this is rare that users complete commands containing
> !%^~:, with the exception of '.'. Outside of command names,
> the '.' character is also rarely used in function names
> and never used in variable names.).
> 
> The variable for backward compatibility could be defined
> as one of the following, or a variation of them:
>    (defvar sh-mode-syntax-table-respect-variable-name-limits t)
>    (defvar sh-mode-symbol-respect-variable-name-limits t)
>    (defvar sh-mode-respect-variable-name-limits t)
> 
> (It could also default to nil, mitigating the risk of any
> user encountering issues with this new behavior. As I
> mentioned earlier, I haven't faced any problems with this
> patch applied for several months.)
> 
> -- 
> James Cherti
> GitHub: https://github.com/jamescherti
> Website: https://www.jamescherti.com/
> 
> On 2025-04-15 02:17, Eli Zaretskii wrote:
>>> Date: Mon, 14 Apr 2025 15:39:24 -0400
>>> Cc: [email-masked]
>>> From: James Cherti <[email-masked]>
>>>
>>> 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.)
>>
>> Should this backward-incompatible change be controlled by a user
>> variable?  I can easily imagine some user who'd come complaining about
>> this compromise.  Without a knob to get back previous behavior, we
>> will have no way of satisfying such users without reverting the
>> change.
>>
>>
>>
> 
> 
> 
> 
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