From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani
+;; XDG User Directories
+;; https://www.freedesk= top.org/wiki/Software/xdg-user-dirs/
+
+(defconst xdg-line-regexp
+=C2=A0 (eval-when-compile
+=C2=A0 =C2=A0 (rx "XDG_"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (group-n 1 (or "DESKTOP" "DOWNL= OAD" "TEMPLATES" "PUBLICSHARE"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0"DOCUMENTS" "MUSIC" "PICTURES" &quo= t;VIDEOS"))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 "_DIR=3D\""
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (group-n 2 (or "/" "$HOME/"= ;) (*? (or (not (any "\"")) "\\\"")))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 "\""))
+=C2=A0 "Regexp matching non-comment lines in xdg-user-dirs config fil= es.")
+
+(defvar xdg-user-dirs nil
+=C2=A0 "Alist of directory keys and values.")
+
+(defun xdg--user-dirs-parse-line ()
+=C2=A0 "Return pair of user-dirs key to directory value in LINE, othe= rwise nil.
+This should be called at the beginning of a line."
+=C2=A0 (skip-chars-forward "[:blank:]")
+=C2=A0 (when (and (/=3D (following-char) ?#)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(looking-at xdg-line-regex= p))
+=C2=A0 =C2=A0 (let ((k (match-string 1))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (v (match-string 2)))
+=C2=A0 =C2=A0 =C2=A0 (when (and k v) (cons k v)))))
+
+(defun xdg--user-dirs-parse-file (filename)
+=C2=A0 "Return alist of xdg-user-dirs from FILENAME."
+=C2=A0 (let (elt res)
+=C2=A0 =C2=A0 (with-temp-buffer
+=C2=A0 =C2=A0 =C2=A0 (insert-file-contents filename)
+=C2=A0 =C2=A0 =C2=A0 (goto-char (point-min))
+=C2=A0 =C2=A0 =C2=A0 (while (not (eobp))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq elt (xdg--user-dirs-parse-line))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (consp elt) (push elt res))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (forward-line)))
+=C2=A0 =C2=A0 res))
+
+(defun xdg-user-dir (name)
+=C2=A0 "Return the path of user directory referred to by NAME."<= br class=3D"gmail_msg"> +=C2=A0 (when (null xdg-user-dirs)
+=C2=A0 =C2=A0 (setq xdg-user-dirs
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (xdg--user-dirs-parse-file
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(expand-file-name "user-dirs= .dirs" (xdg-config-home)))))
+=C2=A0 (cdr (assoc name xdg-user-dirs)))