views:

60

answers:

3

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?

+2  A: 

line-number-mode and linum-mode are not the same.

Try this:

(defun my-c-mode-hook () 
  (linum-mode 1)) 
(add-hook 'c-mode-hook 'my-c-mode-hook) 

(defun my-python-mode-hook () 
  (linum-mode 1)) 
(add-hook 'python-mode-hook 'my-python-mode-hook) 
Starkey
@Starkey : Unfortunately, it doesn't work after the change. Is there any way to debug what might be wrong?
prosseek
Remove the common from the hook name. I fixed the code above.
Starkey
@Starkey : Thanks. It works well.
prosseek
+1  A: 

You also have the option of setting linum-mode globally.

;; In your .emacs
(global-linum-mode 1)
kjfletch
A: 

Not sure what hooks C-mode is supposed to use (never used C-mode), but this should do what you want:

(dolist (hook '(python-mode-hook
            c-mode-common-hook))
  (add-hook hook (lambda () (linum-mode t))))
monotux