diff options
| author | Damien Cassou | 2017-04-09 12:46:57 +0200 |
|---|---|---|
| committer | Nicolas Petton | 2017-06-19 11:17:56 +0200 |
| commit | ae98cdf9431604d0f722f1db217ca06debfbb7b6 (patch) | |
| tree | 282b0658d520e638e6905f40153343de34259ff0 /lisp | |
| parent | dbe3e416af5d845dc774341eb66971ab1a72983b (diff) | |
| download | emacs-ae98cdf9431604d0f722f1db217ca06debfbb7b6.tar.gz emacs-ae98cdf9431604d0f722f1db217ca06debfbb7b6.zip | |
Add current-line in simple.el
* lisp/simple.el (current-line): New function.
* test/list/simple-tests.el: Add tests for current-line.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/simple.el | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index a5565ab6e73..e3b7665bf5a 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -1270,18 +1270,25 @@ and the greater of them is not at the start of a line." | |||
| 1270 | done))) | 1270 | done))) |
| 1271 | (- (buffer-size) (forward-line (buffer-size))))))) | 1271 | (- (buffer-size) (forward-line (buffer-size))))))) |
| 1272 | 1272 | ||
| 1273 | (defun line-number-at-pos (&optional pos) | 1273 | (defun line-number-at-pos (&optional pos absolute-p) |
| 1274 | "Return (narrowed) buffer line number at position POS. | 1274 | "Return buffer line number at position POS. |
| 1275 | If POS is nil, use current buffer location. | 1275 | If POS is nil, use current buffer location. |
| 1276 | Counting starts at (point-min), so the value refers | 1276 | |
| 1277 | to the contents of the accessible portion of the buffer." | 1277 | If ABSOLUTE-P is nil, the default, counting starts |
| 1278 | (let ((opoint (or pos (point))) start) | 1278 | at (point-min), so the value refers to the contents of the |
| 1279 | (save-excursion | 1279 | accessible portion of the (potentially narrowed) buffer. If |
| 1280 | (goto-char (point-min)) | 1280 | ABSOLUTE-P is non-nil, ignore any narrowing and return the |
| 1281 | (setq start (point)) | 1281 | absolute line number." |
| 1282 | (goto-char opoint) | 1282 | (save-restriction |
| 1283 | (forward-line 0) | 1283 | (when absolute-p |
| 1284 | (1+ (count-lines start (point)))))) | 1284 | (widen)) |
| 1285 | (let ((opoint (or pos (point))) start) | ||
| 1286 | (save-excursion | ||
| 1287 | (goto-char (point-min)) | ||
| 1288 | (setq start (point)) | ||
| 1289 | (goto-char opoint) | ||
| 1290 | (forward-line 0) | ||
| 1291 | (1+ (count-lines start (point))))))) | ||
| 1285 | 1292 | ||
| 1286 | (defun what-cursor-position (&optional detail) | 1293 | (defun what-cursor-position (&optional detail) |
| 1287 | "Print info on cursor position (on screen and within buffer). | 1294 | "Print info on cursor position (on screen and within buffer). |