advice-add 中的 depth property 怎样加?

我这样加的时候总是报错:

(advice-add #'some-function :after #'some-advice '(depth . -100))

wrong-type-argument listp -100

这个怎么用 Google 上面没搜到例子。

文档:

add-function is a Lisp macro in ‘nadvice.el’.

(add-function WHERE PLACE FUNCTION &optional PROPS)

Add a piece of advice on the function stored at PLACE.
FUNCTION describes the code to add.  WHERE describes where to add it.
WHERE can be explained by showing the resulting new function, as the
result of combining FUNCTION and the previous value of PLACE, which we
call OLDFUN here:
‘:before’	(lambda (&rest r) (apply FUNCTION r) (apply OLDFUN r))
‘:after’	(lambda (&rest r) (prog1 (apply OLDFUN r) (apply FUNCTION r)))
‘:around’	(lambda (&rest r) (apply FUNCTION OLDFUN r))
‘:override’	(lambda (&rest r) (apply FUNCTION r))
‘:before-while’	(lambda (&rest r) (and (apply FUNCTION r) (apply OLDFUN r)))
‘:before-until’	(lambda (&rest r) (or  (apply FUNCTION r) (apply OLDFUN r)))
‘:after-while’	(lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r)))
‘:after-until’	(lambda (&rest r) (or  (apply OLDFUN r) (apply FUNCTION r)))
‘:filter-args’	(lambda (&rest r) (apply OLDFUN (funcall FUNCTION r)))
‘:filter-return’(lambda (&rest r) (funcall FUNCTION (apply OLDFUN r)))
If FUNCTION was already added, do nothing.
PROPS is an alist of additional properties, among which the following have
a special meaning:
- ‘name’: a string or symbol.  It can be used to refer to this piece of advice.
- ‘depth’: a number indicating a preference w.r.t ordering.
  The default depth is 0.  By convention, a depth of 100 means that
  the advice  should be innermost (i.e. at the end of the list),
  whereas a depth of -100 means that the advice should be outermost.

If PLACE is a symbol, its ‘default-value’ will be affected.
Use (local 'SYMBOL) if you want to apply FUNCTION to SYMBOL buffer-locally.
Use (var VAR) if you want to apply FUNCTION to the (lexical) VAR.

If one of FUNCTION or OLDFUN is interactive, then the resulting function
is also interactive.  There are 3 cases:
- FUNCTION is not interactive: the interactive spec of OLDFUN is used.
- The interactive spec of FUNCTION is itself a function: it should take one
  argument (the interactive spec of OLDFUN, which it can pass to
  ‘advice-eval-interactive-spec’) and return the list of arguments to use.
- Else, use the interactive spec of FUNCTION and ignore the one of OLDFUN.

好吧,我自己试出来了,应该这么用:

(advice-add #'some-function :after #'some-advice '((depth . -100)))

然而这样的顺序并没有什么卵用,这是不是得向 nadvice.el 提出 issue 啊?不行还换回 defadvice 算了。

这点上 nadvice 不如老的 defadvice 有效啊,defadvice 的 first 还有 last 简单直接有效。这个折腾半天还没有用。

此处应有乌龙

还真是,正在 debug 中

这里已经说是 Alist 了,你第一次用的 '(depth . -100) 不是 Alist。

你这里下了个结论,但没有说依据。nadvice.el 是 Emacs 的一部分,因此你要向 Emacs 提 Bug,报告时不要忘记说明理由(比如如何重现)。

肯定不是 emacs 的 bug 了,我大概知道原因了。那会儿总失败搞得没耐心了才会下那个结论,实在是不应该。