emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7c5938a: Use `line-number-at-pos' in `count-lines'


From: Lars Ingebrigtsen
Subject: master 7c5938a: Use `line-number-at-pos' in `count-lines'
Date: Sun, 7 Feb 2021 11:30:09 -0500 (EST)

branch: master
commit 7c5938ad7d8884d03471e2395937e11611faadb9
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Use `line-number-at-pos' in `count-lines'
    
    * lisp/simple.el (count-lines): Use `line-number-at-pos', which
    should be faster.
---
 lisp/simple.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 60c1316..568deba 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'."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]