右线对齐linum模式?

mon*_*tux 9 emacs elisp

我想我的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)))
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

acu*_*ich 19

您可以使用该值,'dynamic因此您不必选择任意数量的填充:

(custom-set-variables '(linum-format 'dynamic))
Run Code Online (Sandbox Code Playgroud)

或者您也可以使用以下方式对其进 M-x customize-variable RET linum-format

此外,@ asmeurer询问如何在数字后添加空格dynamic.没有简单的方法可以做到这一点,但它可以使用我从代码中修改defadvicelinum-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))
Run Code Online (Sandbox Code Playgroud)


Jér*_*dix 4

自定义变量 linum-format,例如在 7 个字符右侧对齐:

(custom-set-variables '(linum-format (quote "%7d")))
Run Code Online (Sandbox Code Playgroud)

  • 如果它是动态完成的,我会更喜欢它,但一旦文件传递了 1000 行,无论如何都没关系。谢谢!:) 我选择了“%4d”。 (2认同)