From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 7/7] emacs: Add interface for licenses.
Date: Fri, 22 Jan 2016 11:19:35 +0300 [thread overview]
Message-ID: <1453450775-594-8-git-send-email-alezost@gmail.com> (raw)
In-Reply-To: <1453450775-594-1-git-send-email-alezost@gmail.com>
* emacs/guix-main.scm (%license-param-alist): New variable.
(license->sexp, find-licenses, license-entries): New procedures.
* emacs/guix-license.el (guix-license-get-entries)
(guix-license-get-display, guix-license-insert-packages-button)
(guix-license-insert-comment, guix-license-list-describe)
(guix-license-list-show-packages): New procedures.
(guix-licenses): New command.
* doc/emacs.texi (Emacs Licenses): New node.
(Emacs Interface): Add it.
* doc/guix.texi (Top): Add it.
* NEWS: Mention new interface.
---
NEWS | 1 +
doc/emacs.texi | 22 +++++++++++++
doc/guix.texi | 1 +
emacs/guix-license.el | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
emacs/guix-main.scm | 22 +++++++++++++
5 files changed, 132 insertions(+)
diff --git a/NEWS b/NEWS
index b27ebc7..010789e 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Please send Guix bug reports to bug-guix@gnu.org.
** Package management
+*** Emacs interface for licenses
*** Emacs interface for system generations
*** Emacs interface for hydra.gnu.org
*** Changes in Emacs interface variables and faces
diff --git a/doc/emacs.texi b/doc/emacs.texi
index e72a386..2fa28c9 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -9,6 +9,7 @@ Guix convenient and fun.
@menu
* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
* Package Management: Emacs Package Management. Managing packages and generations.
+* Licenses: Emacs Licenses. Interface for licenses of Guix packages.
* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
@@ -520,6 +521,27 @@ Various settings for ``info'' buffers.
@end table
+@node Emacs Licenses
+@section Licenses
+
+If you want to browse an URL of a particular license, or to look at a
+list of licenses, you may use the following commands:
+
+@table @kbd
+
+@item M-x guix-browse-license-url
+Choose a license from a completion list to browse its URL using
+@code{browse-url} function (@pxref{Browse-URL,,, emacs, The GNU Emacs
+Manual}).
+
+@item M-x guix-licenses
+Display a list of available licenses. You can press @kbd{@key{RET}}
+there to display packages with this license in the same way as @kbd{M-x
+guix-packages-by-license} would do (@pxref{Emacs Commands}).
+
+@end table
+
+
@node Emacs Popup Interface
@section Popup Interface
diff --git a/doc/guix.texi b/doc/guix.texi
index 592ec3c..1f513da 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -111,6 +111,7 @@ Emacs Interface
* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
* Package Management: Emacs Package Management. Managing packages and generations.
+* Licenses: Emacs Licenses. Interface for licenses of Guix packages.
* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
diff --git a/emacs/guix-license.el b/emacs/guix-license.el
index a28b45e..5904979 100644
--- a/emacs/guix-license.el
+++ b/emacs/guix-license.el
@@ -23,22 +23,108 @@
;;; 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
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index c39501d..b2f307a 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -1071,3 +1071,25 @@ Return #t if the shell command was executed successfully."
(define (license-name->uri name)
(and=> (license-name->license name)
license-uri))
+
+(define %license-param-alist
+ `((id . ,license-name)
+ (name . ,license-name)
+ (url . ,license-uri)
+ (comment . ,license-comment)))
+
+(define license->sexp
+ (object-transformer %license-param-alist))
+
+(define (find-licenses search-type . search-values)
+ "Return a list of licenses depending on SEARCH-TYPE and SEARCH-VALUES."
+ (case search-type
+ ((id name)
+ (let ((names search-values))
+ (filter-map license-name->license names)))
+ ((all)
+ %licenses)))
+
+(define (license-entries search-type . search-values)
+ (map license->sexp
+ (apply find-licenses search-type search-values)))
--
2.7.0
next prev 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 ` [PATCH 3/7] emacs: Add 'guix-browse-license-url' command Alex Kost
2016-01-23 17:13 ` 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 ` Alex Kost [this message]
2016-01-23 17:17 ` [PATCH 7/7] emacs: Add interface for licenses 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
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1453450775-594-8-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 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).