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

后端 未结 4 1741
难免孤独
难免孤独 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))
    
    0 讨论(0)
  • 2020-12-31 17:58

    Update: I ended up patching the source for linum.el. I added an extra hook that runs before updates.

    Here's the patched file: linum.el (github)

    Here's the code I have in my init.el:

    ;; Load custom linum.
    (load-file "~/.emacs.d/linum.el")
    
    ;; Suppress line number updates while auto-complete window
    ;; is displayed.
    (add-hook 'linum-before-update-hook
              '(lambda ()
                 (when auto-complete-mode
                   (if (ac-menu-live-p)
                       (setq linum-suppress-updates t)
                     (setq linum-suppress-updates nil)))))
    

    Hope it helps!

    0 讨论(0)
  • 2020-12-31 18:06

    Just have the same problem, after seeing 'patching the source' I believe it could be done with advice. Here is what I come up with

    (defadvice linum-update
      (around tung/suppress-linum-update-when-popup activate)
      (unless (ac-menu-live-p)
        ad-do-it))
    

    I would like to use popup-live-p as mentioned but unfortunately it requires the variable for the popup, which we couldn't know in advance.

    0 讨论(0)
  • 2020-12-31 18:10

    Simply put the following line in .emacs which resolves this issue. It is in auto-complete.el.

    (ac-linum-workaround)
    
    0 讨论(0)
提交回复
热议问题