From: Lars Ingebrigtsen Date: Sun, 7 Feb 2021 16:29:57 +0000 (+0100) Subject: Use `line-number-at-pos' in `count-lines' X-Git-Tag: emacs-28.0.90~3883 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7c5938ad7d8884d03471e2395937e11611faadb9;p=emacs.git Use `line-number-at-pos' in `count-lines' * lisp/simple.el (count-lines): Use `line-number-at-pos', which should be faster. --- diff --git a/lisp/simple.el b/lisp/simple.el index 60c13166e70..568debaa612 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1453,9 +1453,9 @@ included in the count." (save-excursion (save-restriction (narrow-to-region start end) - (goto-char (point-min)) (cond ((and (not ignore-invisible-lines) (eq selective-display t)) + (goto-char (point-min)) (save-match-data (let ((done 0)) (while (re-search-forward "\n\\|\r[^\n]" nil t 40) @@ -1468,6 +1468,7 @@ included in the count." (1+ done) done)))) (ignore-invisible-lines + (goto-char (point-min)) (save-match-data (- (buffer-size) (forward-line (buffer-size)) @@ -1482,7 +1483,11 @@ included in the count." (assq prop buffer-invisibility-spec))) (setq invisible-count (1+ invisible-count)))) invisible-count)))) - (t (- (buffer-size) (forward-line (buffer-size)))))))) + (t + (goto-char (point-max)) + (if (bolp) + (1- (line-number-at-pos)) + (line-number-at-pos))))))) (defcustom what-cursor-show-names nil "Whether to show character names in `what-cursor-position'."