GNU bug report logs -
#79944
30.2; bash-ts-mode fontification of command invocations
Previous Next
To reply to this bug, email your comments to 79944 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79944; Package
emacs.
(Wed, 03 Dec 2025 20:14:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Robert Brown <robert.brown <at> gmail.com>:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Wed, 03 Dec 2025 20:14:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
With bash-ts-mode every invocation of a command in a bash script is
incorrectly fontified using face font-lock-function-name-face. In
non-ts modes font-lock-function-name-face has historically only been
used to fontify a function name where the function is defined, not every
place where it's used. As an example, let's say we have this bash
script:
logout() { exit }
who
Mode sh-mode fontifies "logout" using font-lock-function-name-face and
"who" using the default face. Mode bash-ts-mode fontifies both "logout"
and "who" using font-lock-function-name-face.
I believe the bug is here in sh-script.el:
:feature 'command
:language 'bash
`(;; function/non-builtin command calls
(command_name (word) @font-lock-function-name-face)
The last line should be deleted.
In GNU Emacs 30.2 (build 2, x86_64-pc-linux-gnu) of 2025-11-19 built on
chuwi
System Description: Ubuntu 24.04.3 LTS
Configured using:
'configure --without-x
--prefix=/home/brown/local/software/package/emacs-30.2'
Configured features:
DBUS GMP GNUTLS LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER SECCOMP SOUND THREADS TREE_SITTER XIM ZLIB
Important settings:
value of $LC_COLLATE: C
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix
Major mode: ELisp/l
Minor modes in effect:
bug-reference-prog-mode: t
company-mode: t
tooltip-mode: t
global-eldoc-mode: t
eldoc-mode: t
show-paren-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
minibuffer-regexp-mode: t
line-number-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
Load-path shadows:
/home/brown/lib/emacs/lisp/yow hides
/home/brown/local/software/package/emacs-30.2/share/emacs/30.2/lisp/obsolete/yow
Features:
(shadow sort mail-extr warnings emacsbug message yank-media puny dired
dnd dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 epg-config
gnus-util time-date mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils compile text-property-search comint
ansi-osc ansi-color comp-run comp-common cl-extra pp wid-edit descr-text
help-mode sh-script smie treesit executable mule-util
display-line-numbers ebuff-menu misearch multi-isearch bug-reference
thingatpt term/xterm xterm company-oddmuse company-keywords
company-etags etags fileloop generator xref project ring company-gtags
company-dabbrev-code company-dabbrev company-files company-clang
company-capf company-cmake company-semantic company-template
company-bbdb company pcase slime-autoloads cc-styles cc-align cc-engine
cc-vars cc-defs regexp-opt rx company-autoloads info tool-bar
dash-autoloads markdown-mode-autoloads package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs icons password-cache json
subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib
rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify multi-tty
make-network-process native-compile emacs)
Memory information:
((conses 16 213996 409137) (symbols 48 25457 72) (strings 32 100807 16993)
(string-bytes 1 2588670) (vectors 16 20693) (vector-slots 8 297302 169755)
(floats 8 77 193) (intervals 56 9953 1809) (buffers 992 19))
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79944; Package
emacs.
(Thu, 04 Dec 2025 07:00:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 79944 <at> debbugs.gnu.org (full text, mbox):
> From: Robert Brown <robert.brown <at> gmail.com>
> Date: Wed, 3 Dec 2025 15:13:07 -0500
>
> With bash-ts-mode every invocation of a command in a bash script is
> incorrectly fontified using face font-lock-function-name-face. In
> non-ts modes font-lock-function-name-face has historically only been
> used to fontify a function name where the function is defined, not every
> place where it's used. As an example, let's say we have this bash
> script:
>
> logout() { exit }
> who
>
> Mode sh-mode fontifies "logout" using font-lock-function-name-face and
> "who" using the default face. Mode bash-ts-mode fontifies both "logout"
> and "who" using font-lock-function-name-face.
>
> I believe the bug is here in sh-script.el:
>
> :feature 'command
> :language 'bash
> `(;; function/non-builtin command calls
> (command_name (word) @font-lock-function-name-face)
>
> The last line should be deleted.
Thanks.
Jostein and Yuan, WDYT?
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#79944; Package
emacs.
(Thu, 04 Dec 2025 07:52:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 79944 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> On 4 Dec 2025, at 07:59, Eli Zaretskii <eliz <at> gnu.org> wrote:
>
>> From: Robert Brown <robert.brown <at> gmail.com>
>> Date: Wed, 3 Dec 2025 15:13:07 -0500
>>
>> With bash-ts-mode every invocation of a command in a bash script is
>> incorrectly fontified using face font-lock-function-name-face.
I agree this sounds like an error.
>> In
>> non-ts modes font-lock-function-name-face has historically only been
>> used to fontify a function name where the function is defined, not every
>> place where it's used.
;; START short philosphy preamble :)
Tree-sitter allows us to get much more rich and accurate grammar for a buffer than we've historically been able to achieve using reg-exp and Elisp.
Based on that I don't necessarily agree that the new tree-sitter based major-modes should mimic previous Reg-exp based major-modes down to the last detail. If so, why even implement them?
What I think makes more sense is using the richer grammar which we can now get for most languages to craft a consistent editing experience in Emacs, across all languages:
- classes being declared
- functions being defined
- variables being declared
- functions being called
- variables being referenced
- properties being declared
- string templating
- variables and function-calls made inside string-templates
- etc
All those constructs can now reliably be identified across most languages, and this gives us the possibility to fontify them consistently too.
For all tree-sitter major-modes I've been contributing to (at least 7), this has been my high-level goal, as opposed to mimicking whatever existed before.
;; END preamble
>> As an example, let's say we have this bash
>> script:
>>
>> logout() { exit }
>> who
>>
>> Mode sh-mode fontifies "logout" using font-lock-function-name-face and
>> "who" using the default face. Mode bash-ts-mode fontifies both "logout"
I would argue that semantically "who" is a command which does something. It's a function in form of an external binary or command.
So this would semantically constitute a function call.
>> and "who" using font-lock-function-name-face.
I agree this is inappropriate and incorrect. font-lock-function-name-face should ideally only be used for function-definitions. And this is not a function definition.
>>
>> I believe the bug is here in sh-script.el:
>>
>> :feature 'command
>> :language 'bash
>> `(;; function/non-builtin command calls
>> (command_name (word) @font-lock-function-name-face)
That seems to be the culprit indeed.
>>
>> The last line should be deleted.
Disagree.
I think instead changing it to font-lock-function-call-face would make it more consistent with the semantics of the other tree-sitter based major-modes we currently have in Emacs.
>
> Thanks.
>
> Jostein and Yuan, WDYT?
If there's no big disagreements to the design, approach and philosophy outlined above, below is a patch which implements this change :)
[0001-sh-script-Fix-fontification-of-command-invocations-i.patch (application/octet-stream, attachment)]
[Message part 3 (text/plain, inline)]
--
Jostein
This bug report was last modified today.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.