Use OClosure to drop advice--buffer-local-function-sample hack

* lisp/emacs-lisp/nadvice.el (advice--forward): New OClosure, to
replace `advice--buffer-local-function-sample`.
(advice--set-buffer-local, advice--buffer-local): Adjust accordingly.
This commit is contained in:
Stefan Monnier 2023-10-29 14:12:22 -04:00
parent 99d4d65cc2
commit b27e2bbb34

View file

@ -292,14 +292,13 @@ HOW is a symbol to select an entry in `advice--how-alist'."
(equal function (cdr (assq 'name props))))
(list (advice--remove-function rest function)))))))
(defvar advice--buffer-local-function-sample nil
"Keeps an example of the special \"run the default value\" functions.
These functions play the same role as t in buffer-local hooks, and to recognize
them, we keep a sample here against which to compare. Each instance is
different, but `function-equal' will hopefully ignore those differences.")
(oclosure-define (advice--forward
(:predicate advice--forward-p))
"Redirect to the global value of a var.
These functions act like the t special value in buffer-local hooks.")
(defun advice--set-buffer-local (var val)
(if (function-equal val advice--buffer-local-function-sample)
(if (advice--forward-p val)
(kill-local-variable var)
(set (make-local-variable var) val)))
@ -308,11 +307,10 @@ different, but `function-equal' will hopefully ignore those differences.")
"Buffer-local value of VAR, presumed to contain a function."
(declare (gv-setter advice--set-buffer-local))
(if (local-variable-p var) (symbol-value var)
(setq advice--buffer-local-function-sample
;; This function acts like the t special value in buffer-local hooks.
;; FIXME: Provide an `advice-bottom' function that's like
;; `advice-cd*r' but also follows through this proxy.
(lambda (&rest args) (apply (default-value var) args)))))
;; FIXME: Provide an `advice-bottom' function that's like
;; `advice--cd*r' but also follows through this proxy.
(oclosure-lambda (advice--forward) (&rest args)
(apply (default-value var) args))))
(eval-and-compile
(defun advice--normalize-place (place)