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

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

[nongnu] elpa/recomplete 802c85b02d 04/14: Replace cl-letf with advice m


From: ELPA Syncer
Subject: [nongnu] elpa/recomplete 802c85b02d 04/14: Replace cl-letf with advice macro
Date: Thu, 7 Jul 2022 12:02:21 -0400 (EDT)

branch: elpa/recomplete
commit 802c85b02d99bce4cf540ed4b716eaa39df45c4a
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Replace cl-letf with advice macro
    
    This was causing an error which I didn't want to investigate,
    prefer temporary advice over common-lisp.
---
 recomplete.el | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/recomplete.el b/recomplete.el
index af547651f0..ad22572693 100644
--- a/recomplete.el
+++ b/recomplete.el
@@ -81,6 +81,17 @@
 ;; ---------------------------------------------------------------------------
 ;; Generic Functions/Macros
 
+(defmacro recomplete--with-advice (fn-orig where fn-advice &rest body)
+  "Execute BODY with advice added WHERE using FN-ADVICE temporarily added to 
FN-ORIG."
+  `
+  (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))))
+
+
 ;; See: https://emacs.stackexchange.com/a/54412/2418
 (defmacro recomplete--with-undo-collapse (&rest body)
   "Like `progn' but perform BODY with undo collapsed."
@@ -114,13 +125,12 @@
   (declare (indent 1))
   `
   (let ((temp-message-list (list)))
-    (cl-letf
-      (
-        ((symbol-function 'message)
-          (lambda (&rest args)
-            ;; Only check if non-null because this is a signal not to log at 
all.
-            (when message-log-max
-              (push (apply 'format-message args) temp-message-list)))))
+    (recomplete--with-advice 'message
+      :override
+      (lambda (&rest args)
+        ;; Only check if non-null because this is a signal not to log at all.
+        (when message-log-max
+          (push (apply #'format-message args) temp-message-list)))
       (unwind-protect
         (progn
           ,@body)
@@ -205,16 +215,15 @@ Argument FN-CACHE stores the result for reuse."
   (pcase-let ((`(,result-choices ,word-beg ,word-end) (or fn-cache '(nil nil 
nil))))
 
     (unless result-choices
-      (cl-letf
-        (
-          ((symbol-function 'ispell-command-loop)
-            (lambda (miss _guess _word start end)
-              (when miss
-                (setq result-choices miss)
-                (setq word-beg (marker-position start))
-                (setq word-end (marker-position end))
-                ;; Return the word would make the correction, we do this 
ourselves next.
-                nil))))
+      (recomplete--with-advice 'ispell-command-loop
+        :override
+        (lambda (miss _guess _word start end)
+          (when miss
+            (setq result-choices miss)
+            (setq word-beg (marker-position start))
+            (setq word-end (marker-position end))
+            ;; Return the word would make the correction, we do this ourselves 
next.
+            nil))
         (ispell-word))
 
       (when result-choices



reply via email to

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