unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 59049793d50a02c4f65e4c3d64708d4aec16f715 4063 bytes (raw)
name: emacs/guix-license.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
 
;;; guix-license.el --- Licenses

;; Copyright © 2016 Alex Kost <alezost@gmail.com>

;; This file is part of GNU Guix.

;; GNU Guix is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Guix is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This file provides the code to work with licenses of Guix packages.

;;; Code:

(require 'guix-buffer)
(require 'guix-list)
(require 'guix-info)
(require 'guix-read)
(require 'guix-backend)
(require 'guix-guile)

(guix-define-entry-type license)

(defun guix-license-name->url (license)
  "Return URL of a LICENSE."
  (or (guix-eval-read (guix-make-guile-expression
                       'license-name->uri license))
      (error "Hm, I don't know URL of '%s' license" license)))

(defun guix-license-get-entries (search-type &rest args)
  "Receive 'license' entries.
SEARCH-TYPE may be one of the following symbols: `all', `id', `name'."
  (guix-eval-read
   (apply #'guix-make-guile-expression
          'license-entries search-type args)))

(defun guix-license-get-display (search-type &rest args)
  "Search for licenses and show results."
  (apply #'guix-list-get-display-entries
         'license search-type args))

\f
;;; License 'info'

(guix-info-define-interface license
  :buffer-name "*Guix License Info*"
  :get-entries-function 'guix-license-get-entries
  :format '((name ignore (simple guix-info-heading))
            ignore
            guix-license-insert-packages-button
            (url ignore (simple guix-url))
            guix-license-insert-comment)
  :titles '((url . "URL")))

(declare-function guix-packages-by-license "guix-ui-package")

(defun guix-license-insert-packages-button (entry)
  "Insert button to display packages by license ENTRY."
  (guix-info-insert-action-button
   "Packages"
   (lambda (btn)
     (guix-packages-by-license (button-get btn 'license)))
   "Show packages with this license"
   'license (guix-entry-value entry 'name)))

(defun guix-license-insert-comment (entry)
  "Insert 'comment' of a license ENTRY."
  (let ((comment (guix-entry-value entry 'comment)))
    (if (and comment
             (string-match-p "^http" comment))
        (guix-info-insert-value-simple comment 'guix-url)
      (guix-info-insert-title-simple
       (guix-info-param-title 'license 'comment))
      (guix-info-insert-value-indent comment))))

\f
;;; License 'list'

(guix-list-define-interface license
  :buffer-name "*Guix Licenses*"
  :get-entries-function 'guix-license-get-entries
  :describe-function 'guix-license-list-describe
  :format '((name nil 40 t)
            (url guix-list-get-url 50 t))
  :titles '((name . "License"))
  :sort-key '(name))

(let ((map guix-license-list-mode-map))
  (define-key map (kbd "RET") 'guix-license-list-show-packages))

(defun guix-license-list-describe (ids)
  "Describe licenses with IDS (list of identifiers)."
  (guix-buffer-display-entries
   (guix-entries-by-ids ids (guix-buffer-current-entries))
   'info 'license (cl-list* 'id ids) 'add))

(defun guix-license-list-show-packages ()
  "Display packages with the license at point."
  (interactive)
  (guix-packages-by-license (guix-list-current-id)))

\f
;;; Interactive commands

;;;###autoload
(defun guix-browse-license-url (license)
  "Browse URL of a LICENSE."
  (interactive (list (guix-read-license-name)))
  (browse-url (guix-license-name->url license)))

;;;###autoload
(defun guix-licenses ()
  "Display licenses of the Guix packages."
  (interactive)
  (guix-license-get-display 'all))

(provide 'guix-license)

;;; guix-license.el ends here

debug log:

solving 5904979 ...
found 5904979 in https://yhetil.org/guix-devel/1453450775-594-8-git-send-email-alezost@gmail.com/
found a28b45e in https://yhetil.org/guix-devel/1453450775-594-4-git-send-email-alezost@gmail.com/

applying [1/2] https://yhetil.org/guix-devel/1453450775-594-4-git-send-email-alezost@gmail.com/
diff --git a/emacs/guix-license.el b/emacs/guix-license.el
new file mode 100644
index 0000000..a28b45e


applying [2/2] https://yhetil.org/guix-devel/1453450775-594-8-git-send-email-alezost@gmail.com/
diff --git a/emacs/guix-license.el b/emacs/guix-license.el
index a28b45e..5904979 100644

Checking patch emacs/guix-license.el...
Applied patch emacs/guix-license.el cleanly.
Checking patch emacs/guix-license.el...
Applied patch emacs/guix-license.el cleanly.

index at:
100644 59049793d50a02c4f65e4c3d64708d4aec16f715	emacs/guix-license.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).