From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter api Date: Tue, 24 Aug 2021 18:51:45 -0400 Message-ID: References: <83r1f7hydn.fsf@gnu.org> <95F37923-5BF9-4D81-B361-267CF119FBCA@gmail.com> <735AF34C-FD18-4A6A-A99D-E5D8EB4DE4F3@gmail.com> <86im02bobr.fsf@stephe-leake.org> <8B9072FF-02F5-48CC-844A-1E0C2FC42CE9@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="35533"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Stephen Leake , Eli Zaretskii , Theodor Thornhill , =?windows-1252?Q?Cl=E9ment?= Pit-Claudel , emacs-devel To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Aug 25 00:53:02 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 1mIfHx-00090G-NY for ged-emacs-devel@m.gmane-mx.org; Wed, 25 Aug 2021 00:53:01 +0200 Original-Received: from localhost ([::1]:35038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIfHv-0005M3-Eu for ged-emacs-devel@m.gmane-mx.org; Tue, 24 Aug 2021 18:52:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIfGp-0004fX-DF for emacs-devel@gnu.org; Tue, 24 Aug 2021 18:51:51 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:12710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIfGn-0004b1-MF; Tue, 24 Aug 2021 18:51:50 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 28E0C10020E; Tue, 24 Aug 2021 18:51:48 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B97051000C9; Tue, 24 Aug 2021 18:51:46 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1629845506; bh=HSrMbqg5tiwFK5YFzYqB9AzkXHh3/V0UIUsQAW1QlwQ=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=m+OrkEV46R6i7dolUsk/7qR9+82FLuHVjT5eyX4H9te+RSl4VkpCPeF4+o7mEgDYJ hoGfXh3VQF3iZwn+ptTaljAML6Bga/lDjDZ3HZ3WUEj5Fln/Y86sj7Z+MAeBQT7ZXW a/B8MHDXSMZILcPSFhsgcGSGgv/sEYdpwcTqwhdeg1NDNlr0heUUP8TbAnNlKmwfIs sLvQOxoT4w0TYL5+qp5TDr46QFPkuVsPahXJL++yoJUZLPEo11nE33mBYVJBxMDN/N wYld5U+y0HsSQUjLULlJhJw2OLsdqSC7pM0b9fdMZ9vjQzoEbbGxICCfStonvObPq8 re8weZziPcitw== Original-Received: from alfajor (unknown [104.247.244.135]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 70C70120388; Tue, 24 Aug 2021 18:51:46 -0400 (EDT) In-Reply-To: <8B9072FF-02F5-48CC-844A-1E0C2FC42CE9@gmail.com> (Yuan Fu's message of "Sun, 22 Aug 2021 23:51:08 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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:272933 Archived-At: > (I think most indentation engine works line-by-line from the > first line.) FWIW, the vast majority of the code performing indentation in the various major modes in Emacs does it by parsing backward from the position of point and doesn't work "line by line". The "line by line" is only used for `indent-region` but the workhorse function is in `indent-line-function` and only performs indentation of a single line without touching anything else. IOW, `indent-region` will usually go "line-by-line" but for each line the actual work will be by parsing backward from that line (i.e. re-parsing the previous lines that had just been parsed for the previous line's indentation). This is obviously not ideal in terms of efficiency, but in practice indenting a single line usually only needs to parse a small number of lines (I suspect it's almost O(1) of *amortized* complexity so in most cases the algorithmic complexity of `indent-region` is not really affected). > Stefan, can you have a look at tree-sitter-simple-indent? It=E2=80=99s li= ke two > messages up? It goes generally along the (pos . offset) idea but has > some twists. It's in my todo list, yes. I'm still backlog'd, tho. Stefan