我不確定我是否正在使用ad-get-args and ad-get-arg。Emacs Lisp:如何使用ad-get-arg和ad-get-args?
例如,下面的代碼不起作用。
(defun my-add (a b)
(+ a b))
(defadvice my-add (after my-log-on activate)
(message "my-add: %s" (ad-get-args)))
(my-add 1 2)
最後一個表達式導致錯誤:
Debugger entered--Lisp error: (void-function ad-get-args).
下也不起作用。
(defun my-substract (a b)
(- a b))
(defadvice my-substract (around my-log-on activate)
(message "my-substract: %s" (ad-get-arg 0))
(ad-do-it))
(my-substract 10 1)
的defadvice發出警告:
Warning: `(setq ad-return-value (ad-Orig-my-substract a b))' is a malformed
function
而最後的表達提供了一個錯誤:
Debugger entered--Lisp error: (invalid-function (setq ad-return-value (ad-Orig-my-substract a b)))
(setq ad-return-value (ad-Orig-my-substract a b))()
我試圖用defadvice觀看啓動過程中的參數進行調試的目的我發現我使用ad-get-arg的方式不起作用。
更新:回答,
從原來的答案,我應該在(defadvice my-add ..)
已經使用(ad-get-args 0)
代替(ad-get-args)
,我應該在(defadvice my-substract ..)
已經使用ad-do-it
代替(ad-do-it)
英寸 而且最好使用trace-function
。
表達式(消息「my-add:%s」(list 1 2))運行良好。 – Yoo 2010-04-13 12:57:00