-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
nix-edit.el
38 lines (30 loc) · 1.01 KB
/
nix-edit.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
;;; nix-edit.el --- Run nix commands -*- 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)
;;;###autoload
(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 (zerop (buffer-size))
(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