gpt4 book ai didi

emacs - elisp中如何管理底层接口(interface)的变化

转载 作者:行者123 更新时间:2023-12-04 17:41:10 31 4
gpt4 key购买 nike

在 emacs 23.1 和 24.1 之间的某个地方,url-retrieve 的接口(interface)改变了。在 emacs 23.1 中,它看起来像这样:

(url-retrieve URL CALLBACK &optional CBARGS)

在 24.1 版本中,它看起来像这样:
(url-retrieve URL CALLBACK &optional CBARGS SILENT INHIBIT-COOKIES)

我有一个使用此功能的 emacs 包。我想利用 emacs 24.1 上新的 SILENT 参数,同时保持与不支持它的旧版本 emacs 的向后兼容性。

管理此问题的最佳方法是什么?我可以在运行时获取最大数量的参数吗?

最佳答案

您可以使用此函数来获取参数列表:

(defun my-get-arglist (obj)
;; code taken from disassemble-internal
(let ((macro 'nil)
(name 'nil)
(doc 'nil)
args)
(while (symbolp obj)
(setq name obj
obj (symbol-function obj)))
(if (subrp obj)
(error "Can't disassemble #<subr %s>" name))
(if (and (listp obj) (eq (car obj) 'autoload))
(progn
(load (nth 1 obj))
(setq obj (symbol-function name))))
(if (eq (car-safe obj) 'macro) ;handle macros
(setq macro t
obj (cdr obj)))
(if (and (listp obj) (eq (car obj) 'byte-code))
(setq obj (list 'lambda nil obj)))
(if (and (listp obj) (not (eq (car obj) 'lambda)))
(error "not a function"))
(if (consp obj)
(if (assq 'byte-code obj)
nil
(setq obj (byte-compile obj))))
(cond ((consp obj)
(setq obj (cdr obj)) ;throw lambda away
(setq args (car obj)) ;save arg list
(setq obj (cdr obj)))
((byte-code-function-p obj)
(setq args (aref obj 0)))
(t (error "Compilation failed")))
args))

关于emacs - elisp中如何管理底层接口(interface)的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11123114/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com