Reputation: 5825
As you can see in that image, I can move my cursor to the last line (if I use RET on the last column of the last line), and the last line doesn't appear on the left line number column.
It is also not highlighted, but as soon as I type on it, like if I enter an "a", it will be highlighted and appear on the line number list on the left.
This is a very tiny bug, but it slightly annoys me - it really isn't a major issue, but I'd really like a way to fix it.
Thanks!
Upvotes: 0
Views: 2141
Reputation: 30988
Assuming you use the Linum
package for your line numbers (in the left-hand margin), here's the patch that numbers the last line of the buffer:
--- linum.el-rev474.svn000.tmp.el Fri May 08 11:30:24 2009
+++ linum.el Fri May 08 11:29:38 2009
@@ -135,8 +135,15 @@
- (let ((line (line-number-at-pos))
- (limit (window-end win t))
- (fmt (cond ((stringp linum-format) linum-format)
- ((eq linum-format 'dynamic)
- (let ((w (length (number-to-string
- (count-lines (point-min) (point-max))))))
- (concat "%" (number-to-string w) "d")))))
- (width 0))
+ (let* ((line (line-number-at-pos))
+ (limit (window-end win t))
+ ;; set empty-line-at-eob flag
+ (empty-line-at-eob (or (equal ?\n (char-before (point-max)))
+ (equal (point-min) (point-max))))
+ ;; we will automatically number the line at eob if it's not empty
+ ;; (so we'll say it's already done)
+ (numbered-line-at-eob (not empty-line-at-eob))
+ (fmt (cond ((stringp linum-format) linum-format)
+ ((eq linum-format 'dynamic)
+ (let* ((c (count-lines (point-min) (point-max)))
+ (w (length (number-to-string
+ (+ c (if empty-line-at-eob 1 0))))))
+ (concat "%" (number-to-string w) "d")))))
+ (width 0))
@@ -146 +153,2 @@
- (while (and (not (eobp)) (<= (point) limit))
+ ;; stop if point>limit, or if eobp and numbered-line-at-eob
+ (while (and (not (and (eobp) numbered-line-at-eob)) (<= (point) limit))
@@ -165,0 +174,4 @@
+ ;; before moving forward, if we're already at eob
+ (if (eobp)
+ ;; then we've numbered the empty line
+ (setq numbered-line-at-eob t))
Upvotes: 6
Reputation: 1233
You can edit linum.el if you really want to change the functionality. Here is the code to do what you want.
You should be aware it isn't a bug, though. What you want is subjective; it was a design decision.
Upvotes: 2
Reputation: 22262
Actually, it's not a bug. The line is empty and there is nothing on it. So it doesn't really count as "a line" until content is on it. The very last character in the file is the newline character on line 99. Line 100 is functionally treated as "it doesn't exist" until there is content on it.
Upvotes: 8