guix-ui-package-location.el 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ;;; guix-ui-package-location.el --- Interface for displaying package locations -*- lexical-binding: t -*-
  2. ;; Copyright © 2016–2018 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 a 'list' interface for displaying locations of Guix
  18. ;; packages.
  19. ;;; Code:
  20. (require 'bui)
  21. (require 'guix nil t)
  22. (require 'guix-location)
  23. (require 'guix-repl)
  24. (require 'guix-utils)
  25. (guix-define-groups package-location)
  26. (defun guix-package-location-get-entries ()
  27. "Receive 'package location' entries."
  28. (guix-eval-read "(package-location-sexps)"))
  29. ;;; Location 'list'
  30. (bui-define-interface guix-package-location list
  31. :mode-name "Location-List"
  32. :buffer-name "*Guix Package Locations*"
  33. :get-entries-function 'guix-package-location-get-entries
  34. :format '((location guix-location-list-specification 50 t)
  35. (number-of-packages nil 10 bui-list-sort-numerically-1
  36. :right-align t))
  37. :hint 'guix-package-location-list-hint
  38. :sort-key '(location))
  39. (let ((map guix-package-location-list-mode-map))
  40. (define-key map (kbd "RET") 'guix-package-location-list-show-packages)
  41. (define-key map (kbd "P") 'guix-package-location-list-show-packages)
  42. (define-key map (kbd "e") 'guix-package-location-list-edit)
  43. ;; "Location Info" buffer is not defined (it would be useless), so
  44. ;; unbind "i" key (by default, it is used to display Info buffer).
  45. (define-key map (kbd "i") nil))
  46. (defvar guix-package-location-list-default-hint
  47. '(("\\[guix-package-location-list-show-packages]") " show packages;\n"
  48. ("\\[guix-package-location-list-edit]")
  49. " edit (go to) the location file;\n"))
  50. (defun guix-package-location-list-hint ()
  51. (bui-format-hints
  52. guix-package-location-list-default-hint
  53. bui-list-sort-hint
  54. bui-common-hint))
  55. (defun guix-package-location-list-edit ()
  56. "Go to the package location file at point."
  57. (interactive)
  58. (guix-find-location (bui-list-current-id)))
  59. (declare-function guix-packages-by-location "guix-ui-package" t)
  60. (defun guix-package-location-list-show-packages ()
  61. "Display packages placed in the location at point."
  62. (interactive)
  63. (guix-packages-by-location (bui-list-current-id)))
  64. ;;; Interactive commands
  65. (defun guix-package-locations-show ()
  66. "Display locations of the Guix packages.
  67. Unlike `guix-package-locations', this command always recreates
  68. `guix-package-location-list-buffer-name' buffer."
  69. (interactive)
  70. (bui-list-get-display-entries 'guix-package-location))
  71. ;;;###autoload
  72. (defun guix-package-locations ()
  73. "Display locations of the Guix packages.
  74. Switch to the `guix-package-location-list-buffer-name' buffer if
  75. it already exists."
  76. (interactive)
  77. (guix-switch-to-buffer-or-funcall
  78. guix-package-location-list-buffer-name
  79. #'guix-package-locations-show 'message))
  80. ;;;###autoload
  81. (define-obsolete-function-alias 'guix-locations
  82. 'guix-package-locations "0.4")
  83. (provide 'guix-ui-package-location)
  84. ;;; guix-ui-package-location.el ends here