6

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?

Barry Kelly
  • 41,404
  • 5
  • 117
  • 189
  • The line number is shown in the mode line. – abo-abo Oct 03 '13 at 11:18
  • This is instantaneous for me on Emacs 24.3.50.1 – Tyler Oct 03 '13 at 12:22
  • @Tyler it is not instantaneous for me, running 24.3.1 on Ubuntu precise 3.5.0-40-generic, and with default config loaded (as you can see, I'm using -q). Running in rxvt window. – Barry Kelly Oct 03 '13 at 12:53
  • @abo-abo the mode line is too big a visual gap to be scanning back and forth between cursor – Barry Kelly Oct 03 '13 at 12:54
  • @Tyler I'm using Damien Cassou's PPA to get a semi-recent emacs on Ubuntu. Do you know how I can get yet a more recent version without having to build it myself? – Barry Kelly Oct 03 '13 at 12:59
  • I've found that emacs bug 14259 is relevant, reported in April. Simply setting window margin is enough to trigger slowdown (`(set-window-margins (selected-window) 2)`) – Barry Kelly Oct 03 '13 at 13:22
  • @BarryKelly sorry, I build my own from the bzr repo, running Debian. Not sure what's available for Ubuntu. – Tyler Oct 03 '13 at 15:37
  • I can't reproduce it with Debian's 24.1 nor with Emacs's trunk (only tested with nlinum.el). – Stefan Oct 03 '13 at 19:34
  • I'm using the regular Emacs 24.2.1 package on Ubuntu 13.04 and can't reproduce this problem, neither with Emacs running in its own graphical frame nor in a gnome-terminal. – Rörd Oct 04 '13 at 05:19
  • @Rörd I'm on Ubuntu 12.04 LTS. It's not just me, see http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-04/msg00577.html – Barry Kelly Oct 04 '13 at 13:03

4 Answers4

5

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)
juanleon
  • 9,220
  • 30
  • 41
4

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.

PythonNut
  • 6,182
  • 1
  • 25
  • 41
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

phils
  • 71,335
  • 11
  • 153
  • 198
0

Add this to .emacs file.

(global-linum-mode 1)
이승현
  • 81
  • 2
  • 9
  • The question discounted `linum` as too slow. – phils May 30 '22 at 05:26
  • The settings for M-x linum-mode and .emacs files are different. I've been using it on centos with this setup so far and it works without any issues. – 이승현 May 30 '22 at 06:19
  • @phils What is the difference between the method you suggested and mine? I think it is more advantageous to use it by presetting it in the initialization file. – 이승현 May 30 '22 at 06:54
  • One can, of course, put `(global-display-line-numbers-mode 1)` in the init file; I hadn't said that explicitly, but assumed people would know. `global-display-line-numbers-mode` and `global-linum-mode` are two very different things. The former is newer and (crucially for this question) very fast (because it's integrated into the core redisplay C code). `linum-mode` does not have those benefits, and is much slower. The only reason I gave your answer a down-vote was that your suggestion had been specifically mentioned in the question as one of the options which was too slow. – phils May 30 '22 at 20:23