diff options
author | Mark Oteiza <mvoteiza@udel.edu> | 2017-02-12 20:25:57 -0500 |
---|---|---|
committer | Mark Oteiza <mvoteiza@udel.edu> | 2017-02-12 20:31:38 -0500 |
commit | 4c1d7acf81a4dcec97fa4daf9e9f414e1321bfdb (patch) | |
tree | 97d3a0f3be844664076735b6803e5e2f03029daf /lisp/xdg.el | |
parent | 01ebe5dc0b1c71191f6a713fec245a188d587772 (diff) | |
download | emacs-4c1d7acf81a4dcec97fa4daf9e9f414e1321bfdb.tar.gz emacs-4c1d7acf81a4dcec97fa4daf9e9f414e1321bfdb.tar.bz2 emacs-4c1d7acf81a4dcec97fa4daf9e9f414e1321bfdb.zip |
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.
Diffstat (limited to 'lisp/xdg.el')
-rw-r--r-- | lisp/xdg.el | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lisp/xdg.el b/lisp/xdg.el index b11e104e2b7..4973065f91a 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) |