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.

38 lines
1.0 KiB

5 years ago
  1. ;;; nix-edit.el -- run nix commands in Emacs -*- lexical-binding: t -*-
  2. ;; Author: Matthew Bauer <mjbauer95@gmail.com>
  3. ;; Homepage: https://github.com/NixOS/nix-mode
  4. ;; Keywords: nix
  5. ;; Version: 1.4.0
  6. ;; This file is NOT part of GNU Emacs.
  7. ;;; Commentary:
  8. ;;; Code:
  9. (require 'nix)
  10. (require 'nix-search)
  11. (defun nix-edit (&optional file attr)
  12. "Open the nix log.
  13. FILE the nix file to load from.
  14. ATTR the attribute to find in nix expressions."
  15. (interactive (list (nix-read-file) nil))
  16. (unless attr (setq attr (nix-read-attr file)))
  17. (let ((stdout (generate-new-buffer "nix-edit"))
  18. (process-environment (cons "EDITOR=echo" process-environment))
  19. result)
  20. (call-process nix-executable nil (list stdout nil) nil
  21. "edit" "-f" file attr)
  22. (with-current-buffer stdout
  23. (when (eq (buffer-size) 0)
  24. (error
  25. "Error: nix edit failed to produce any output"))
  26. (setq result (substring (buffer-string) 0 (- (buffer-size) 1))))
  27. (kill-buffer stdout)
  28. (find-file result)))
  29. (provide 'nix-edit)
  30. ;;; nix-edit.el ends here