guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/05: emacs: 'C-u M-x guix-edit' prompts for directory.


From: Alex Kost
Subject: 01/05: emacs: 'C-u M-x guix-edit' prompts for directory.
Date: Wed, 10 Feb 2016 07:44:38 +0000

alezost pushed a commit to branch master
in repository guix.

commit 2c04e2eec8bf250d1e928b7c8b1e60424b0b32fa
Author: Alex Kost <address@hidden>
Date:   Sun Feb 7 11:08:57 2016 +0300

    emacs: 'C-u M-x guix-edit' prompts for directory.
    
    * emacs/guix-base.el (guix-read-directory): New procedure.
    (guix-find-location, guix-edit): Add optional 'directory' argument.
    * emacs/guix-ui-package.el (guix-package-list-edit)
    (guix-output-list-edit): Likewise.
    * doc/emacs.texi (Emacs Commands): Mention "C-u".
---
 doc/emacs.texi           |    3 +++
 emacs/guix-base.el       |   27 ++++++++++++++++++++-------
 emacs/guix-ui-package.el |   19 +++++++++++--------
 3 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/doc/emacs.texi b/doc/emacs.texi
index d46c17c..dbe59f0 100644
--- a/doc/emacs.texi
+++ b/doc/emacs.texi
@@ -240,6 +240,9 @@ this:
 @kbd{M-x guix-edit guix} opens
 @file{~/src/guix/gnu/packages/package-management.scm} file.
 
+Also you can use @kbd{C-u} prefix argument to specify a directory just
+for the current @kbd{M-x guix-edit} command.
+
 
 @node Emacs General info
 @subsection General information
diff --git a/emacs/guix-base.el b/emacs/guix-base.el
index 9f9f258..1248ecb 100644
--- a/emacs/guix-base.el
+++ b/emacs/guix-base.el
@@ -55,6 +55,14 @@
 If it is not set by a user, it is set after starting Guile REPL.
 This directory is used to define location of the packages.")
 
+(defun guix-read-directory ()
+  "Return `guix-directory' or prompt for it.
+This function is intended for using in `interactive' forms."
+  (if current-prefix-arg
+      (read-directory-name "Directory with Guix modules: "
+                           guix-directory)
+    guix-directory))
+
 (defun guix-set-directory ()
   "Set `guix-directory' if needed."
   (or guix-directory
@@ -63,17 +71,17 @@ This directory is used to define location of the packages.")
 
 (add-hook 'guix-after-start-repl-hook 'guix-set-directory)
 
-(defun guix-find-location (location)
+(defun guix-find-location (location &optional directory)
   "Go to LOCATION of a package.
 LOCATION is a string of the form:
 
   \"PATH:LINE:COLUMN\"
 
 If PATH is relative, it is considered to be relative to
-`guix-directory'."
+DIRECTORY (`guix-directory' by default)."
   (cl-multiple-value-bind (path line col)
       (split-string location ":")
-    (let ((file (expand-file-name path guix-directory))
+    (let ((file (expand-file-name path (or directory guix-directory)))
           (line (string-to-number line))
           (col  (string-to-number col)))
       (find-file file)
@@ -113,12 +121,17 @@ See `guix-packages-profile'."
                     (guix-packages-profile profile generation system?)))
 
 ;;;###autoload
-(defun guix-edit (id-or-name)
-  "Edit (go to location of) package with ID-OR-NAME."
-  (interactive (list (guix-read-package-name)))
+(defun guix-edit (id-or-name &optional directory)
+  "Edit (go to location of) package with ID-OR-NAME.
+See `guix-find-location' for the meaning of package location and
+DIRECTORY.
+Interactively, with prefix argument, prompt for DIRECTORY."
+  (interactive
+   (list (guix-read-package-name)
+         (guix-read-directory)))
   (let ((loc (guix-package-location id-or-name)))
     (if loc
-        (guix-find-location loc)
+        (guix-find-location loc directory)
       (message "Couldn't find package location."))))
 
 
diff --git a/emacs/guix-ui-package.el b/emacs/guix-ui-package.el
index 0971fdd..ff10a1e 100644
--- a/emacs/guix-ui-package.el
+++ b/emacs/guix-ui-package.el
@@ -746,10 +746,11 @@ The specification is suitable for 
`guix-process-package-actions'."
   (let ((specs (guix-list-get-marked-args action-type)))
     (and specs (cons action-type specs))))
 
-(defun guix-package-list-edit ()
-  "Go to the location of the current package."
-  (interactive)
-  (guix-edit (guix-list-current-id)))
+(defun guix-package-list-edit (&optional directory)
+  "Go to the location of the current package.
+See `guix-find-location' for the meaning of DIRECTORY."
+  (interactive (list (guix-read-directory)))
+  (guix-edit (guix-list-current-id) directory))
 
 (defun guix-package-list-latest-builds (number &rest args)
   "Display latest NUMBER of Hydra builds of the current package.
@@ -906,11 +907,13 @@ See `guix-package-info-type'."
                  'id (cl-remove-duplicates pids))
        'add))))
 
-(defun guix-output-list-edit ()
-  "Go to the location of the current package."
-  (interactive)
+(defun guix-output-list-edit (&optional directory)
+  "Go to the location of the current package.
+See `guix-find-location' for the meaning of DIRECTORY."
+  (interactive (list (guix-read-directory)))
   (guix-edit (guix-entry-value (guix-list-current-entry)
-                               'package-id)))
+                               'package-id)
+             directory))
 
 
 ;;; Interactive commands



reply via email to

[Prev in Thread] Current Thread [Next in Thread]