From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Oteiza Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Add XDG utility library Date: Wed, 1 Feb 2017 07:17:02 -0500 Message-ID: <20170201121702.GB997@holos.localdomain> References: <20170201002606.GA4224@holos.localdomain> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1485953176 4490 195.159.176.226 (1 Feb 2017 12:46:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Feb 2017 12:46:16 +0000 (UTC) User-Agent: Mutt/1.7.2+27 (e4ad1dc9bfbd) (2016-11-26) Cc: emacs-devel@gnu.org To: Philipp Stephani Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 01 13:46:10 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 1cYuIb-0000kr-38 for ged-emacs-devel@m.gmane.org; Wed, 01 Feb 2017 13:46:09 +0100 Original-Received: from localhost ([::1]:50390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYuIe-0007EL-O5 for ged-emacs-devel@m.gmane.org; Wed, 01 Feb 2017 07:46:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYtqX-0004KE-9K for emacs-devel@gnu.org; Wed, 01 Feb 2017 07:17:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYtqT-0004yl-5U for emacs-devel@gnu.org; Wed, 01 Feb 2017 07:17:09 -0500 Original-Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:36635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cYtqT-0004yd-0U for emacs-devel@gnu.org; Wed, 01 Feb 2017 07:17:05 -0500 Original-Received: by mail-qt0-x243.google.com with SMTP id h53so27372563qth.3 for ; Wed, 01 Feb 2017 04:17:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=udel-edu.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1LqFmkJRBWsymmACBsmxCJKNtRMNCI3epT41q9+Nhbg=; b=Fdu7YpZFZXUJdfhNvMYellPKwhkwhAMDOpKBE9SZd89+E3oKtV93Kkno+VaGnx6meG mJVucQc6g5FLOboDU8obMtmNtYINNc8GEmixrb5ySCIvkMk1Q8IqEtZAQjMAFJg/wm0Y yg/BfvWFQHiWuUnqvKGYBYcFlTB2SDTHfFivNsXOsADmUVk/SiYK+Bm0XFjMLi8PFczR 5JRLD/fHAnYJJgkcykpJGM/G/QrBKnIV1rRYITD/lhO4VKEq8BnKfH+UsEXuHXAaGixH fO03QmIey05v1AWTR590uM4LYH5fqlAAL7ksPtSvzqw1RqtT6e+WTUf3cU/PoXMtV6lv JC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1LqFmkJRBWsymmACBsmxCJKNtRMNCI3epT41q9+Nhbg=; b=LoosZnGDTvV1MGYQ0/xhOiDm+WVyxO6S29cWhKfXWLybacHzFVv0O/QLLL2Cj9EDZo HM2x9nLojoHirK2zG1ruix+XQnU31VrUYTzSQQ6w9HhClDdmJb4x3h3pDLmxYLrDq7iG DeiZ/uKzLP/DZkXbzT6VMpHM+awzWPZeKhQBKmY7RYdkUFUH99gpraQMRYzxI+GG9zTQ bBIyfHGYXTCACKyRiBMjr+rIxH1TsiEKrpJT2BB6tmMmodzqoHVNE3Dnk1U+/dWGzlh0 ssF5fp4hdFLsV6Rrf8RUvMPHa3HG0DGRHRBpkId/bCFUpGcmKC0wihMHKrK9fvrFCn3p YjCg== X-Gm-Message-State: AIkVDXJA5lRhpfbIs8PB5x8a/IUoa4TjP74AT105wM5DoAzoh3DhDSn7SLah5lvmKTfFRg1F X-Received: by 10.200.39.200 with SMTP id x8mr2214457qtx.159.1485951424443; Wed, 01 Feb 2017 04:17:04 -0800 (PST) Original-Received: from holos.localdomain (pool-173-67-40-97.bltmmd.fios.verizon.net. [173.67.40.97]) by smtp.gmail.com with ESMTPSA id 11sm18379428qke.38.2017.02.01.04.17.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Feb 2017 04:17:03 -0800 (PST) Original-Received: by holos.localdomain (Postfix, from userid 1000) id 0AB4A60D6A; Wed, 1 Feb 2017 07:17:03 -0500 (EST) Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c0d::243 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:211838 Archived-At: On 01/02/17 at 11:24am, Philipp Stephani wrote: > 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. Then it's not valid. There's no point in depending on a binary for this. https://cgit.freedesktop.org/xdg/xdg-user-dirs/tree/xdg-user-dir-lookup.c