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

Previous Next

Package: emacs;

Reported by: James Cherti <contact <at> jamescherti.com>

Date: Fri, 11 Apr 2025 14:56:02 UTC

Severity: normal

Tags: patch

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


Message #113 received at 77746 <at> debbugs.gnu.org (full text, mbox):

From: James Cherti <contact <at> jamescherti.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 77746 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#77746: [PATCH] sh-mode: Fix incorrect word syntax for
 punctuation in sh-mode
Date: Thu, 17 Apr 2025 08:29:40 -0400
On 2025-04-16 19:43, Dmitry Gutov wrote:
> Hi! Regarding this:
> 
> On 15/04/2025 23:46, Stefan Monnier via Bug reports for GNU Emacs, the 
> Swiss army knife of text editors wrote:
>> 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<dgutov <at> yandex.ru>
>>      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.
> 
> Sorry to say, I don't have much more experience with these files. The 
> '/' character seemed safe enough, since it sounds silly to define 
> symbols including it, given how prevalent its other use in scripts.

The '/' character is allowed as a function name in Bash, but
you chose to remove it because you recognized that it is
rarely used in practice.

The same reasoning applies to this patch. Characters like
`!`, `%`, `^`, `~`, `.`, and `:` are technically allowed as
function names, but this patch reclassifies them as
punctuation, just as you did with `/`, because they are
rarely used as function names and never used as variable
names.

Treating them as punctuation is more convenient, as it
improves the accuracy of symbol detection.

> A lot of the questions that have been brought up in this thread seem 
> very good. In particular, is there a more urgent subset of the 
> characters that we would want to change, and what are the code examples 
> that would be affected? Even if we just list the positive cases. But 
> preferably realistic.
> 
> E.g. this one from the screenshot:
> 
>    var%name=1

I intentionally used symbols like % in my example to
illustrate that those symbols should be treated as
punctuation rather than symbol constituents.

(I recommend reading my other message in this thread for more
details.)

I believe merging this patch is just as beneficial
as your modification to `/`. (I have been using this patch
for over a year without encountering any issues in my
workflow.)

> What is such code supposed to do? Is that an assignment inside the 
> modulo operation?
> 
> More generally, a good argument for a wholesale change could be made 
> with be an analysis of some larger body of shell scripts. For example, 
> the Git codebase has a lot of .sh files (even if a lot of them are in 
> the 't' directory). Better examples welcome.

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




This bug report was last modified 107 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.