unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Most efficient way of getting position of visual-line?
@ 2021-07-06  7:45 Thomas F. K. Jorna
  2021-07-06  9:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-07-06 11:33 ` Eli Zaretskii
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas F. K. Jorna @ 2021-07-06  7:45 UTC (permalink / raw)
  To: help-gnu-emacs

Hello!

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))
   (save-excursion
     (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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Most efficient way of getting position of visual-line?
  2021-07-06  7:45 Most efficient way of getting position of visual-line? Thomas F. K. Jorna
@ 2021-07-06  9:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-07-06 11:33 ` Eli Zaretskii
  1 sibling, 0 replies; 3+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-06  9:16 UTC (permalink / raw)
  To: help-gnu-emacs

Thomas F. K. Jorna wrote:

> (let ((vl-list '(0))
>       (n 10))
>   (save-excursion
>     (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 [...]

Ah, good enough for government work...

But you can replace "line" with `_' otherwise the
byte-compiler will complain it isn't used...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Most efficient way of getting position of visual-line?
  2021-07-06  7:45 Most efficient way of getting position of visual-line? Thomas F. K. Jorna
  2021-07-06  9:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-06 11:33 ` Eli Zaretskii
  1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2021-07-06 11:33 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Thomas F. K. Jorna" <hello@tefkah.com>
> Date: Tue, 6 Jul 2021 09:45:16 +0200
> 
> Anyone have any better ways of solving this? Thank you for your time!

Assuming you already tried beginning-of-visual-line, I guess that's
about it.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-06 11:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-06  7:45 Most efficient way of getting position of visual-line? Thomas F. K. Jorna
2021-07-06  9:16 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-06 11:33 ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).