26

I've recently moved from vim to Emacs because I want to use org-mode. I opened a ~10000 line, 50kb file in Emacs23 Org-mode and proceeded to add about 10 first-level headings. Performance on a quad-core with 3GB RAM in Emacs23 under Ubuntu 10.04/32bit was so slow that it was unusable. I found two threads on the Org-mode email list discussing this. It seems that enabling linum causes the slow performance. I can live without line numbers in .org files if I have to, but I don't want to disable line numbers for all files I edit. If I'm going to "live" in `Emacs', I'll want line numbers for all other files.

How can I disable linum for some or all .org files only? Is it possible to do this if I have several files open in Emacs and switch between them? I found some discussion about disabling line numbers for major modes here, but there was nothing that I could implement (although the linum-off.el script mentioned on the page looks promising, I don't (yet) know (E)Lisp, so I can't change it as I would need).

I updated Org-mode from version 6.21b which came with Emacs23 to version 7.5, but it made no difference. Performance in Emacs GUI is so bad that the application fails to respond at all. Performance with -nw is "better", but still unusable.

SabreWolfy
  • 5,392
  • 11
  • 50
  • 73

6 Answers6

10

Try adding this to your .emacs:

(defun nolinum ()
  (global-linum-mode 0)
)
(add-hook 'org-mode-hook 'nolinum)

This is assuming that you use linum and not something else to number lines. Anyway, you can add this hook to org-mode to disable anything that might make org slow only when you're using org-mode.

Disclaimer: I don't have linum installed so I can't test this, but it should work.

Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
  • Thanks. I added the lines to .emacs and opened a .org file (which automatically puts Emacs into org-mode), but line numbers are still present. The same is true if I open some other file and then visit a .org file -- the line numbers are still present. I might try the `linum-off.el` script mentioned in my question. – SabreWolfy Mar 08 '11 at 08:08
  • I changed your script to read "nil" instead of "0" and when opening a .org file, Emacs reports "Toggling global-linum-mode off; better pass an explicit argument.", but line numbers remain. This text is not shown when the line contains "0" instead of "nil" (as I said, I don't know Elisp). – SabreWolfy Mar 08 '11 at 08:14
  • Solved. See "Update" in question. – SabreWolfy Mar 08 '11 at 09:37
  • 3
    Global minor modes tend not to cooperate with the usual way of doing things with mode hooks -- the standard macros for defining global minor modes use `after-change-major-mode-hook` to turn the mode on, and that hook runs after the mode hook. So your mode hook briefly switches the mode off, and then it gets switched back on again. – phils Mar 08 '11 at 11:32
8

If you type M-x customize, go to Linum in the Convenience group, change Linum Eager to off, or change Linum Delay to on, it will improve performance greatly.

On my laptop (3 GB RAM, dual core) the performance drawback (of this versus having linum off) is unnoticeable, however on my netbook there may still be some slight performance issues with a ~3000 line 130KB file (~50-150 ms delay when paging).

unhammer
  • 4,306
  • 2
  • 39
  • 52
blake314
  • 81
  • 1
  • 2
    Actually, reading the code of linum, it's one or the other, not both. ` (if linum-eager (add-hook 'post-command-hook (if linum-delay 'linum-schedule 'linum-update-current) nil t)` – Benoît Oct 13 '12 at 22:43
6

linum-off.el mentioned in my quesiton has solved this. Instructions are in the file: place the file into the Emacs load-path and add (require 'linum-off) to ~/.emacs. This script turns off line numbering for the modes specified only. I've tested it and it works fine.

SabreWolfy
  • 5,392
  • 11
  • 50
  • 73
  • Simpler to use (global-linum-mode) and (add-hook 'org-mode-hook (lambda () (linenum-mode 0))) in your ~/.emacs.el. – bzg May 13 '12 at 11:21
  • @bzg: Thanks for your comment, which addresses my question directly. However, "linum-off.el" allows line numbers to be disabled in several modes, which is useful [`(defcustom linum-disabled-modes-list '(eshell-mode wl-summary-mode compilation-mode org-mode dired-mode)`]. – SabreWolfy May 13 '12 at 15:04
5

Use nlinum, a much faster alternative.

mcandre
  • 22,868
  • 20
  • 88
  • 147
4

You only need to add (add-hook 'org-mode-hook (lambda () (linum-mode 0))).

2

I tried the following which worked out pretty well:

(defun nolinum ()
  (interactive)
  (message "Deactivated linum mode")
  (global-linum-mode 0)
  (linum-mode 0)
)

(global-set-key (kbd "<f6>") 'nolinum)

(add-hook 'org-mode-hook 'nolinum)

Of course, you do not need the keybinding. I suggest you leave it in for testing purposes and disable it if everything works fine.

phimuemue
  • 34,669
  • 9
  • 84
  • 115