Search code examples
emacspython-modec-mode

Turning on linum-mode when in python/c mode


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?


Solution

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