From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Add XDG utility library Date: Wed, 01 Feb 2017 11:24:03 +0000 Message-ID: References: <20170201002606.GA4224@holos.localdomain> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113e3028da9d7405477649a0 X-Trace: blaine.gmane.org 1485948264 14647 195.159.176.226 (1 Feb 2017 11:24:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Feb 2017 11:24:24 +0000 (UTC) To: Mark Oteiza , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 01 12:24:19 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cYt1O-0003Zp-FL for ged-emacs-devel@m.gmane.org; Wed, 01 Feb 2017 12:24:18 +0100 Original-Received: from localhost ([::1]:49983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYt1T-0003k2-Us for ged-emacs-devel@m.gmane.org; Wed, 01 Feb 2017 06:24:23 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYt1M-0003jk-IV for emacs-devel@gnu.org; Wed, 01 Feb 2017 06:24:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYt1L-00089V-5r for emacs-devel@gnu.org; Wed, 01 Feb 2017 06:24:16 -0500 Original-Received: from mail-ot0-x229.google.com ([2607:f8b0:4003:c0f::229]:35999) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cYt1K-00089Q-Vr for emacs-devel@gnu.org; Wed, 01 Feb 2017 06:24:15 -0500 Original-Received: by mail-ot0-x229.google.com with SMTP id 32so129027569oth.3 for ; Wed, 01 Feb 2017 03:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=s666/fjFh+pfnNZtPmwEVLU9MgUC18/0VltM4P/WF3E=; b=EPOrjk9Ma3UNfRxGETJST6pG4hlZvMzn15HBG34Ijrs5vU5FwQJjTaCT1NDkkZUYah wwAwBeGkFog3+4QO3OQ3UiOnakKU9wRp2H1I3IXP4Bjkj87xGhERMzUDU+UzIVHZfO+4 jvX7jcilmhyLwMkJ3MzcFR04U+v13TWIpOF5+FbiG3jLFe3duzZdO/Z1iTx82V6ng8hn TutgpSIvM0JOV/suXjSoCo9+W6rBsqbzmvf1yP80hswqyTKtpVdQX4Uz9ZZC7/3meZUR 3bpiUIwBV4P+kqYIG6VI2KVMbeCc9P1pMoBmH1hIT73viUkXpskQWMavp3nbAqCZOiG1 wC3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=s666/fjFh+pfnNZtPmwEVLU9MgUC18/0VltM4P/WF3E=; b=QOqa2MyzVPpML0NRH54MIDk6G8hk3huwbtprH4GTZWpgvf4w72Ndwls9G6tIwd2W4+ bHchpNAUQywsG7z3x8O2Eu6H6/nZTTkCxitCSj2skYBjM7qoHLLfZIe56EbDuhAVhgh5 qkPws8W533r7kgZjJUL6Q5YbvZv5JPYe6SLzx8Tp3Ktoq0Rouf5gA/+2HTZTSzcacbyq 437MnGwpMa0mc+fvknXfX5GreFmiXOuJVujaFmAZ6ybQAgbxX7GowGThn1g1JZFSkymx XyE4m9Q8Wtc0SzkpXba9RZoUQhOXTl1GotlXzm59rS0Ar6f7s1VkgrLi9DMZyJjHG4VF IeQw== X-Gm-Message-State: AMke39mk4+jSIkU8fuxI6QowPc+K05qQ45Xd/4kIpX2OJ5X6nORQNd8GA1+LfioC444qaQEF/BDCKqQVdPYUyg== X-Received: by 10.157.37.99 with SMTP id j32mr1194807otd.232.1485948254328; Wed, 01 Feb 2017 03:24:14 -0800 (PST) In-Reply-To: <20170201002606.GA4224@holos.localdomain> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c0f::229 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211836 Archived-At: --001a113e3028da9d7405477649a0 Content-Type: text/plain; charset=UTF-8 Mark Oteiza schrieb am Mi., 1. Feb. 2017 um 01:28 Uhr: > > +;; XDG User Directories > +;; https://www.freedesktop.org/wiki/Software/xdg-user-dirs/ > + > +(defconst xdg-line-regexp > + (eval-when-compile > + (rx "XDG_" > + (group-n 1 (or "DESKTOP" "DOWNLOAD" "TEMPLATES" "PUBLICSHARE" > + "DOCUMENTS" "MUSIC" "PICTURES" "VIDEOS")) > + "_DIR=\"" > + (group-n 2 (or "/" "$HOME/") (*? (or (not (any "\"")) "\\\""))) > + "\"")) > + "Regexp matching non-comment lines in xdg-user-dirs config files.") > + > +(defvar xdg-user-dirs nil > + "Alist of directory keys and values.") > + > +(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." > + (skip-chars-forward "[:blank:]") > + (when (and (/= (following-char) ?#) > + (looking-at xdg-line-regexp)) > + (let ((k (match-string 1)) > + (v (match-string 2))) > + (when (and k v) (cons k v))))) > + > +(defun xdg--user-dirs-parse-file (filename) > + "Return alist of xdg-user-dirs from FILENAME." > + (let (elt res) > + (with-temp-buffer > + (insert-file-contents filename) > + (goto-char (point-min)) > + (while (not (eobp)) > + (setq elt (xdg--user-dirs-parse-line)) > + (when (consp elt) (push elt res)) > + (forward-line))) > + res)) > + > +(defun xdg-user-dir (name) > + "Return the path of user directory referred to by NAME." > + (when (null xdg-user-dirs) > + (setq xdg-user-dirs > + (xdg--user-dirs-parse-file > + (expand-file-name "user-dirs.dirs" (xdg-config-home))))) > + (cdr (assoc name xdg-user-dirs))) > This parsing seems a bit brittle (what if the file contains ${HOME} instead of $HOME?); probably this should call the xdg-user-dir program instead. --001a113e3028da9d7405477649a0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


Mark O= teiza <mvoteiza@udel.edu> sc= hrieb am Mi., 1. Feb. 2017 um 01:28=C2=A0Uhr:

+;; 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)))

This parsing seems a bit brittle (what if = the file contains ${HOME} instead of $HOME?); probably this should call the= xdg-user-dir program instead.
--001a113e3028da9d7405477649a0--