Francisco Miguel Colaço
2018-05-06 19:04:27 UTC
Â I have one again written a library to segregate user configuration
files among different concerns --- data, config, runtime and cache ---
following the XDG user directory specification.Â I enclose the library.
Â From the commentary in user-directories/user-directories.el
;; Following the XDG Base Directory Specification
;; user-directories strives to allow a package writer or an Emacs user
;; to segregate the various Emacs configuration and runtime files into
;; appropriate directories.
;; Thus, following the specification, a configuration file (normally a
;; file that is written by the user or in behalf of him) will reside
;; in the configuration directory (normally ~/.config/emacs).Â It ca
;; be located with:
;;Â Â (locate-user-config-file "init.el")
;;Â Â "/home/fhc/.config/emacs/init.el"
;; Similarly, there are locator functions for third party files ---
;; `locate-user-data-file' --- and for cache files ---
;; `locate-user-cache-file'.Â Run time files, locatable with
;; `locate-user-runtime-files' will be erased at the last logout,
;; according to the specification, and are thus appropriate for
;; security-sensitive data.
;; There are also directories defined for :documents, :music, :videos,
;; :pictures and :downloads.Â In Linux, also other that the command
;; xdg-user-dir can reference, like :templates or :publicshare.
;; Locator functions are concomitantly created.Â For instance, in one
;; of my machines (Linux, portuguese):
;;Â Â (locate-user-documents-file "org/index.txt")
;;Â Â "/home/fhc/Documentos/org/index.txt"
;;Â Â (locate-user-pictures-file "image.png")
;;Â Â "/home/fhc/Imagens/image.png"
;; Emacs Lisp package writers may use the former functions to
;; segregate files among different concerns.Â For instance:
;;Â Â (setq abbrev-file-name (locate-user-config-file "abbrev_defs"))
;;Â Â (setq projectile-known-projects-file (locate-user-data-file
;;Â Â (setq projectile-cache-file (locate-user-cache-file
* HOW DO I INSTALL IT?
Â Just including the two directories in a site-lisp directory is enough
on my machine to recognize ~/.config/emacs/init.el and run it at the
Â Unfortunately, user-init-file will not be set, because I think it is
hardcoded in C from an array of possibilities.Â However,
user-emacs-directory is correctly set, and thus all the files that would
be in ~/.emacs.d will be located by default at the :data directory ---
and elisp package writers can start to put all created files to the
correct directories, according to their concerns.
* WHAT ABOUT FREEBSD, OSX, ETC?
Â Discovery is provided on Windows and Linux.Â The value at system-type
will determine which discovery provider is loaded.Â A value of gnu/linux
will load user-directories-linux.el and a value of windows-nt will load
Â If one wants to add a file named user-directories-darwin.el or
user-directories-kfreebsd.el, patterned after user-directories-linux.el
or user-directories-windows-nt.el, then the directories for the two
systems would be correctly discovered.Â As a cavaet emptor, I haven't
tested any windows-nt discovery, since I do not use Emacs on Windows.Â
If the value system-type has no file to provide discoveries, all the
:data, :cache, :runtime and :config directories will be created, but
this time inside user-emacs-directory.
Â I have assigned the copyright to the Free Software Foundation.
* WHAT CAN STILL BE DONE?
Â - user-directories/user-directories-darwin.el;
Â - user-directories/user-directories-kfreebsd.el;
Â - improve setup-user-directories-default, if the layout specified at
that function is not sensible
Â - make user-init-file writable during initialisation --- while one
loads the XDG file, and tries to set user-init-file at
user-directories-init.el, the value reverts to ~/.emacs for no reason.Â
Help needed here.
Â Thanks for your time.
Â Â Â Best wishes,
Â Â Â Â Â Francisco ColaÃ§o