guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/07: emacs: Add 'guix-browse-license-url' command.


From: Alex Kost
Subject: 02/07: emacs: Add 'guix-browse-license-url' command.
Date: Mon, 25 Jan 2016 19:17:38 +0000

alezost pushed a commit to branch master
in repository guix.

commit 71310ccc56f24c7975ddc3bb9893083e138be808
Author: Alex Kost <address@hidden>
Date:   Tue Jan 19 20:27:58 2016 +0300

    emacs: Add 'guix-browse-license-url' command.
    
    * emacs/guix-main.scm (%licenses): New variable.
    (licenses, license-names, lookup-license, lookup-license-uri): New
    procedures.
    * emacs/guix-read.el (guix-license-names, guix-read-license-name): New
    procedures.
    * emacs/guix-license.el: New file.
    (guix-lookup-license-url): New procedure.
    (guix-browse-license-url): New command.
    * emacs.am (ELFILES): Add new file.
---
 emacs.am              |    3 ++-
 emacs/guix-license.el |   44 ++++++++++++++++++++++++++++++++++++++++++++
 emacs/guix-main.scm   |   30 ++++++++++++++++++++++++++++++
 emacs/guix-read.el    |   11 ++++++++++-
 4 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/emacs.am b/emacs.am
index d0d4dfb..6af9596 100644
--- a/emacs.am
+++ b/emacs.am
@@ -1,5 +1,5 @@
 # GNU Guix --- Functional package management for GNU
-# Copyright © 2014, 2015 Alex Kost <address@hidden>
+# Copyright © 2014, 2015, 2016 Alex Kost <address@hidden>
 #
 # This file is part of GNU Guix.
 #
@@ -37,6 +37,7 @@ ELFILES =                                     \
   emacs/guix-hydra-jobset.el                   \
   emacs/guix-info.el                           \
   emacs/guix-init.el                           \
+  emacs/guix-license.el                                \
   emacs/guix-list.el                           \
   emacs/guix-messages.el                       \
   emacs/guix-pcomplete.el                      \
diff --git a/emacs/guix-license.el b/emacs/guix-license.el
new file mode 100644
index 0000000..940f551
--- /dev/null
+++ b/emacs/guix-license.el
@@ -0,0 +1,44 @@
+;;; guix-license.el --- Licenses
+
+;; Copyright © 2016 Alex Kost <address@hidden>
+
+;; 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-read)
+(require 'guix-backend)
+(require 'guix-guile)
+
+(defun guix-lookup-license-url (license)
+  "Return URL of a LICENSE."
+  (or (guix-eval-read (guix-make-guile-expression
+                       'lookup-license-uri license))
+      (error "Hm, I don't know URL of '%s' license" license)))
+
+;;;###autoload
+(defun guix-browse-license-url (license)
+  "Browse URL of a LICENSE."
+  (interactive (list (guix-read-license-name)))
+  (browse-url (guix-lookup-license-url license)))
+
+(provide 'guix-license)
+
+;;; guix-license.el ends here
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 236c882..0aee206 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -1042,3 +1042,33 @@ Return #t if the shell command was executed 
successfully."
 ;; See the comment to 'guix-package-names' function in "guix-popup.el".
 (define (package-names-lists)
   (map list (package-names)))
+
+
+;;; Licenses
+
+(define %licenses
+  (delay
+    (filter license?
+            (module-map (lambda (_ var)
+                          (variable-ref var))
+                        (resolve-interface '(guix licenses))))))
+
+(define (licenses)
+  (force %licenses))
+
+(define (license-names)
+  "Return a list of names of available licenses."
+  (map license-name (licenses)))
+
+(define lookup-license
+  (memoize
+   (lambda (name)
+     "Return a license by its name."
+     (find (lambda (l)
+             (string=? name (license-name l)))
+           (licenses)))))
+
+(define (lookup-license-uri name)
+  "Return a license URI by its name."
+  (and=> (lookup-license name)
+         license-uri))
diff --git a/emacs/guix-read.el b/emacs/guix-read.el
index 3bc7b16..a1a6b86 100644
--- a/emacs/guix-read.el
+++ b/emacs/guix-read.el
@@ -1,6 +1,6 @@
 ;;; guix-read.el --- Minibuffer readers
 
-;; Copyright © 2015 Alex Kost <address@hidden>
+;; Copyright © 2015, 2016 Alex Kost <address@hidden>
 
 ;; This file is part of GNU Guix.
 
@@ -58,6 +58,10 @@
                             'package-names-lists)))
    #'string<))
 
+(guix-memoized-defun guix-license-names ()
+  "Return a list of names of available licenses."
+  (guix-eval-read (guix-make-guile-expression 'license-names)))
+
 
 ;;; Readers
 
@@ -122,6 +126,11 @@
  :multiple-prompt "Package,s: "
  :multiple-separator " ")
 
+(guix-define-readers
+ :completions-getter guix-license-names
+ :single-reader guix-read-license-name
+ :single-prompt "License: ")
+
 (provide 'guix-read)
 
 ;;; guix-read.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]