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: Update on tree-sitter structure navigation Date: Sat, 2 Sep 2023 15:12:32 -0700 Message-ID: References: <5E7F2A94-4377-45C0-8541-7F59F3B54BA1@gmail.com> <87h6odhxs6.fsf@localhost> <87h6oddkm1.fsf@hugot.nl> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="18296"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Ihor Radchenko , emacs-devel , Danny Freeman , Theodor Thornhill , =?utf-8?Q?Jostein_Kj=C3=B8nigsen?= , Randy Taylor , Wilhelm Kirschbaum , Perry Smith , Dmitry Gutov To: Hugo Thunnissen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 03 00:13:06 2023 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 1qcYra-0004Vo-9N for ged-emacs-devel@m.gmane-mx.org; Sun, 03 Sep 2023 00:13:06 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcYrJ-00033B-CD; Sat, 02 Sep 2023 18:12:49 -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 1qcYrI-00032s-31 for emacs-devel@gnu.org; Sat, 02 Sep 2023 18:12:48 -0400 Original-Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcYrF-0003jM-GZ for emacs-devel@gnu.org; Sat, 02 Sep 2023 18:12:47 -0400 Original-Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3a7ca8720a0so179564b6e.2 for ; Sat, 02 Sep 2023 15:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693692764; x=1694297564; darn=gnu.org; 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=1KpdL+0QGza0etGBJo1onlavM+wCsMGWu5kh1iAbLwg=; b=PsvtPvknOw6bcB3mKek0Ge7r3tiD65JIJ9H/Zkexhve7o9e6hXECKqRT3z5FmHjG7j cKPCAr0Q0016gw7baUfrumxFjQ/4WIEQupUXEDUSyv5DYIIT3tnHoNSM6HjCseXUj8cd M6FSGgHvXGMnIstlZupIwzv7+afxszNo/YoH4lvCXKPq5EaIGx2YZ30T0Zp4mpmbu8Fb BArbq3qsCDAiem2esLEFD49mnTm3rNrcixqG933nGo9nTO/mLzMKjbwG/6bIiGBdUlNy IZ04RF78vCchSqtTQabzOZV2ucVPrW3JIa3GnK4HfF4tonFZcqcD4aglSKj5QXcKlXSO VVGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693692764; x=1694297564; 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=1KpdL+0QGza0etGBJo1onlavM+wCsMGWu5kh1iAbLwg=; b=FYZZS1rEafY26lJ0EGloJnXH2t9DPljjb4AsygZ76tBZVilsXA6EuK0srNXvhXoXSh cxp0Va4/pmfiUPi44SHB9flepcmF1lA6ltKsvTnHBf1EgGpKnATFA66AzCn4ZKJ7PHO/ HrVqSdx7FkfdCwFVj2qhKnGUT1oYxqDDItRjc73kAukVc0FL4gNE8iU8evZ2to7CTC/L VN+vcWBwZjl1i2zSCpEkJkVnnD4qZgDwbhG8DiIiyjCmy9Lq3kOwyepOzXqyJLoa/gRi G6dceGFuTuQSKWBrlNGsDC47zDJ+GbxXha3xYnLHrUkPZVKQKMDed9AoAehUOUI0Xpf0 Nvig== X-Gm-Message-State: AOJu0YwSI6GH4E4Xj4XMm5Ydpf8kXNU3rXClReXdB9jfhHZRPruPMeXn wMbUl9KUFYvxBzwcz8Us5es= X-Google-Smtp-Source: AGHT+IGx6FLVjx/UjVXUu9VZB/ODkkC8zedhiOFofQwEefTwPTB7GngVIrAWL7eOHZKY/k5PiRl3MQ== X-Received: by 2002:a05:6808:2a5a:b0:3a8:b056:c3a2 with SMTP id fa26-20020a0568082a5a00b003a8b056c3a2mr6441200oib.47.1693692764170; Sat, 02 Sep 2023 15:12:44 -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 m185-20020a633fc2000000b005642314f05fsm4922348pga.1.2023.09.02.15.12.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Sep 2023 15:12:43 -0700 (PDT) In-Reply-To: <87h6oddkm1.fsf@hugot.nl> X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=casouri@gmail.com; helo=mail-oi1-x233.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: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:309917 Archived-At: > On Sep 2, 2023, at 1:50 AM, Hugo Thunnissen wrote: >=20 > Ihor Radchenko writes: >=20 >> Yuan Fu writes: >>=20 >>> In the months after wrapping up tree-sitter stuff in emacs-29, I was >>> thinking about how to implement structural navigation and extracting >>> information from the parser with tree-sitter. In emacs-29 we have >>> things like treesit-beginning/end-of-defun, and treesit-defun-name. = I >>> was thinking maybe we can generalize this to support getting = arbitrary >>> =E2=80=9Cthing=E2=80=9D at point, move around them, and getting = information like the >>> name of a defun, its arglist, parent of a class, type of an variable >>> declaration, etc, in a language-agnostic way. >>=20 >> Note that Org mode also does all of these using >> https://orgmode.org/worg/dev/org-element-api.html >>=20 >> It would be nice if we could converge to more consistent interface >> across all the modes. For example, by extending `thing-at-point' to = handle >> parsed elements, not just simplistic regexp-based "thing" boundaries >> exposed by `thing-at-point' now. >>=20 >> Org approaches getting name/begin/end/arguments using a common API: >>=20 >> (org-element-property :begin NODE) >> (org-element-property :end NODE) >> (org-element-property :contents-begin NODE) >> (org-element-property :contents-end NODE) >> (org-element-property :name NODE) >> (org-element-property :args NODE) >>=20 >> Language-agnostic "thing"s will certainly be welcome, especially = given >> that tree-sitter grammars use inconsistent naming schemes, which have = to >> be learned separately, and may even change with grammar versions. >>=20 >> I think that both NODE types and attributes can be standardized. >>=20 >=20 > It would be great to see standardization that can work with more than > just tree-sitter. Depending on how extensive such a generic NODE type > and accompanying API are, I could see standardization of a lot of = things > that are currently implemented in major modes, to name a few: >=20 > - indentation > - fontification > - thing-at-point > - imenu > - simple forms of completion (variables, function names in buffer) >=20 > I have some idea of the underpinnings, but I have never implemented a > full major mode so it is hard for me to judge the practicality of > this. How much would be practical to standardize, without needlessly > complicated/resource-heavy abstractions? I don=E2=80=99t know which level of standardization you are thinking = about, but aren=E2=80=99t they already standardized? - indentation: indent-line/region-function - fontification: font-lock-defaults - thing-at-point: thing-at-point function - imenu: imenu-create-index-function - completion: completion-at-point-function Yuan=