about summary refs log tree commit diff
path: root/configs/shared/emacs/.emacs.d/elpa/nix-mode-20180908.2240/nix-drv-mode.el
blob: b9e184270f179d600ac956eb481ebfc6b9890054 (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
;;; nix-drv-mode.el --- Major mode for viewing .drv files

;; Maintainer: Matthew Bauer <mjbauer95@gmail.com>
;; Homepage: https://github.com/NixOS/nix-mode
;; Version: 1.2.1
;; Keywords: nix, languages, tools, unix
;; Package-Requires: ((emacs "24.3"))

;; This file is NOT part of GNU Emacs.

;;; Commentary:

;; A major mode for viewing Nix derivations (.drv files). See the Nix
;; manual for more information available at
;; https://nixos.org/nix/manual/.

;;; Code:

(require 'json-mode)
(require 'nix)

(defvar-local nix-drv-mode nil)

;;;###autoload
(defun nix-drv-mode ()
  "Pretty print Nix’s .drv files."
  (interactive)
  (when (string-match (format "^%s/" nix-store-dir) (buffer-file-name))
    (if nix-drv-mode
        (progn
          (erase-buffer)
          (insert-file-contents (buffer-file-name))
          (setq nix-drv-mode nil)
          (set-buffer-modified-p nil)
          (read-only-mode nil))
      (let ((inhibit-read-only t))
        (setq nix-drv-mode t)
        (erase-buffer)
        (insert (shell-command-to-string
                 (format "%s show-derivation \"%s\""
		         nix-executable
		         (buffer-file-name))))
        (json-mode)
        (set-buffer-modified-p nil)
        (read-only-mode 1)))))

(provide 'nix-drv-mode)
;;; nix-drv-mode.el ends here