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

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

[nongnu] elpa/nix-mode e167b82e64 493/500: nix-flake: Fix inconsistent s


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode e167b82e64 493/500: nix-flake: Fix inconsistent state after switching the flake
Date: Sat, 29 Jan 2022 08:27:59 -0500 (EST)

branch: elpa/nix-mode
commit e167b82e64ce794ff9e08f76625a879164dcf0cd
Author: Akira Komamura <akira.komamura@gmail.com>
Commit: Akira Komamura <akira.komamura@gmail.com>

    nix-flake: Fix inconsistent state after switching the flake
    
    The transient and the relevant variables must be updated after
    switching the flake.
---
 nix-flake.el | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/nix-flake.el b/nix-flake.el
index fbd99084cb..b759a513c7 100644
--- a/nix-flake.el
+++ b/nix-flake.el
@@ -45,14 +45,12 @@ already registered in either the user or the global 
registry."
 ;;;;; flake-ref
 
 (defclass nix-flake-ref-variable (transient-variable)
-  ((variable :initarg :variable)
-   (constant-value :initarg :constant-value :initform nil)
+  ((constant-value :initarg :constant-value :initform nil)
+   (on-change :initarg :on-change)
    (reader :initarg :reader :initform nil)))
 
-(cl-defmethod transient-init-value ((obj nix-flake-ref-variable))
-  "Set the initial value of the object OBJ."
-  (unless (oref obj value)
-    (oset obj value (eval (oref obj variable)))))
+(cl-defmethod transient-init-value ((_obj nix-flake-ref-variable))
+  "Set the initial value of the object.")
 
 (cl-defmethod transient-infix-read ((obj nix-flake-ref-variable))
   "Determine the new value of the infix object OBJ."
@@ -67,7 +65,8 @@ already registered in either the user or the global registry."
 (cl-defmethod transient-infix-set ((obj nix-flake-ref-variable) value)
   "Set the value of infix object OBJ to VALUE."
   (oset obj value value)
-  (set (oref obj variable) value))
+  (when-let (func (oref obj on-change))
+    (funcall func value)))
 
 (cl-defmethod transient-format-value ((_obj nix-flake-ref-variable))
   "Format the object's value for display and return the result."
@@ -143,13 +142,19 @@ readers in transient.el."
 ;;;;; Setting the flake
 (transient-define-infix nix-flake:from-registry ()
   :class 'nix-flake-ref-variable
-  :variable 'nix-flake-ref
+  :on-change
+  (lambda (flake-ref)
+    (nix-flake--set-flake flake-ref :remote t)
+    (transient-update))
   :description "Select a flake from the registry")
 
 (transient-define-infix nix-flake:flake-directory ()
   :class 'nix-flake-ref-variable
-  :variable 'nix-flake-ref
   :reader 'nix-flake--read-directory
+  :on-change
+  (lambda (flake-ref)
+    (nix-flake--set-flake flake-ref)
+    (transient-update))
   :description "Select a directory")
 
 (defun nix-flake--read-directory (prompt &optional initial-input _history)
@@ -388,13 +393,19 @@ For OPTIONS and FLAKE-REF, see the documentation of
    ("l" "flake lock" nix-flake-lock)
    ("u" "flake update" nix-flake-update)]
   (interactive (list (convert-standard-filename default-directory)))
+  (nix-flake--set-flake flake-ref :remote remote)
+  (transient-setup 'nix-flake-dispatch))
+
+(cl-defun nix-flake--set-flake (flake-ref &key remote)
+  "Set the flake of the transient interface.
+
+FLAKE-REF and REMOTE should be passed down from `nix-flake-dispatch'."
   (setq nix-flake-ref flake-ref)
   (setq nix-flake-outputs
         (if remote
-            (nix--process-json "flake" "show" "--json" nix-flake-ref)
-          (let ((default-directory flake-ref))
-           (nix--process-json "flake" "show" "--json"))))
-  (transient-setup 'nix-flake-dispatch))
+           (nix--process-json "flake" "show" "--json" nix-flake-ref)
+         (let ((default-directory flake-ref))
+            (nix--process-json "flake" "show" "--json")))))
 
 (defun nix-flake--description ()
   "Describe the current flake."



reply via email to

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