将Linum模式配置为在空格模式下不显示空格符号?

3

目前启用了linum模式和空格模式的我的缓冲区如下所示:

enter image description here

如何配置linum区域以不渲染空格符号?

2个回答

3
你可以改进@lawlists的第二个解决方案,但是不要使用0作为空格替换,可以使用一些奇异的空格,如en-space,它将是"\u2002"。由于我们没有使用比例字体,这看起来就像是一个空格,但whitespace不会干扰它。
实际上,我正在使用linum-relative-mode,你可以方便地对linum-relative进行advice:
(advice-add 'linum-relative :filter-return
          (lambda (num)
            (if (not (get-text-property 0 'invisible num))
                (propertize (replace-regexp-in-string " " "\u2002" num)
                            'face (get-text-property 0 'face num)))))

3
观察:没有必要在行号右侧添加空格(如问题所示),因为可以使用边缘宽度来控制行号与正文之间的间距。
(setq-default left-fringe-width  10)
(setq-default right-fringe-width  0)
(set-face-attribute 'fringe nil :background "black")

选项1:然而,这个并不是靠右对齐。
(setq linum-format "%d")

选项#2:使用前导零 - 是靠右对齐的。
(eval-after-load 'linum
  '(progn
     (defface linum-leading-zero
       `((t :inherit 'linum
            :foreground ,(face-attribute 'linum :background nil t)))
       "Face for displaying leading zeroes for line numbers in display margin."
       :group 'linum)
     (defun linum-format-func (line)
       (let ((w (length
                 (number-to-string (count-lines (point-min) (point-max))))))
         (concat
        (propertize (make-string (- w (length (number-to-string line))) ?0)
                      'face 'linum-leading-zero)
          (propertize (number-to-string line) 'face 'linum))))
     (setq linum-format 'linum-format-func)))

你的 linum-format 函数效率低下(就像 linum 本身曾经一样,但已经被修复)。具体来说,你正在为屏幕上的每一行重新生成格式——运行 (count-lines (point-min) (point-max))。请参考 https://dev59.com/3GbWa4cB1Zd3GeqPTRx2#11496199 以获取如何解决此问题的示例。 - phils

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接