【问题标题】:How to detect if the current major mode is derived from prog-mode如何检测当前主模式是否源自 prog-mode
【发布时间】:2017-12-01 06:31:57
【问题描述】:

我想编写一个调用 2 个函数之一的函数,具体取决于当前的主要模式是否为 prog 模式。如何检测当前主模式是否为 prog-mode?​​p>

【问题讨论】:

    标签: emacs mode


    【解决方案1】:
    (if (derived-mode-p 'prog-mode) ...)
    

    【讨论】:

    • 如果 prog-modedefalias'd,例如,这不起作用groovy-mode;; For compatibility with Emacs < 24 (defalias 'groovy-parent-mode (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode)),而(derived-mode-p 'prog-mode) 计算结果为nil(我的Emacs 是26.x,别名是prog-mode)。您是否知道如何解决这个问题?
    • @kkm 这是debbugs.gnu.org/cgi/bugreport.cgi?bug=32795,在 Emacs 27 中已修复。
    • 太好了,谢谢!在我看来,它确实像一个错误。
    • 我注意到当前的修复反转了事情——(derived-mode-p 'prog-mode) 将是真的,但(derived-mode-p 'groovy-parent-mode) 不再是。这是一种更好的方法,但最好让它们工作。
    • 很难说有多少蠕虫会打开。根据定义,一种模式最多有一个父模式,groovy-parent-mode 实际上是一个内部包变量(应该使用-- 内部变量约定定义,如错误中提到的cmake--parent-mode)。一个可能的意外副作用是粗心的别名引入的依赖循环。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-08
    • 2017-04-02
    • 2021-01-18
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多