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: Tree-sitter integration on feature/tree-sitter Date: Mon, 9 May 2022 14:10:36 -0700 Message-ID: <73DE25BA-5EEF-4497-8F98-8C5F20853A61@gmail.com> References: <5bada349-2f43-4325-b696-70918584cd3d@email.android.com> <83mtfsuluo.fsf@gnu.org> <87sfpjhm33.fsf@thornhill.no> <83a6brufe5.fsf@gnu.org> <87pmkmhp8i.fsf@thornhill.no> <83v8ueuc7i.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.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="37593"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Theodor Thornhill , Stefan Monnier , Emacs Devel , Daniel Colascione To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 09 23:13:21 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 1noAgz-0009gO-Ha for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 23:13:21 +0200 Original-Received: from localhost ([::1]:54970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noAgy-00048q-F6 for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 17:13:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noAeQ-0001EV-G5 for emacs-devel@gnu.org; Mon, 09 May 2022 17:10:42 -0400 Original-Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]:39501) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1noAeO-00077Y-Le; Mon, 09 May 2022 17:10:42 -0400 Original-Received: by mail-oi1-x22f.google.com with SMTP id l16so16563945oil.6; Mon, 09 May 2022 14:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/m9zUTzhM/CNNwC0VB+X8Vk1N79HY6vZwITrl120thc=; b=kJl3+QGOH8pXm0e9jgRuGzXIIYREq+DbFTUnjml2rE96RkKASwxwAOFwBwd0H3jnQ3 f+rLwnsClckMxxhbsDTt6IqaT9UyM0yJmgHCoyH7SwXYf/dtF6Bgm8NIi035xKXS8OZv 8KXjaD/9k1lvH1lUOXBezVmUdx7xFV9fep/DM1zDa+hvcfyu/PLO/Nv0ea/GP3v8QVYP nGKMQh3VRKFHQhrKhvJP8X8OEv67+URnJFXWONq7Z9TI19JHBP7KX6/PmoQ9EKajlHgp KkuMeUJD2NZQVF45Xr54/IEsnd7sbVHI9Za3sKFp2/wCeqbJDP15LbwZSyJTV3h0iJaz N7Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/m9zUTzhM/CNNwC0VB+X8Vk1N79HY6vZwITrl120thc=; b=qVAVu8n5lVa+5btbJmmtW0hn5UOjGCm625m2u3thYMwVWrGHxoT+m+x8QzUiNf7H0C QhYGl4VZhH1nfLMafC609V0W7crVBpCZWHg6Vsd+DVwxHiKXsOUdxlBKLmtkbSJwbDFn veFvjigoVwJkqGQSXq2H4EudN8jFpk3LoW+CIgdNzfNHDzh1yMeJMdirkz7lfGRWhwMS htqSU8CRWOgRip9gbn++Y/KfeEln7MTeSgat9xzHgXnPhduEv2OUQqa+YBiq+gR41tg2 +rT6heCgEF4G+CR/eETY4XqGHzFJs13YGuLbnQWd4l9BjZO3jZKpbgwd8bO2EXjJf1P6 F2ug== X-Gm-Message-State: AOAM532Va6LYZ5UmW0sjSMlKCajEIPzGO34OPmOeAqY4T3/uIC3DwGW6 PGLqUhfc9QUe9argrv6mGNacg50rcTg= X-Google-Smtp-Source: ABdhPJxVycVf/wO1DJiQZfD+FHLNm9QfWntyZmS2Mr0qnQ/tpN4x/tjxrgp//1KLMVB62Hnc0ufWyg== X-Received: by 2002:a05:6808:1644:b0:2ef:b05:1cdc with SMTP id az4-20020a056808164400b002ef0b051cdcmr8507174oib.66.1652130638629; Mon, 09 May 2022 14:10:38 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c90:45d2:2f3d:5494:d9ad]) by smtp.gmail.com with ESMTPSA id m22-20020a9d6ad6000000b0060603221276sm5040452otq.70.2022.05.09.14.10.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 May 2022 14:10:37 -0700 (PDT) In-Reply-To: <83v8ueuc7i.fsf@gnu.org> X-Mailer: Apple Mail (2.3696.80.82.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=casouri@gmail.com; helo=mail-oi1-x22f.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:289552 Archived-At: > On May 9, 2022, at 5:23 AM, Eli Zaretskii wrote: >=20 >> From: Theodor Thornhill >> Cc: monnier@iro.umontreal.ca, casouri@gmail.com, emacs-devel@gnu.org >> Date: Mon, 09 May 2022 14:20:13 +0200 >>=20 >> Did you get to look at the patch I sent? Should these efforts, when >> their form is discovered be applied to this branch going forward? Or >> should we wait until it lands on master? I can look into more modes, >> like css and others, but I'm a little wary of touching C, as they = have a >> lot of lineage and opinions and isn't my expertise. >>=20 >> Also I'm sure that bugs will be found when it is used, so I'm in = favour >> of applying the modes to this branch, if only to discover how best to >> use tree sitter. >=20 > I'll leave it to Yuan's decision. I didn't yet have time to build the > branch, and without that I don't want to apply changes I cannot test. >=20 > Thanks. I have some comments below, I haven=E2=80=99t tested the patch yet. +(defvar js-treesit-font-lock-settings-1 + '((javascript + ( + ((identifier) @font-lock-constant-face + (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face)) I would use treesit-expand-query to =E2=80=9Cexpand=E2=80=9D the sexp = query to string, so Emacs don=E2=80=99t need to re-expand it every time = treesit-query-capture is called. I don=E2=80=99t know how much it speed = things up, but hey its free. +(defun js-treesit-move-to-node (fn) + (when-let ((found-node (treesit-parent-until + (treesit-node-at (point) (point) 'javascript) + (lambda (parent) + (let ((parent-type (treesit-node-type = parent))) + (or (equal "function_declaration" = parent-type) + ;;; More declarations here + )))))) + (goto-char (funcall fn found-node)))) + +(defun js-treesit-beginning-of-defun (&optional arg) + (js-treesit-move-to-node #'treesit-node-start)) + +(defun js-treesit-end-of-defun (&optional arg) + (js-treesit-move-to-node #'treesit-node-end)) Maybe I could extract this into treesit.el, so major modes can specify = simply the node name for a function definition and get function = traversal for free. +(defcustom js-use-treesit-p nil + "Use tree sitter for font locking, indentation and navigation" + :version "29.1" + :type 'boolean + :safe 'booleanp) Maybe I should ditch treesit-disble-list and let major modes define = their controlling variables like this? I also cc=E2=80=99d maintainer of js.el, since I don=E2=80=99t know = anything about js.el. Yuan=