正如您在该图像中看到的,我可以将光标移动到最后一行(如果我在最后一行的最后一列使用RET),最后一行不会出现在左行号列上。
它也没有突出显示,但只要我输入它,就像我输入“a”一样,它会突出显示并显示在左侧的行号列表中。
这是一个非常小的错误,但它有点让我烦恼 - 它确实不是一个主要问题,但我真的想要一种解决它的方法。
谢谢!
答案 0 :(得分:8)
实际上,这不是一个错误。这条线是空的,上面没有任何东西。因此,在内容开始之前,它并不算作“一条线”。文件中的最后一个字符是第99行的换行符。第100行在功能上被视为“它不存在”,直到有内容为止。
答案 1 :(得分:6)
假设您使用Linum
包作为行号(在左侧边距中),here's编号为缓冲区最后一行的补丁:
--- 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))
答案 2 :(得分:2)