Line numbers only in certain modes
Asked Answered
D

2

10

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.

Demented answered 8/12, 2013 at 3:32 Comment(0)
V
6

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

Valdovinos answered 8/12, 2013 at 4:42 Comment(2)
Good links. Thank you.Demented
You can simplify this to (add-hook 'clojure-mode-hook 'linum-mode).Tetramethyldiarsine
T
19

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)
Tetramethyldiarsine answered 8/12, 2013 at 18:24 Comment(1)
'prog-mode-hook has got to be the coolest thing since sliced bread. Thanks so much for this!Cannae
V
6

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

Valdovinos answered 8/12, 2013 at 4:42 Comment(2)
Good links. Thank you.Demented
You can simplify this to (add-hook 'clojure-mode-hook 'linum-mode).Tetramethyldiarsine

© 2022 - 2024 — McMap. All rights reserved.