diff options
| author | Alex Kost <alezost@gmail.com> | 2016-01-21 22:07:10 +0300 |
|---|---|---|
| committer | Alex Kost <alezost@gmail.com> | 2016-01-25 22:11:47 +0300 |
| commit | 687c9bc0233facde4068ea7f9fed2b2ae931adab (patch) | |
| tree | b7416d582c3354c856ba1fa64704434cebfde7dc | |
| parent | 6dd460c8565882a9ef3f76cc259bbfe1a9342b6e (diff) | |
emacs: Add interface for licenses.
* 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.
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | doc/emacs.texi | 22 | ||||
| -rw-r--r-- | doc/guix.texi | 1 | ||||
| -rw-r--r-- | emacs/guix-license.el | 86 | ||||
| -rw-r--r-- | emacs/guix-main.scm | 22 |
5 files changed, 132 insertions, 0 deletions
| @@ -14,6 +14,7 @@ Please send Guix bug reports to bug-guix@gnu.org. | |||
| 14 | 14 | ||
| 15 | ** Package management | 15 | ** Package management |
| 16 | 16 | ||
| 17 | *** Emacs interface for licenses | ||
| 17 | *** Emacs interface for system generations | 18 | *** Emacs interface for system generations |
| 18 | *** Emacs interface for hydra.gnu.org | 19 | *** Emacs interface for hydra.gnu.org |
| 19 | *** Changes in Emacs interface variables and faces | 20 | *** Changes in Emacs interface variables and faces |
diff --git a/doc/emacs.texi b/doc/emacs.texi index e72a386303e..8020e0ace36 100644 --- a/doc/emacs.texi +++ b/doc/emacs.texi | |||
| @@ -9,6 +9,7 @@ Guix convenient and fun. | |||
| 9 | @menu | 9 | @menu |
| 10 | * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}. | 10 | * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}. |
| 11 | * Package Management: Emacs Package Management. Managing packages and generations. | 11 | * Package Management: Emacs Package Management. Managing packages and generations. |
| 12 | * Licenses: Emacs Licenses. Interface for licenses of Guix packages. | ||
| 12 | * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands. | 13 | * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands. |
| 13 | * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names. | 14 | * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names. |
| 14 | * Build Log Mode: Emacs Build Log. Highlighting Guix build logs. | 15 | * Build Log Mode: Emacs Build Log. Highlighting Guix build logs. |
| @@ -520,6 +521,27 @@ Various settings for ``info'' buffers. | |||
| 520 | @end table | 521 | @end table |
| 521 | 522 | ||
| 522 | 523 | ||
| 524 | @node Emacs Licenses | ||
| 525 | @section Licenses | ||
| 526 | |||
| 527 | If you want to browse the URL of a particular license, or to look at a | ||
| 528 | list of licenses, you may use the following commands: | ||
| 529 | |||
| 530 | @table @kbd | ||
| 531 | |||
| 532 | @item M-x guix-browse-license-url | ||
| 533 | Choose a license from a completion list to browse its URL using | ||
| 534 | @code{browse-url} function (@pxref{Browse-URL,,, emacs, The GNU Emacs | ||
| 535 | Manual}). | ||
| 536 | |||
| 537 | @item M-x guix-licenses | ||
| 538 | Display a list of available licenses. You can press @kbd{@key{RET}} | ||
| 539 | there to display packages with this license in the same way as @kbd{M-x | ||
| 540 | guix-packages-by-license} would do (@pxref{Emacs Commands}). | ||
| 541 | |||
| 542 | @end table | ||
| 543 | |||
| 544 | |||
| 523 | @node Emacs Popup Interface | 545 | @node Emacs Popup Interface |
| 524 | @section Popup Interface | 546 | @section Popup Interface |
| 525 | 547 | ||
diff --git a/doc/guix.texi b/doc/guix.texi index a650a55d510..8476408ec97 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -111,6 +111,7 @@ Emacs Interface | |||
| 111 | 111 | ||
| 112 | * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}. | 112 | * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}. |
| 113 | * Package Management: Emacs Package Management. Managing packages and generations. | 113 | * Package Management: Emacs Package Management. Managing packages and generations. |
| 114 | * Licenses: Emacs Licenses. Interface for licenses of Guix packages. | ||
| 114 | * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands. | 115 | * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands. |
| 115 | * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names. | 116 | * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names. |
| 116 | * Build Log Mode: Emacs Build Log. Highlighting Guix build logs. | 117 | * Build Log Mode: Emacs Build Log. Highlighting Guix build logs. |
diff --git a/emacs/guix-license.el b/emacs/guix-license.el index 940f5518e27..a99d7af98d7 100644 --- a/emacs/guix-license.el +++ b/emacs/guix-license.el | |||
| @@ -23,22 +23,108 @@ | |||
| 23 | 23 | ||
| 24 | ;;; Code: | 24 | ;;; Code: |
| 25 | 25 | ||
| 26 | (require 'guix-buffer) | ||
| 27 | (require 'guix-list) | ||
| 28 | (require 'guix-info) | ||
| 26 | (require 'guix-read) | 29 | (require 'guix-read) |
| 27 | (require 'guix-backend) | 30 | (require 'guix-backend) |
| 28 | (require 'guix-guile) | 31 | (require 'guix-guile) |
| 29 | 32 | ||
| 33 | (guix-define-entry-type license) | ||
| 34 | |||
| 30 | (defun guix-lookup-license-url (license) | 35 | (defun guix-lookup-license-url (license) |
| 31 | "Return URL of a LICENSE." | 36 | "Return URL of a LICENSE." |
| 32 | (or (guix-eval-read (guix-make-guile-expression | 37 | (or (guix-eval-read (guix-make-guile-expression |
| 33 | 'lookup-license-uri license)) | 38 | 'lookup-license-uri license)) |
| 34 | (error "Hm, I don't know URL of '%s' license" license))) | 39 | (error "Hm, I don't know URL of '%s' license" license))) |
| 35 | 40 | ||
| 41 | (defun guix-license-get-entries (search-type &rest args) | ||
| 42 | "Receive 'license' entries. | ||
| 43 | SEARCH-TYPE may be one of the following symbols: `all', `id', `name'." | ||
| 44 | (guix-eval-read | ||
| 45 | (apply #'guix-make-guile-expression | ||
| 46 | 'license-entries search-type args))) | ||
| 47 | |||
| 48 | (defun guix-license-get-display (search-type &rest args) | ||
| 49 | "Search for licenses and show results." | ||
| 50 | (apply #'guix-list-get-display-entries | ||
| 51 | 'license search-type args)) | ||
| 52 | |||
| 53 | |||
| 54 | ;;; License 'info' | ||
| 55 | |||
| 56 | (guix-info-define-interface license | ||
| 57 | :buffer-name "*Guix License Info*" | ||
| 58 | :get-entries-function 'guix-license-get-entries | ||
| 59 | :format '((name ignore (simple guix-info-heading)) | ||
| 60 | ignore | ||
| 61 | guix-license-insert-packages-button | ||
| 62 | (url ignore (simple guix-url)) | ||
| 63 | guix-license-insert-comment) | ||
| 64 | :titles '((url . "URL"))) | ||
| 65 | |||
| 66 | (declare-function guix-packages-by-license "guix-ui-package") | ||
| 67 | |||
| 68 | (defun guix-license-insert-packages-button (entry) | ||
| 69 | "Insert button to display packages by license ENTRY." | ||
| 70 | (guix-info-insert-action-button | ||
| 71 | "Packages" | ||
| 72 | (lambda (btn) | ||
| 73 | (guix-packages-by-license (button-get btn 'license))) | ||
| 74 | "Show packages with this license" | ||
| 75 | 'license (guix-entry-value entry 'name))) | ||
| 76 | |||
| 77 | (defun guix-license-insert-comment (entry) | ||
| 78 | "Insert 'comment' of a license ENTRY." | ||
| 79 | (let ((comment (guix-entry-value entry 'comment))) | ||
| 80 | (if (and comment | ||
| 81 | (string-match-p "^http" comment)) | ||
| 82 | (guix-info-insert-value-simple comment 'guix-url) | ||
| 83 | (guix-info-insert-title-simple | ||
| 84 | (guix-info-param-title 'license 'comment)) | ||
| 85 | (guix-info-insert-value-indent comment)))) | ||
| 86 | |||
| 87 | |||
| 88 | ;;; License 'list' | ||
| 89 | |||
| 90 | (guix-list-define-interface license | ||
| 91 | :buffer-name "*Guix Licenses*" | ||
| 92 | :get-entries-function 'guix-license-get-entries | ||
| 93 | :describe-function 'guix-license-list-describe | ||
| 94 | :format '((name nil 40 t) | ||
| 95 | (url guix-list-get-url 50 t)) | ||
| 96 | :titles '((name . "License")) | ||
| 97 | :sort-key '(name)) | ||
| 98 | |||
| 99 | (let ((map guix-license-list-mode-map)) | ||
| 100 | (define-key map (kbd "RET") 'guix-license-list-show-packages)) | ||
| 101 | |||
| 102 | (defun guix-license-list-describe (ids) | ||
| 103 | "Describe licenses with IDS (list of identifiers)." | ||
| 104 | (guix-buffer-display-entries | ||
| 105 | (guix-entries-by-ids ids (guix-buffer-current-entries)) | ||
| 106 | 'info 'license (cl-list* 'id ids) 'add)) | ||
| 107 | |||
| 108 | (defun guix-license-list-show-packages () | ||
| 109 | "Display packages with the license at point." | ||
| 110 | (interactive) | ||
| 111 | (guix-packages-by-license (guix-list-current-id))) | ||
| 112 | |||
| 113 | |||
| 114 | ;;; Interactive commands | ||
| 115 | |||
| 36 | ;;;###autoload | 116 | ;;;###autoload |
| 37 | (defun guix-browse-license-url (license) | 117 | (defun guix-browse-license-url (license) |
| 38 | "Browse URL of a LICENSE." | 118 | "Browse URL of a LICENSE." |
| 39 | (interactive (list (guix-read-license-name))) | 119 | (interactive (list (guix-read-license-name))) |
| 40 | (browse-url (guix-lookup-license-url license))) | 120 | (browse-url (guix-lookup-license-url license))) |
| 41 | 121 | ||
| 122 | ;;;###autoload | ||
| 123 | (defun guix-licenses () | ||
| 124 | "Display licenses of the Guix packages." | ||
| 125 | (interactive) | ||
| 126 | (guix-license-get-display 'all)) | ||
| 127 | |||
| 42 | (provide 'guix-license) | 128 | (provide 'guix-license) |
| 43 | 129 | ||
| 44 | ;;; guix-license.el ends here | 130 | ;;; guix-license.el ends here |
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index bec26c7c40a..335686ed25c 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm | |||
| @@ -1083,3 +1083,25 @@ Return #t if the shell command was executed successfully." | |||
| 1083 | "Return a license URI by its name." | 1083 | "Return a license URI by its name." |
| 1084 | (and=> (lookup-license name) | 1084 | (and=> (lookup-license name) |
| 1085 | license-uri)) | 1085 | license-uri)) |
| 1086 | |||
| 1087 | (define %license-param-alist | ||
| 1088 | `((id . ,license-name) | ||
| 1089 | (name . ,license-name) | ||
| 1090 | (url . ,license-uri) | ||
| 1091 | (comment . ,license-comment))) | ||
| 1092 | |||
| 1093 | (define license->sexp | ||
| 1094 | (object-transformer %license-param-alist)) | ||
| 1095 | |||
| 1096 | (define (find-licenses search-type . search-values) | ||
| 1097 | "Return a list of licenses depending on SEARCH-TYPE and SEARCH-VALUES." | ||
| 1098 | (case search-type | ||
| 1099 | ((id name) | ||
| 1100 | (let ((names search-values)) | ||
| 1101 | (filter-map lookup-license names))) | ||
| 1102 | ((all) | ||
| 1103 | (licenses)))) | ||
| 1104 | |||
| 1105 | (define (license-entries search-type . search-values) | ||
| 1106 | (map license->sexp | ||
| 1107 | (apply find-licenses search-type search-values))) | ||
