【问题标题】:Configure Linum mode to not show whitespace symbols in whitespace mode?将 Linum 模式配置为在空白模式下不显示空白符号?
【发布时间】:2013-10-23 11:19:36
【问题描述】:

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

如何将 linum 区域配置为不呈现空白符号?

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    注意:行号右侧不需要空格(如问题所示),因为可以使用边缘宽度来控制行号与正文之间的分隔。

    (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))。有关如何解决此问题的示例,请参阅 stackoverflow.com/a/11496199/324105
    【解决方案2】:

    您可以改进@lawlists 的第二种解决方案,但您可以使用一些奇特的空格,例如"\u2002",而不是使用0 作为空格替换。由于我们没有使用看起来像空格的比例字体,但whitespace 不会弄乱它。

    我实际上正在使用linum-relative-mode,您可以方便地建议linum-relative

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2010-12-14
      • 2014-02-19
      • 1970-01-01
      相关资源
      最近更新 更多