[Top][All Lists]

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

Most efficient way of getting position of visual-line?

From: Thomas F. K. Jorna
Subject: Most efficient way of getting position of visual-line?
Date: Tue, 6 Jul 2021 09:45:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0


For a package I'm developing I need to insert an overlay every n visual lines. The fastest way of obtaining the positions of those lines I found is something like

 (let ((vl-list '(0))
        (n 10))
    (goto-line (point-min))
    (dotimes (line (/ (count-screen-lines) n))
      (vertical-motion n)
      (setq vl-list (append vl-list (list (point))))))

Perhaps not the most elegant written, but I've found no faster way than simply scrolling somewhere using vertical-motion

I had hoped that compute-motion could help me, but that does not seem to work well with word-wrapping, as that causes the width of the lines to change.

Ideally I would use something like what display-line-numbers-mode uses for its 'visual setting, but I have to admit that reading the source code is still a bit beyond me, in addition to the fact that those methods do not seem accessible from outsidedisplay-line-numbers-mode.

Anyone have any better ways of solving this? Thank you for your time!

- Thomas F. K. Jorna

reply via email to

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