[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 9d8dc3c8d8 495/500: Merge pull request #143 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 9d8dc3c8d8 495/500: Merge pull request #143 from akirak/fix-flake-switching |
Date: |
Sat, 29 Jan 2022 08:28:00 -0500 (EST) |
branch: elpa/nix-mode
commit 9d8dc3c8d86adc9a894379780c25661612978442
Merge: e7bf2e4cc4 c4abb64a64
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #143 from akirak/fix-flake-switching
Fix some bugs in nix-flake.el
---
nix-flake.el | 48 ++++++++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/nix-flake.el b/nix-flake.el
index 0e07b07458..6729f2961b 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."
@@ -103,6 +102,10 @@ already registered in either the user or the global
registry."
(cl-remove-if-not (pcase-lambda (`(,type . ,_))
(member type '("user" "global"))))
(mapcar (lambda (cells)
+ ;; Both references and referees are included in the output.
+ ;; It may be better to pick only one and show others as
+ ;; decoration, e.g. using marginalia, but it is not supported
+ ;; for now.
(list (nth 1 cells)
(nth 2 cells))))
(flatten-list)))
@@ -143,25 +146,32 @@ 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)
"Select a directory containing a flake.
For PROMPT and INITIAL-INPUT, see the documentation of transient.el."
- (let ((input (read-directory-name prompt initial-input nil t)))
+ (let ((input (string-remove-suffix "/" (read-directory-name prompt
initial-input nil t))))
(prog1 (expand-file-name input)
(unless (file-exists-p (expand-file-name "flake.nix" input))
(user-error "The selected directory does not contain flake.nix"))
(when (and nix-flake-add-to-registry
- (not (member input (nix-flake--registry-refs))))
+ (not (member (concat "path:" input)
+ (nix-flake--registry-refs))))
(nix-flake--registry-add-1 input)))))
;;;;; --update-input
@@ -387,13 +397,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."
@@ -416,7 +432,7 @@ whatever supported by Nix."
(list nil :flake-ref nix-flake-ref)
(user-error "Last flake is unavailable")))
(_ (list default-directory))))
- (cl-assert (or (file-directory-p dir)
+ (cl-assert (or (and (stringp dir) (file-directory-p dir))
flake-ref)
nil
"DIR or FLAKE-REF must be specified")
- [nongnu] elpa/nix-mode c016c5503d 473/500: nix-flake: Reuse the last flake when two C-u is given, (continued)
- [nongnu] elpa/nix-mode c016c5503d 473/500: nix-flake: Reuse the last flake when two C-u is given, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c2d96ced52 447/500: Fix wrong documentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1ac42cd103 465/500: Update lock file, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1789c83b83 454/500: nix-format.el: Properly escape string in error message, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e645310c88 458/500: Introduce `nix-store-show-path` command, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ef92acd96c 453/500: nix-format.el: Use replace-buffer-contents when available, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ed00d8dff2 463/500: nix.el: Fix for Nix 2.5, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 327175e768 460/500: Merge pull request #138 from phikal/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b1257d3ea6 461/500: Merge branch 'master' into store-path, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ae1f5253be 478/500: nix-flake: Add documentation to README, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9d8dc3c8d8 495/500: Merge pull request #143 from akirak/fix-flake-switching,
ELPA Syncer <=
- [nongnu] elpa/nix-mode e7bf2e4cc4 489/500: Merge pull request #140 from akirak/flake-transient, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1f922d78eb 291/500: Fix regex regression that caused the indent to indent too much, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9ebf7389eb 298/500: Merge branch 'etu-fix-issue-72', ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d5a53e2050 300/500: Indent using SMIE - initial working version., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8118355e81 306/500: Change smie indent functions in a cleaner (and correct) way., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9d1d025cb7 313/500: Use "check" as test target, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8812eec39a 314/500: Allow using nix-indent-region without arguments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 29a93838bb 316/500: Add hello.nix to tests, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0cb2b32485 323/500: Add a failing test that checks the indentation of function bodies., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 79507ee193 327/500: Add more test cases to smie-lambdas.nix, ELPA Syncer, 2022/01/29