Avoid leaving garbage on screen when using 'raise' display property
[emacs.git] / lisp / emacs-lisp / nadvice.el
blobfd1cd2c7aafc992e7e3e51b18fc9598eaa4d5945
1 ;;; nadvice.el --- Light-weight advice primitives for Elisp functions -*- lexical-binding: t -*-
3 ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
6 ;; Keywords: extensions, lisp, tools
7 ;; Package: emacs
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This package lets you add behavior (which we call "piece of advice") to
25 ;; existing functions, like the old `advice.el' package, but with much fewer
26 ;; bells and whistles. It comes in 2 parts:
28 ;; - The first part lets you add/remove functions, similarly to
29 ;; add/remove-hook, from any "place" (i.e. as accepted by `setf') that
30 ;; holds a function.
31 ;; This part provides mainly 2 macros: `add-function' and `remove-function'.
33 ;; - The second part provides `advice-add' and `advice-remove' which are
34 ;; refined version of the previous macros specially tailored for the case
35 ;; where the place that we want to modify is a `symbol-function'.
37 ;;; Code:
39 ;;;; Lightweight advice/hook
40 (defvar advice--where-alist
41 '((:around "\300\301\302\003#\207" 5)
42 (:before "\300\301\002\"\210\300\302\002\"\207" 4)
43 (:after "\300\302\002\"\300\301\003\"\210\207" 5)
44 (:override "\300\301\x02\"\207" 4)
45 (:after-until "\300\302\002\"\206\013\000\300\301\002\"\207" 4)
46 (:after-while "\300\302\002\"\205\013\000\300\301\002\"\207" 4)
47 (:before-until "\300\301\002\"\206\013\000\300\302\002\"\207" 4)
48 (:before-while "\300\301\002\"\205\013\000\300\302\002\"\207" 4)
49 (:filter-args "\300\302\301\x03!\"\207" 5)
50 (:filter-return "\301\300\302\x03\"!\207" 5))
51 "List of descriptions of how to add a function.
52 Each element has the form (WHERE BYTECODE STACK) where:
53 WHERE is a keyword indicating where the function is added.
54 BYTECODE is the corresponding byte-code that will be used.
55 STACK is the amount of stack space needed by the byte-code.")
57 (defvar advice--bytecodes (mapcar #'cadr advice--where-alist))
59 (defun advice--p (object)
60 (and (byte-code-function-p object)
61 (eq 128 (aref object 0))
62 (memq (length object) '(5 6))
63 (memq (aref object 1) advice--bytecodes)
64 (eq #'apply (aref (aref object 2) 0))))
66 (defsubst advice--car (f) (aref (aref f 2) 1))
67 (defsubst advice--cdr (f) (aref (aref f 2) 2))
68 (defsubst advice--props (f) (aref (aref f 2) 3))
70 (defun advice--cd*r (f)
71 (while (advice--p f)
72 (setq f (advice--cdr f)))
75 (defun advice--where (f)
76 (let ((bytecode (aref f 1))
77 (where nil))
78 (dolist (elem advice--where-alist)
79 (if (eq bytecode (cadr elem)) (setq where (car elem))))
80 where))
82 (defun advice--make-docstring (function)
83 "Build the raw docstring for FUNCTION, presumably advised."
84 (let* ((flist (indirect-function function))
85 (docfun nil)
86 (docstring nil))
87 (if (eq 'macro (car-safe flist)) (setq flist (cdr flist)))
88 (while (advice--p flist)
89 (let ((doc (aref flist 4))
90 (where (advice--where flist)))
91 ;; Hack attack! For advices installed before calling
92 ;; Snarf-documentation, the integer offset into the DOC file will not
93 ;; be installed in the "core unadvised function" but in the advice
94 ;; object instead! So here we try to undo the damage.
95 (if (integerp doc) (setq docfun flist))
96 (setq docstring
97 (concat
98 docstring
99 (propertize (format "%s advice: " where)
100 'face 'warning)
101 (let ((fun (advice--car flist)))
102 (if (symbolp fun) (format-message "`%S'" fun)
103 (let* ((name (cdr (assq 'name (advice--props flist))))
104 (doc (documentation fun t))
105 (usage (help-split-fundoc doc function)))
106 (if usage (setq doc (cdr usage)))
107 (if name
108 (if doc
109 (format "%s\n%s" name doc)
110 (format "%s" name))
111 (or doc "No documentation")))))
112 "\n")))
113 (setq flist (advice--cdr flist)))
114 (if docstring (setq docstring (concat docstring "\n")))
115 (unless docfun (setq docfun flist))
116 (let* ((origdoc (unless (eq function docfun) ;Avoid inf-loops.
117 (documentation docfun t)))
118 (usage (help-split-fundoc origdoc function)))
119 (setq usage (if (null usage)
120 (let ((arglist (help-function-arglist flist)))
121 ;; "[Arg list not available until function
122 ;; definition is loaded]", bug#21299
123 (if (stringp arglist) t
124 (help--make-usage-docstring function arglist)))
125 (setq origdoc (cdr usage)) (car usage)))
126 (help-add-fundoc-usage (concat docstring origdoc) usage))))
128 (defun advice-eval-interactive-spec (spec)
129 "Evaluate the interactive spec SPEC."
130 (cond
131 ((stringp spec)
132 ;; There's no direct access to the C code (in call-interactively) that
133 ;; processes those specs, but that shouldn't stop us, should it?
134 ;; FIXME: Despite appearances, this is not faithful: SPEC and
135 ;; (advice-eval-interactive-spec SPEC) will behave subtly differently w.r.t
136 ;; command-history (and maybe a few other details).
137 (call-interactively `(lambda (&rest args) (interactive ,spec) args)))
138 ;; ((functionp spec) (funcall spec))
139 (t (eval spec))))
141 (defun advice--interactive-form (function)
142 ;; Like `interactive-form' but tries to avoid autoloading functions.
143 (when (commandp function)
144 (if (not (and (symbolp function) (autoloadp (indirect-function function))))
145 (interactive-form function)
146 `(interactive (advice-eval-interactive-spec
147 (cadr (interactive-form ',function)))))))
149 (defun advice--make-interactive-form (function main)
150 ;; TODO: make it so that interactive spec can be a constant which
151 ;; dynamically checks the advice--car/cdr to do its job.
152 ;; For that, advice-eval-interactive-spec needs to be more faithful.
153 (let* ((iff (advice--interactive-form function))
154 (ifm (advice--interactive-form main))
155 (fspec (cadr iff)))
156 (when (eq 'function (car-safe fspec)) ;; Macroexpanded lambda?
157 (setq fspec (nth 1 fspec)))
158 (if (functionp fspec)
159 `(funcall ',fspec ',(cadr ifm))
160 (cadr (or iff ifm)))))
162 (defun advice--make-1 (byte-code stack-depth function main props)
163 "Build a function value that adds FUNCTION to MAIN."
164 (let ((adv-sig (gethash main advertised-signature-table))
165 (advice
166 (apply #'make-byte-code 128 byte-code
167 (vector #'apply function main props) stack-depth nil
168 (and (or (commandp function) (commandp main))
169 (list (advice--make-interactive-form
170 function main))))))
171 (when adv-sig (puthash advice adv-sig advertised-signature-table))
172 advice))
174 (defun advice--make (where function main props)
175 "Build a function value that adds FUNCTION to MAIN at WHERE.
176 WHERE is a symbol to select an entry in `advice--where-alist'."
177 (let ((fd (or (cdr (assq 'depth props)) 0))
178 (md (if (advice--p main)
179 (or (cdr (assq 'depth (advice--props main))) 0))))
180 (if (and md (> fd md))
181 ;; `function' should go deeper.
182 (let ((rest (advice--make where function (advice--cdr main) props)))
183 (advice--make-1 (aref main 1) (aref main 3)
184 (advice--car main) rest (advice--props main)))
185 (let ((desc (assq where advice--where-alist)))
186 (unless desc (error "Unknown add-function location `%S'" where))
187 (advice--make-1 (nth 1 desc) (nth 2 desc)
188 function main props)))))
190 (defun advice--member-p (function use-name definition)
191 (let ((found nil))
192 (while (and (not found) (advice--p definition))
193 (if (if (eq use-name :use-both)
194 (or (equal function
195 (cdr (assq 'name (advice--props definition))))
196 (equal function (advice--car definition)))
197 (equal function (if use-name
198 (cdr (assq 'name (advice--props definition)))
199 (advice--car definition))))
200 (setq found definition)
201 (setq definition (advice--cdr definition))))
202 found))
204 (defun advice--tweak (flist tweaker)
205 (if (not (advice--p flist))
206 (funcall tweaker nil flist nil)
207 (let ((first (advice--car flist))
208 (rest (advice--cdr flist))
209 (props (advice--props flist)))
210 (let ((val (funcall tweaker first rest props)))
211 (if val (car val)
212 (let ((nrest (advice--tweak rest tweaker)))
213 (if (eq rest nrest) flist
214 (advice--make-1 (aref flist 1) (aref flist 3)
215 first nrest props))))))))
217 ;;;###autoload
218 (defun advice--remove-function (flist function)
219 (advice--tweak flist
220 (lambda (first rest props)
221 (cond ((not first) rest)
222 ((or (equal function first)
223 (equal function (cdr (assq 'name props))))
224 (list (advice--remove-function rest function)))))))
226 (defvar advice--buffer-local-function-sample nil
227 "keeps an example of the special \"run the default value\" functions.
228 These functions play the same role as t in buffer-local hooks, and to recognize
229 them, we keep a sample here against which to compare. Each instance is
230 different, but `function-equal' will hopefully ignore those differences.")
232 (defun advice--set-buffer-local (var val)
233 (if (function-equal val advice--buffer-local-function-sample)
234 (kill-local-variable var)
235 (set (make-local-variable var) val)))
237 ;;;###autoload
238 (defun advice--buffer-local (var)
239 "Buffer-local value of VAR, presumed to contain a function."
240 (declare (gv-setter advice--set-buffer-local))
241 (if (local-variable-p var) (symbol-value var)
242 (setq advice--buffer-local-function-sample
243 ;; This function acts like the t special value in buffer-local hooks.
244 (lambda (&rest args) (apply (default-value var) args)))))
246 (eval-and-compile
247 (defun advice--normalize-place (place)
248 (cond ((eq 'local (car-safe place)) `(advice--buffer-local ,@(cdr place)))
249 ((eq 'var (car-safe place)) (nth 1 place))
250 ((symbolp place) `(default-value ',place))
251 (t place))))
253 ;;;###autoload
254 (defmacro add-function (where place function &optional props)
255 ;; TODO:
256 ;; - maybe let `where' specify some kind of predicate and use it
257 ;; to implement things like mode-local or eieio-defmethod.
258 ;; Of course, that only makes sense if the predicates of all advices can
259 ;; be combined and made more efficient.
260 ;; :before is like a normal add-hook on a normal hook.
261 ;; :before-while is like add-hook on run-hook-with-args-until-failure.
262 ;; :before-until is like add-hook on run-hook-with-args-until-success.
263 ;; Same with :after-* but for (add-hook ... 'append).
264 "Add a piece of advice on the function stored at PLACE.
265 FUNCTION describes the code to add. WHERE describes where to add it.
266 WHERE can be explained by showing the resulting new function, as the
267 result of combining FUNCTION and the previous value of PLACE, which we
268 call OLDFUN here:
269 `:before' (lambda (&rest r) (apply FUNCTION r) (apply OLDFUN r))
270 `:after' (lambda (&rest r) (prog1 (apply OLDFUN r) (apply FUNCTION r)))
271 `:around' (lambda (&rest r) (apply FUNCTION OLDFUN r))
272 `:override' (lambda (&rest r) (apply FUNCTION r))
273 `:before-while' (lambda (&rest r) (and (apply FUNCTION r) (apply OLDFUN r)))
274 `:before-until' (lambda (&rest r) (or (apply FUNCTION r) (apply OLDFUN r)))
275 `:after-while' (lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r)))
276 `:after-until' (lambda (&rest r) (or (apply OLDFUN r) (apply FUNCTION r)))
277 `:filter-args' (lambda (&rest r) (apply OLDFUN (funcall FUNCTION r)))
278 `:filter-return'(lambda (&rest r) (funcall FUNCTION (apply OLDFUN r)))
279 If FUNCTION was already added, do nothing.
280 PROPS is an alist of additional properties, among which the following have
281 a special meaning:
282 - `name': a string or symbol. It can be used to refer to this piece of advice.
283 - `depth': a number indicating a preference w.r.t ordering.
284 The default depth is 0. By convention, a depth of 100 means that
285 the advice should be innermost (i.e. at the end of the list),
286 whereas a depth of -100 means that the advice should be outermost.
288 If PLACE is a symbol, its `default-value' will be affected.
289 Use (local \\='SYMBOL) if you want to apply FUNCTION to SYMBOL buffer-locally.
290 Use (var VAR) if you want to apply FUNCTION to the (lexical) VAR.
292 If one of FUNCTION or OLDFUN is interactive, then the resulting function
293 is also interactive. There are 3 cases:
294 - FUNCTION is not interactive: the interactive spec of OLDFUN is used.
295 - The interactive spec of FUNCTION is itself a function: it should take one
296 argument (the interactive spec of OLDFUN, which it can pass to
297 `advice-eval-interactive-spec') and return the list of arguments to use.
298 - Else, use the interactive spec of FUNCTION and ignore the one of OLDFUN."
299 (declare
300 ;;(indent 2)
301 (debug (form [&or symbolp ("local" form) ("var" sexp) gv-place]
302 form &optional form)))
303 `(advice--add-function ,where (gv-ref ,(advice--normalize-place place))
304 ,function ,props))
306 ;;;###autoload
307 (defun advice--add-function (where ref function props)
308 (let* ((name (cdr (assq 'name props)))
309 (a (advice--member-p (or name function) (if name t) (gv-deref ref))))
310 (when a
311 ;; The advice is already present. Remove the old one, first.
312 (setf (gv-deref ref)
313 (advice--remove-function (gv-deref ref)
314 (or name (advice--car a)))))
315 (setf (gv-deref ref)
316 (advice--make where function (gv-deref ref) props))))
318 ;;;###autoload
319 (defmacro remove-function (place function)
320 "Remove the FUNCTION piece of advice from PLACE.
321 If FUNCTION was not added to PLACE, do nothing.
322 Instead of FUNCTION being the actual function, it can also be the `name'
323 of the piece of advice."
324 (declare (debug ([&or symbolp ("local" form) ("var" sexp) gv-place]
325 form)))
326 (gv-letplace (getter setter) (advice--normalize-place place)
327 (macroexp-let2 nil new `(advice--remove-function ,getter ,function)
328 `(unless (eq ,new ,getter) ,(funcall setter new)))))
330 (defun advice-function-mapc (f function-def)
331 "Apply F to every advice function in FUNCTION-DEF.
332 F is called with two arguments: the function that was added, and the
333 properties alist that was specified when it was added."
334 (while (advice--p function-def)
335 (funcall f (advice--car function-def) (advice--props function-def))
336 (setq function-def (advice--cdr function-def))))
338 (defun advice-function-member-p (advice function-def)
339 "Return non-nil if ADVICE is already in FUNCTION-DEF.
340 Instead of ADVICE being the actual function, it can also be the `name'
341 of the piece of advice."
342 (advice--member-p advice :use-both function-def))
344 ;;;; Specific application of add-function to `symbol-function' for advice.
346 (defun advice--subst-main (old new)
347 (advice--tweak old
348 (lambda (first _rest _props) (if (not first) new))))
350 (defun advice--normalize (symbol def)
351 (cond
352 ((special-form-p def)
353 ;; Not worth the trouble trying to handle this, I think.
354 (error "Advice impossible: %S is a special form" symbol))
355 ((and (symbolp def) (macrop def))
356 (let ((newval `(macro . ,(lambda (&rest r) (macroexpand `(,def . ,r))))))
357 (put symbol 'advice--saved-rewrite (cons def (cdr newval)))
358 newval))
359 ;; `f' might be a pure (hence read-only) cons!
360 ((and (eq 'macro (car-safe def))
361 (not (ignore-errors (setcdr def (cdr def)) t)))
362 (cons 'macro (cdr def)))
363 (t def)))
365 (defsubst advice--strip-macro (x)
366 (if (eq 'macro (car-safe x)) (cdr x) x))
368 (defun advice--symbol-function (symbol)
369 ;; The value conceptually stored in `symbol-function' is split into two
370 ;; parts:
371 ;; - the normal function definition.
372 ;; - the list of advice applied to it.
373 ;; `advice--symbol-function' is intended to return the second part (i.e. the
374 ;; list of advice, which includes a hole at the end which typically holds the
375 ;; first part, but this function doesn't care much which value is found
376 ;; there).
377 ;; In the "normal" state both parts are combined into a single value stored
378 ;; in the "function slot" of the symbol. But the way they are combined is
379 ;; different depending on whether the definition is a function or a macro.
380 ;; Also if the function definition is nil (i.e. unbound) or is an autoload,
381 ;; the second part is stashed away temporarily in the `advice--pending'
382 ;; symbol property.
383 (or (get symbol 'advice--pending)
384 (advice--strip-macro (symbol-function symbol))))
386 (defun advice--defalias-fset (fsetfun symbol newdef)
387 (unless fsetfun (setq fsetfun #'fset))
388 (when (get symbol 'advice--saved-rewrite)
389 (put symbol 'advice--saved-rewrite nil))
390 (setq newdef (advice--normalize symbol newdef))
391 (let ((oldadv (advice--symbol-function symbol)))
392 (if (and newdef (not (autoloadp newdef)))
393 (let* ((snewdef (advice--strip-macro newdef))
394 (snewadv (advice--subst-main oldadv snewdef)))
395 (put symbol 'advice--pending nil)
396 (funcall fsetfun symbol
397 (if (eq snewdef newdef) snewadv (cons 'macro snewadv))))
398 (unless (eq oldadv (get symbol 'advice--pending))
399 (put symbol 'advice--pending (advice--subst-main oldadv nil)))
400 (funcall fsetfun symbol newdef))))
402 ;;;###autoload
403 (defun advice-add (symbol where function &optional props)
404 "Like `add-function' but for the function named SYMBOL.
405 Contrary to `add-function', this will properly handle the cases where SYMBOL
406 is defined as a macro, alias, command, ..."
407 ;; TODO:
408 ;; - record the advice location, to display in describe-function.
409 ;; - change all defadvice in lisp/**/*.el.
410 ;; - obsolete advice.el.
411 (let* ((f (symbol-function symbol))
412 (nf (advice--normalize symbol f)))
413 (unless (eq f nf) (fset symbol nf))
414 (add-function where (cond
415 ((eq (car-safe nf) 'macro) (cdr nf))
416 ;; Reasons to delay installation of the advice:
417 ;; - If the function is not yet defined, installing
418 ;; the advice would affect `fboundp'ness.
419 ;; - the symbol-function slot of an autoloaded
420 ;; function is not itself a function value.
421 ;; - `autoload' does nothing if the function is
422 ;; not an autoload or undefined.
423 ((or (not nf) (autoloadp nf))
424 (get symbol 'advice--pending))
425 (t (symbol-function symbol)))
426 function props)
427 (put symbol 'function-documentation `(advice--make-docstring ',symbol))
428 (add-function :around (get symbol 'defalias-fset-function)
429 #'advice--defalias-fset))
430 nil)
432 ;;;###autoload
433 (defun advice-remove (symbol function)
434 "Like `remove-function' but for the function named SYMBOL.
435 Contrary to `remove-function', this also works when SYMBOL is a macro
436 or an autoload and it preserves `fboundp'.
437 Instead of the actual function to remove, FUNCTION can also be the `name'
438 of the piece of advice."
439 (let ((f (symbol-function symbol)))
440 (remove-function (cond ;This is `advice--symbol-function' but as a "place".
441 ((get symbol 'advice--pending)
442 (get symbol 'advice--pending))
443 ((eq (car-safe f) 'macro) (cdr f))
444 (t (symbol-function symbol)))
445 function)
446 (unless (advice--p (advice--symbol-function symbol))
447 (remove-function (get symbol 'defalias-fset-function)
448 #'advice--defalias-fset)
449 (let ((asr (get symbol 'advice--saved-rewrite)))
450 (and asr (eq (cdr-safe (symbol-function symbol))
451 (cdr asr))
452 (fset symbol (car (get symbol 'advice--saved-rewrite)))))))
453 nil)
455 ;;;###autoload
456 (defmacro define-advice (symbol args &rest body)
457 "Define an advice and add it to function named SYMBOL.
458 See `advice-add' and `add-function' for explanation on the
459 arguments. Note if NAME is nil the advice is anonymous;
460 otherwise it is named `SYMBOL@NAME'.
462 \(fn SYMBOL (WHERE LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
463 (declare (indent 2) (doc-string 3) (debug (sexp sexp body)))
464 (or (listp args) (signal 'wrong-type-argument (list 'listp args)))
465 (or (<= 2 (length args) 4)
466 (signal 'wrong-number-of-arguments (list 2 4 (length args))))
467 (let* ((where (nth 0 args))
468 (lambda-list (nth 1 args))
469 (name (nth 2 args))
470 (depth (nth 3 args))
471 (props (and depth `((depth . ,depth))))
472 (advice (cond ((null name) `(lambda ,lambda-list ,@body))
473 ((or (stringp name) (symbolp name))
474 (intern (format "%s@%s" symbol name)))
475 (t (error "Unrecognized name spec `%S'" name)))))
476 `(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
477 (advice-add ',symbol ,where #',advice ,@(and props `(',props))))))
479 (defun advice-mapc (fun symbol)
480 "Apply FUN to every advice function in SYMBOL.
481 FUN is called with a two arguments: the function that was added, and the
482 properties alist that was specified when it was added."
483 (advice-function-mapc fun (advice--symbol-function symbol)))
485 ;;;###autoload
486 (defun advice-member-p (advice symbol)
487 "Return non-nil if ADVICE has been added to SYMBOL.
488 Instead of ADVICE being the actual function, it can also be the `name'
489 of the piece of advice."
490 (advice-function-member-p advice (advice--symbol-function symbol)))
492 ;; When code is advised, called-interactively-p needs to be taught to skip
493 ;; the advising frames.
494 ;; FIXME: This Major Ugly Hack won't handle calls to called-interactively-p
495 ;; done from the advised function if the deepest advice is an around advice!
496 ;; In other cases (calls from an advice or calls from the advised function when
497 ;; the deepest advice is not an around advice), it should hopefully get
498 ;; it right.
499 (add-hook 'called-interactively-p-functions
500 #'advice--called-interactively-skip)
501 (defun advice--called-interactively-skip (origi frame1 frame2)
502 (let* ((i origi)
503 (get-next-frame
504 (lambda ()
505 (setq frame1 frame2)
506 (setq frame2 (backtrace-frame i #'called-interactively-p))
507 ;; (message "Advice Frame %d = %S" i frame2)
508 (setq i (1+ i)))))
509 ;; FIXME: Adjust this for the new :filter advices, since they use `funcall'
510 ;; rather than `apply'.
511 ;; FIXME: Somehow this doesn't work on (advice-add :before
512 ;; 'call-interactively #'ignore), see bug#3984.
513 (when (and (eq (nth 1 frame2) 'apply)
514 (progn
515 (funcall get-next-frame)
516 (advice--p (indirect-function (nth 1 frame2)))))
517 (funcall get-next-frame)
518 ;; If we now have the symbol, this was the head advice and
519 ;; we're done.
520 (while (advice--p (nth 1 frame1))
521 ;; This was an inner advice called from some earlier advice.
522 ;; The stack frames look different depending on the particular
523 ;; kind of the earlier advice.
524 (let ((inneradvice (nth 1 frame1)))
525 (if (and (eq (nth 1 frame2) 'apply)
526 (progn
527 (funcall get-next-frame)
528 (advice--p (indirect-function
529 (nth 1 frame2)))))
530 ;; The earlier advice was something like a before/after
531 ;; advice where the "next" code is called directly by the
532 ;; advice--p object.
533 (funcall get-next-frame)
534 ;; It's apparently an around advice, where the "next" is
535 ;; called by the body of the advice in any way it sees fit,
536 ;; so we need to skip the frames of that body.
537 (while
538 (progn
539 (funcall get-next-frame)
540 (and frame2
541 (not (and (eq (nth 1 frame2) 'apply)
542 (eq (nth 3 frame2) inneradvice))))))
543 (funcall get-next-frame)
544 (funcall get-next-frame))))
545 (- i origi 1))))
548 (provide 'nadvice)
549 ;;; nadvice.el ends here