1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-23 07:19:15 +00:00

(line-at-pos): New defun.

(what-line): Use it.  Optimize by only counting lines in narrowed region once.
This commit is contained in:
Kim F. Storm 2004-01-22 20:42:52 +00:00
parent 455316e213
commit f076870ac3
2 changed files with 26 additions and 14 deletions

View File

@ -1,3 +1,9 @@
2004-01-22 Kim F. Storm <storm@cua.dk>
* simple.el (line-at-pos): New defun.
(what-line): Use it. Optimize by only counting lines in narrowed
region once.
2004-01-22 Kenichi Handa <handa@m17n.org> 2004-01-22 Kenichi Handa <handa@m17n.org>
* language/cyrillic.el (ccl-encode-windows-1251-font): Rearrange * language/cyrillic.el (ccl-encode-windows-1251-font): Rearrange

View File

@ -498,20 +498,15 @@ that uses or sets the mark."
(defun what-line () (defun what-line ()
"Print the current buffer line number and narrowed line number of point." "Print the current buffer line number and narrowed line number of point."
(interactive) (interactive)
(let ((opoint (point)) start) (let ((opoint (point)) (start (point-min))
(save-excursion (n (line-at-pos)))
(save-restriction (if (= start 1)
(goto-char (point-min)) (message "Line %d" n)
(widen) (save-excursion
(forward-line 0) (save-restriction
(setq start (point)) (widen)
(goto-char opoint) (message "line %d (narrowed line %d)"
(forward-line 0) (+ n (line-at-pos start) -1) n))))))
(if (/= start (point-min))
(message "line %d (narrowed line %d)"
(1+ (count-lines (point-min) (point)))
(1+ (count-lines start (point))))
(message "Line %d" (1+ (count-lines (point-min) (point)))))))))
(defun count-lines (start end) (defun count-lines (start end)
"Return number of lines between START and END. "Return number of lines between START and END.
@ -536,6 +531,17 @@ and the greater of them is not at the start of a line."
done))) done)))
(- (buffer-size) (forward-line (buffer-size))))))) (- (buffer-size) (forward-line (buffer-size)))))))
(defun line-at-pos (&optional pos)
"Return (narrowed) buffer line number at position POS.
If POS is nil, use current buffer location."
(let ((opoint (or pos (point))) start)
(save-excursion
(goto-char (point-min))
(setq start (point))
(goto-char opoint)
(forward-line 0)
(1+ (count-lines start (point))))))
(defun what-cursor-position (&optional detail) (defun what-cursor-position (&optional detail)
"Print info on cursor position (on screen and within buffer). "Print info on cursor position (on screen and within buffer).
Also describe the character after point, and give its character code Also describe the character after point, and give its character code