Emacs - 空行没有行号

1 emacs line-numbers

我正在尝试在Emacs中设置行号.
Linum效果很好,但是当我打开两个缓冲区时,空行的编号会消失.我使用Manjaro Linux.Emacs在终端工作.

这是截图.

来自.emacs文件的代码:

(add-hook 'find-file-hook (lambda () (linum-mode 1)))

(unless window-system
  (add-hook 'linum-before-numbering-hook
    (lambda ()
      (setq-local linum-format-fmt
          (let ((w (length (number-to-string
                (count-lines (point-min) (point-max))))))
            (concat "%"(number-to-string w) "d"))))))

(defun linum-format-func (line)
  (concat
   (propertize (format linum-format-fmt line) 'face 'linum)
   (propertize " " 'face 'mode-line)))

(unless window-system
  (setq linum-format 'linum-format-func))
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

Bri*_*orn 5

  1. 您可以通过仅使用替换所有上述代码来解决此问题

    (global-linum-mode 1)
    
    Run Code Online (Sandbox Code Playgroud)
  2. linum-mode应该已经为你做了可变大小格式的事情.不知道你为什么要重新发明轮子.

  3. 也许你的问题是你正在尝试将concat两个propertize-d对象串起来.您可以通过您的格式样避免这种情况"%3d ",而不是"%3d"和concatting " "更高版本:

    (add-hook 'find-file-hook (lambda () (linum-mode 1)))
    
    (unless window-system
      (add-hook 'linum-before-numbering-hook
        (lambda ()
          (setq-local linum-format-fmt
              (let ((w (length (number-to-string
                    (count-lines (point-min) (point-max))))))
                (concat "%" (number-to-string w) "d "))))))
    
    (defun linum-format-func (line)
      (propertize (format linum-format-fmt line) 'face 'linum))
    
    (unless window-system
      (setq linum-format 'linum-format-func))
    
    Run Code Online (Sandbox Code Playgroud)