guix-ui-service-location.el 3.3 KB

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