Question

I've tried linum and nlinum. Both have dreadful performance on files with 100k+ lines.

$ for x in {1.100000}; do echo $x; done > 100k.txt
$ emacs -q 100k.txt
M-x load-library linum
M-x linum-mode
M-> ;; it's not too bad to go to end of file
M-< ;; now this completely locks up emacs

The same operation with editors like joe is instantaneous.

Is there any solution other than to turn off line numbers with big files (exactly the type of files that you want to navigate with line numbers - I have in mind locating error lines in concatenated Javascript files)?

Or just use a different editor?

Was it helpful?

Solution

I think you found a bug, and you may report (report-emacs-bug) it. As per Tyler comment, it may have been already solved.

Things that may help you in the meanwhile... line-number-mode, goto-line, narrow-to-region and this cheapo-number-my-lines-in-a-tmp-buffer trick:

(shell-command-on-region (point-min) (point-max)
    (concat "grep -n ^ " buffer-file-name)
    (get-buffer-create "*tmp-linum*") nil t)

OTHER TIPS

As far as I know, both linum and its derivative nlinum number lines even if you don't see them. In the case of 100k+ lines, this can be slow if numbering an individual line takes more than a few tenths of a millisecond. For me, (Fedora 19, Emacs 24.3.1), there's no noticeable delay. Try line-num.el, which only numbers lines that are currently visible and see if it fixes the problem.

Add this to .emacs file.

(global-linum-mode 1)

Since Emacs 26 you should use [global-]display-line-numbers-mode instead.

For example:

(global-display-line-numbers-mode 1)

or:

(add-hook 'prog-mode-hook #'display-line-numbers-mode)

(Or toggle them manually via M-x.)

The line numbering for these is implemented as part of the redisplay in C code, and is therefore efficient and performs well even with extremely large buffers.

To customize this feature use:

M-x customize-group RET display-line-numbers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top