Emacs Org-Mode: Turn off line numbers - emacs

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.

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.

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).

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.

Use nlinum, a much faster alternative.

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

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.

Related

How do I disable line numbers in Helm buffers?

I'm using linum to show line numbers. What I want is to have them enabled by default, but disabled in certain major modes, like eshell, compilation, etc.
This works well, but what I can't figure out is how to disable them in Helm buffers.
There doesn't seem to be a major mode I can hook into
(add-hook 'helm-before-initialize-hook '(lambda () (linum-mode 0))) turns off line numbers globally. Not sure how to disable linum for the current buffer only, since Helm buffers usually appear alongside another one
Tried advice around helm-find-files, but doesn't seem to work
I didn't have linum-off set up properly. It overrides a function which global-linum-mode calls, so the latter has to be active in order for it to work.
; init.el
(require 'linum-off)
(global-linum-mode t)

Line numbers only in certain modes

Is there a way to get line numbering only in specific modes, i.e Python, Java, C++, etc., rather than in every window? I thought I saw something about this the other day, but I can't find it.
Currently I'm set up that the default is just to have linum-mode on persistenly. It's kind of annoying in the shell.
Thanks.
Assuming you want to use it all major programming modes and you're using Emacs 24.x, you can use this snippet:
(add-hook 'prog-mode-hook 'linum-mode)
I didn't turn linum on globally.
Instead I turn linum on for the major mode in which I want it. For example:
(add-hook 'clojure-mode-hook '(lambda () (linum-on)))
or simply:
(add-hook 'clojure-mode-hook 'linum-mode)
Related here:
Turning on linum-mode when in python/c mode
and here:
Emacs Org-Mode: Turn off line numbers

how to change variables for specific fundamental-mode buffers

Goal: I want to have show-trailing-whitespace enabled for all buffers save a few. Exceptions posing a problem are *Shell Command Output* and its cousin *Async Shell Command*.
I usually have show-trailing-whitespace customized to t. Therefore it is active in all new buffers.
I would also like to have it turned off for certain buffers, foremost amongst them *Shell Command Output*. This poses a problem for me:
The output buffer doesn't use a special mode; it is still in fundamental-mode. There is no fundamental-mode-hook that I could hook this setting into.
There is the after-major-mode-change-hook which is run when the major mode is changed to fundamental-mode, but the buffer starts out in that mode and therefore this hook is not run.
There doesn't seem to be a way to hook into get-buffer-create.
I know I can always advise the function get-buffer-create for this particular example, but I try to avoid that as much as possible.
Any hints?
You might be better off looking at the problem from the other side, and only set the var in those modes where you want to see trailing whitespace.
But I think you have a good point: these shell output buffers should not use fundamental-mode. It's probably time for M-x report-emacs-bug
In accordance with the accepted answer, here's a code snippet that enables trailing whitespaces highlighting for specific modes only:
(setq-default show-trailing-whitespace nil)
(defun namespace/show-trailing-whitespace ()
"Highlight trailing whitespaces in this buffer."
(setq-local show-trailing-whitespace t))
(dolist (hook '(prog-mode-hook text-mode-hook))
(add-hook hook 'namespace/show-trailing-whitespace))
This snippet is essentially taken from Steve Purcell's configuration.

why eldoc mode makes emacs use 100% cpu?

when i use eldoc,i add this to .emacs:
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
and then when i use emacs,the emacs will use 100% cpu and it stucks.
but when i delete this code in .emacs,the emacs works.
anyone has idea about this?Or how to debug the problem.
Or anyother way to substitute for the eldoc mode
You can run M-x toggle-debug-on-quit RET, then C-g will bring up a backtrace of what it is doing at the moment. You can update the question with the result if you can't figure out the problem at that point.
An alternate way is to comment out the rest of your .emacs file (everything except eldoc-mode stuff) and then uncomment pieces of it and see where things break. It's probably the interaction of eldoc with something else since eldoc has always worked great for me.
You might also want to check the value of eldoc-documentation-function to see if it's set to something weird.

How can I get emacs to show line numbers when the 'text-mode-hook appears not to be working?

I am trying to use setnu.el to give me line numbers in emacs, which as you might imagine I want in pretty much every mode. It seemed like the preffered way of doing this in Emacs is to use
(add-hook 'text-mode-hook 'turn-on-setnu-mode)
but this isn't working for me. Using
(add-hook 'emacs-lisp-mode-hook 'turn-on-setnu-mode)
works just fine when I am editing emacs lisp files, but I want line numbers in all my text viewing and don't want to have a special case for each kind of file in my init.d file. Help would be much appreciated.
Linum seems to be distributed with emacs >=22.
Try:
(require 'linum)
Then toggle the display of line numbers with
M-x linum-mode
http://web.student.tuwien.ac.at/~e0225855/linum/linum.html