[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 38061187ca 265/500: Add nix-read-file & nix-read-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 38061187ca 265/500: Add nix-read-file & nix-read-attr |
Date: |
Sat, 29 Jan 2022 08:27:12 -0500 (EST) |
branch: elpa/nix-mode
commit 38061187ca16fa9973622777e6087730b72ebfc1
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>
Add nix-read-file & nix-read-attr
Useful for interactives
---
nix-search.el | 17 ++++++++++-------
nix-shell.el | 50 ++++++++++++++++++++++++--------------------------
2 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/nix-search.el b/nix-search.el
index c0d0ab61a7..85a1e837f2 100644
--- a/nix-search.el
+++ b/nix-search.el
@@ -11,20 +11,23 @@
;;; Code:
(require 'nix)
+(require 'nix-instantiate)
+(require 'nix-shell)
(require 'json)
;;;###autoload
-(defun nix-search (&optional search nix-file)
+(defun nix-search (&optional search file)
"Run nix search.
SEARCH a search term to use.
-NIX-FILE a Nix expression to search in."
+FILE a Nix expression to search in."
(interactive)
(unless search (setq search ""))
- (unless nix-file (setq nix-file "<nixpkgs>"))
+ (unless file (nix-read-file))
+
(let ((stdout (generate-new-buffer "nix search"))
result)
(call-process nix-executable nil (list stdout nil) nil
- "search" "--json" "-f" nix-file search)
+ "search" "--json" "-f" file search)
(with-current-buffer stdout
(when (eq (buffer-size) 0)
(error "Error: nix search %s failed to produce any output" search))
@@ -46,12 +49,12 @@ NIX-FILE a Nix expression to search in."
(kill-buffer stdout)
result))
-(defun nix-search-read-attr (nix-file)
+(defun nix-search-read-attr (file)
"Read from a list of attributes.
-NIX-FILE the nix file to look in."
+FILE the nix file to look in."
(let ((collection
(sort (mapcar (lambda (x) (symbol-name (car x)))
- (nix-search "" nix-file))
+ (nix-search "" file))
'string<))
(read (cond ((fboundp 'ivy-read) 'ivy-read)
(t 'completing-read))))
diff --git a/nix-shell.el b/nix-shell.el
index e0307c02c3..8f6da2b098 100644
--- a/nix-shell.el
+++ b/nix-shell.el
@@ -19,7 +19,6 @@
(require 'nix)
(require 'nix-instantiate)
(require 'nix-store)
-(require 'nix-search)
(defgroup nix-shell nil
"All nix-shell options."
@@ -63,27 +62,31 @@ Should only be set in dir-locals.el file."
"Run Nix’s unpackPhase.
FILE is the file to unpack from.
ATTR is the attribute to unpack."
- (interactive
- (list
- (if nix-file nix-file "<nixpkgs>")
- (if nix-attr nix-attr (nix-search-read-attr "<nixpkgs>"))))
+ (interactive (list (nix-read-file) nil))
+ (unless attr (setq attr (nix-read-attr file)))
+
(nix-shell--run-phase "unpack" file attr))
-(defun nix-shell--find-file ()
+(defun nix-read-attr (_)
+ "Get nix attribute from user."
+ (read-string "Nix attr: "))
+
+(defun nix-read-file ()
+ "Get nix file from user."
(cond
(nix-file nix-file)
((file-exists-p "shell.nix") "shell.nix")
((file-exists-p "default.nix") "default.nix")
- (t (read-file-name "Nix file: "))))
+ (t (read-file-name "Nix file: " nil "<nixpkgs>"))))
;;;###autoload
(defun nix-shell-configure (file attr)
"Run Nix’s configurePhase.
FILE is the file to configure from.
ATTR is the attribute to configure."
- (interactive
- (list (nix-shell--find-file)
- (if nix-attr nix-attr (nix-search-read-attr "<nixpkgs>"))))
+ (interactive (list (nix-read-file) nil))
+ (unless attr (setq attr (nix-read-attr file)))
+
(nix-shell--run-phase "configure" file attr))
;;;###autoload
@@ -91,9 +94,9 @@ ATTR is the attribute to configure."
"Run Nix’s buildPhase.
FILE is the file to build from.
ATTR is the attribute to build."
- (interactive
- (list (nix-shell--find-file)
- (if nix-attr nix-attr (nix-search-read-attr "<nixpkgs>"))))
+ (interactive (list (nix-read-file) nil))
+ (unless attr (setq attr (nix-read-attr file)))
+
(nix-shell--run-phase "build" file attr))
(defun nix-shell--run-phase (phase file attr)
@@ -197,7 +200,7 @@ PKGS-FILE a file to use to get the packages."
(nix-shell--callback
(current-buffer)
(nix-instantiate
- (nix-shell--with-packages-file packages pkgs-file)))
+ (nix-shell--with-packages-file packages pkgs-file) nil t))
(eshell-mode)
buffer))
@@ -206,11 +209,8 @@ PKGS-FILE a file to use to get the packages."
"Create an Eshell buffer that has the shell environment in it.
FILE the .nix expression to create a shell for.
ATTR attribute to instantiate in NIX-FILE."
- (interactive
- (list
- (if nix-file nix-file "<nixpkgs>")
- (when (not nix-file)
- (if nix-attr nix-attr (nix-search-read-attr "<nixpkgs>")))))
+ (interactive (list (nix-read-file) nil))
+ (unless attr (setq attr (nix-read-attr nix-file)))
(let ((buffer (generate-new-buffer "*nix-eshell*")))
(pop-to-buffer-same-window buffer)
@@ -219,7 +219,7 @@ ATTR attribute to instantiate in NIX-FILE."
(nix-shell--callback
(current-buffer)
- (nix-instantiate file attribute))
+ (nix-instantiate file attr t))
(eshell-mode)
buffer))
@@ -238,12 +238,10 @@ STRING the nix expression to use."
(defun nix-shell (file &optional attr)
"A nix-shell emulator in Emacs.
FILE the file to instantiate.
-ATTRIBUTE an attribute of the Nix file to use."
- (interactive
- (list
- (if nix-file nix-file "<nixpkgs>")
- (when (not nix-file)
- (if nix-attr nix-attr (nix-search-read-attr "<nixpkgs>")))))
+ATTR an attribute of the Nix file to use."
+ (interactive (list (nix-read-file) nil))
+ (unless attr (setq attr (nix-read-attr file)))
+
(nix-instantiate-async (apply-partially 'nix-shell--callback
(current-buffer))
file attr))
- [nongnu] elpa/nix-mode 1b3424ade0 190/500: Don't ignore errors when loading nix-format / nix-shebang, (continued)
- [nongnu] elpa/nix-mode 1b3424ade0 190/500: Don't ignore errors when loading nix-format / nix-shebang, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 93a59d9acb 179/500: Use cl-lib instead of cl., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7c732faf3a 183/500: Handle smartparens in nix-mode., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7716e6d1e4 208/500: fix (cond) usage, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 236318101e 217/500: Cleanup global-nix-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 857d963d1e 219/500: Add nix-system function, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 58325164ca 232/500: Update README.md, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 36070654c8 243/500: Don’t autoload nix-instantiate., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d2f4a629a8 258/500: Only show derivations in nix store, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d0eb92e97a 263/500: Package linting, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 38061187ca 265/500: Add nix-read-file & nix-read-attr,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 7d65288c72 266/500: Fix erroneous use of function as variable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8b3a9927e7 270/500: Add dependency on json-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7a7f600133 288/500: travis: Add travis badge, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode da16900326 293/500: tests: Add a testcase with broken identation to have as a check if it indents at all, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aa43b72a45 014/500: Revert "Use warning font lock for upper case vars", ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5a2674592f 033/500: Don't save-excursion for nix-indent-line., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 233bf03b96 040/500: Add nixfmt command., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ff550f9bbd 036/500: Add comments., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ea95e3c9c6 068/500: Add nix-prettify-mode.el., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6eaf2a97d2 069/500: Fixup hanging indent., ELPA Syncer, 2022/01/29