【问题标题】:How can I find out which version of emacs introduced a function?如何找出哪个版本的 emacs 引入了函数?
【发布时间】:2010-03-22 14:57:17
【问题描述】:

我想编写一个 .emacs,尽可能多地使用主线 emacs 功能,在以前的版本下运行时优雅地回退。我通过试验和错误发现了一些不存在的函数,例如,在 emacs 22 中,但现在在 emacs 23 中,在极少数情况下我最终在 emacs 下运行我的点文件22. 但是,我想对此采取更主动的方法,并让我的点文件子集仅在版本 >= <some-threshold> 时生效(例如)。我现在关注的功能是scroll-bar-mode,但我想要一个通用的解决方案。

我没有看到此信息的一致来源;我已经检查了 gnu.org 在线文档、函数代码本身,但到目前为止一无所获。在不保留我想要支持的每个版本的 emacs 的情况下,如何确定这一点?

【问题讨论】:

  • 我建议您在伟大的博客 "Emacs Fu" 上查看此 post。它显示了一种类似于 PP 建议的方法,但更通用。在处理此类问题时,我自己也使用类似的方法。

标签: emacs robustness


【解决方案1】:

我无法直接回答您的问题,但我使用的一种技术是检查functionp 函数,它告诉我函数是否存在。

例如

(if (load "completion" t)
  (progn
    (initialize-completions)
    (if (functionp 'dynamic-completion-mode)
      (dynamic-completion-mode) ; if exists
      (completion-mode)         ; otherwise use old version
    )
  ) ; progn
) ; if

更新:添加特定于版本的宏

除了使用functionp,我还有一些特定于版本的宏:

(defmacro GNU_EMACS_21 (&rest stuff)
   (list 'if (string-match "GNU Emacs 21" (emacs-version)) (cons 'progn stuff)))
(defmacro GNU_EMACS_20 (&rest stuff)
  (list 'if (string-match "GNU Emacs 20" (emacs-version)) (cons 'progn stuff)))
(defmacro GNU_EMACS_19 (&rest stuff)
  (list 'if (string-match "GNU Emacs 19" (emacs-version)) (cons 'progn stuff))) 
(defmacro WINSYS_X (&rest stuff)
  (list 'if (eq window-system 'x) (cons 'progn stuff)))
(defmacro WINSYS_W32 (&rest stuff)
  (list 'if (eq window-system 'w32) (cons 'progn stuff)))
(defmacro WINSYS_NIL (&rest stuff)
  (list 'if (eq window-system nil) (cons 'progn stuff)))
(defmacro SYSTYPE_LINUX (&rest stuff)
  (list 'if (string-match "linux" (symbol-name system-type)) (cons 'progn stuff)))

然后我可以使用这些:

(GNU_EMACS_21
  (if (load "cua" t)
    (CUA-mode t)
  )
)
(WINSYS_NIL ; when running in text mode
  (push (cons 'foreground-color "white") default-frame-alist)
  (push (cons 'background-color "black") default-frame-alist)
  (push (cons 'cursor-color "cyan") default-frame-alist)
  (push (cons 'minibuffer t) default-frame-alist)
)

不过,我猜你已经知道了;并且诸如“Emacs 何时包含 CUA 模式”之类的问题很难回答..

【讨论】:

  • 这是我现在正在使用的方法,但我不喜欢它;我必须一遍又一遍地重复相同的检查。我宁愿按版本对事物进行分组,而不是按缺少的功能。
  • 是的,你有一种更简洁的表达方式,但基本概念是相同的。但是,我认为您对回答核心问题的难度的猜测是在按钮上。我会再坚持一周左右,然后如果我还没有看到答案,我将不得不接受你的“无法完成”的答案。
【解决方案2】:

“NEWS”文件(可通过 C-h N 访问)可能会提示何时引入函数。

【讨论】:

  • 涉及到一些功能,但似乎没有我要找的所有信息。
  • 是的。另一种方法可能是 grep ChangeLog 文件;您应该找到“新功能:等等”之类的条目。获取此信息的权威方法可能是检查修订控制日志,但这可能需要一些努力,特别是如果您不熟悉 bzr(或 CVS 或 git)。但无论如何,我会这样做(例如,如果我对“auto-revert-tail-mode”功能感到好奇): * git clone git://repo.or.cz/emacs.git * cd emacs * git log -Sauto-revert-tail-mode 这可能很慢:-|
【解决方案3】:

通常更好的做法是测试您要使用的函数或变量是否存在,而不是测试 Emacs 版本。例如,使用fboundpboundp。有时检查featurep 是有意义的,但通常最好还是使用fboundpboundp

【讨论】:

    猜你喜欢
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多