guix-read.el 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. ;;; guix-read.el --- Minibuffer readers
  2. ;; Copyright © 2015–2017 Alex Kost <alezost@gmail.com>
  3. ;; This file is part of Emacs-Guix.
  4. ;; Emacs-Guix is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;;
  9. ;; Emacs-Guix is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with Emacs-Guix. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This file provides functions to prompt a user for packages, system
  18. ;; types, hash formats and other guix related stuff.
  19. ;;; Code:
  20. (require 'guix-help-vars)
  21. (require 'guix-utils)
  22. (require 'guix-repl)
  23. ;;; Receivable lists of packages, lint checkers, etc.
  24. (guix-memoized-defun guix-graph-backend-names ()
  25. "Return a list of names of available graph backends."
  26. (guix-eval-read "(graph-backend-names)"))
  27. (guix-memoized-defun guix-graph-node-type-names ()
  28. "Return a list of names of available graph node types."
  29. (guix-eval-read "(graph-node-type-names)"))
  30. (guix-memoized-defun guix-refresh-updater-names ()
  31. "Return a list of names of available refresh updater types."
  32. (guix-eval-read "(refresh-updater-names)"))
  33. (guix-memoized-defun guix-lint-checker-names ()
  34. "Return a list of names of available lint checkers."
  35. (guix-eval-read "(lint-checker-names)"))
  36. (guix-memoized-defun guix-compressor-names ()
  37. "Return a list of names of available compressors."
  38. (guix-eval-read "(compressor-names)"))
  39. (guix-memoized-defun guix-pack-format-names ()
  40. "Return a list of names of available pack formats."
  41. (guix-eval-read "(pack-format-names)"))
  42. (guix-memoized-defun guix-package-names ()
  43. "Return a list of names of available packages."
  44. (sort (guix-eval-read "(package-names)")
  45. #'string<))
  46. (guix-memoized-defun guix-license-names ()
  47. "Return a list of names of available licenses."
  48. (guix-eval-read "(license-names)"))
  49. (guix-memoized-defun guix-package-locations ()
  50. "Return a list of available package locations."
  51. (sort (guix-eval-read "(package-location-files)")
  52. #'string<))
  53. ;;; Readers
  54. (defcustom guix-read-package-name-function #'guix-read-package-name-default
  55. "Function used to read a package name from minibuffer.
  56. The function is called with 2 strings as arguments: a prompt and
  57. initial-contents."
  58. :type '(choice (function-item guix-read-package-name-default)
  59. (function-item guix-read-package-name-at-point)
  60. (function :tag "Other function"))
  61. :group 'guix)
  62. (defun guix-read-package-name-at-point (&optional prompt initial-contents)
  63. "Read symbol at point and if it is a package name, return it.
  64. If it is not a package name or if current command has a prefix
  65. argument, read the name from minibuffer."
  66. (if current-prefix-arg
  67. (guix-read-package-name-default prompt initial-contents)
  68. (let* ((at-point (thing-at-point 'symbol))
  69. (name (and at-point
  70. (substring-no-properties at-point))))
  71. (if (and name
  72. (member name (guix-package-names)))
  73. name
  74. (guix-read-package-name-default prompt
  75. initial-contents)))))
  76. (defun guix-read-package-name (&optional prompt initial-contents)
  77. "Read a package name using `guix-read-package-name-function'."
  78. (funcall guix-read-package-name-function
  79. prompt initial-contents))
  80. (guix-define-readers
  81. :completions-var guix-help-system-types
  82. :single-reader guix-read-system-type
  83. :single-prompt "System type: ")
  84. (guix-define-readers
  85. :completions-var guix-help-source-types
  86. :single-reader guix-read-source-type
  87. :single-prompt "Source type: ")
  88. (guix-define-readers
  89. :completions-var guix-help-hash-formats
  90. :default guix-default-hash-format
  91. :single-reader guix-read-hash-format
  92. :single-prompt "Hash format: ")
  93. (guix-define-readers
  94. :completions-var guix-help-refresh-subsets
  95. :single-reader guix-read-refresh-subset
  96. :single-prompt "Refresh subset: ")
  97. (guix-define-readers
  98. :completions-getter guix-refresh-updater-names
  99. :multiple-reader guix-read-refresh-updater-names
  100. :multiple-prompt "Refresh updater,s: "
  101. :multiple-separator ",")
  102. (guix-define-readers
  103. :completions-var guix-help-key-policies
  104. :default guix-default-key-policy
  105. :single-reader guix-read-key-policy
  106. :single-prompt "Key policy: ")
  107. (guix-define-readers
  108. :completions-var guix-help-elpa-archives
  109. :default guix-default-elpa-archive
  110. :single-reader guix-read-elpa-archive
  111. :single-prompt "ELPA archive: ")
  112. (guix-define-readers
  113. :completions-var guix-help-verify-options
  114. :multiple-reader guix-read-verify-options
  115. :multiple-prompt "Verify option,s: "
  116. :multiple-separator ",")
  117. (guix-define-readers
  118. :completions-var guix-help-size-sort-keys
  119. :default guix-default-size-sort-key
  120. :single-reader guix-read-size-sort-key
  121. :single-prompt "Sort key: ")
  122. (guix-define-readers
  123. :completions-var guix-help-search-paths-types
  124. :default guix-default-search-paths-type
  125. :single-reader guix-read-search-paths-type
  126. :single-prompt "Search paths type: ")
  127. (guix-define-readers
  128. :completions-getter guix-graph-backend-names
  129. :default guix-default-graph-backend
  130. :single-reader guix-read-graph-backend
  131. :single-prompt "Graph backend: ")
  132. (guix-define-readers
  133. :completions-getter guix-graph-node-type-names
  134. :default guix-default-graph-node-type
  135. :single-reader guix-read-graph-node-type
  136. :single-prompt "Graph node type: ")
  137. (guix-define-readers
  138. :completions-getter guix-lint-checker-names
  139. :multiple-reader guix-read-lint-checker-names
  140. :multiple-prompt "Linter,s: "
  141. :multiple-separator ",")
  142. (guix-define-readers
  143. :completions-getter guix-compressor-names
  144. :single-reader guix-read-compressor-name
  145. :single-prompt "Compressor: ")
  146. (guix-define-readers
  147. :completions-getter guix-pack-format-names
  148. :single-reader guix-read-pack-format-name
  149. :single-prompt "Pack format: ")
  150. (guix-define-readers
  151. :completions-getter guix-package-names
  152. :require-match nil
  153. :single-reader guix-read-package-name-default
  154. :single-prompt "Package: "
  155. :multiple-reader guix-read-package-names
  156. :multiple-prompt "Package,s: "
  157. :multiple-separator " ")
  158. (guix-define-readers
  159. :completions-getter guix-license-names
  160. :single-reader guix-read-license-name
  161. :single-prompt "License: ")
  162. (guix-define-readers
  163. :completions-getter guix-package-locations
  164. :single-reader guix-read-package-location
  165. :single-prompt "Location: ")
  166. (provide 'guix-read)
  167. ;;; guix-read.el ends here