Skip to content

Instantly share code, notes, and snippets.

@abelardojarab
Created November 12, 2017 18:41
Show Gist options
  • Save abelardojarab/12ab581f1ebff69682f5e8c093ad75fa to your computer and use it in GitHub Desktop.
Save abelardojarab/12ab581f1ebff69682f5e8c093ad75fa to your computer and use it in GitHub Desktop.
Advice functions in Emacs (defadvice, around, add-do-it)

Around means that the advice is executed instead of the function. You can still call the original with ad-do-it.

Just to add a small example:

(defun foo (x)
  (* 2 x))

(defadvice foo (around bar activate)
  (setq ad-return-value
        (if (= x 1)
            42
          (+ 1 ad-do-it))))

(foo 1)
;; 42
(foo 2)
;; 5
(foo 3)
;; 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment