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 api Date: Thu, 26 Aug 2021 22:45:06 -0700 Message-ID: References: <83r1f7hydn.fsf@gnu.org> <95F37923-5BF9-4D81-B361-267CF119FBCA@gmail.com> <735AF34C-FD18-4A6A-A99D-E5D8EB4DE4F3@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) 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="28511"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stephen Leake , Eli Zaretskii , Theodor Thornhill , =?utf-8?Q?Cl=C3=A9ment_Pit-Claudel?= , emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Aug 27 07:46:22 2021 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 1mJUh4-00079W-Ct for ged-emacs-devel@m.gmane-mx.org; Fri, 27 Aug 2021 07:46:22 +0200 Original-Received: from localhost ([::1]:38158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJUh2-0004Bl-DI for ged-emacs-devel@m.gmane-mx.org; Fri, 27 Aug 2021 01:46:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJUfx-0003Qd-2w for emacs-devel@gnu.org; Fri, 27 Aug 2021 01:45:13 -0400 Original-Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]:36616) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJUfv-0002MH-3n; Fri, 27 Aug 2021 01:45:12 -0400 Original-Received: by mail-oi1-x22a.google.com with SMTP id s20so8166564oiw.3; Thu, 26 Aug 2021 22:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Zx8SbYtcUhB0QoffDaTvW77eGyoOoy+YsSAFNO6FofA=; b=iWIr0WcirECDhyVn28RW+rXwOf4era5BxpgooT2ehKseQa++ETk7WMl14GB6W/xh2L k+xlOGpTiwOsN1J1OX7wMBcUvSezGoIq84SdGxO9DqRBtM12JXJ4yyhqJxSmiTA+0hAR VPkABIf4PoIdX4oaDjqZf+LV1QXGIVMoGDZNO5m8y2d4unrd91ShmCsNpGEP/DtO+GdI DAzt0Yt8xoLIv4jz3wK5kJb9Jj6GwKwrO++S4+DPcvjaOI7hwf8VgUROkVfLK9/r2biu jaS52VsT7/BK3EZ/QDWUeYWuWgT2lf8jNZdTlez6ZbQAxFZlHT8tqIAB1mf+XAxB0X9e 87EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Zx8SbYtcUhB0QoffDaTvW77eGyoOoy+YsSAFNO6FofA=; b=SJ4yilLCS7YDMZUwSv5gmjKplZgRFNOT7NZAMjG2U7IG7r/DPz6+JLSb1kg80xSz9h LmBzOMCpj13xReRf9+SfaMBoEJSz1VcNfetUg/EPj42GcMlrh2WbnbITcRRLmyat3cNu VWTFetEX5v+rGzuBu8skIh4N2qLZ/FYX2ppiWpvKA2Y+BHyYv6iNnhACsz03j09JZO+e ufC5aRQVz/KPoNlE32nKQoPVoN6HRhArDQ1GJfVqGGZyw4STOKoH3M+oaLoAC2/8aDjq BugfeOeBqmPjKkL06cI11KE2JS/DdQQqsJko3g4B8VQO9Ozc8Sp/P1hFKoSkqXkPPbZ5 xrlA== X-Gm-Message-State: AOAM533VanswxoUuj9skdVVQNc/s0twr1bwjnO3r0ZBUO9DkYlJVqmVJ upt04MTIdGYSoj1AETQUoIorg1GiWhg= X-Google-Smtp-Source: ABdhPJz4XPMx8/8t13sStoKynBAStsiIqV08Iu9kmQUflNWPm50xB+HjtlOiPw7wKHc7pEOxEG3v9w== X-Received: by 2002:a54:4e8f:: with SMTP id c15mr14017434oiy.114.1630043107654; Thu, 26 Aug 2021 22:45:07 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c9f:c59b:314a:fb16:6e26]) by smtp.gmail.com with ESMTPSA id f132sm1179554oia.48.2021.08.26.22.45.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Aug 2021 22:45:07 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.13) Received-SPF: pass client-ip=2607:f8b0:4864:20::22a; envelope-from=casouri@gmail.com; helo=mail-oi1-x22a.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.23 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:273114 Archived-At: > On Aug 24, 2021, at 5:21 PM, Stefan Monnier = wrote: >=20 >> Okay, here is the (ad-hoc) infrastructure I came up with: >=20 > It's more than what I proposed, but it looks fairly good. > See patch below which is the "side effect" of reading your code. >=20 > You'll see that I removed the "-function" from the function name (this > suffix is used for variables holding functions rather than for the > function themselves) and I split that function into two, the outer one > (tree-sitter-indent) implementing basically what I suggested and the > inner one (tree-sitter-simple-indent) implementing the extra structure > you added to it, mediated by a new var `tree-sitter-indent-function` > which modes can set if they want to use another algorithm than the one > you implemented in `tree-sitter-simple-indent`. >=20 > The reason why I divided it this way is that my experience with > indentation code is that it can be useful occasionally to call > recursively the indentation code to know where a node *would* be > indented. This comes in handy when you want to be able to provide > indentation styles like: >=20 > let myvariable =3D if (foo) { > bar > } else { > baz > } >=20 > where the body of the `if` branches needs to be indented relative to = the > position where the `if` itself would be indented if it were on its own = line. Thanks, Stefan :-) I applied your patch and fixed the two FIXME=E2=80=99s.= Yuan=