all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Emacs Devel <emacs-devel@gnu.org>
Cc: Eli Zaretskii <eliz@gnu.org>
Subject: Re: Performance of getting line number for positions around point?
Date: Wed, 5 Feb 2025 00:06:29 -0800	[thread overview]
Message-ID: <CB0E4230-7DD9-475F-AD5E-6B945F76CC27@gmail.com> (raw)
In-Reply-To: <DB5A1089-DE61-42D6-8609-CCA977638732@gmail.com>



> On Jan 19, 2025, at 11:18 PM, Yuan Fu <casouri@gmail.com> wrote:
> 
> When sending buffer edits to tree-sitter, we’re supposed to pass it both the byte position and (line, col) position. Up until this point we’ve been only passing the byte position, and just pass a dummy (line, col) position. Most of the time, the (line, col) position just gets carried around in tree-sitter and comes out when tree-sitter reports positions back to us. So as long as we don’t use the (line, col) positions it’s fine.
> 
> However, it turns out that for some languages, the (line, col) information is significant and can affect parsing. As shown in [1]. Most editors do track line and columns so I don’t think tree-sitter will ever track line and column itself just for Emacs.
> 
> So now the question is, is there an existing, performant way to get line numbers? We only need to send line and column positions for buffer edits, so we just need line numbers for positions around point. Also, because narrowing is transparent to tree-sitter, when the buffer is narrowed, the line number also needs to change with it.
> 
> IIUC count_line just counts lines, and redisplay_count_line depends on redisplay?
> 
> [1] https://github.com/tree-sitter/tree-sitter/issues/4001

I haven’t yet started seriously looking into this, but my initial idea is to keep a cache in buffer local variables that stores the line number of a position near point. And in insert/delete functions, we update the line number cache. If we need to get the line number of a point, just scan the content between the cached position and that point.

Does that sound like a good idea? Or there are existing and better ways to do it?

Yuan


       reply	other threads:[~2025-02-05  8:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <DB5A1089-DE61-42D6-8609-CCA977638732@gmail.com>
2025-02-05  8:06 ` Yuan Fu [this message]
2025-02-05 14:20   ` Performance of getting line number for positions around point? Eli Zaretskii
2025-02-08  6:15     ` Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CB0E4230-7DD9-475F-AD5E-6B945F76CC27@gmail.com \
    --to=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.