diff --git a/doc/emacs-guix.texi b/doc/emacs-guix.texi index 8a54edc..1c61d53 100644 --- a/doc/emacs-guix.texi +++ b/doc/emacs-guix.texi @@ -501,24 +501,6 @@ complete a package name. @end table -@vindex guix-directory -If you are contributing to Guix, you may find it useful for -@kbd{M-x@tie{}guix-find-package-location-file} and -@kbd{M-x@tie{}guix-find-package-definition} to open locations from -your Git checkout. This can be done by setting @code{guix-directory} -variable. For example, after this: - -@example -(setq guix-directory "~/src/guix") -@end example - -@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@tie{}guix-find-package-location-file} or -@kbd{M-x@tie{}guix-edit} command. - @vindex guix-read-package-name-function By default, when you should specify a package name (for example, after @kbd{M-x guix-edit}), you will be prompted for it in the minibuffer, diff --git a/elisp/guix-license.el b/elisp/guix-license.el index d51e1b1..50cbd2a 100644 --- a/elisp/guix-license.el +++ b/elisp/guix-license.el @@ -31,7 +31,7 @@ "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))) + (or directory (guix-directory)))) (defun guix-lookup-license-url (license) "Return URL of a LICENSE." diff --git a/elisp/guix-location.el b/elisp/guix-location.el index 8d41360..bbeff04 100644 --- a/elisp/guix-location.el +++ b/elisp/guix-location.el @@ -64,7 +64,7 @@ DIRECTORY (if it is specified and exists)." (cl-multiple-value-bind (file line column) (split-string location ":") (let* ((file-name (expand-file-name file (or directory - guix-directory))) + (guix-directory)))) (file-name (if (file-exists-p file-name) file-name (guix-eval-read diff --git a/elisp/guix-repl.el b/elisp/guix-repl.el index 9ba70c5..7897863 100644 --- a/elisp/guix-repl.el +++ b/elisp/guix-repl.el @@ -434,18 +434,30 @@ additional internal REPL if it exists." (defvar guix-directory nil "Default directory with Guix source. -If it is not set by a user, it is set after starting Guix REPL. + This directory is used to find packages and licenses by such commands as `guix-find-package-definition' or -`guix-find-license-definition'.") +`guix-find-license-definition'. + +Most likely you don't need to set this variable because it is set +automatically when needed. However, you can still set it if you +really want; your value will not be overwritten.") + +(defun guix-directory () + "Set if needed and return `guix-directory'." + (or guix-directory + (let* ((guix.scm (guix-eval-read "(%search-load-path \"guix\")")) + (dir (and guix.scm + (file-name-directory guix.scm)))) + (setq guix-directory dir)))) (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)) + (guix-directory)) + (guix-directory))) ;; XXX Remove `guix-latest-directory' in future: it exists for backward ;; compatibility (in the past "guix pull" populated