On 7/26/21 14:32, chad wrote: > > In order to exercise many of its over-all benefits, tree-sitter builds > and maintains a parse tree of the whole file, and takes care to modify > that tree in-place with minimized changes. If emacs+ts were to remove > everything outside the narrow and then re-add it each time something > temporarily narrowed a file (say, to enhance mental focus), then > emacs+ts would be (wastefully) throwing away some of the > underlying assumptions that makes ts useful. > > Emacs' internals use narrow/widen *and mostly honor them at most > levels* because they are emacs' abstraction for separating parts of a > buffer from other parts. Tree-sitter has a separate abstraction for > doing this -- the developer can have ts use different internal objects > for different parts of the file. This allows editors like Atom (a > major influence on ts' original feature set) to support what emacs > would call multiple major modes. (Emacs could still use some help > here, c.f. Alan's proposal for "islands" from a few years back.) > > Using the ts multiple parsers support inside emacs+ts to "handle" > narrowing seems like a strong idea, but there are likely some > complexities involved in "switching" back and forth between the > full-file parse and the narrowed parse, plus making sure that the > right parses are updated when the buffer changes. With that in mind, > it might be easier to start with an emacs+ts prototype that always > uses the full-file parse, and then adding the "sub-parses" later. In > that sense, it seems like it's primarily a matter of what level of > itch people want to start scratching when. > >  emacs-dev islands discussion: > https://lists.gnu.org/archive/html/emacs-devel/2016-04/msg00585.html > I strongly agree with what's said here. I'll also note that some languages will not parse correctly if you narrow to (say) only a block or part of a function and not a whole file, and it would be unexpected by users to narrow to a part of their code and suddenly have things like tree sitter go haywire. If I narrow to a part of a function, I'd like my indentation and highlighting to remain correct. My suggestion is that we at least experiment with allowing Tree Sitter to see the whole file or just the narrowed parts, and see what works in practice works better. Perry