(defun my-message (format-string &rest args)
(apply 'message
(concat "my-message: " format-string)
args))
(my-message "abc %d" 123)
;; ==> "my-message: abc 123"
(message "abc %d" 123)
;; ==> "abc 123"
(advice-add 'message :around 'my-message)
;;(advice-remove 'message 'my-message)在advice-add到message之后,将发出错误Wrong type argument: sequencep, #<subr message>信号。有什么问题吗?
发布于 2016-04-09 04:24:30
由于您使用的是:around通知,所以您的my-message函数将原始函数作为其第一个参数。您的代码缺少这个参数,而是将第一个参数作为消息格式字符串处理。更改my-message以指定附加参数:
(defun my-message (orig-fun format-string &rest args)
(apply orig-fun
(concat "my-message: " format-string)
args))然后这些建议就会像预期的那样起作用。注意这个版本是如何调用orig-fun而不是硬编码'message作为apply目标的。
不过,对于这种情况,您不需要:around建议。您所做的只是修改格式字符串,因此您可以使用:filter-args,它允许您在参数传递给原始函数之前修改它们。下面是一个适用于您的案例的示例:
(defun my-message (args)
(nconc (list (concat "my-message: " (car args))) (cdr args)))
(advice-add 'message :filter-args #'my-message)https://stackoverflow.com/questions/36476845
复制相似问题