emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tree-sitter api


From: Stefan Monnier
Subject: Re: Tree-sitter api
Date: Tue, 24 Aug 2021 18:51:45 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> (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’s like 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]