all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 3/7] emacs: Add 'guix-browse-license-url' command.
Date: Fri, 22 Jan 2016 11:19:31 +0300	[thread overview]
Message-ID: <1453450775-594-4-git-send-email-alezost@gmail.com> (raw)
In-Reply-To: <1453450775-594-1-git-send-email-alezost@gmail.com>

* emacs/guix-main.scm (license-names, license-name->license)
  (license-name->uri): New procedures.
* emacs/guix-read.el (guix-license-names, guix-read-license-name): New
  procedures.
* emacs/guix-license.el: New file.
* emacs.am (ELFILES): Add it.
---
 emacs.am              |  3 ++-
 emacs/guix-license.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
 emacs/guix-main.scm   | 18 ++++++++++++++++++
 emacs/guix-read.el    | 11 ++++++++++-
 4 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 emacs/guix-license.el

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 <alezost@gmail.com>
+# Copyright © 2014, 2015, 2016 Alex Kost <alezost@gmail.com>
 #
 # 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..a28b45e
--- /dev/null
+++ b/emacs/guix-license.el
@@ -0,0 +1,44 @@
+;;; 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-read)
+(require 'guix-backend)
+(require 'guix-guile)
+
+(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)))
+
+;;;###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)))
+
+(provide 'guix-license)
+
+;;; guix-license.el ends here
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 236c882..7706921 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -1042,3 +1042,21 @@ 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)))
+
+\f
+;;; Licenses
+
+(define (license-names)
+  "Return a list of names of available licenses."
+  (map license-name %licenses))
+
+(define license-name->license
+  (memoize
+   (lambda (name)
+     (find (lambda (l)
+             (string=? name (license-name l)))
+           %licenses))))
+
+(define (license-name->uri name)
+  (and=> (license-name->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 <alezost@gmail.com>
+;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
 
 ;; 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)))
+
 \f
 ;;; 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
-- 
2.7.0

  parent reply	other threads:[~2016-01-22  8:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-22  8:19 [PATCH 0/7]: Add "M-x guix-licenses" and friends Alex Kost
2016-01-22  8:19 ` [PATCH 1/7] emacs: Rename 'file-path' to 'file-name' Alex Kost
2016-01-23 17:06   ` Ludovic Courtès
2016-01-22  8:19 ` [PATCH 2/7] licenses: Add a list of licenses Alex Kost
2016-01-23 17:08   ` Ludovic Courtès
2016-01-23 22:37     ` Alex Kost
2016-01-24 20:59       ` Ludovic Courtès
2016-01-22  8:19 ` Alex Kost [this message]
2016-01-23 17:13   ` [PATCH 3/7] emacs: Add 'guix-browse-license-url' command Ludovic Courtès
2016-01-25 19:18     ` Alex Kost
2016-01-23 17:18   ` Ludovic Courtès
2016-01-23 22:49     ` Alex Kost
2016-01-24 21:00       ` Ludovic Courtès
2016-01-22  8:19 ` [PATCH 4/7] emacs: Buttonize licenses in "Package Info" Alex Kost
2016-01-23 17:14   ` Ludovic Courtès
2016-01-22  8:19 ` [PATCH 5/7] emacs: Add 'guix-packages-by-license' command Alex Kost
2016-01-23 17:15   ` Ludovic Courtès
2016-01-22  8:19 ` [PATCH 6/7] emacs: list: Support displaying URL links Alex Kost
2016-01-23 17:15   ` Ludovic Courtès
2016-01-22  8:19 ` [PATCH 7/7] emacs: Add interface for licenses Alex Kost
2016-01-23 17:17   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453450775-594-4-git-send-email-alezost@gmail.com \
    --to=alezost@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.