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.

Att Righ
  • 725
  • 4
  • 14
  • 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 Nov 30 '22 at 15:36
  • Aha, that does what I'm after. `(count-lines (point-min) (point-max) 't)` works great. – Att Righ Nov 30 '22 at 16:19
  • 1
    No quote required on `t` (or `nil` for that matter): it is a self-evaluating symbol. – NickD Nov 30 '22 at 16:47

1 Answers1

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.

NickD
  • 27,023
  • 3
  • 23
  • 42