Attached is a patch to add this feature based on 25.0.94. Please consider applying it to Emacs. I have also included the full new version of the function below. --------------------- (defun count-lines (start end &optional ignore-invisible-lines-flag) "Return number of lines between START and END. This is usually the number of newlines between them, but can be one more if START is not equal to END and the greater of them is not at the start of a line. With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed with selective-display are excluded from the line count." (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) (cond ((and (not ignore-invisible-lines-flag) (eq selective-display t)) (save-match-data (let ((done 0)) (while (re-search-forward "\n\\|\r[^\n]" nil t 40) (setq done (+ 40 done))) (while (re-search-forward "\n\\|\r[^\n]" nil t 1) (setq done (+ 1 done))) (goto-char (point-max)) (if (and (/= start end) (not (bolp))) (1+ done) done)))) (ignore-invisible-lines-flag (- (buffer-size) (forward-line (buffer-size)) (let ((invisible-count 0) prop) (goto-char (point-min)) (while (re-search-forward "\n\\|\r[^\n]" nil t) (setq prop (get-char-property (1- (point)) 'invisible)) (if (if (eq buffer-invisibility-spec t) prop (or (memq prop buffer-invisibility-spec) (assq prop buffer-invisibility-spec))) (setq invisible-count (1+ invisible-count)))) invisible-count))) (t (- (buffer-size) (forward-line (buffer-size)))))))) --------------------- On Wed, Jun 1, 2016 at 10:23 AM, Robert Weiner wrote: > > Often when particular lines are hidden, one wants to count only visible lines. count-lines presently cannot do this. XEmacs has for a long-time had count-lines take an optional 3rd parameter flag which if non-nil, ignores invisible lines in the line count. This would be very helpful whenever selective-display is in use. >