首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >flet工作,但与过时的消息;cl-flet不工作。

flet工作,但与过时的消息;cl-flet不工作。
EN

Stack Overflow用户
提问于 2013-06-25 17:37:08
回答 1查看 523关注 0票数 2

我试图暂时关闭在其他地方定义的函数中的yes-or-no-p,然后将事物恢复到原来的状态。使用flet可以工作,但是会创建一个*compile-log*缓冲区,告诉我它已经过时了,而应该使用cl。然而,cl似乎不适用于defadvice的这一尝试--也就是说,什么都没有发生,是或否-p仍然是活跃的。对于如何避免错误信息并使其工作,有什么想法吗?

代码语言:javascript
运行
复制
(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 instad of flet,过时的行已被注释掉:

代码语言:javascript
运行
复制
(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过时相关的错误消息。

代码语言:javascript
运行
复制
(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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-26 01:03:36

我建议你这样做:

代码语言:javascript
运行
复制
(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正在发生某些事情。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17303914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档