From 0111d16547d730fda81374714267775b06897501 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Sat, 15 Sep 2018 00:02:45 +0300 Subject: [PATCH] elisp: Add and use 'guix-file-name' Various Guix (Guile) procedures are sensitive to "non-expanded" file names and to trailing slashes in directory names, so 'directory-file-name' and 'expand-file-name' are called here and there. Make a single function to fix it once and for all. * elisp/guix-utils.el (guix-file-name): New function. * elisp/guix-hash.el (guix-hash): Use it. * elisp/guix-profiles.el (guix-profile): Use it. * elisp/guix-misc.el (guix-apply-manifest): Use it. * elisp/guix-repl.el (guix-repl-guile-args): Use it. * elisp/guix-ui.el (guix-ui-buffer-name-short): Use it. * elisp/guix-ui-profile.el (guix-profiles): Use it. * elisp/guix-ui-generation.el (guix-generation-packages-buffer-name-default): Use it. --- elisp/guix-hash.el | 4 ++-- elisp/guix-misc.el | 4 ++-- elisp/guix-profiles.el | 2 +- elisp/guix-repl.el | 4 ++-- elisp/guix-ui-generation.el | 2 +- elisp/guix-ui-profile.el | 2 +- elisp/guix-ui.el | 2 +- elisp/guix-utils.el | 4 ++++ 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/elisp/guix-hash.el b/elisp/guix-hash.el index b525f90..3e9d94b 100644 --- a/elisp/guix-hash.el +++ b/elisp/guix-hash.el @@ -48,7 +48,7 @@ See also Info node `(guix) Invoking guix hash'." (list (guix-read-file-name-maybe) (and current-prefix-arg (guix-read-hash-format)))) - (let* ((file (expand-file-name file)) + (let* ((file (guix-file-name file)) (args (list :format (or format guix-default-hash-format))) (args (if (file-directory-p file) (append '(:recursive? t) args) @@ -58,7 +58,7 @@ See also Info node `(guix) Invoking guix hash'." 'file-hash file args)))) (kill-new hash) (message "Hash of \"%s\" (%s) has been added to the kill ring." - (file-name-nondirectory (directory-file-name file)) + (file-name-nondirectory file) hash))) (provide 'guix-hash) diff --git a/elisp/guix-misc.el b/elisp/guix-misc.el index 8c461e6..4071a35 100644 --- a/elisp/guix-misc.el +++ b/elisp/guix-misc.el @@ -183,8 +183,8 @@ FILE. With a prefix argument, also prompt for PROFILE." (guix-make-guile-expression 'guix-command "package" - (concat "--profile=" (expand-file-name profile)) - (concat "--manifest=" (expand-file-name file))) + (concat "--profile=" (guix-file-name profile)) + (concat "--manifest=" (guix-file-name file))) operation-buffer))) (defcustom guix-search-paths-buffer-name "*Guix Search Paths*" diff --git a/elisp/guix-profiles.el b/elisp/guix-profiles.el index 1cd79a9..37810c0 100644 --- a/elisp/guix-profiles.el +++ b/elisp/guix-profiles.el @@ -112,7 +112,7 @@ have a trailing slash and it is `guix-default-profile' if PROFILE is `guix-user-profile'. `guix-user-profile' is special because it is actually a symlink to a real user profile, and the HOME directory does not contain profile generations." - (let ((profile (directory-file-name (expand-file-name profile)))) + (let ((profile (guix-file-name profile))) (if (string= profile guix-user-profile) guix-default-profile profile))) diff --git a/elisp/guix-repl.el b/elisp/guix-repl.el index 26548fc..cb0268a 100644 --- a/elisp/guix-repl.el +++ b/elisp/guix-repl.el @@ -225,8 +225,8 @@ See `guix-emacs-activate-after-operation' for details." (lcp (if guix-load-compiled-path (guix-list-maybe guix-load-compiled-path) lp))) - (append (--mapcat (list "-L" (expand-file-name it)) lp) - (--mapcat (list "-C" (expand-file-name it)) lcp)))) + (append (--mapcat (list "-L" (guix-file-name it)) lp) + (--mapcat (list "-C" (guix-file-name it)) lcp)))) "-L" ,guix-scheme-directory ,@(and guix-config-scheme-compiled-directory (list "-C" guix-config-scheme-compiled-directory)) diff --git a/elisp/guix-ui-generation.el b/elisp/guix-ui-generation.el index aaeae31..436b067 100644 --- a/elisp/guix-ui-generation.el +++ b/elisp/guix-ui-generation.el @@ -491,7 +491,7 @@ and its store file name." (defun guix-generation-packages-buffer-name-default (profile generation) "Return name of a buffer for displaying GENERATION's package outputs. Use base name of PROFILE file name." - (let ((profile-name (file-name-base (directory-file-name profile)))) + (let ((profile-name (file-name-base (guix-file-name profile)))) (format "*Guix %s: generation %s*" profile-name generation))) diff --git a/elisp/guix-ui-profile.el b/elisp/guix-ui-profile.el index 02b489e..419dce8 100644 --- a/elisp/guix-ui-profile.el +++ b/elisp/guix-ui-profile.el @@ -49,7 +49,7 @@ guix-system-profile guix-pulled-profile (--when-let (getenv "GUIX_PROFILE") - (expand-file-name it))))) + (guix-file-name it))))) "List of profiles displayed by '\\[guix-profiles]' command." :type '(repeat file) :group 'guix-profile) diff --git a/elisp/guix-ui.el b/elisp/guix-ui.el index 3d2f6be..23993e6 100644 --- a/elisp/guix-ui.el +++ b/elisp/guix-ui.el @@ -109,7 +109,7 @@ The function is called with 2 arguments: BASE-NAME and PROFILE." (defun guix-ui-buffer-name-short (base-name profile) "Return buffer name by appending BASE-NAME and PROFILE's base file name." (guix-compose-buffer-name base-name - (file-name-base (directory-file-name profile)))) + (file-name-base (guix-file-name profile)))) (defun guix-ui-buffer-name-full (base-name profile) "Return buffer name by appending BASE-NAME and PROFILE's full name." diff --git a/elisp/guix-utils.el b/elisp/guix-utils.el index 14b8d37..9109741 100644 --- a/elisp/guix-utils.el +++ b/elisp/guix-utils.el @@ -289,6 +289,10 @@ If nil, always prompt for a file name." :type 'boolean :group 'guix) +(defun guix-file-name (file-name) + "Expand FILE-NAME and remove trailing slash if needed." + (directory-file-name (expand-file-name file-name))) + (defun guix-read-file-name (&optional prompt dir default-filename mustmatch initial predicate) "Read file name.