line-number-at-pos
works fine when visual-line-mode
is off.
But I can't find its equivalent for visual-line-mode
.
1 Answer
The "visual line number, counting from point-min" depends on the window width, font choice, font size, etc... so a given buffer's position can have several different "visual line numbers" at the same time if it's displayed in different windows.
So Emacs does not really try to provide this info.
OTOH you can easily get the "visual line number, counting from windows-start", using posn-at-point
.
Oh, and there's apparently count-screen-lines
(as well as compute-motion
) which should be able to provide the info you want.
Example code:
(defun visual-line-number-at-pos ()
(count-screen-lines
(point-min)
(save-excursion (beginning-of-visual-line) (point))))
-
The window width, font choice, etc are all fixed at the moment that I'm asking for the visual line number. Is there a way to calculate it efficiently?– abo-aboCommented Nov 16, 2015 at 14:10