Anyway to calculate it? (either in lines or pixels)
E.g.,
+-------------------+
4| | <- top line
5| |
6| |
7| ■ <- cursor here. |
Here it is 3 (or 4, if you prefer to include both lines).
I don't know if there is a straightforward way to know that, but you can have:
(windows-text-height)
, which is the amount of lines in current window(line-number-at-pos)
will return the line number in this buffer.(move-to-window-line)
will be able to move the point to the first visible line using argument 0.Knowning this writing a piece of elisp code wich will return the desired distance in lines and letting the point where it was is pretty trivial.
window-line-height
will return the height in pixels of a given line. If you're not using variable fonts it can be used to have the pixel length too, but I'm not sure at all of its accuracy.
(count-lines (window-start) (point))
Better method:
(keymap-global-set "C-c p"
(lambda ()
"Report the distance in lines & pixels."
(interactive)
(let ((posn (posn-at-point)))
(message "%s; %spx"
(cdr (posn-col-row posn))
(cdr (posn-x-y posn))))))