guix-ui-location.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; guix-ui-location.el --- Interface for displaying package locations -*- lexical-binding: t -*-
  2. ;; Copyright © 2016–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 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 location)
  26. (defun guix-location-get-entries ()
  27. "Receive 'package location' entries."
  28. (guix-eval-read "(package-location-sexps)"))
  29. ;;; Location 'list'
  30. (bui-define-interface guix-location list
  31. :mode-name "Location-List"
  32. :buffer-name "*Guix Package Locations*"
  33. :get-entries-function 'guix-location-get-entries
  34. :format '((location guix-location-list-file-name-specification 50 t)
  35. (number-of-packages nil 10 bui-list-sort-numerically-1
  36. :right-align t))
  37. :hint 'guix-location-list-hint
  38. :sort-key '(location))
  39. (let ((map guix-location-list-mode-map))
  40. (define-key map (kbd "RET") 'guix-location-list-show-packages)
  41. (define-key map (kbd "P") 'guix-location-list-show-packages)
  42. (define-key map (kbd "e") 'guix-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-location-list-default-hint
  47. '(("\\[guix-location-list-show-packages]") " show packages;\n"
  48. ("\\[guix-location-list-edit]") " edit (go to) the location file;\n"))
  49. (defun guix-location-list-hint ()
  50. (bui-format-hints
  51. guix-location-list-default-hint
  52. bui-list-sort-hint
  53. bui-common-hint))
  54. (defun guix-location-list-file-name-specification (location &optional _)
  55. "Return LOCATION button specification for `tabulated-list-entries'."
  56. (bui-get-non-nil location
  57. (list location
  58. :type 'bui-file
  59. 'action (lambda (btn)
  60. (guix-find-location (button-get btn 'location)))
  61. 'help-echo (concat "Find location: " location)
  62. 'location location)))
  63. (defun guix-location-list-edit ()
  64. "Go to the package location file at point."
  65. (interactive)
  66. (guix-find-location (bui-list-current-id)))
  67. (declare-function guix-packages-by-location "guix-ui-package" t)
  68. (defun guix-location-list-show-packages ()
  69. "Display packages placed in the location at point."
  70. (interactive)
  71. (guix-packages-by-location (bui-list-current-id)))
  72. ;;; Interactive commands
  73. (defun guix-locations-show ()
  74. "Display locations of the Guix packages.
  75. Unlike `guix-locations', this command always recreates
  76. `guix-location-list-buffer-name' buffer."
  77. (interactive)
  78. (bui-list-get-display-entries 'guix-location))
  79. ;;;###autoload
  80. (defun guix-locations ()
  81. "Display locations of the Guix packages.
  82. Switch to the `guix-location-list-buffer-name' buffer if it
  83. already exists."
  84. (interactive)
  85. (guix-switch-to-buffer-or-funcall
  86. guix-location-list-buffer-name #'guix-locations-show 'message))
  87. (provide 'guix-ui-location)
  88. ;;; guix-ui-location.el ends here