Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / emacs / guix-license.el
CommitLineData
71310ccc
AK
1;;; guix-license.el --- Licenses
2
3;; Copyright © 2016 Alex Kost <alezost@gmail.com>
4
5;; This file is part of GNU Guix.
6
7;; GNU Guix is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Guix is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;; This file provides the code to work with licenses of Guix packages.
23
24;;; Code:
25
26(require 'guix-read)
27(require 'guix-backend)
28(require 'guix-guile)
29
8472b2fd
AK
30(defun guix-license-file (&optional directory)
31 "Return name of the file with license definitions.
32DIRECTORY is a directory with Guix source (`guix-directory' by default)."
33 (expand-file-name "guix/licenses.scm"
34 (or directory guix-directory)))
35
71310ccc
AK
36(defun guix-lookup-license-url (license)
37 "Return URL of a LICENSE."
38 (or (guix-eval-read (guix-make-guile-expression
39 'lookup-license-uri license))
40 (error "Hm, I don't know URL of '%s' license" license)))
41
8472b2fd
AK
42;;;###autoload
43(defun guix-find-license-definition (license &optional directory)
44 "Open licenses file from DIRECTORY and move to the LICENSE definition.
45See `guix-license-file' for the meaning of DIRECTORY.
46Interactively, with prefix argument, prompt for DIRECTORY."
47 (interactive
48 (list (guix-read-license-name)
49 (guix-read-directory)))
50 (find-file (guix-license-file directory))
51 (goto-char (point-min))
52 (when (re-search-forward (concat "\"" (regexp-quote license) "\"")
53 nil t)
54 (beginning-of-defun)
55 (recenter 1)))
56
71310ccc
AK
57;;;###autoload
58(defun guix-browse-license-url (license)
59 "Browse URL of a LICENSE."
60 (interactive (list (guix-read-license-name)))
61 (browse-url (guix-lookup-license-url license)))
62
63(provide 'guix-license)
64
65;;; guix-license.el ends here