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

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

问题描述

我已经全局激活了居中光标模式,如下所示:

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天全站免登陆