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: Fri, 13 May 2022 17:03:17 -0700 Message-ID: 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> <87v8uewfuq.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6520"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , Stefan Monnier , Emacs Devel , Daniel Colascione To: Theodor Thornhill Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat May 14 02:05:57 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 1npfID-0001Wy-1r for ged-emacs-devel@m.gmane-mx.org; Sat, 14 May 2022 02:05:57 +0200 Original-Received: from localhost ([::1]:56176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npfIB-0005ve-O9 for ged-emacs-devel@m.gmane-mx.org; Fri, 13 May 2022 20:05:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npfFj-0004vo-9Z for emacs-devel@gnu.org; Fri, 13 May 2022 20:03:23 -0400 Original-Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:41878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npfFh-0002iM-IQ; Fri, 13 May 2022 20:03:22 -0400 Original-Received: by mail-pl1-x62d.google.com with SMTP id s14so9387176plk.8; Fri, 13 May 2022 17:03:20 -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=SxLNqIfDc3ZDkrZgOoELtPh0Bgqg/1hvEsCufpjOQC0=; b=BFSMrsY6t0msY3+b6KuWtKXAsTUbz8SVEcqegojnSoElsn3n0Wd5u+UP/hNU1mw41o P1PZkB3lKDaD8pYVjSi0hPGgjyVoby0xOI/vsH8V0FWGGKs6fo8EWa3pqEDEO8hTEZ1m Zsa/wENgTDUXLTDQ3dcMW5hDn/lHWZq8X0RdUu+j5PaSRFgVbYZlmKKeG5deve2Irhx9 SF/kBWN328eKWUh3A4s0v8REyVZcs5XC02EPimxcK64NL3K/CFv6444vRTInd1Zfy0YG IMYIN5lXmhK5m4v8KSmmErjN37Q0o96uN4Cy3CQZMFm9fKz9jX6436s7iMR3dMJgadvQ WGOA== 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=SxLNqIfDc3ZDkrZgOoELtPh0Bgqg/1hvEsCufpjOQC0=; b=U/4rrVCTjvYj1/Bu60dNLleo7guaAFIMZWzszmUX+l4EAk8aVfQMwsWQbNf/55zNLZ txejXq5uSIPm2/kKNsyMGwF/q+YNHqd71AmNDTzCuEHzex37hC7V4VIB/z8etL9VQGZz q//I6Qp6Yr8/fx1g+ezamZWiN1y7j2vo1gVcwraKaj97D4IvKd74JsrO0pz63lx26rCB HjXQlh47yGluwhs/6m+Cnl93Jrq5e6IX7MP/RkUQ4qGsZSSLdfwF6SNtTDxIPhrQ1ik+ MGRfjk9AkVYGP+qUSp9ZuShdEgGN7+aP06+iSSIjLzK1k/jLJl4reYktMYO5p8p7dOww SQqw== X-Gm-Message-State: AOAM532gjeGwpHwbPHYK+Ul9J8ANrWq972ghagWl25KdY0xOEbQifDTw uTfYRb2MP4MFTQw4TURsyUk= X-Google-Smtp-Source: ABdhPJy6PwwLCPSdA8sJ+nuZfqzvABhIOQkeO55bSaxHD9KejSrVSzfRA9mYLmH6wd4DLFNHqahsKw== X-Received: by 2002:a17:90a:ec0e:b0:1d9:7f4d:23be with SMTP id l14-20020a17090aec0e00b001d97f4d23bemr7241347pjy.181.1652486599238; Fri, 13 May 2022 17:03:19 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c90:c48:babf:bfaa:d815]) by smtp.gmail.com with ESMTPSA id a29-20020a62d41d000000b0050dc7628160sm2340668pfh.58.2022.05.13.17.03.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 May 2022 17:03:18 -0700 (PDT) In-Reply-To: <87v8uewfuq.fsf@thornhill.no> X-Mailer: Apple Mail (2.3696.80.82.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=casouri@gmail.com; helo=mail-pl1-x62d.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:289761 Archived-At: > On May 9, 2022, at 2:33 PM, Theodor Thornhill = wrote: >=20 >>=20 >> +(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)) >>=20 >> 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. >>=20 >=20 > 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. Now there is treesit-beginning/end-of-defun. You just need to set = treesit-defun-query and everything else come for free. I needed to = invent some heavy machinery for that, resulting in some new handy = functions: - treesit-traverse-depth-first - treesit-traverse-breadth-first - treesit-traverse-forward-depth-first (maybe this should be named = simply treesit-traverse-forward?) - treesit-search-forward - treesit-search-beginning - treesit-search-end They are untested & undocumented (in manual), so please play with them = and report problems :-) (BREAKING) I also changed the semantic of treesit-node-at, the old = semantic sometimes returns unexpected result and it is best to change it = to something more intuitive. The old semantic can still be found in = treesit-node-on. Yuan