branch: externals/compat commit a7d9649d369dc8a14aae2a08b3cd9875f3054a16 Author: Philip Kaludercic <phil...@posteo.net> Commit: Philip Kaludercic <phil...@posteo.net>
Manually advise functions when nadvice is not available --- compat-macs.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/compat-macs.el b/compat-macs.el index 02609bc..6144eff 100644 --- a/compat-macs.el +++ b/compat-macs.el @@ -152,15 +152,17 @@ attributes (see `compat-generate-common')." ;; function. `(defalias ',name #',realname)) ((eq type 'advice) - ;; nadvice.el was introduced in Emacs 24.4, so - ;; older versions have to use `defadvice'. + ;; nadvice.el was introduced in Emacs 24.4, so older versions + ;; have to manually advise the old function. (if (version<= "24.4" emacs-version) `(advice-add ',name :around #',realname) - `(ad-add-advice - ',name - (list ,(format "setup:%S" name) - nil t (cons 'advice ,(lambda ())) - 'around 'first)))))) + ;; FIXME consider using advice.el and `ad-add-advice'. + (let ((oldfun (make-symbol (format "oldfun-%S" name)))) + `(progn + (defvar ,oldfun (indirect-function ',name)) + (defalias ',name + (lambda (&rest args) + (apply #',realname (cons ,oldfun args)))))))))) (lambda () (cond ((memq type '(func macro))