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

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

[nongnu] elpa/nix-mode 295cd6729b 261/500: Add nix-edit.el


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 295cd6729b 261/500: Add nix-edit.el
Date: Sat, 29 Jan 2022 08:27:12 -0500 (EST)

branch: elpa/nix-mode
commit 295cd6729b16797b0e1a133943a70fbe6f7254c4
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>

    Add nix-edit.el
---
 nix-edit.el | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/nix-edit.el b/nix-edit.el
new file mode 100644
index 0000000000..3e5c255f34
--- /dev/null
+++ b/nix-edit.el
@@ -0,0 +1,37 @@
+;;; nix-edit.el -- run nix commands in Emacs -*- lexical-binding: t -*-
+
+;; Author: Matthew Bauer <mjbauer95@gmail.com>
+;; Homepage: https://github.com/NixOS/nix-mode
+;; Keywords: nix
+
+;; This file is NOT part of GNU Emacs.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'nix)
+(require 'nix-search)
+
+(defun nix-edit (&optional file attr)
+  "Open the nix log.
+FILE the nix file to load from.
+ATTR the attribute to find in nix expressions."
+  (interactive (list (nix-read-file) nil))
+  (unless attr (setq attr (nix-read-attr file)))
+
+  (let ((stdout (generate-new-buffer "nix-edit"))
+        (process-environment (cons "EDITOR=echo" process-environment))
+       result)
+    (call-process nix-executable nil (list stdout nil) nil
+                 "edit" "-f" file attr)
+    (with-current-buffer stdout
+      (when (eq (buffer-size) 0)
+       (error
+        "Error: nix edit failed to produce any output"))
+      (setq result (substring (buffer-string) 0 (- (buffer-size) 1))))
+    (kill-buffer stdout)
+    (find-file result)))
+
+(provide 'nix-edit)
+;;; nix-edit.el ends here



reply via email to

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