advice

Table of Contents

advice system in emacs-lisp allow you to modify existing function behaviour without having to redefine it

It’s behaviour is in its doc:

Signature
(advice-add SYMBOL HOW FUNCTION &optional PROPS)


HOW can be one of:
 :around        (lambda (&rest r) (apply FUNCTION OLDFUN r))
 :before        (lambda (&rest r) (apply FUNCTION r) (apply OLDFUN r))
 :after         (lambda (&rest r) (prog1 (apply OLDFUN r) (apply FUNCTION r)))
 :override      (lambda (&rest r) (apply FUNCTION r))
 :after-until   (lambda (&rest r) (or (apply OLDFUN r) (apply FUNCTION r)))
 :after-while   (lambda (&rest r) (and (apply OLDFUN r) (apply FUNCTION r)))
 :before-until  (lambda (&rest r) (or (apply FUNCTION r) (apply OLDFUN r)))
 :before-while  (lambda (&rest r) (and (apply FUNCTION r) (apply OLDFUN r)))
 :filter-args   (lambda (&rest r) (apply OLDFUN (funcall FUNCTION r)))
 :filter-return (lambda (&rest r) (funcall FUNCTION (apply OLDFUN r)))

Pretty straight forward

Backlinks

Author: Linfeng He

Created: 2024-04-03 Wed 20:16