Turn off linum-mode when file is too big

  |   Source

CREATED: <2016-07-14 Thu>

UPDATED: <2016-08-07 Sun>

It's well known that linum-mode slows Emacs when the file contains thousands of lines.

Here is the fix,

(defun buffer-too-big-p ()
  (or (> (buffer-size) (* 5000 80))
      (> (line-number-at-pos (point-max)) 5000)))
(add-hook 'prog-mode-hook
          (lambda ()
            ;; turn off `linum-mode' when there are more than 5000 lines
            (if (buffer-too-big-p) (linum-mode -1))))

Though nlinum-mode has performance, I still stick to linum-mode because git-gutter only supports linum-mode.

You can check the interesting discussion about git-gutter/linum-mode/nlinum-mode. Syohei Yoshida made git-gutter 95% functional when linum-mode off.

Comments powered by Disqus