emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/undo-fu 0c34b6747e 52/82: Cleanup: replace cl-letf with ma


From: ELPA Syncer
Subject: [nongnu] elpa/undo-fu 0c34b6747e 52/82: Cleanup: replace cl-letf with macro that temporarily sets advice
Date: Thu, 7 Jul 2022 12:04:53 -0400 (EDT)

branch: elpa/undo-fu
commit 0c34b6747eb633652343cad76e6f1051cf56d6e9
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Cleanup: replace cl-letf with macro that temporarily sets advice
    
    Removes cl-lib use and avoids dealing with function symbol swapping.
---
 undo-fu.el | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/undo-fu.el b/undo-fu.el
index dbd2e771a8..3d355df807 100644
--- a/undo-fu.el
+++ b/undo-fu.el
@@ -100,20 +100,28 @@ Instead, explicitly call `undo-fu-disable-checkpoint'."
   (setq undo-fu--in-region nil)
   (undo-fu--checkpoint-unset))
 
+(defmacro undo-fu--with-advice (fn-orig where fn-advice &rest body)
+  "Execute BODY with advice temporarily enabled."
+  `
+  (let ((fn-advice-var ,fn-advice))
+    (unwind-protect
+      (progn
+        (advice-add ,fn-orig ,where fn-advice-var)
+        ,@body)
+      (advice-remove ,fn-orig fn-advice-var))))
+
 (defmacro undo-fu--with-message-suffix (suffix &rest body)
   "Add text after the message output.
-Argument SUFFIX is the text to add at the end of the message.
+Argument SUFFIX is the text to add at the start of the message.
 Optional argument BODY runs with the message suffix."
   (declare (indent 1))
-  (let ((message-orig (cl-gensym "--message-suffix-")))
-    `
-    (cl-letf*
-      (
-        (,message-orig (symbol-function 'message))
-        ((symbol-function 'message)
-          (lambda (arg &rest args)
-            (apply ,message-orig (append (list (concat arg "%s")) args (list 
,suffix))))))
-      ,@body)))
+  `
+  (undo-fu--with-advice
+    'message
+    :around
+    (lambda (fn-orig arg &rest args)
+      (apply fn-orig (append (list (concat arg "%s")) args (list ,suffix))))
+    ,@body))
 
 (defun undo-fu--undo-enabled-or-error ()
   "Raise a user error when undo is disabled."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]