fix an auto-complete-mode and linum-mode annoyance

后端 未结 4 1745
难免孤独
难免孤独 2020-12-31 17:17

I\'m using auto-complete-mode which I think is totally fantastic. I\'m also a big fan of linum-mode but I\'ve got a very irritating issue when the

4条回答
  •  旧巷少年郎
    2020-12-31 17:49

    I've written a couple of previous answers on modifying the linum-mode output, which you could probably adapt to your purposes.

    • Relative Line Numbers In Emacs
    • Colorize current line number

    Edit: Here's the most basic version of that code (also on EmacsWiki, albeit somewhat buried), which doesn't modify the default output at all, but uses the techniques from those other answers to be more efficient than the default code. That's probably a more useful starting point for you.

    (defvar my-linum-format-string "%4d")
    
    (add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
    
    (defun my-linum-get-format-string ()
      (let* ((width (length (number-to-string
                             (count-lines (point-min) (point-max)))))
             (format (concat "%" (number-to-string width) "d")))
        (setq my-linum-format-string format)))
    
    (setq linum-format 'my-linum-format)
    
    (defun my-linum-format (line-number)
      (propertize (format my-linum-format-string line-number) 'face 'linum))
    

提交回复
热议问题