自动禁用特定主要模式的全局小模式 [英] automatically disable a global minor mode for a specific major mode

查看:126
本文介绍了自动禁用特定主要模式的全局小模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有中心光标模式激活全局,如下所示:

I have centered-cursor-mode activated globaly, like this:

(require 'centered-cursor-mode)
(global-centered-cursor-mode 1)

它工作正常,但有一些主要模式,我想自动禁用它。例如slime-repl和shell。

It works fine, but there are some major modes where I would like to disable it automatically. For example slime-repl and shell.

另一个问题是处理相同的问题,但是另一个次要模式。不幸的是,答案只提供了这种特定的次要模式(全局智能选项卡模式)的解决方法,这不适用于居中的光标模式。

There is another question dealing with the same problem, but another minor mode. Unfortunately the answers only offer workarounds for this specific minor mode (global-smart-tab-mode), that doesn't work with centered-cursor-mode.

我试过这个钩子,但它没有效果。变量不变。

I tried this hook, but it has no effect. The variable doesn't change.

(eval-after-load "slime"
  (progn
    (add-hook 'slime-repl-mode-hook (lambda ()
                                      (set (make-local-variable 'centered-cursor-mode) nil)))
    (slime-setup '(slime-repl slime-autodoc))))


推荐答案

一种新的全局小型模式,在某些模式下不会被激活。 lambda是在每个新缓冲区中调用以激活次模式的函数。这是正确的例外情况。

I made a new global minor mode, that doesn't get activated in certain modes. The lambda is the function that gets called in every new buffer to activate the minor mode. That is the right place to make exceptions.

(require 'centered-cursor-mode)

(define-global-minor-mode my-global-centered-cursor-mode centered-cursor-mode
  (lambda ()
    (when (not (memq major-mode
                     (list 'slime-repl-mode 'shell-mode)))
      (centered-cursor-mode))))

(my-global-centered-cursor-mode 1)

它应该适用于每个其他全局小模式。只需复制定义global-xxx-mode并作出正确的例外。

It should work for every other global minor mode. Just copy the definition global-xxx-mode and make the right exceptions.

这篇关于自动禁用特定主要模式的全局小模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆