*** simple-orig.el 2016-06-06 19:24:50.000000000 -0400 --- simple.el 2016-06-06 19:24:50.000000000 -0400 *************** *** 1214,1241 **** (message "line %d (narrowed line %d)" (+ n (line-number-at-pos start) -1) n)))))) ! (defun count-lines (start end) "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." (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) ! (if (eq selective-display t) ! (save-match-data ! (let ((done 0)) ! (while (re-search-forward "[\n\C-m]" nil t 40) ! (setq done (+ 40 done))) ! (while (re-search-forward "[\n\C-m]" nil t 1) ! (setq done (+ 1 done))) ! (goto-char (point-max)) ! (if (and (/= start end) ! (not (bolp))) ! (1+ done) ! done))) ! (- (buffer-size) (forward-line (buffer-size))))))) (defun line-number-at-pos (&optional pos) "Return (narrowed) buffer line number at position POS. --- 1214,1258 ---- (message "line %d (narrowed line %d)" (+ n (line-number-at-pos start) -1) n)))))) ! (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)))))))) (defun line-number-at-pos (&optional pos) "Return (narrowed) buffer line number at position POS.