Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 line
1.3 KiB

5 年之前
  1. ;;; nix-drv-mode.el --- Major mode for viewing .drv files
  2. ;; Maintainer: Matthew Bauer <mjbauer95@gmail.com>
  3. ;; Homepage: https://github.com/NixOS/nix-mode
  4. ;; Version: 1.2.1
  5. ;; Keywords: nix, languages, tools, unix
  6. ;; Package-Requires: ((emacs "24.3") (json-mode "1.6.0"))
  7. ;; This file is NOT part of GNU Emacs.
  8. ;;; Commentary:
  9. ;; A major mode for viewing Nix derivations (.drv files). See the Nix
  10. ;; manual for more information available at
  11. ;; https://nixos.org/nix/manual/.
  12. ;;; Code:
  13. (require 'json-mode)
  14. (require 'nix)
  15. (defvar-local nix-drv-mode nil)
  16. ;;;###autoload
  17. (defun nix-drv-mode ()
  18. "Pretty print Nix’s .drv files."
  19. (interactive)
  20. (when (string-match (format "^%s/" nix-store-dir) (buffer-file-name))
  21. (if nix-drv-mode
  22. (progn
  23. (erase-buffer)
  24. (insert-file-contents (buffer-file-name))
  25. (setq nix-drv-mode nil)
  26. (set-buffer-modified-p nil)
  27. (read-only-mode nil))
  28. (let ((inhibit-read-only t))
  29. (setq nix-drv-mode t)
  30. (erase-buffer)
  31. (insert (shell-command-to-string
  32. (format "%s show-derivation \"%s\""
  33. nix-executable
  34. (buffer-file-name))))
  35. (json-mode)
  36. (set-buffer-modified-p nil)
  37. (read-only-mode 1)))))
  38. (provide 'nix-drv-mode)
  39. ;;; nix-drv-mode.el ends here