From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.devel Subject: Re: xdg.el and eww custom load [Was: Re: Automatically set eww-download-directory according xdg dir] Date: Wed, 31 Oct 2018 12:41:45 +0000 Message-ID: <87pnvqp9ti.fsf@tcd.ie> References: <87woq0sf4a.fsf@portable.galex-713.eu> <87h8h4tblg.fsf@tcd.ie> <87va5km6h3.fsf_-_@portable.galex-713.eu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1540989602 15342 195.159.176.226 (31 Oct 2018 12:40:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 31 Oct 2018 12:40:02 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel To: "Garreau\, Alexandre" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 31 13:39:57 2018 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 1gHpmu-0003rR-K7 for ged-emacs-devel@m.gmane.org; Wed, 31 Oct 2018 13:39:56 +0100 Original-Received: from localhost ([::1]:59257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHpp1-0001nB-72 for ged-emacs-devel@m.gmane.org; Wed, 31 Oct 2018 08:42:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHpot-0001mr-Vz for emacs-devel@gnu.org; Wed, 31 Oct 2018 08:42:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHpon-0003ig-9f for emacs-devel@gnu.org; Wed, 31 Oct 2018 08:41:59 -0400 Original-Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:37010) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHpom-0003Zg-UL for emacs-devel@gnu.org; Wed, 31 Oct 2018 08:41:53 -0400 Original-Received: by mail-ed1-x536.google.com with SMTP id u12-v6so10604948eds.4 for ; Wed, 31 Oct 2018 05:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=gKuO7X3bgSK0nxSfda/QqDQw/XtaYD/gItb/ai+7KVY=; b=A4msn+fV4uGOQ2F+e5G1PGLtDOH7th+2V1MGyBTTFlLyeoU2ti/cJTlzSxy+F+HD8J RzFXQoM1LofHWyD8JisWS1A/h7TFbjNkNYEE2+4SuVGb7+/mLnsS1g6NkegdRDn4tkJj Hcw0WdBARq4r8htNjnN86btejDbFzeQUWokJFajkNSTveEB1t0ZoxjhJdFCa89mwhW4j W1p/HpaAPYw9YuZ+RQmnrLxuKYdNb6NcmXlVgwewycuM13NrsFDZ1+wmg2JCF099/Ym7 lMBBTKMlZ8y13kiI1pGAuQw21gl870xkSytS0msKI0cVKNXUpnB8I1o0jNEei1fJiZ7l jX+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=gKuO7X3bgSK0nxSfda/QqDQw/XtaYD/gItb/ai+7KVY=; b=DaG6R8KyfoZtMcagLeLcacunVRWlkOTzshVMkqCELKtwh55I3Y0iyhazPDYgf+JkD6 kGTCAJq9h4uLwI8m5FNSvTWfu+/QPKs6Z+7AcC9Q2AWC1647WC2WqHrKPkn/c/OPc0KS E1tAyuO8mo2R1c1ScXAhpuzK1PA8cjyMsUfsh2eP6KiL22hkUOQMVmyLvBfW/8S6l2yz DEvpnOfITN9vNT+wKSai+RGSjdP8xBR2REs+w8ZGRzageoVnGzHXOA+cUTE/Aa3bAAZ6 0137NthLKOAYR+6QlSmRtSylkbmPwLJK2YM9k3psG7qZAitI9olxXWsk1bD3IBcHfZuI eUCA== X-Gm-Message-State: AGRZ1gKiBQzZB2zWndVqHP2BkKuMiHoAS0d33dNlaizeII6XfNlfWXJ0 ZA7Rxy8zxhSvDLRQ6R3xHnG/oL+/RxE= X-Google-Smtp-Source: AJdET5eUd7hTqZizxTYa6XS+Ei3GDNnVz56AypYxTvXzR6b9k1vNeCyUlXMsylKj00WAe3YNFjTZ6g== X-Received: by 2002:a50:abc1:: with SMTP id u59-v6mr1791000edc.49.1540989707777; Wed, 31 Oct 2018 05:41:47 -0700 (PDT) Original-Received: from localhost (51-171-243-2-dynamic.agg2.clk.blp-srl.eircom.net. [51.171.243.2]) by smtp.gmail.com with ESMTPSA id b18-v6sm4796157eju.38.2018.10.31.05.41.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 05:41:47 -0700 (PDT) In-Reply-To: <87va5km6h3.fsf_-_@portable.galex-713.eu> (Garreau, Alexandre's message of "Tue, 30 Oct 2018 04:57:44 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::536 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:230870 Archived-At: "Garreau, Alexandre" writes: > On 2018/10/30 at 02:25, Basil L. Contovounesios wrote: >> I think the simplest (often too simple) way to synchronously get process >> output without using the shell is via the function process-lines: >> >> (car (process-lines "xdg-user-dir" "DOWNLOAD")) > > Oh I didn=E2=80=99t know it! It=E2=80=99s pretty handy and I don=E2=80= =99t understand why it > isn=E2=80=99t more advertised (though I can=E2=80=99t judge formally as I= forgot how I > learnt `call-process'). I wouldn=E2=80=99t have thought to it either (as= show > the other followup of my OP). It's documented along with call-process under (info "(elisp) Synchronous Processes"). >> "Garreau, Alexandre" writes: >>> Or should, instead, a xdg.el file be created where to put variables (or >>> functions) referring to correct (and up-to-date) names of XDG variables: >>> desktop, download, templates, publicshare, documents, music, pictures, >>> and videos, and maybe =E2=80=9Cxdg-settings get default-url-scheme-hand= ler=E2=80=9D. >>> Maybe among other xdg stuff, such as localization language, or=E2=80=A6= dunno >>> yet, but there must be things to get. >> >> FWIW, Emacs 26 includes the file lisp/xdg.el, which provides, amongst >> other things, the function xdg-user-dir: >> >> (require 'xdg) >> (xdg-user-dir "DOWNLOAD") > > Then that could be used (sorry to have forgotten the =E2=80=9Cor=E2=80=9D= first time, > anyway it wouldn=E2=80=99t have worked if the program wasn=E2=80=99t here= , as it would > have, as you said, =E2=80=9Ccaused other issues=E2=80=9D, while xdg-user-= dir returns nil > if no config file to read): > > #+BEGIN_SRC emacs-lisp > (defcustom eww-download-directory > (or (xdg-user-dir "DOWNLOAD") "~/Downloads/") > "Directory where files will downloaded." > :version "24.4" > :require 'xdg > :group 'eww > :type 'string) > #+END_SRC > > I find sad it doesn=E2=80=99t use the command xdg-user-dir per se, as I u= sually > prefer to always use the highest level interface, in case lower level > was changed. But, if a that much complete xdg implementation use that, > it must be as much standard=E2=80=A6 and anyway it saves time (which may = be not > that much important as it will lazily load it only once per session). The merits of parsing in Emacs vs delegating to an external tool were briefly discussed in the emacs-devel thread I linked below. > It is also sad it takes a (especially *uppercase*, yuck) string as an > argument, instead of a symbol. That=E2=80=99s lower-level and avoid furt= her > processing (be it `symbol-name', an assoc-list or raw strings), but > sound a lot less lispy to me: it=E2=80=99s like if xdg shell command synt= ax had > began to intrusivly delve into emacs lisp! I'm sure patches for more convenient APIs would be welcome. >> But you wouldn't want to use this to set the value of >> eww-download-directory in its defcustom declaration > > Why so? Simply loading a package should have as few effects and be as fast as possible. Think, for example, of loading eww.el for the purposes of testing on various environments both local and remote. I'm sure there are more serious dangers than I'm letting on. > otherwise it=E2=80=99s just broken and by default wrongly put downloaded > files in the wrong dir, might create it, or fail. Alternative approaches include and are not limited to using the built-in function xdg-user-dir and/or adding a new customisation type to the defcustom which asks for xdg-user-dir to be called when needed, rather than when eww.el is being loaded. >> as that would slow down or potentially cause other issues when loading >> eww.el. It would also need to handle the case where xdg-user-dir is >> not found in exec-path. > > Maybe then using the *variable* xdg-user-dirs: if `xdg-user-dir' already > have been called once, it will lazily use what it already stored in this > variable, instead of rereading, so the I/O will stay constant. That is the approach currently taken by the built-in function xdg-user-dir. > Maybe it should be loaded earlier in emacs startup? But I guess either > it is already the case, either it has been deemed too much for emacs > startup speed: then I guess lazily making eww one of the applications > that might trigger its first-time load in the session is acceptable, as > it is so to save emacs initial startup time. I think it will be hard to argue for a web browser to be preloaded. Even if it were preloaded, though, I don't see how that would solve the XDG issue. Don't forget that there's nothing stopping users from adding the following perfectly valid and reasonable customisation (or similar) to their configuration: (with-eval-after-load 'eww (setq eww-download-directory (file-name-as-directory (car (process-lines "xdg-user-dir" "DOWNLOAD"))))) > Or, rather, maybe there should exist some facilities in custom.el so > that xdg-user-dirs becomes a saved custom option, so it=E2=80=99s loaded = once at > first emacs startup and kept for further sessions: it may not be > up-to-date but it=E2=80=99d be faster, with no load overhead, and anyway = that > value isn=E2=80=99t meant to change much in time (however that might conf= use > some users if they ran emacs before to change their xdg dir settings). Again, I'm sure patches would be welcome. Don't forget, though, that XDG isn't universal. >> See also the following thread for some discussion of XDG support: >> https://lists.gnu.org/archive/html/emacs-devel/2018-05/msg00081.html > > Wow that=E2=80=99s awesome: replacing .emacs.d with something following x= dg (why > not .config/emacs/?) so to cleanse home, I=E2=80=99ve dreamt it (I also d= reamt > of an =E2=80=9Cexternal=E2=80=9D customization method for defcustom where= it would go > get its default or saved custom values from external non-elisp files > instead (or exteral programs), such as the xdg ones), but procrastinated > to suggest it. He did it. > > Strangly, the thread is about adding it to ELPA, but nowadays as you > tell it it is in mainline emacs 27, and not in ELPA: from the sources I > cloned, I tried to load it, and it worked out of the box, so it would > especially be useful in ELPA as it would right away provide it to older > emacsen (like mine, debian=E2=80=99s one). Just to be clear: the package proposed in that emacs-devel thread is different to the lisp/xdg.el library added to Emacs 26 core. --=20 Basil