-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
nix-drv-mode.el
49 lines (36 loc) · 1.35 KB
/
nix-drv-mode.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
39
40
41
42
43
44
45
46
47
48
49
;;; nix-drv-mode.el --- Major mode for viewing .drv files -*- lexical-binding: t -*-
;; Maintainer: Matthew Bauer <[email protected]>
;; Homepage: https://github.com/NixOS/nix-mode
;; Keywords: nix, languages, tools, unix
;; 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 'js)
(require 'nix)
;;;###autoload
(define-derived-mode nix-drv-mode js-mode "Nix-Derivation"
"Pretty print Nix’s .drv files."
(let ((inhibit-read-only t))
(erase-buffer)
(insert (shell-command-to-string
(format "%s show-derivation \"%s\""
nix-executable
(buffer-file-name))))
(set-buffer-modified-p nil)
(read-only-mode 1))
(add-hook 'change-major-mode-hook #'nix-drv-mode-dejsonify-buffer nil t))
(defun nix-drv-mode-dejsonify-buffer ()
"Restore nix-drv-mode when switching to another mode."
(remove-hook 'change-major-mode-hook #'nix-drv-mode-dejsonify-buffer t)
(let ((inhibit-read-only t))
(erase-buffer)
(insert-file-contents (buffer-file-name))
(set-buffer-modified-p nil)
(read-only-mode nil)))
;;;###autoload
(add-to-list 'auto-mode-alist '("^/nix/store/.+\\.drv\\'" . nix-drv-mode))
(provide 'nix-drv-mode)
;;; nix-drv-mode.el ends here