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.

65 lines
1.8 KiB

5 years ago
  1. ;;; nix-search.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-instantiate)
  11. (require 'nix-shell)
  12. (require 'json)
  13. ;;;###autoload
  14. (defun nix-search (&optional search file)
  15. "Run nix search.
  16. SEARCH a search term to use.
  17. FILE a Nix expression to search in."
  18. (interactive)
  19. (unless search (setq search ""))
  20. (unless file (nix-read-file))
  21. (let ((stdout (generate-new-buffer "nix search"))
  22. result)
  23. (call-process nix-executable nil (list stdout nil) nil
  24. "search" "--json" "-f" file search)
  25. (with-current-buffer stdout
  26. (when (eq (buffer-size) 0)
  27. (error "Error: nix search %s failed to produce any output" search))
  28. (goto-char (point-min))
  29. (setq result (json-read)))
  30. (kill-buffer stdout)
  31. (when (called-interactively-p 'any)
  32. (let ((display (generate-new-buffer "*nix search*")))
  33. (with-current-buffer display
  34. (dolist (entry result)
  35. (widget-insert
  36. (format "attr: %s\nname: %s\nversion: %s\ndescription: %s\n\n"
  37. (car entry)
  38. (alist-get 'pkgName (cdr entry))
  39. (alist-get 'version (cdr entry))
  40. (alist-get 'description (cdr entry)))))
  41. )
  42. (display-buffer display 'display-buffer-pop-up-window)))
  43. (kill-buffer stdout)
  44. result))
  45. (defun nix-search-read-attr (file)
  46. "Read from a list of attributes.
  47. FILE the nix file to look in."
  48. (let ((collection
  49. (sort (mapcar (lambda (x) (symbol-name (car x)))
  50. (nix-search "" file))
  51. 'string<))
  52. (read (cond ((fboundp 'ivy-read) 'ivy-read)
  53. (t 'completing-read))))
  54. (funcall read "Attribute: " collection)))
  55. (provide 'nix-search)
  56. ;;; nix-search.el ends here