【问题标题】:Turning on linum-mode when in python/c mode在 python/c 模式下打开 linum-mode
【发布时间】:2011-04-21 23:19:54
【问题描述】:

我想用 python 和 c 模式自动打开 linum 模式(M-x 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)

可能出了什么问题?

【问题讨论】:

    标签: emacs python-mode c-mode


    【解决方案1】:

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

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

    编辑: 在我的配置中,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)
    

    【讨论】:

      【解决方案2】:

      line-number-modelinum-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) 
      

      【讨论】:

      • 不幸的是,更改后它不起作用。有什么方法可以调试可能出错的地方吗?
      • 从钩子名称中删除共同点。我修复了上面的代码。
      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        不确定 C 模式应该使用什么钩子(从未使用过 C 模式),但这应该可以满足您的要求:

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

        【讨论】:

          猜你喜欢
          • 2014-02-05
          • 1970-01-01
          • 1970-01-01
          • 2022-10-06
          • 1970-01-01
          • 2013-10-15
          • 1970-01-01
          • 1970-01-01
          • 2022-12-05
          相关资源
          最近更新 更多