emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 4c1d7ac: Substitute leading $HOME/ in xdg-user-dirs


From: Mark Oteiza
Subject: [Emacs-diffs] master 4c1d7ac: Substitute leading $HOME/ in xdg-user-dirs
Date: Sun, 12 Feb 2017 20:33:06 -0500 (EST)

branch: master
commit 4c1d7acf81a4dcec97fa4daf9e9f414e1321bfdb
Author: Mark Oteiza <address@hidden>
Commit: Mark Oteiza <address@hidden>

    Substitute leading $HOME/ in xdg-user-dirs
    
    * lisp/xdg.el (xdg--substitute-home-env): New function.
    (xdg--user-dirs-parse-line): Use it.
    (xdg-user-dir): Expand ~/ in xdg-user-dirs values.
---
 lisp/xdg.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/xdg.el b/lisp/xdg.el
index b11e104..4973065 100644
--- a/lisp/xdg.el
+++ b/lisp/xdg.el
@@ -109,6 +109,12 @@ file:///foo/bar.jpg"
 (defvar xdg-user-dirs nil
   "Alist of directory keys and values.")
 
+(defun xdg--substitute-home-env (str)
+  (if (file-name-absolute-p str) str
+    (save-match-data
+      (and (string-match "^$HOME/" str)
+           (replace-match "~/" t nil str 0)))))
+
 (defun xdg--user-dirs-parse-line ()
   "Return pair of user-dirs key to directory value in LINE, otherwise nil.
 This should be called at the beginning of a line."
@@ -117,7 +123,7 @@ This should be called at the beginning of a line."
              (looking-at xdg-line-regexp))
     (let ((k (match-string 1))
           (v (match-string 2)))
-      (when (and k v) (cons k v)))))
+      (when (and k v) (cons k (xdg--substitute-home-env v))))))
 
 (defun xdg--user-dirs-parse-file (filename)
   "Return alist of xdg-user-dirs from FILENAME."
@@ -137,7 +143,8 @@ This should be called at the beginning of a line."
     (setq xdg-user-dirs
           (xdg--user-dirs-parse-file
            (expand-file-name "user-dirs.dirs" (xdg-config-home)))))
-  (cdr (assoc name xdg-user-dirs)))
+  (let ((dir (cdr (assoc name xdg-user-dirs))))
+    (when dir (expand-file-name dir))))
 
 (provide 'xdg)
 



reply via email to

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