]> git.eshelyaron.com Git - emacs.git/commitdiff
Use OClosure to drop `advice--buffer-local-function-sample` hack
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 29 Oct 2023 18:12:22 +0000 (14:12 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sun, 29 Oct 2023 18:12:22 +0000 (14:12 -0400)
* 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.

lisp/emacs-lisp/nadvice.el

index cd80df2c41d8b29c62f9f4c355879eb846d6a042..ce5467f3c5c1d1f582c0ccc2978a13d806b629d2 100644 (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)