开发者

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-mod开发者_如何学Pythone-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?


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

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

Edit: In my configuration I have global-linum-mode active and inhibit it for certain major modes:

(setq linum-mode-inhibit-modes-list '(eshell-mode
                                      shell-mode
                                      erc-mode
                                      jabber-roster-mode
                                      jabber-chat-mode
                                      gnus-group-mode
                                      gnus-summary-mode
                                      gnus-article-mode))

(defadvice linum-on (around linum-on-inhibit-for-modes)
  "Stop the load of linum-mode for some major modes."
    (unless (member major-mode linum-mode-inhibit-modes-list)
      ad-do-it))

(ad-activate 'linum-on)


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) 


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜