guix-license.el 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ;;; guix-license.el --- Licenses
  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 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-location-file (&optional directory)
  34. "Open FILE with license definitions.
  35. See `guix-license-file' for the meaning of DIRECTORY.
  36. Interactively, with prefix argument, prompt for DIRECTORY."
  37. (interactive (list (guix-read-directory)))
  38. (find-file (guix-license-file directory)))
  39. ;;;###autoload
  40. (defun guix-find-license-definition (license &optional directory)
  41. "Open licenses file from DIRECTORY and move to the LICENSE definition.
  42. See `guix-license-file' for the meaning of DIRECTORY.
  43. Interactively, with prefix argument, prompt for DIRECTORY."
  44. (interactive
  45. (list (guix-read-license-name)
  46. (guix-read-directory)))
  47. (guix-find-license-location-file directory)
  48. (goto-char (point-min))
  49. (when (re-search-forward (concat "\"" (regexp-quote license) "\"")
  50. nil t)
  51. (beginning-of-defun)
  52. (recenter 1)))
  53. ;;;###autoload
  54. (defun guix-browse-license-url (license)
  55. "Browse URL of a LICENSE."
  56. (interactive (list (guix-read-license-name)))
  57. (browse-url (guix-lookup-license-url license)))
  58. (provide 'guix-license)
  59. ;;; guix-license.el ends here