diff options
| author | Kim F. Storm | 2004-01-22 20:42:52 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2004-01-22 20:42:52 +0000 |
| commit | f076870ac39d43bd070cb3c8666a6837dc7ae4be (patch) | |
| tree | f1080dec1e4e893ffca6ce136914b76dacf10805 | |
| parent | 455316e213b0cadbba0545a095243f90e242d16a (diff) | |
| download | emacs-f076870ac39d43bd070cb3c8666a6837dc7ae4be.tar.gz emacs-f076870ac39d43bd070cb3c8666a6837dc7ae4be.zip | |
(line-at-pos): New defun.
(what-line): Use it. Optimize by only counting lines in narrowed region once.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/simple.el | 34 |
2 files changed, 26 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0073e5143ab..9373f8aa984 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2004-01-22 Kim F. Storm <storm@cua.dk> | ||
| 2 | |||
| 3 | * simple.el (line-at-pos): New defun. | ||
| 4 | (what-line): Use it. Optimize by only counting lines in narrowed | ||
| 5 | region once. | ||
| 6 | |||
| 1 | 2004-01-22 Kenichi Handa <handa@m17n.org> | 7 | 2004-01-22 Kenichi Handa <handa@m17n.org> |
| 2 | 8 | ||
| 3 | * language/cyrillic.el (ccl-encode-windows-1251-font): Rearrange | 9 | * language/cyrillic.el (ccl-encode-windows-1251-font): Rearrange |
diff --git a/lisp/simple.el b/lisp/simple.el index d23ed11c6c3..3d2be573012 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -498,20 +498,15 @@ that uses or sets the mark." | |||
| 498 | (defun what-line () | 498 | (defun what-line () |
| 499 | "Print the current buffer line number and narrowed line number of point." | 499 | "Print the current buffer line number and narrowed line number of point." |
| 500 | (interactive) | 500 | (interactive) |
| 501 | (let ((opoint (point)) start) | 501 | (let ((opoint (point)) (start (point-min)) |
| 502 | (save-excursion | 502 | (n (line-at-pos))) |
| 503 | (save-restriction | 503 | (if (= start 1) |
| 504 | (goto-char (point-min)) | 504 | (message "Line %d" n) |
| 505 | (widen) | 505 | (save-excursion |
| 506 | (forward-line 0) | 506 | (save-restriction |
| 507 | (setq start (point)) | 507 | (widen) |
| 508 | (goto-char opoint) | 508 | (message "line %d (narrowed line %d)" |
| 509 | (forward-line 0) | 509 | (+ n (line-at-pos start) -1) n)))))) |
| 510 | (if (/= start (point-min)) | ||
| 511 | (message "line %d (narrowed line %d)" | ||
| 512 | (1+ (count-lines (point-min) (point))) | ||
| 513 | (1+ (count-lines start (point)))) | ||
| 514 | (message "Line %d" (1+ (count-lines (point-min) (point))))))))) | ||
| 515 | 510 | ||
| 516 | (defun count-lines (start end) | 511 | (defun count-lines (start end) |
| 517 | "Return number of lines between START and END. | 512 | "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." | |||
| 536 | done))) | 531 | done))) |
| 537 | (- (buffer-size) (forward-line (buffer-size))))))) | 532 | (- (buffer-size) (forward-line (buffer-size))))))) |
| 538 | 533 | ||
| 534 | (defun line-at-pos (&optional pos) | ||
| 535 | "Return (narrowed) buffer line number at position POS. | ||
| 536 | If POS is nil, use current buffer location." | ||
| 537 | (let ((opoint (or pos (point))) start) | ||
| 538 | (save-excursion | ||
| 539 | (goto-char (point-min)) | ||
| 540 | (setq start (point)) | ||
| 541 | (goto-char opoint) | ||
| 542 | (forward-line 0) | ||
| 543 | (1+ (count-lines start (point)))))) | ||
| 544 | |||
| 539 | (defun what-cursor-position (&optional detail) | 545 | (defun what-cursor-position (&optional detail) |
| 540 | "Print info on cursor position (on screen and within buffer). | 546 | "Print info on cursor position (on screen and within buffer). |
| 541 | Also describe the character after point, and give its character code | 547 | Also describe the character after point, and give its character code |