介于emacs 23.1和24.1之间,界面发生了url-retrieve变化.在emacs 23.1中,它看起来像这样:
(url-retrieve URL CALLBACK &optional CBARGS)
Run Code Online (Sandbox Code Playgroud)
在版本24.1中,它看起来像这样:
(url-retrieve URL CALLBACK &optional CBARGS SILENT INHIBIT-COOKIES)
Run Code Online (Sandbox Code Playgroud)
我有一个使用此功能的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))
Run Code Online (Sandbox Code Playgroud)