在python/c模式下打开linum模式

pro*_*eek 8 emacs c-mode python-mode

我想用python和c模式自动打开linum模式(Mx linum-mode).我在.emacs中添加以下代码,但它似乎不起作用.

(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)
Run Code Online (Sandbox Code Playgroud)

可能有什么问题?

kjf*_*tch 15

您还可以选择全局设置linum-mode.

;; In your .emacs
(global-linum-mode 1)
Run Code Online (Sandbox Code Playgroud)

编辑: 在我的配置中,我已global-linum-mode激活并禁止某些主要模式:

(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)
Run Code Online (Sandbox Code Playgroud)


Sta*_*key 9

line-number-mode并且linum-mode不一样.

试试这个:

(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) 
Run Code Online (Sandbox Code Playgroud)