Last active
January 29, 2023 02:11
-
-
Save hidsh/24f8abcade9aba2f4cfa7d416381574d to your computer and use it in GitHub Desktop.
emacs: test for advice-add :before, :around, :after
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun func-1 () (message "aaa")) ;; target function | |
(defun my-func-1-adv () ;; advice function | |
(message "before")) | |
(advice-add 'func-1 :before #'my-func-1-adv) | |
;(func-1) | |
;---> before | |
;---> aaa | |
(advice-remove 'func-1 #'my-func-1-adv) | |
;(func-1) | |
;---> aaa | |
;; ---------------------------------------------------------------- | |
(defun func (a b c) ;; target func | |
(message (concat a b c))) | |
(defun my-adv (orig-fun &rest _) ;; advice | |
(message "-----") | |
(apply orig-fun _) | |
(message "-----") | |
nil) | |
(advice-add 'func :around #'my-adv) | |
(func "foo" "bar" "baz") | |
=> | |
----- | |
foobarbaz | |
----- | |
;; ---------------------------------------------------------------- | |
(defun func-3 () (message "ccc")) ;; target function | |
(defun my-func-3-adv () ;; advice function | |
(message "after")) | |
(advice-add 'func-3 :after #'my-func-3-adv) | |
;(func-3) | |
;---> ccc | |
;---> after | |
;; ---------------------------------------------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment