[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

user-directory: New library to find user {conf,data,state,...} files

From: Stefan Kangas
Subject: user-directory: New library to find user {conf,data,state,...} files
Date: Fri, 5 Nov 2021 18:38:40 -0700

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> The only decision we need to make is whether we want a single function
>> that accepts an argument telling it the purpose of the standard
>> directory (in this case, I'd use 'PICTURES, a symbol), or maybe a
>> separate function for each kind of directory, like user-pictures-dir.
> I'd vote for a single defgeneric function.

I hacked something quick together and pushed it to
features/user-directory, mostly so that we can decide on the basic API.
It needs more work, but the interface should hopefully be clear.

The one I propose is:

    (user-directory 'cache)
    => "/home/skangas/.cache"

    (user-file 'cache "foo")
    => "/home/skangas/.cache/foo"

There's also a defcustom `user-directory-alist' for overrides:

    (let ((user-directory-alist '((downloads "/foo"))))
      (user-directory 'downloads))
    => "/foo"

I thought about having defuns like `user-directory-cache', which gives
us autocompletion, but I feel like the symbol approach is more
straightforward and means we can avoid code like this:

    (intern (concat "user-directory-" (symbol-name sym)))

This is implemented with a defgeneric, as suggested by Stefan Monnier
(thanks!), but we could easily convert it to regular defuns if we need
to preload it.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]