summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-02-07 17:29:57 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-02-07 17:30:02 +0100
commit7c5938ad7d8884d03471e2395937e11611faadb9 (patch)
treeb177a0664482391bab587f37a4dedbcd238beca2
parent9380a7ed906e667df4fc5b9d9c8e487fafa7c654 (diff)
downloademacs-7c5938ad7d8884d03471e2395937e11611faadb9.tar.gz
Use `line-number-at-pos' in `count-lines'
* lisp/simple.el (count-lines): Use `line-number-at-pos', which should be faster.
-rw-r--r--lisp/simple.el9
1 files changed, 7 insertions, 2 deletions
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'."