From 27986d7b192f23eb4185d5ff0135d0a0470cd86a Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Thu, 7 Apr 2016 19:07:23 +0300 Subject: emacs: Separate package license code. Move list/info interface code from "guix-license.el" to "guix-ui-license.el". * emacs/guix-license.el (guix-license-get-entries, guix-license-get-display) (guix-license-insert-packages-button, guix-license-insert-comment) (guix-licenses): Move to... * emacs/guix-ui-license.el: ... here. New file. * emacs.am (ELFILES): Add it. --- emacs/guix-license.el | 86 --------------------------------------------------- 1 file changed, 86 deletions(-) (limited to 'emacs/guix-license.el') diff --git a/emacs/guix-license.el b/emacs/guix-license.el index a99d7af98d..940f5518e2 100644 --- a/emacs/guix-license.el +++ b/emacs/guix-license.el @@ -23,108 +23,22 @@ ;;; 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-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))) -(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)) - - -;;; 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)))) - - -;;; 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))) - - -;;; Interactive commands - ;;;###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))) -;;;###autoload -(defun guix-licenses () - "Display licenses of the Guix packages." - (interactive) - (guix-license-get-display 'all)) - (provide 'guix-license) ;;; guix-license.el ends here -- cgit v1.2.3 From 8472b2fd2d4c4d060b1333c9c527575d965a0ebd Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Fri, 8 Apr 2016 11:49:39 +0300 Subject: emacs: Add 'guix-find-license-definition' command. * emacs/guix-license.el (guix-license-file): New procedure. (guix-find-license-definition): New command. * doc/emacs.texi (Emacs Licenses): Document it. --- doc/emacs.texi | 3 +++ emacs/guix-license.el | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'emacs/guix-license.el') diff --git a/doc/emacs.texi b/doc/emacs.texi index ed8896ad43..575e87c262 100644 --- a/doc/emacs.texi +++ b/doc/emacs.texi @@ -544,6 +544,9 @@ 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}). +@item M-x guix-find-license-definition +Open @file{@dots{}/guix/licenses.scm} and move to the specified license. + @end table diff --git a/emacs/guix-license.el b/emacs/guix-license.el index 940f5518e2..6003a21aac 100644 --- a/emacs/guix-license.el +++ b/emacs/guix-license.el @@ -27,12 +27,33 @@ (require 'guix-backend) (require 'guix-guile) +(defun guix-license-file (&optional directory) + "Return name of the file with license definitions. +DIRECTORY is a directory with Guix source (`guix-directory' by default)." + (expand-file-name "guix/licenses.scm" + (or directory guix-directory))) + (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-find-license-definition (license &optional directory) + "Open licenses file from DIRECTORY and move to the LICENSE definition. +See `guix-license-file' for the meaning of DIRECTORY. +Interactively, with prefix argument, prompt for DIRECTORY." + (interactive + (list (guix-read-license-name) + (guix-read-directory))) + (find-file (guix-license-file directory)) + (goto-char (point-min)) + (when (re-search-forward (concat "\"" (regexp-quote license) "\"") + nil t) + (beginning-of-defun) + (recenter 1))) + ;;;###autoload (defun guix-browse-license-url (license) "Browse URL of a LICENSE." -- cgit v1.2.3