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 14:58:29 -0400

On 2025-04-14 13:23, Stefan Monnier via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
>> 1. Completion
>> --------------
>> Given the variable name `varname` in a comment,
>> followed by ".":
>>    #!/usr/bin/env bash
>>    # The name of this variable is varname. Code:
>>    var
>>
>> Completing "var" includes "varname." in the list of
>> completions.
> 
> `varname.` is a valid command name and at the spot where you have `var`
> above, you could very well be completing a command rather than a variable.
> 
>> (e.g. dabbrev completion. I am using Corfu/Cape,
>> which displays all suggestions)
> 
> dabbrev doesn't even try to distinguish whether you're completing a var
> or a command or a type or anything else for that matter, so it's mostly
> unavoidable that it includes "useless" candidates (and that it misses
> valid candidates, as well).  IOW you can't argue that it's correct or
> not: you need to argue whether something will be usually useless or not.
> 
>> 2. Highlight symbol at point
>> ----------------------------
>> When the cursor is on the comment `varname.`,
>> Emacs highlights `varname.` instead of `varname` when
>> using `(hi-lock-face-symbol-at-point)`:
>>    #!/usr/bin/env bash
>>    # The name of this variable is varname. Code:
>>    var
> 
> Same here.  `varname.` is a valid command name so it can make perfect
> sense to highlight it.  Admittedly, I'd never seen a command with a `.`
> at the end, but removing `.` from the symbol constituents would rule out
> not just `varname.` but also all commands with a `.` in the middle of
> their names:
> 
>      % ls /usr/bin/??*.* | wc
>          180     180    4274
>      %
Yes, I agree that 'varname.' is:
- A valid command in both Sh and Bash,
- A valid function name in Bash (not in Sh).

However, it is an *invalid* variable name in both
Sh and Bash.

This is what complicates addressing this issue.

Applying this patch will impose the same limitations on
function names as those applied to variables, specifically
in terms of what is considered a valid symbol when
developing Sh or Bash scripts.

Here, in my opinion, is the difference between merging and
not merging this patch:

- Merging this patch: The symbol representation of variable
   names will be more accurate. However, functions/commands
   containing characters like !%^~:.,
   will be treated as two separate symbols.

- Not merging this patch: The symbol representation of
   functions/commands containing !%^~:. will be more accurate.
   However, for variables, characters like !%^~:., will be
   included in symbols, leading to extraneous characters when
   completing or highlighting symbols.

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