[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode d27820b040 442/500: Merge pull request #131 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode d27820b040 442/500: Merge pull request #131 from nagy/nix-process-refactor |
Date: |
Sat, 29 Jan 2022 08:27:54 -0500 (EST) |
branch: elpa/nix-mode
commit d27820b0408b3e9067c264e25c009bd5cd9dfcd1
Merge: 1b1b9fb61d b4b7518231
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #131 from nagy/nix-process-refactor
Refactor process calling
---
flake.nix | 1 +
nix-instantiate.el | 15 ++-------------
nix-mode.el | 8 +++-----
nix-search.el | 12 ++++--------
nix.el | 47 ++++++++++++++++++++++++++++++++++-------------
5 files changed, 44 insertions(+), 39 deletions(-)
diff --git a/flake.nix b/flake.nix
index 8c16c7ddfa..cc5199796c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -13,6 +13,7 @@
org-plus-contrib
company
mmm-mode
+ f
]);
in stdenvNoCC.mkDerivation {
name = "nix-mode-1.4.5";
diff --git a/nix-instantiate.el b/nix-instantiate.el
index 9f047d2170..e7230ed0f1 100644
--- a/nix-instantiate.el
+++ b/nix-instantiate.el
@@ -17,19 +17,8 @@
(defun nix-instantiate--parsed (drv)
"Get the parsed version of the .drv file.
DRV file to load from."
- (let ((stdout (generate-new-buffer "nix show-derivation"))
- result)
- (call-process nix-executable nil (list stdout nil) nil
- "show-derivation" drv)
- (setq result
- (cdar (with-current-buffer stdout
- (when (eq (buffer-size) 0)
- (error "Nix’s show-derivation %s failed to produce any
output"
- drv))
- (goto-char (point-min))
- (json-read))))
- (kill-buffer stdout)
- result))
+ (cdar
+ (nix--process-json "show-derivation" drv)))
(defun nix-instantiate (nix-file &optional attribute parse)
"Run nix-instantiate on a Nix expression.
diff --git a/nix-mode.el b/nix-mode.el
index 0c1c0596f6..1d79abea5d 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -913,11 +913,9 @@ location of STR. If `nix-instantiate' has a nonzero exit
code,
don’t do anything"
(when (and (string-match nix-re-bracket-path str)
(executable-find nix-instantiate-executable))
- (with-temp-buffer
- (when (eq (call-process nix-instantiate-executable nil (current-buffer)
- nil "--eval" "-E" str) 0)
- ;; Remove trailing newline
- (substring (buffer-string) 0 (- (buffer-size) 1))))))
+ (let ((nix-executable nix-instantiate-executable))
+ (ignore-errors
+ (nix--process-string "--eval" "-E" str)))))
;; Key maps
diff --git a/nix-search.el b/nix-search.el
index 38116bf678..beaebb111e 100644
--- a/nix-search.el
+++ b/nix-search.el
@@ -18,14 +18,10 @@
;;;###autoload
(defun nix-search--search (search file &optional no-cache use-flakes)
- (with-temp-buffer
- (if use-flakes
- (call-process nix-executable nil (list t nil) nil
- "search" "--json" file (if (string= search "") "."
search))
- (call-process nix-executable nil (list t nil) nil
- "search" "--json" (if no-cache "--no-cache" "") "--file"
file search))
- (goto-char (point-min))
- (json-read)))
+ (nix--process-json-nocheck "search" "--json"
+ (if use-flakes "" "--file") file
+ (if no-cache "--no-cache" "")
+ search))
(defface nix-search-pname
'((t :height 1.5
diff --git a/nix.el b/nix.el
index 35735abaef..48f802c005 100644
--- a/nix.el
+++ b/nix.el
@@ -18,6 +18,7 @@
(require 'pcomplete)
(require 'json)
+(require 'f)
(defgroup nix nil
"Nix-related customizations"
@@ -60,26 +61,20 @@
(defun nix-system ()
"Get the current system tuple."
- (with-temp-buffer
- (if (nix-is-24)
- (call-process nix-executable nil (list t nil) nil "eval" "--impure"
"--raw" "--expr" "(builtins.currentSystem)")
- (call-process nix-executable nil (list t nil) nil "eval" "--raw"
"(builtins.currentSystem)"))
- (buffer-string)))
+ (nix--process-string "eval"
+ "--raw"
+ (if (nix-is-24) "--impure" )
+ (if (nix-is-24) "--expr" )
+ "(builtins.currentSystem)"))
(defvar nix-version nil)
(defun nix-version ()
"Get the version of Nix"
- (or nix-version
- (with-temp-buffer
- (call-process nix-executable nil (list t nil) nil "--version")
- (buffer-string))))
+ (or nix-version (nix--process-string "--version")))
(defun nix-show-config ()
"Show nix config."
- (with-temp-buffer
- (call-process nix-executable nil (list t nil) nil "show-config" "--json")
- (goto-char (point-min))
- (json-read)))
+ (nix--process-json "show-config" "--json"))
(defvar nix-commands
'("add-to-store"
@@ -331,5 +326,31 @@ OPTIONS a list of options to accept."
(_ (nix--pcomplete-flags nix-toplevel-options)))
(pcomplete-here (pcomplete-entries)))))
+(defun nix--process (&rest args)
+ (with-temp-buffer
+ (let* ((tmpfile (make-temp-file "nix--process-stderr"))
+ (cleaned-args (seq-filter #'stringp args))
+ (exitcode (apply #'call-process `(,nix-executable nil (t ,tmpfile) nil
,@cleaned-args )))
+ (stderr (f-read-text tmpfile)))
+ (delete-file tmpfile)
+ (list (buffer-string) stderr exitcode))))
+
+(defun nix--process-string (&rest args)
+ (cl-multiple-value-bind (stdout stderr exitcode) (apply #'nix--process args)
+ (if (not (eq exitcode 0))
+ (error stderr))
+ ;; cut-off the trailing newline
+ (string-trim-right stdout)))
+
+(defun nix--process-json (&rest args)
+ (json-read-from-string
+ (apply #'nix--process-string args)))
+
+(defun nix--process-json-nocheck (&rest args)
+ ;; No checking of exitcode is possible here until
+ ;; https://github.com/NixOS/nix/issues/2474 is resolved
+ (let ((result (apply #'nix--process args)))
+ (json-read-from-string (car result))))
+
(provide 'nix)
;;; nix.el ends here
- [nongnu] elpa/nix-mode c08ae1cdfe 049/500: Add limit arg to looking-back., (continued)
- [nongnu] elpa/nix-mode c08ae1cdfe 049/500: Add limit arg to looking-back., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 504285ce39 138/500: Remove nix-buffer, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c06222659c 185/500: Don’t enable mmm-mode automatically, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 858d127fb5 259/500: Add custom for directory location, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6445ebfad6 285/500: Merge pull request #63 from etu/ert-indent-testing, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 54ef833100 294/500: Merge pull request #68 from etu/fix-recent-regressions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e8921b8a78 295/500: Prioritize closing } over regular indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 80a1e96c71 296/500: Merge branch 'grahamc-fix-issue-69', ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 53ea839a52 418/500: Replace javascript-mode with js-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aae6f710e0 404/500: Address review comments, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d27820b040 442/500: Merge pull request #131 from nagy/nix-process-refactor,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 5f44621864 474/500: nix-flake: Make the argument bindings more predictable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a18a226ce9 123/500: Add nix-mode tests., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9e59bcf59e 216/500: Fix read only .drv file issue, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8ab089b251 230/500: Set nix-shell-attribute, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 84ee98019f 271/500: Skip over comments in indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a30e88362a 290/500: Remove line that caused tests to not indent at all in the tests, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 82399e6bc3 305/500: Add missing check for '?' when lexing forward., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ec19a472ec 318/500: Update documentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 75b907c767 328/500: Improve indentation of function bodies., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 78c3832e48 333/500: Make smie-setup optional, ELPA Syncer, 2022/01/29