0

I want to count the number of lines shown with hide-lines-matching.

count-lines seems to return the wrong number.

(length hide-lines-invisible-areas) seems to be related in that we hide the regions between the lines.

3
  • 1
    Does (count-lines start end t) return the right number? If so, do C-h f count-lines and read about the IGNORE-INVISIBLE-LINES optional argument.
    – NickD
    Commented Nov 30, 2022 at 15:36
  • Aha, that does what I'm after. (count-lines (point-min) (point-max) 't) works great.
    – Att Righ
    Commented Nov 30, 2022 at 16:19
  • 1
    No quote required on t (or nil for that matter): it is a self-evaluating symbol.
    – NickD
    Commented Nov 30, 2022 at 16:47

1 Answer 1

1

C-h f count-lines says:

(count-lines START END &optional IGNORE-INVISIBLE-LINES)

...

When IGNORE-INVISIBLE-LINES is non-nil, invisible lines are not included in the count.

So, in order to count visible lines between start and end, use (count-lines start end t), setting the optional argument IGNORE-INVISIBLE-LINES to t.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.