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.
This commit is contained in:
Alex Kost 2016-04-08 11:49:39 +03:00
parent f674439433
commit 8472b2fd2d
2 changed files with 24 additions and 0 deletions

View File

@ -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 there to display packages with this license in the same way as @kbd{M-x
guix-packages-by-license} would do (@pxref{Emacs Commands}). 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 @end table

View File

@ -27,12 +27,33 @@
(require 'guix-backend) (require 'guix-backend)
(require 'guix-guile) (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) (defun guix-lookup-license-url (license)
"Return URL of a LICENSE." "Return URL of a LICENSE."
(or (guix-eval-read (guix-make-guile-expression (or (guix-eval-read (guix-make-guile-expression
'lookup-license-uri license)) 'lookup-license-uri license))
(error "Hm, I don't know URL of '%s' license" 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 ;;;###autoload
(defun guix-browse-license-url (license) (defun guix-browse-license-url (license)
"Browse URL of a LICENSE." "Browse URL of a LICENSE."