I want to turn on linum mode (M-x linum-mode) automatically with python and c mode. I add the following code in .emacs, but it doesn't seem to work.
(defun my-c-mode-common-hook ()
(line-number-mode 1))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(defun my-python-mode-common-hook ()
(line-number-mode 1))
(add-hook 'python-mode-common-hook 'my-python-mode-common-hook)
What might be wrong?
Not sure what hooks C-mode is supposed to use (never used C-mode), but this should do what you want:
line-number-mode
andlinum-mode
are not the same.Try this:
You also have the option of setting linum-mode globally.
Edit: In my configuration I have
global-linum-mode
active and inhibit it for certain major modes:All major mode for programming languages derive from prog-mode, so
(add-hook 'prog-mode-hook 'linum-mode)
will enable linum-mode for all programming modes.