【问题标题】:Emacs - No line numbering for empty linesEmacs - 空行没有行号
【发布时间】:2016-07-21 12:47:41
【问题描述】:

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

Here's screenshot.

.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))

我该如何解决?

【问题讨论】:

标签: emacs line-numbers


【解决方案1】:
  1. 您可以通过将上述代码的全部替换为仅

    来解决此问题
    (global-linum-mode 1)
    
  2. linum-mode 应该已经为 你。不知道你为什么要重新发明轮子。

  3. 也许您的问题是您试图将concat 两个propertize-d 对象串起来。您可以通过将格式设置为 "%3d " 而不是 "%3d" 并稍后连接 " " 来避免这种情况:

    (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))
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 2011-07-10
    • 1970-01-01
    • 2021-11-12
    相关资源
    最近更新 更多