[英]Right align line numbers with linum-mode?
我希望我的linum-mode
編號是右對齊的。 我發現的最接近的東西是在 emacswiki 上,但它不起作用 - 它似乎是左對齊數字而不是右對齊。 該片段可在此處找到。 對不起,可怕的縮進,lisp 對我來說很陌生:)
(setq linum-format
(lambda (line)
(propertize
(format
(let
((w (length (number-to-string (count-lines (point-min)
(point-max))))))
(concat "%" (number-to-string w) "d ")) line) 'face 'linum)))
有任何想法嗎?
您可以使用值'dynamic
因此您不必選擇任意數量的填充:
(custom-set-variables '(linum-format 'dynamic))
或者您也可以使用以下命令對其進行自定義: Mx customize-variable RET linum-format
此外,@ asmeurer詢問如何在dynamic
數字后面添加一個空格。 沒有簡單的方法可以做到這一點,但它可以使用defadvice
linum-update-window
函數的linum-update-window
來完成,我根據已經在該函數中的dynamic
代碼進行了改編:
(defadvice linum-update-window (around linum-dynamic activate)
(let* ((w (length (number-to-string
(count-lines (point-min) (point-max)))))
(linum-format (concat "%" (number-to-string w) "d ")))
ad-do-it))
自定義變量linum格式,例如在7個字符的右側對齊:
(custom-set-variables '(linum-format (quote "%7d")))
2022年,對於Emacs 28.1,命令為:
(setq linum-format 'dynamic)
將linum.el和byte-compile-file更改為.elc。
對於emacs 23.3
linum.el的第143行
(concat "%" (number-to-string w) "d" " | ")))))
我將默認堡壘更改為“xxx |”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.