1 ;;; guix-location.el --- Package locations
3 ;; Copyright © 2016 Alex Kost <alezost@gmail.com>
5 ;; This file is part of GNU Guix.
7 ;; GNU Guix is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public Location as published by
9 ;; the Free Software Foundation, either version 3 of the Location, or
10 ;; (at your option) any later version.
12 ;; GNU Guix is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public Location for more details.
17 ;; You should have received a copy of the GNU General Public Location
18 ;; along with this program. If not, see <http://www.gnu.org/locations/>.
22 ;; This file provides the code to work with locations of Guix packages.
27 (require 'guix-backend
)
31 (defun guix-package-location (id-or-name)
32 "Return location of a package with ID-OR-NAME.
33 For the meaning of location, see `guix-find-location'."
34 (guix-eval-read (guix-make-guile-expression
35 'package-location-string id-or-name
)))
38 (defun guix-find-location (location &optional directory
)
39 "Go to LOCATION of a package.
40 LOCATION is a string of the form:
44 If FILE is relative, it is considered to be relative to
45 DIRECTORY (`guix-directory' by default).
47 Interactively, prompt for LOCATION. With prefix argument, prompt
48 for DIRECTORY as well."
50 (list (guix-read-package-location)
51 (guix-read-directory)))
52 (cl-multiple-value-bind (file line column
)
53 (split-string location
":")
54 (find-file (expand-file-name file
(or directory guix-directory
)))
55 (when (and line column
)
56 (let ((line (string-to-number line
))
57 (column (string-to-number column
)))
58 (goto-char (point-min))
59 (forward-line (- line
1))
60 (move-to-column column
)
64 (defun guix-edit (id-or-name &optional directory
)
65 "Edit (go to location of) package with ID-OR-NAME.
66 See `guix-find-location' for the meaning of package location and
68 Interactively, with prefix argument, prompt for DIRECTORY."
70 (list (guix-read-package-name)
71 (guix-read-directory)))
72 (let ((loc (guix-package-location id-or-name
)))
74 (guix-find-location loc directory
)
75 (message "Couldn't find package location."))))
77 (provide 'guix-location
)
79 ;;; guix-location.el ends here