guix-popup.el 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ;;; guix-popup.el --- Popup interface for Emacs-Guix commands
  2. ;; Copyright © 2018–2019, 2021 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 popup interface (using `magit-popup' library) for
  18. ;; Emacs-Guix commands.
  19. ;;; Code:
  20. (require 'magit-popup)
  21. (require 'guix-profiles)
  22. (defgroup guix-popup nil
  23. "Popup interface for Emacs-Guix commands."
  24. :group 'guix)
  25. ;;;###autoload (autoload 'guix-popup "guix-popup" nil t)
  26. (magit-define-popup guix-popup
  27. "Show popup buffer for Emacs-Guix commands."
  28. 'guix-popup
  29. :actions '("Sub-popups"
  30. (?p "packages" guix-package-popup)
  31. (?P "profiles" guix-profile-popup)
  32. (?s "services" guix-service-popup)
  33. (?y "system commands" guix-system-popup)
  34. (?l "package licenses" guix-license-popup)
  35. (?S "store" guix-store-popup)
  36. (?m "major/minor modes" guix-mode-popup)
  37. (?c "guix shell commands" guix-command)
  38. "Miscellaneous commands"
  39. (?H "calculate file hash" guix-hash)
  40. (?E "set Emacs environment" guix-set-emacs-environment)
  41. "Auxiliary commands"
  42. (?a "about" guix-about)
  43. (?h "help (\"refcard\")" guix-help)
  44. (?i "info manual" guix-info)
  45. (?v "version" guix-version)
  46. (?b "switch to buffer" guix-switch-to-buffer)
  47. (?B "report guix bug" guix-report-bug))
  48. :max-action-columns #'guix-popup-max-columns)
  49. (defun guix-popup-max-columns (heading)
  50. "Return the number of `:max-action-columns' for HEADING.
  51. This function is used by command `guix-popup'."
  52. (pcase heading
  53. ("Sub-popups" 1)
  54. ("Miscellaneous commands" 1)
  55. (_ 2)))
  56. ;;;###autoload
  57. (defalias 'guix #'guix-popup
  58. "Popup interface for Emacs-Guix commands.")
  59. (defun guix-popup-variable-value (var-name)
  60. "Return string formatted for popup buffer.
  61. String is made of variable VAR-NAME and its value."
  62. (concat (propertize (symbol-name var-name)
  63. 'face font-lock-variable-name-face)
  64. " "
  65. (propertize (prin1-to-string (symbol-value var-name))
  66. 'face 'magit-popup-option-value)))
  67. (defun guix-popup-format-profile ()
  68. "Return profile, formatted for '\\[guix-popup]'."
  69. (guix-popup-variable-value 'guix-current-profile))
  70. (defvar guix-popup-profile-variable
  71. '(?p "profile"
  72. guix-set-current-profile
  73. guix-popup-format-profile)
  74. "Popup structure for variable `guix-current-profile'.")
  75. ;;; Sub-popups
  76. (magit-define-popup guix-package-popup
  77. "Show popup buffer for package commands."
  78. 'guix-package-popup
  79. :variables (list guix-popup-profile-variable)
  80. :actions '("Show packages"
  81. (?a "all" guix-all-packages)
  82. (?i "installed" guix-installed-packages)
  83. (?o "obsolete" guix-obsolete-packages)
  84. (?s "superseded" guix-superseded-packages)
  85. (?h "hidden" guix-hidden-packages)
  86. "Search for packages"
  87. (?n "by name" guix-packages-by-name)
  88. (?N "by regexp (in name only)" guix-packages-by-name-regexp)
  89. (?r "by regexp (in name, synopsis, description)"
  90. guix-packages-by-regexp)
  91. (?L "by location" guix-packages-by-location)
  92. (?c "by license" guix-packages-by-license)
  93. (?d "depending on other package(s)" guix-dependent-packages)
  94. (?f "packages from file" guix-package-from-file)
  95. (?y "packages from system config file"
  96. guix-packages-from-system-config-file)
  97. "Package locations"
  98. (?l "show package locations" guix-package-locations)
  99. (?e "\"edit\" package (find package definition)"
  100. guix-find-package-definition)
  101. (?F "find location file" guix-find-package-location-file)
  102. "Other commands"
  103. (?g "package graph" guix-package-graph)
  104. (?z "package size" guix-package-size)
  105. (?t "package lint" guix-package-lint)
  106. (?C "lint checkers" guix-lint-checkers)
  107. (?T "total number of packages" guix-number-of-packages))
  108. :max-action-columns #'guix-package-popup-max-columns)
  109. (defun guix-package-popup-max-columns (heading)
  110. "Return the number of `:max-action-columns' for HEADING.
  111. This function is used by command `guix-package-popup'."
  112. (pcase heading
  113. ("Show packages" 2)
  114. ("Other commands" 2)
  115. (_ 1)))
  116. (magit-define-popup guix-profile-popup
  117. "Show popup buffer for profiles and generations commands."
  118. 'guix-profile-popup
  119. :variables (list guix-popup-profile-variable)
  120. :actions '("Show profiles"
  121. (?a "all" guix-profiles)
  122. (?s "system" guix-system-profile)
  123. (?c "current" guix-current-profile)
  124. "Show generations (of the current profile)"
  125. (?g "all" guix-generations)
  126. (?t "by time" guix-generations-by-time)
  127. (?l "last" guix-last-generations)
  128. "Other commands"
  129. (?M "apply manifest to the current profile"
  130. guix-apply-manifest))
  131. :max-action-columns 1)
  132. (magit-define-popup guix-service-popup
  133. "Show popup buffer for service commands."
  134. 'guix-service-popup
  135. :actions '("Show services"
  136. (?a "all" guix-all-services)
  137. (?d "default" guix-default-services)
  138. (?n "by name" guix-services-by-name)
  139. (?r "by regexp" guix-services-by-regexp)
  140. (?L "by location" guix-services-by-location)
  141. (?y "services from system config file"
  142. guix-services-from-system-config-file)
  143. "Service locations"
  144. (?l "show service locations" guix-service-locations)
  145. (?e "\"edit\" service (find service definition)"
  146. guix-find-service-definition)
  147. (?F "find location file" guix-find-service-location-file))
  148. :max-action-columns 1)
  149. (magit-define-popup guix-system-popup
  150. "Show popup buffer for system commands."
  151. 'guix-system-popup
  152. :actions '("From system profile"
  153. (?p "packages" guix-installed-system-packages)
  154. (?P "profile" guix-system-profile)
  155. (?g "all generations" guix-system-generations)
  156. (?t "generations by time" guix-system-generations-by-time)
  157. (?l "last generations" guix-last-system-generations)
  158. "From system configuration file"
  159. (?y "system" guix-system-from-file)
  160. (?k "packages" guix-packages-from-system-config-file)
  161. (?s "services" guix-services-from-system-config-file))
  162. :max-action-columns 1)
  163. (magit-define-popup guix-license-popup
  164. "Show popup buffer for license commands."
  165. 'guix-license-popup
  166. :actions '((?a "show all package licenses" guix-licenses)
  167. (?u "browse license URL" guix-browse-license-url)
  168. (?e "\"edit\" license (find license definition)"
  169. guix-find-license-definition)
  170. (?F "find license location file"
  171. guix-find-license-location-file))
  172. :max-action-columns 1)
  173. (magit-define-popup guix-store-popup
  174. "Show popup buffer for store commands."
  175. 'guix-store-popup
  176. :actions '("Show store items"
  177. (?l "live items" guix-store-live-items)
  178. (?d "dead items" guix-store-dead-items)
  179. (?e "failures" guix-store-failures)
  180. (?i "single item" guix-store-item)
  181. (?D "derivers" guix-store-item-derivers)
  182. (?R "requisites" guix-store-item-requisites)
  183. (?f "referrers" guix-store-item-referrers)
  184. (?F "references" guix-store-item-references))
  185. :max-action-columns 2)
  186. (magit-define-popup guix-mode-popup
  187. "Show popup buffer for Emacs-Guix major/minor modes."
  188. 'guix-mode-popup
  189. :actions '("Modes"
  190. (?p "guix-prettify-mode" guix-prettify-mode)
  191. (?P "global-guix-prettify-mode" global-guix-prettify-mode)
  192. (?b "guix-build-log-minor-mode" guix-build-log-minor-mode)
  193. (?B "guix-build-log-mode" guix-build-log-mode)
  194. (?d "guix-devel-mode" guix-devel-mode)
  195. (?D "guix-derivation-mode" guix-derivation-mode)
  196. (?e "guix-env-var-mode" guix-env-var-mode))
  197. :max-action-columns 1)
  198. (provide 'guix-popup)
  199. ;;; guix-popup.el ends here