gnu: octave: Update to 4.2.0.
[jackhill/guix/guix.git] / emacs / guix-location.el
CommitLineData
79c7a8f2
AK
1;;; guix-location.el --- Package locations
2
3;; Copyright © 2016 Alex Kost <alezost@gmail.com>
4
5;; This file is part of GNU Guix.
6
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.
11
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.
16
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/>.
19
20;;; Commentary:
21
22;; This file provides the code to work with locations of Guix packages.
23
24;;; Code:
25
26(require 'cl-lib)
27(require 'guix-backend)
28(require 'guix-read)
29(require 'guix-guile)
30
31(defun guix-package-location (id-or-name)
32 "Return location of a package with ID-OR-NAME.
33For the meaning of location, see `guix-find-location'."
34 (guix-eval-read (guix-make-guile-expression
35 'package-location-string id-or-name)))
36
e81a89d1 37;;;###autoload
79c7a8f2
AK
38(defun guix-find-location (location &optional directory)
39 "Go to LOCATION of a package.
40LOCATION is a string of the form:
41
e81a89d1
AK
42 \"FILE:LINE:COLUMN\"
43
44If FILE is relative, it is considered to be relative to
45DIRECTORY (`guix-directory' by default).
79c7a8f2 46
e81a89d1
AK
47Interactively, prompt for LOCATION. With prefix argument, prompt
48for DIRECTORY as well."
49 (interactive
50 (list (guix-read-package-location)
51 (guix-read-directory)))
52 (cl-multiple-value-bind (file line column)
79c7a8f2 53 (split-string location ":")
e81a89d1
AK
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)
61 (recenter 1)))))
79c7a8f2
AK
62
63;;;###autoload
64(defun guix-edit (id-or-name &optional directory)
65 "Edit (go to location of) package with ID-OR-NAME.
66See `guix-find-location' for the meaning of package location and
67DIRECTORY.
68Interactively, with prefix argument, prompt for DIRECTORY."
69 (interactive
70 (list (guix-read-package-name)
71 (guix-read-directory)))
72 (let ((loc (guix-package-location id-or-name)))
73 (if loc
74 (guix-find-location loc directory)
75 (message "Couldn't find package location."))))
76
77(provide 'guix-location)
78
79;;; guix-location.el ends here