简体   繁体   中英

Turning on linum-mode when in python/c mode

I want to turn on linum mode (Mx 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?

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) 

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

编程语言的所有主要模式都来自prog模式,因此(add-hook 'prog-mode-hook 'linum-mode)将为所有编程模式启用linum模式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM