From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter integration on feature/tree-sitter Date: Mon, 09 May 2022 23:33:49 +0200 Message-ID: <87v8uewfuq.fsf@thornhill.no> 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> <73DE25BA-5EEF-4497-8F98-8C5F20853A61@gmail.com> Mime-Version: 1.0 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="10218"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , Emacs Devel , Daniel Colascione To: Yuan Fu , Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 09 23:40:26 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 1noB7B-0002VI-1I for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 23:40:25 +0200 Original-Received: from localhost ([::1]:52094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1noB79-0007xp-Hh for ged-emacs-devel@m.gmane-mx.org; Mon, 09 May 2022 17:40:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noB0v-0007ks-Fk for emacs-devel@gnu.org; Mon, 09 May 2022 17:33:57 -0400 Original-Received: from out2.migadu.com ([188.165.223.204]:35029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noB0s-0001pv-WF; Mon, 09 May 2022 17:33:57 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1652132031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kym7qvfHA6bTZKyADScyAVK2DOfewEXSl7l9cd9PoFU=; b=Cg89HfZU+Z1TobN1dvdbeWnTYGW7tFg2+cwpQJb2ukCz2+5C2BuA5IdoH/H1nLUXDf96SL Yu8RdYYS8t3CUvYM0xvYp0UjMHHjkbjQf1i+4riazzWDQQIsUGEYqBsvFuAaHO5FdTpSFk 6f3LsEHDLdz269hipmkDrgZ4qgs6EEvRyIbUnTYYlhakOK39ogkIlKnIuS9sd07bFolpyk DL620ZvaNmsJ9nAn8/0xmzJzdGFBgfjHLVTDbqzV0rt6n9EH698CAh87Ca9m6ESQ9gtPNz YyENH0X+ChOf0uYqIx7yuv3TRE7YH6urY+g7cZnHUHVqWaV1Q1L6pB+c3658LQ== In-Reply-To: <73DE25BA-5EEF-4497-8F98-8C5F20853A61@gmail.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: thornhill.no Received-SPF: pass client-ip=188.165.223.204; envelope-from=theo@thornhill.no; helo=out2.migadu.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, 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:289554 Archived-At: > > I have some comments below, I haven=E2=80=99t tested the patch yet. > Thank you! > +(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 que= ry to string, > so Emacs don=E2=80=99t need to re-expand it every time treesit-query-capt= ure > is called. I don=E2=80=99t know how much it speed things up, but hey its = free. > Great, I did not know of this. I'll try it out. > +(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-t= ype) > + ;;; 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. > Yeah! My plan was to use `M-a` and `M-e` for siblings and `C-M-a` and `C-M-e` for beginning/end-of-defun. Some way of supplying "defun-nodes" and make treesit handle the rest would be awesome. > +(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? Makes sense. The advantage with this is that you can decide more granularly where you want to inject tree-sitter in the major mode initialization phase, I guess? > > I also cc=E2=80=99d maintainer of js.el, since I don=E2=80=99t know anyth= ing about js.el. > Great! I don't think this is "done", per se, but at least it is something useful to look at, hopefully. Theodor