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

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

[elpa] externals/transient 95389b31ec 137/366: transient-init-value: Alw


From: Jonas Bernoulli
Subject: [elpa] externals/transient 95389b31ec 137/366: transient-init-value: Always prefer saved over default value
Date: Tue, 25 Jan 2022 18:54:35 -0500 (EST)

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

    transient-init-value: Always prefer saved over default value
    
    The previous implementation would have worked if only `slot-boundp'
    returned nil for slots that have a default value that is *not*
    shadowed by an explicitly set value.  But that is not so; the slot
    is considered bound in that case too.
    
    So we need two slots -- one for the default and one for the actual
    value.  We keep using `value' for the actual value because that is
    used much more often.  Only when implementing a `transient-init-value'
    method should one have to deal with the new `default-value' slot.
    Note that `value' now has no initarg and that `default-value's initarg
    is `:value'; but luckily that is an implementation detail that users
    of the `define-transient-command' macro don't have to know about that.
    
    Closes #68.
---
 lisp/transient.el | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/lisp/transient.el b/lisp/transient.el
index f7d9e260cb..94c2d75992 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -451,7 +451,7 @@ If `transient-save-history' is nil, then do nothing."
    (command     :initarg :command)
    (level       :initarg :level)
    (variable    :initarg :variable    :initform nil)
-   (value       :initarg :value)
+   (value) (default-value :initarg :value)
    (scope       :initarg :scope       :initform nil)
    (history     :initarg :history     :initform nil)
    (history-pos :initarg :history-pos :initform 0)
@@ -2113,13 +2113,14 @@ Non-infix suffix commands usually don't have a value."
   nil)
 
 (cl-defmethod transient-init-value ((obj transient-prefix))
-  (if (slot-boundp obj 'value)
-      (let ((value (oref obj value)))
-        (when (functionp value)
-          (oset obj value (funcall value))))
-    (oset obj value
-          (if-let ((saved (assq (oref obj command) transient-values)))
-              (cdr saved)
+  (oset obj value
+        (if-let ((saved (assq (oref obj command) transient-values)))
+            (cdr saved)
+          (if-let ((default (and (slot-boundp obj 'default-value)
+                                 (oref obj default-value))))
+              (if (functionp default)
+                  (funcall default)
+                default)
             nil))))
 
 (cl-defmethod transient-init-value ((obj transient-switch))



reply via email to

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