diff options
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" | |||
| 109 | (defvar xdg-user-dirs nil | 109 | (defvar xdg-user-dirs nil |
| 110 | "Alist of directory keys and values.") | 110 | "Alist of directory keys and values.") |
| 111 | 111 | ||
| 112 | (defun xdg--substitute-home-env (str) | ||
| 113 | (if (file-name-absolute-p str) str | ||
| 114 | (save-match-data | ||
| 115 | (and (string-match "^$HOME/" str) | ||
| 116 | (replace-match "~/" t nil str 0))))) | ||
| 117 | |||
| 112 | (defun xdg--user-dirs-parse-line () | 118 | (defun xdg--user-dirs-parse-line () |
| 113 | "Return pair of user-dirs key to directory value in LINE, otherwise nil. | 119 | "Return pair of user-dirs key to directory value in LINE, otherwise nil. |
| 114 | This should be called at the beginning of a line." | 120 | This should be called at the beginning of a line." |
| @@ -117,7 +123,7 @@ This should be called at the beginning of a line." | |||
| 117 | (looking-at xdg-line-regexp)) | 123 | (looking-at xdg-line-regexp)) |
| 118 | (let ((k (match-string 1)) | 124 | (let ((k (match-string 1)) |
| 119 | (v (match-string 2))) | 125 | (v (match-string 2))) |
| 120 | (when (and k v) (cons k v))))) | 126 | (when (and k v) (cons k (xdg--substitute-home-env v)))))) |
| 121 | 127 | ||
| 122 | (defun xdg--user-dirs-parse-file (filename) | 128 | (defun xdg--user-dirs-parse-file (filename) |
| 123 | "Return alist of xdg-user-dirs from FILENAME." | 129 | "Return alist of xdg-user-dirs from FILENAME." |
| @@ -137,7 +143,8 @@ This should be called at the beginning of a line." | |||
| 137 | (setq xdg-user-dirs | 143 | (setq xdg-user-dirs |
| 138 | (xdg--user-dirs-parse-file | 144 | (xdg--user-dirs-parse-file |
| 139 | (expand-file-name "user-dirs.dirs" (xdg-config-home))))) | 145 | (expand-file-name "user-dirs.dirs" (xdg-config-home))))) |
| 140 | (cdr (assoc name xdg-user-dirs))) | 146 | (let ((dir (cdr (assoc name xdg-user-dirs)))) |
| 147 | (when dir (expand-file-name dir)))) | ||
| 141 | 148 | ||
| 142 | (provide 'xdg) | 149 | (provide 'xdg) |
| 143 | 150 | ||