It's simple to find the number of lines from the cursor to top of the screen, eg:
(- (line-number-at-pos (point)) (line-number-at-pos (window-start)))) However when the hideshow library is used to hide certain text, this is no longer valid in that my cursor may have an on-screen offset of N lines from the top of the screen, which is a much larger number if the hidden text is not taken into account.
Is there a way to calculate the number of lines the cursor is from the top of the screen that takes hidden text into account?
n.b. This question initially referred to "narrowing", which is why so many of the comments are about that.
(- (line-number-at-pos X) (line-number-at-pos Y))with the more efficient(count-lines Y X); b) the functionline-number-at-poswas extended with an optionalABSOLUTEargument in Emacs 26 which returns the line number disregarding any narrowing in effect.hideshow.el. I have edited the question accordingly. If you have not yet done so you should read the manual page on narrowing (see my previous comment) and experiment with that feature, so that you understand what that term actually means.