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 api Date: Fri, 22 Apr 2022 13:41:47 +0200 Message-ID: <871qxpfipw.fsf@thornhill.no> References: <6D1CD758-2C6F-4843-9739-F2A5D5591648@gmail.com> <67183EAB-5D98-4211-B71B-4618D6266A15@gmail.com> <83lews90ft.fsf@gnu.org> <8D3019A6-83EE-42AB-ADFA-7DA6EBB179B3@gmail.com> <83r16h5npi.fsf@gnu.org> <83v8vs4rd9.fsf@gnu.org> <983C9314-B31C-4785-B075-892CDD883DA2@gmail.com> <877d858fj5.fsf@gmail.com> <5D490FCF-7727-44EE-A153-A95C5F572FC4@gmail.com> <87y1zzseaa.fsf@thornhill.no> <838rrzrnp2.fsf@gnu.org> <871qxq8y5y.fsf@gnus.org> <87wnfi1vtm.fsf@thornhill.no> <3560D8FB-9D85-4A04-B6CE-811A6D793B59@gmail.com> <877d7hg1dh.fsf@thornhill.no> <91E89EA1-C3DC-4B78-8549-B9DEC94F6E87@gmail.com> <874k2lfsw3.fsf@thornhill.no> 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="10561"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , Eli Zaretskii , emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Apr 22 13:58:08 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 1nhrvL-0002V3-IJ for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Apr 2022 13:58:07 +0200 Original-Received: from localhost ([::1]:36698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhrvK-0002HA-GU for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Apr 2022 07:58:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhrfg-0002UH-Rt for emacs-devel@gnu.org; Fri, 22 Apr 2022 07:42:00 -0400 Original-Received: from out0.migadu.com ([94.23.1.103]:21005) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhrfd-0003P9-WD; Fri, 22 Apr 2022 07:41:55 -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=1650627708; 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=tZShvAkqlpdAS0Nr/ZYanroM6ldtcSwqOiCCX/wOmE0=; b=oHiJngEdDOiDby/74AH/AfKprXuKEckrTPCVJMfI7OdtYDu7mETvtqcOsJX6kdStFi/H7A CuJ8ZC4k1K5EMkOntFBCj6aeI4x/gTJYk5NkPd6Lox93M/dawqCYLpaLsjaAaq8DtZfPqs 5pjKUhn+7dcOdKi2qndeeB8kfqF+OQDAZMdbS9R+Ia2W79j5JTMphraBYgyfnPqpYqZ6F5 IFUUjhgz/BROmWDre0YwgN3qqYOEpIg7vV8bDZx4ZeugVwFv0U6EAm2d2EgphHO1jbn9j3 BkANjz7h0JjjdgLUSkgBesE0daAM0I77DOEpoEDJiltUVxLZosY24rG3TdCsWg== In-Reply-To: <874k2lfsw3.fsf@thornhill.no> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: thornhill.no Received-SPF: pass client-ip=94.23.1.103; envelope-from=theo@thornhill.no; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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:288797 Archived-At: >>>=20 >>> What happens is that the arguments list triggers as an indentation step, >>> but it should only do so when when on its own line. I believe this is >>> what SMIE calls "hanging-p" in its engine. >> >> I think an anchor preset that finds the parent that=E2=80=99s at the beg= inning >> of a line should solve this. I=E2=80=99ll definitely add that one. So I made this rule which is a good starting point for this, I think. It's a pretty naive implementation still, but I wanted to share it nonetheless. ```elisp (defun ts-parent-until (type) (lambda (node parent bol &rest _) (when-let ((found-node (tree-sitter-parent-until node (lambda (parent) (equal type (tree-sitter-node-type parent)))))) (save-excursion (goto-char (tree-sitter-node-start found-node)) (back-to-indentation) (tree-sitter-node-start (tree-sitter-node-at (point) (point) 'tree-sitter-tsx)))))) (defvar ts-tsx-tree-sitter-indent-rules `((tree-sitter-tsx ((ts-parent-until "statement_block") (ts-parent-until "statement_block= ") 2) (no-node prev-line 0) ))) ``` This at least marks the start of me understanding how it works, hehe... Theodor