bug#41030: [PATCH] Make EWW respect XDG download directory by default

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Philip K.
---
 lisp/net/eww.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index c83884fd25..0d0aa9f3bc 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -32,6 +32,7 @@
 (require 'thingatpt)
 (require 'mm-url)
 (require 'puny)
+(require 'xdg)
 (eval-when-compile (require 'subr-x)) ;; for string-trim
 
 (defgroup eww nil
@@ -55,7 +56,8 @@ eww-search-prefix
   :group 'eww
   :type 'string)
 
-(defcustom eww-download-directory "~/Downloads/"
+(defcustom eww-download-directory (or (xdg-user-dir "DOWNLOAD")
+                                      "~/Downloads/")
   "Directory where files will downloaded."
   :version "24.4"
   :group 'eww
--
2.20.1




Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Basil L. Contovounesios
severity 41030 wishlist
quit

Stefan Kangas <[hidden email]> writes:

> Philip K <[hidden email]> writes:
>
>> -(defcustom eww-download-directory "~/Downloads/"
>> +(defcustom eww-download-directory (or (xdg-user-dir "DOWNLOAD")
>> +                                      "~/Downloads/")
>
> This makes sense conceptually.  However, on my machine, evaluating
> (xdg-user-dir "DOWNLOAD") just returns $HOME.  That's a worse default
> than "~/Downloads/", no?
>
> But I don't know enough about the XDG standard to propose a solution.
> Nor do I know if this is because my setup is particularly unusual.

It sounds like it could be specific to your environment; have a look at
'man 1 xdg-user-dirs-update'.

> Lars, what do you think?

I'm not Lars, but there's some precedent for this feature.  In the
following thread that prompted the creation of xdg.el, Lars talked about
a general facility for determining the default download directory:

https://lists.gnu.org/archive/html/emacs-devel/2017-01/msg00607.html

In the following thread(s), using the external executable xdg-user-dirs
for eww-download-directory was discussed:

https://lists.gnu.org/archive/html/emacs-devel/2018-10/msg00599.html
https://lists.gnu.org/archive/html/emacs-devel/2018-11/msg00014.html

Some executive questions:

- Does it make sense and is it safe to eagerly load xdg.el on all
  platforms and call xdg-user-dir while eww.el is being loaded?  One
  alternative being to define a symbolic constant such as 'xdg for
  eww-download-directory that is translated to a call to xdg-user-dir on
  demand rather than up front.  This idea can be expanded to cover
  non-XDG systems.

- Should we wait until there's a general utility for this?

- What do we do when xdg-user-dir returns ~/ but ~/Downloads/ also
  exists, as in Stefan's case?  Consider it a user misconfiguration?

Thanks,

--
Basil



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Lars Ingebrigtsen
"Basil L. Contovounesios" <[hidden email]> writes:

> - What do we do when xdg-user-dir returns ~/ but ~/Downloads/ also
>   exists, as in Stefan's case?  Consider it a user misconfiguration?

I think that is ~/Downloads/ exists, it's a good hint that the user
wants to use ~/Downloads/, no matter what xdg-user-dir says.

Probably?

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Philip K.
Lars Ingebrigtsen <[hidden email]> writes:

> "Basil L. Contovounesios" <[hidden email]> writes:
>
>> - What do we do when xdg-user-dir returns ~/ but ~/Downloads/ also
>>   exists, as in Stefan's case?  Consider it a user misconfiguration?
>
> I think that is ~/Downloads/ exists, it's a good hint that the user
> wants to use ~/Downloads/, no matter what xdg-user-dir says.

So should it check for "~/Downloads/" first (and maybe perhaps a few
other popular directory names in other languages), and unless that
hasn't been found load xdg.el and call xdg-user-dir? In the worst case,
the user doesn't have a download directory and $HOME is actually where
they want their files to land.

--
        Philip K.



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Stefan Kangas
In reply to this post by Basil L. Contovounesios
"Basil L. Contovounesios" <[hidden email]> writes:

>>> -(defcustom eww-download-directory "~/Downloads/"
>>> +(defcustom eww-download-directory (or (xdg-user-dir "DOWNLOAD")
>>> +                                      "~/Downloads/")
>>
>> This makes sense conceptually.  However, on my machine, evaluating
>> (xdg-user-dir "DOWNLOAD") just returns $HOME.  That's a worse default
>> than "~/Downloads/", no?
>>
>> But I don't know enough about the XDG standard to propose a solution.
>> Nor do I know if this is because my setup is particularly unusual.
>
> It sounds like it could be specific to your environment; have a look at
> 'man 1 xdg-user-dirs-update'.

In my use-case, I don't think I have ever touched any of this stuff.
Not AFAIR, anyways.

So I wonder if the suggested code would mean to never use
"~/Downloads", since xdg-user-dir will always return something else?

Best regards,
Stefan Kangas



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Noam Postavsky
Stefan Kangas <[hidden email]> writes:

>> It sounds like it could be specific to your environment; have a look at
>> 'man 1 xdg-user-dirs-update'.
>
> In my use-case, I don't think I have ever touched any of this stuff.
> Not AFAIR, anyways.
>
> So I wonder if the suggested code would mean to never use
> "~/Downloads", since xdg-user-dir will always return something else?

I get nil from (xdg-user-dir "DOWNLOAD").  Looking at the code, I guess
you have something in ~/.config/user-dirs.dirs which causes this.



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Stefan Kangas
Noam Postavsky <[hidden email]> writes:

> I get nil from (xdg-user-dir "DOWNLOAD").  Looking at the code, I guess
> you have something in ~/.config/user-dirs.dirs which causes this.

Yup, that seems to be it.

I deleted the file, and now (xdg-user-dir "DOWNLOAD") returns nil as
it should.

Sorry about the noise.

Best regards,
Stefan Kangas



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Lars Ingebrigtsen
In reply to this post by Philip K.
[hidden email] (Philip K.) writes:

>> I think that is ~/Downloads/ exists, it's a good hint that the user
>> wants to use ~/Downloads/, no matter what xdg-user-dir says.
>
> So should it check for "~/Downloads/" first (and maybe perhaps a few
> other popular directory names in other languages), and unless that
> hasn't been found load xdg.el and call xdg-user-dir?

Yes, perhaps something like that.

But we don't want to do that checking at load time, I think?  And the
same goes for the call to xdg-user-dir -- that doesn't be done at load
time, either.

(And the patch isn't correct as is, either, because xdg-user-dir returns
the directory without a trailing slash.)

So perhaps eww-download-directory should default to a function that does
all this checking and calling?

Any opinions?

And... as far as I can see, xdg-user-dir isn't used anywhere else in
Emacs?  What's up with that?

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



Reply | Threaded
Open this post in threaded view
|

bug#41030: [PATCH] Make EWW respect XDG download directory by default

Lars Ingebrigtsen
Lars Ingebrigtsen <[hidden email]> writes:

> So perhaps eww-download-directory should default to a function that does
> all this checking and calling?

I've now done this in Emacs 28.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no