1

试图让行号与分隔符空间和与Spacemacs 中突出显示的行相同的背景颜色对齐是非常复杂的。特别是当它同时在 linum 和 linum-relative 中进行时。

我不知道这段代码是否可以,但到目前为止它管理得很好:

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
 This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
  (global-linum-mode t)
  (unless window-system
    (add-hook 'linum-before-numbering-hook
              (lambda ()
                (setq-local my-linum-format-fmt
                            (let ((w (length (number-to-string
                                              (count-lines (point-min) (point-max))))))
                              (concat "%" (number-to-string w) "d"))))
              (set-face-attribute 'linum nil
                                  :background (face-background 'hl-line nil t))))

  (defface my-linum-hl
    `((t :inherit linum :background ,(face-background 'hl-line nil t)))
    "Face for the current line number."
    :group 'linum)

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

  (unless window-system
    (setq linum-format 'my-linum-format-func))

  ;; linum-relative
  (linum-relative-toggle)
  (unless window-system
    (setq-local my-linum-relative-format-fmt
                (let ((w (length (number-to-string
                                  (count-lines (point-min) (point-max))))))
                  (concat "%" (number-to-string w) "s "))))

  (unless window-system
    (setq linum-relative-format my-linum-relative-format-fmt))
)

问题是:当我在 Emacs 中更改主题时,数字背景颜色不会更改为正确的颜色。颜色保持不变。如何在颜色主题更改后让 emacs 更新 linum 和相对于 linum 的背景颜色?

4

0 回答 0