GNU bug report logs -
#23675
Feature request: Emacs 25.0.94: count-lines should offer a way to ignore invisible lines, e.g. outline mode
Previous Next
Reported by: Robert Weiner <rsw <at> gnu.org>
Date: Wed, 1 Jun 2016 15:34:03 UTC
Severity: wishlist
Tags: fixed, patch
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
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 <rsw <at> gnu.org> 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.
>
[Message part 2 (text/html, inline)]
[count-lines-diff.txt (text/plain, attachment)]
This bug report was last modified 1 year and 295 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.