[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Initial fontification in sh-mode with tree-sittter
From: |
Yuan Fu |
Subject: |
Re: Initial fontification in sh-mode with tree-sittter |
Date: |
Fri, 4 Nov 2022 15:50:57 -0700 |
> On Nov 4, 2022, at 1:44 PM, João Paulo Labegalini de Carvalho
> <jaopaulolc@gmail.com> wrote:
>
> All you need to do is capture these contextual nodes in a special name
> “contextual”.
>
> (heredoc_body) @contextual
> (string) @contextual
>
> I see. I'll give that a try.
>
> But I don’t know about the bleeding you described in the very beginning. Do
> you still see it? Is there a recipe to reproduce it?
>
> It might just be because of how the tree-sitter-bash grammar defines heredoc
> strings.
>
> This are the steps to reproduce the issue on sh-mode:
>
> ;; build emacs from head of feature/tree-sitter branch
> ;; apply the attached patch.
> ;; launch emacs with: emacs -nw -Q
> ;;Write the forms bellow on *scratch* buffer)
>
> (require 'treesit)
> (add-to-list 'treesit-settings '(sh-mode t t))
> (find-file "/tmp/heredoc-issue.sh")
>
> ;; contents of /tmp/heredoc-issue.sh file (also attached)
>
> #!/usr/bin/env bash
>
> cat <<EOF
> heredoc string
> EOF
> echo "<<HELLO>>"
>
> ;; Then execute the commands below
>
> ESC < ;; beginning-of-buffer
> C-s ;; isearch-forward
> heredoc ;; self-insert-command * 7
> RET ;; newline
> C-a ;; move-beginning-of-line
> C-k ;; kill-line
> C-n ;; next-line (At this point the echo command after
> EOF is fontified as heredoc string)
> C-_ ;; undo (After a short delay, the whole buffer is
> correctly fontified)
I see. This is tree-sitter-bash’s problem. When there are only newlines between
two EOF’s, the parser erroneously marks everything that follows as
heredoc_body. I tried tree-sitter’s online demo and it gives the same
result[1]. We should report this to tree-sitter-bash’s author.
Also, when defining sh-mode--treesit-settings, instead of using the value
sh-shell as the language, it’s better to just use ‘bash. Here is what happened
to me: my default value for sh-shell is fish, so sh-mode--treesit-settings was
defined with language = fish. When I open heredoc-issue.sh, sh-mode parses the
shebang and sets sh-shell to bash. Since bash does have a parser,
(treesit-ready-p ’sh-mode sh-shell) returns t, and tree-sitter is activated.
However when font-lock tries to use the query, it errors because query tries to
load a parser for fish.
[1] https://tree-sitter.github.io/tree-sitter/playground
Yuan
- Re: Initial fontification in sh-mode with tree-sittter, Eli Zaretskii, 2022/11/01
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/01
- Re: Initial fontification in sh-mode with tree-sittter, Eli Zaretskii, 2022/11/01
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/11/03
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/03
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/11/04
- Re: Initial fontification in sh-mode with tree-sittter,
Yuan Fu <=
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/11/12
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/12
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/11/12
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/16
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/11/16
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/17
- Re: Initial fontification in sh-mode with tree-sittter, João Paulo Labegalini de Carvalho, 2022/11/17
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/17
- Re: Initial fontification in sh-mode with tree-sittter, Eli Zaretskii, 2022/11/13
- Re: Initial fontification in sh-mode with tree-sittter, Yuan Fu, 2022/11/13