我在用global-linum-mode
对于行号。如果当前行的行号用不同的颜色(和/或不同的背景)突出显示,那就太好了。有人知道如何实现这一目标吗?
谢谢你!
我从之前的回答中得出了这个答案Emacs 中的相对行号,因为它处理在 linum 格式化过程中记住当前行号的相同问题。
I'm inheriting from the linum
face, but using the background colour from hl-line
. If the foreground and background don't match nicely, you can assign a foreground colour explicitly with
M-x customize-face
RET my-linum-hl
RET
(require 'hl-line)
(defface my-linum-hl
`((t :inherit linum :background ,(face-background 'hl-line nil t)))
"Face for the current line number."
:group 'linum)
(defvar my-linum-format-string "%3d")
(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
(defun my-linum-get-format-string ()
(let* ((width (1+ (length (number-to-string
(count-lines (point-min) (point-max))))))
(format (concat "%" (number-to-string width) "d")))
(setq my-linum-format-string format)))
(defvar my-linum-current-line-number 0)
(setq linum-format 'my-linum-format)
(defun my-linum-format (line-number)
(propertize (format my-linum-format-string line-number) 'face
(if (eq line-number my-linum-current-line-number)
'my-linum-hl
'linum)))
(defadvice linum-update (around my-linum-update)
(let ((my-linum-current-line-number (line-number-at-pos)))
ad-do-it))
(ad-activate 'linum-update)
与其他答案一样,这在生成动态宽度方面比默认值更有效dynamic
格式,但您可以通过注释掉该行来使用静态宽度以获得最大速度(add-hook linum-before-numbering-hook 'my-linum-get-format-string)
(并可选择修改初始值my-linum-format-string
设置您的首选宽度)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)