gpt4 book ai didi

emacs - flet 有效,但信息已过时; cl-flet 不起作用

转载 作者:行者123 更新时间:2023-12-04 04:52:00 25 4
gpt4 key购买 nike

我正在尝试暂时关闭 yes-or-no-p在别处定义的函数中,然后将事物恢复到原来的样子。使用 flet有效,但会创建一个 *compile-log*缓冲区告诉我它已经过时并使用 cl-flet 代替。但是,cl-flet 似乎不适用于 defadvice 的这种尝试。 ——即,什么也没有发生,yes-or-no-p 保持事件状态。关于如何避免错误消息并使这项工作也有效的任何想法?

(defun function-without-confirmation ()

(defadvice elmo-dop-queue-flush (around stfu activate)
(flet ((yes-or-no-p (&rest args) t)
(y-or-n-p (&rest args) t))
ad-do-it))

. . . .


(ad-unadvise 'elmo-dop-queue-flush)

)

我不能相信答案,因为这是由 wvxvw 解决的,所以我会将相关修复放在原始问题下方。新宏名为 lawlist-flet flet 的安装,并且已将过时的行注释掉:
(defmacro lawlist-flet (bindings &rest body)
"Make temporary overriding function definitions.
This is an analogue of a dynamically scoped `let' that operates on the function
cell of FUNCs rather than their value cell.
If you want the Common-Lisp style of `flet', you should use `cl-flet'.
The FORMs are evaluated with the specified function definitions in place,
then the definitions are undone (the FUNCs go back to their previous
definitions, or lack thereof).

\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
(declare (indent 1) (debug cl-flet)
;; (obsolete "use either `cl-flet' or `cl-letf'." "24.3")
)
`(letf ,(mapcar
(lambda (x)
(if (or (and (fboundp (car x))
(eq (car-safe (symbol-function (car x))) 'macro))
(cdr (assq (car x) macroexpand-all-environment)))
(error "Use `labels', not `flet', to rebind macro names"))
(let ((func `(cl-function
(lambda ,(cadr x)
(cl-block ,(car x) ,@(cddr x))))))
(when (cl--compiling-file)
;; Bug#411. It would be nice to fix this.
(and (get (car x) 'byte-compile)
(error "Byte-compiling a redefinition of `%s' \
will not work - use `labels' instead" (symbol-name (car x))))
;; FIXME This affects the rest of the file, when it
;; should be restricted to the flet body.
(and (boundp 'byte-compile-function-environment)
(push (cons (car x) (eval func))
byte-compile-function-environment)))
(list `(symbol-function ',(car x)) func)))
bindings)
,@body))

并且,这是消除与 flet 相关的错误消息的修改后的函数。过时了。
(defun function-without-confirmation ()

(defadvice elmo-dop-queue-flush (around stfu activate)
(lawlist-flet ((yes-or-no-p (&rest args) t)
(y-or-n-p (&rest args) t))
ad-do-it))

. . . .


(ad-unadvise 'elmo-dop-queue-flush)

最佳答案

以下是我建议您这样做的方法:

(defvar stfu-inhibit-yonp nil)
(defadvice yes-or-no-p (around stfu activate)
(if stfu-inhibit-yonp (setq ad-return t) ad-do-it))
(defadvice y-or-n-p (around stfu activate)
(if stfu-inhibit-yonp (setq ad-return t) ad-do-it))

(defadvice elmo-dop-queue-flush (around stfu activate)
(let ((stfu-inhibit-yonp t))
ad-do-it))

与 CL 的相反 flet这将清楚地表明(例如在 C-h f yes-or-no-p 中)是或否 p 正在发生的事情。

关于emacs - flet 有效,但信息已过时; cl-flet 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17303914/

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