From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Initial fontification in sh-mode with tree-sittter Date: Fri, 4 Nov 2022 15:50:57 -0700 Message-ID: <42DBD4F5-71D9-434E-B7B4-4E0FF89F934F@gmail.com> References: <6C8B0F8E-DF61-4BC3-B0D0-56DBB66BE637@gmail.com> <7AE71CCA-6F18-4DE6-8608-7D9B3E9E52FB@gmail.com> <9BA853EA-8B7F-41A0-A174-D86DF5CE7788@gmail.com> <83sfj3cfl0.fsf@gnu.org> <03309451-1AEB-458C-88FD-9715CECC27A2@gmail.com> <83mt9bc9ke.fsf@gnu.org> <8335b19ndr.fsf@gnu.org> <39ECD413-BD10-4BF3-90AC-36F02276607E@gmail.com> <8A2361BB-1081-4550-AC29-B9E99BFC2FB8@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31675"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: =?utf-8?Q?Jo=C3=A3o_Paulo_Labegalini_de_Carvalho?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 04 23:52:04 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1or5Xg-0007zv-UJ for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Nov 2022 23:52:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1or5Wr-0001n3-BE; Fri, 04 Nov 2022 18:51:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1or5Wm-0001hT-ST for emacs-devel@gnu.org; Fri, 04 Nov 2022 18:51:10 -0400 Original-Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1or5Wi-0003YB-7Q; Fri, 04 Nov 2022 18:51:07 -0400 Original-Received: by mail-pj1-x102b.google.com with SMTP id gw22so5747158pjb.3; Fri, 04 Nov 2022 15:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+vTq5L67inepjcn20f3zwtTCbRSp4Nkt5HPh85DeQ4E=; b=IAc6nAkhzqfCHu5GXmi399Y7Bfh1/Tud3/BASK1IzClrLvQoelnCgkNnz0ZnxW53TR HEfYhoyzMUqYE3Oc/RZpWgKTCqdaMkgrY8tFveTpNGPaT9R2kwGv/nEZ/un6njDuMT0U YpMrRIB9CrcNb0Kejz5nbayxGbf/sqDeu0dQbUCgT3cv1c7CU1hkn/HHgd+GwIqQERtM +3Q4Co5KsV6UopVx5JVGTWrEYm+rEmYnCDWBRxsWiK4/a/iRzE82ERVScJefGJB958bz ZclrxdCsnXe0LGqnQpf+d3yGjp4FF8Xq0kvMWOHdJxoBEwaoxQd5etCJDe6mEXm+NlCe gm9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+vTq5L67inepjcn20f3zwtTCbRSp4Nkt5HPh85DeQ4E=; b=22ysO/522ObnWfmqr6oqjtp+q3mlrt57L4qfCJpfUlCh/C2DVRs6uYGwt0FgGBlpSk FyOnv9SXtvyIb0tTsQq8EhosqQXN1+Vh+D2Oqrbbfhk9qwbaOEzb8fy+V/7OXxUXJ/4e 9dNAezxqN8DV7Il4WtlpJqwxHxJl+FRc44haqTGX8IjBKAKez57G2VMOiU64gSb7fLiG HH98n2/7bg6If2FmMnqPo7/NKH7ErQ7kf/jmVjv99qN6N6eJV12KggoCDIW6fNJ2uIzj DjKFoTHnVbrjZzc+dOxKrJj9mTJTz6AE9oGIe4Ja6hotbuwJM8nl1J0FLjUCaKeLF6MP z1kQ== X-Gm-Message-State: ACrzQf2t/XtPwpDZPkEtTI10rt4JBa/AFpmOP03jHvFuXWzO1ka0Ng/a D81Ov2H9ITjN7ezJDbpfW18= X-Google-Smtp-Source: AMsMyM7cL3W2EfCC+7tQB1If2DCoA6JqvHeasdgygepQWj86oKAOxwpZqQbUT8mHyqQdMAuEjYxMcA== X-Received: by 2002:a17:90b:1948:b0:214:1ae7:a511 with SMTP id nk8-20020a17090b194800b002141ae7a511mr20050114pjb.89.1667602260763; Fri, 04 Nov 2022 15:51:00 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id j5-20020a170902c3c500b00186b138706fsm268991plj.13.2022.11.04.15.51.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Nov 2022 15:51:00 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=casouri@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:299162 Archived-At: > On Nov 4, 2022, at 1:44 PM, Jo=C3=A3o Paulo Labegalini de Carvalho = wrote: >=20 > All you need to do is capture these contextual nodes in a special name = =E2=80=9Ccontextual=E2=80=9D. >=20 > (heredoc_body) @contextual > (string) @contextual >=20 > I see. I'll give that a try. > =20 > But I don=E2=80=99t know about the bleeding you described in the very = beginning. Do you still see it? Is there a recipe to reproduce it? >=20 > It might just be because of how the tree-sitter-bash grammar defines = heredoc strings. >=20 > This are the steps to reproduce the issue on sh-mode: >=20 > ;; 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) >=20 > (require 'treesit) > (add-to-list 'treesit-settings '(sh-mode t t)) > (find-file "/tmp/heredoc-issue.sh") >=20 > ;; contents of /tmp/heredoc-issue.sh file (also attached) >=20 > #!/usr/bin/env bash >=20 > cat < heredoc string > EOF > echo "<>" >=20 > ;; Then execute the commands below >=20 > 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=E2=80=99s problem. When there are only = newlines between two EOF=E2=80=99s, the parser erroneously marks = everything that follows as heredoc_body. I tried tree-sitter=E2=80=99s = online demo and it gives the same result[1]. We should report this to = tree-sitter-bash=E2=80=99s author. Also, when defining sh-mode--treesit-settings, instead of using the = value sh-shell as the language, it=E2=80=99s better to just use =E2=80=98b= ash. Here is what happened to me: my default value for sh-shell is fish, = so sh-mode--treesit-settings was defined with language =3D 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 =E2=80=99sh-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=