guix-license.el 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ;;; guix-license.el --- Licenses
  2. ;; Copyright © 2016 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 the code to work with licenses of Guix packages.
  18. ;;; Code:
  19. (require 'guix-read)
  20. (require 'guix-repl)
  21. (require 'guix-guile)
  22. (defun guix-license-file (&optional directory)
  23. "Return name of the file with license definitions.
  24. DIRECTORY is a directory with Guix source (`guix-directory' by default)."
  25. (expand-file-name "guix/licenses.scm"
  26. (or directory guix-directory)))
  27. (defun guix-lookup-license-url (license)
  28. "Return URL of a LICENSE."
  29. (or (guix-eval-read (guix-make-guile-expression
  30. 'lookup-license-uri license))
  31. (error "Hm, I don't know URL of '%s' license" license)))
  32. ;;;###autoload
  33. (defun guix-find-license-definition (license &optional directory)
  34. "Open licenses file from DIRECTORY and move to the LICENSE definition.
  35. See `guix-license-file' for the meaning of DIRECTORY.
  36. Interactively, with prefix argument, prompt for DIRECTORY."
  37. (interactive
  38. (list (guix-read-license-name)
  39. (guix-read-directory)))
  40. (find-file (guix-license-file directory))
  41. (goto-char (point-min))
  42. (when (re-search-forward (concat "\"" (regexp-quote license) "\"")
  43. nil t)
  44. (beginning-of-defun)
  45. (recenter 1)))
  46. ;;;###autoload
  47. (defun guix-browse-license-url (license)
  48. "Browse URL of a LICENSE."
  49. (interactive (list (guix-read-license-name)))
  50. (browse-url (guix-lookup-license-url license)))
  51. (provide 'guix-license)
  52. ;;; guix-license.el ends here