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

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

[elpa] externals/transient 79f5ec70f3 2/5: Use static-if to pick an impl


From: Jonas Bernoulli
Subject: [elpa] externals/transient 79f5ec70f3 2/5: Use static-if to pick an implementation of transient--wrap-command
Date: Mon, 27 Nov 2023 10:14:30 -0500 (EST)

branch: externals/transient
commit 79f5ec70f33e86302a773f7c69ad4b3869c8be3d
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Use static-if to pick an implementation of transient--wrap-command
---
 lisp/transient.el | 128 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 69 insertions(+), 59 deletions(-)

diff --git a/lisp/transient.el b/lisp/transient.el
index b235a4b2cc..705ab83c33 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -75,6 +75,17 @@
 (defvar Man-notify-method)
 (defvar pp-default-function) ; since Emacs 29.1
 
+(defmacro static-if (condition then-form &rest else-forms)
+  "A conditional compilation macro.
+Evaluate CONDITION at macro-expansion time.  If it is non-nil,
+expand the macro to THEN-FORM.  Otherwise expand it to ELSE-FORMS
+enclosed in a `progn' form.  ELSE-FORMS may be empty."
+  (declare (indent 2)
+           (debug (sexp sexp &rest sexp)))
+  (if (eval condition lexical-binding)
+      then-form
+    (cons 'progn else-forms)))
+
 (defmacro transient--with-emergency-exit (&rest body)
   (declare (indent defun))
   `(condition-case err
@@ -2272,66 +2283,65 @@ value.  Otherwise return CHILDREN as is."
              (remove-hook 'minibuffer-exit-hook ,exit)))
        ,@body)))
 
-(defun transient--wrap-command ()
-  (if (>= emacs-major-version 30)
-      (transient--wrap-command-30)
-    (transient--wrap-command-29)))
-
-(defun transient--wrap-command-30 ()
-  (letrec
-      ((prefix transient--prefix)
-       (suffix this-command)
-       (advice (lambda (fn &rest args)
-                 (interactive
-                  (lambda (spec)
-                    (let ((abort t))
-                      (unwind-protect
-                          (prog1 (advice-eval-interactive-spec spec)
-                            (setq abort nil))
-                        (when abort
-                          (when-let ((unwind (oref prefix unwind-suffix)))
-                            (transient--debug 'unwind-interactive)
-                            (funcall unwind suffix))
-                          (advice-remove suffix advice)
-                          (oset prefix unwind-suffix nil))))))
-                 (unwind-protect
-                     (apply fn args)
-                   (when-let ((unwind (oref prefix unwind-suffix)))
-                     (transient--debug 'unwind-command)
-                     (funcall unwind suffix))
-                   (advice-remove suffix advice)
-                   (oset prefix unwind-suffix nil)))))
-    (advice-add suffix :around advice '((depth . -99)))))
-
-(defun transient--wrap-command-29 ()
-  (let* ((prefix transient--prefix)
-         (suffix this-command)
-         (advice nil)
-         (advice-interactive
-          (lambda (spec)
-            (let ((abort t))
+(static-if (>= emacs-major-version 30)
+    (defun transient--wrap-command ()
+      (cl-assert
+       (>= emacs-major-version 30) nil
+       "Emacs was downgraded, making it necessary to recompile Transient")
+      (letrec
+          ((prefix transient--prefix)
+           (suffix this-command)
+           (advice (lambda (fn &rest args)
+                     (interactive
+                      (lambda (spec)
+                        (let ((abort t))
+                          (unwind-protect
+                              (prog1 (advice-eval-interactive-spec spec)
+                                (setq abort nil))
+                            (when abort
+                              (when-let ((unwind (oref prefix unwind-suffix)))
+                                (transient--debug 'unwind-interactive)
+                                (funcall unwind suffix))
+                              (advice-remove suffix advice)
+                              (oset prefix unwind-suffix nil))))))
+                     (unwind-protect
+                         (apply fn args)
+                       (when-let ((unwind (oref prefix unwind-suffix)))
+                         (transient--debug 'unwind-command)
+                         (funcall unwind suffix))
+                       (advice-remove suffix advice)
+                       (oset prefix unwind-suffix nil)))))
+        (advice-add suffix :around advice '((depth . -99)))))
+
+  (defun transient--wrap-command ()
+    (let* ((prefix transient--prefix)
+           (suffix this-command)
+           (advice nil)
+           (advice-interactive
+            (lambda (spec)
+              (let ((abort t))
+                (unwind-protect
+                    (prog1 (advice-eval-interactive-spec spec)
+                      (setq abort nil))
+                  (when abort
+                    (when-let ((unwind (oref prefix unwind-suffix)))
+                      (transient--debug 'unwind-interactive)
+                      (funcall unwind suffix))
+                    (advice-remove suffix advice)
+                    (oset prefix unwind-suffix nil))))))
+           (advice-body
+            (lambda (fn &rest args)
               (unwind-protect
-                  (prog1 (advice-eval-interactive-spec spec)
-                    (setq abort nil))
-                (when abort
-                  (when-let ((unwind (oref prefix unwind-suffix)))
-                    (transient--debug 'unwind-interactive)
-                    (funcall unwind suffix))
-                  (advice-remove suffix advice)
-                  (oset prefix unwind-suffix nil))))))
-         (advice-body
-          (lambda (fn &rest args)
-            (unwind-protect
-                (apply fn args)
-              (when-let ((unwind (oref prefix unwind-suffix)))
-                (transient--debug 'unwind-command)
-                (funcall unwind suffix))
-              (advice-remove suffix advice)
-              (oset prefix unwind-suffix nil)))))
-    (setq advice `(lambda (fn &rest args)
-                    (interactive ,advice-interactive)
-                    (apply ',advice-body fn args)))
-    (advice-add suffix :around advice '((depth . -99)))))
+                  (apply fn args)
+                (when-let ((unwind (oref prefix unwind-suffix)))
+                  (transient--debug 'unwind-command)
+                  (funcall unwind suffix))
+                (advice-remove suffix advice)
+                (oset prefix unwind-suffix nil)))))
+      (setq advice `(lambda (fn &rest args)
+                      (interactive ,advice-interactive)
+                      (apply ',advice-body fn args)))
+      (advice-add suffix :around advice '((depth . -99))))))
 
 (defun transient--premature-post-command ()
   (and (equal (this-command-keys-vector) [])



reply via email to

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