guix-ui-lint-checker.el 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ;;; guix-ui-lint-checker.el --- Interface for displaying package lint checkers -*- lexical-binding: t -*-
  2. ;; Copyright © 2019 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 interface to display lint checkers of Guix
  18. ;; packages.
  19. ;;; Code:
  20. (require 'bui)
  21. (require 'guix nil t)
  22. (require 'guix-repl)
  23. (require 'guix-repl)
  24. (require 'guix-guile)
  25. (require 'guix-utils)
  26. (require 'guix-read)
  27. (require 'guix-package)
  28. (guix-define-groups lint-checker)
  29. (bui-define-entry-type guix-lint-checker
  30. :message-function 'guix-lint-checker-message)
  31. (defun guix-lint-checker-get-entries (search-type &rest args)
  32. "Receive 'lint-checker' entries.
  33. SEARCH-TYPE may be one of the following symbols: `all', `local',
  34. `id', `name'."
  35. (guix-eval-read
  36. (apply #'guix-make-guile-expression
  37. 'lint-checker-sexps search-type args)))
  38. (defun guix-lint-checker-get-display (search-type &rest args)
  39. "Search for lint checkers and show results."
  40. (apply #'bui-list-get-display-entries
  41. 'guix-lint-checker search-type args))
  42. (defun guix-lint-checker-message (entries search-type &rest args)
  43. "Display a message after showing lint-checker ENTRIES."
  44. (when (null entries)
  45. (cond
  46. ((memq search-type '(all local))
  47. (message "Oops, lint checkers are not found for some reason."))
  48. ((memq search-type '(id name))
  49. (message "Lint checker '%s' not found." (car args))))))
  50. ;;; Lint-Checker 'list'
  51. (bui-define-interface guix-lint-checker list
  52. :mode-name "Lint-Checker-List"
  53. :buffer-name "*Guix Lint Checkers*"
  54. :get-entries-function 'guix-lint-checker-get-entries
  55. :describe-function 'guix-lint-checker-list-describe
  56. :format '((name nil 30 t)
  57. (type nil 10 t)
  58. (description nil 50 t))
  59. :hint 'guix-lint-checker-list-hint)
  60. (let ((map guix-lint-checker-list-mode-map))
  61. (define-key map (kbd "i") nil)
  62. (define-key map (kbd "RET") nil)
  63. (define-key map (kbd "L") 'guix-lint-checker-list-lint))
  64. (defvar guix-lint-checker-list-default-hint
  65. '(("\\[guix-lint-checker-list-lint]") " lint packages;\n"))
  66. (defun guix-lint-checker-list-hint ()
  67. (bui-format-hints
  68. guix-lint-checker-list-default-hint
  69. (bui-list-hint)
  70. bui-common-hint))
  71. (defun guix-lint-checker-marked-or-current ()
  72. "Return names (strings) of the marked lint checkers."
  73. (mapcar #'symbol-name (bui-list-marked-or-current)))
  74. (defun guix-lint-checker-list-lint (packages)
  75. "Lint PACKAGES with the marked lint checkers.
  76. If there are no marked checkers, use checker on the current line.
  77. Interactively, prompt for PACKAGES."
  78. (interactive
  79. (list (guix-read-package-names "Lint package,s: ")))
  80. (guix-package-lint packages
  81. (guix-lint-checker-marked-or-current)))
  82. ;;; Interactive commands
  83. (defvar guix-lint-checker-types
  84. '(all local network)
  85. "List of types used by `guix-lint-checkers'.")
  86. (defun guix-lint-checker-read-type ()
  87. "Read lint checker type from minibuffer."
  88. (let ((type (guix-completing-read
  89. "Lint checker type: "
  90. (mapcar #'symbol-name
  91. guix-lint-checker-types))))
  92. (and type (intern type))))
  93. ;;;###autoload
  94. (defun guix-lint-checkers (&optional type)
  95. "Display lint checkers of the Guix packages.
  96. TYPE should be one of the following symbols: `all', `local', `network'.
  97. Interactively, with prefix argument, prompt for TYPE."
  98. (interactive
  99. (list (and current-prefix-arg
  100. (guix-lint-checker-read-type))))
  101. (guix-lint-checker-get-display (or type 'all)))
  102. (provide 'guix-ui-lint-checker)
  103. ;;; guix-ui-lint-checker.el ends here