rsnodgrass / emacs-xdg

XDG Base Directory Specification for Emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XDG Base Directory Support for Emacs

beta_badge

Defines variables that conform to the XDG Base Directory Specification that can be used in emacs for configuration.

This makes it convenient to configure various settings to use the XDG standard directories to avoid polluting the user's home directory.

Examples:

;; specify where MELPA/ELPA package installations go in XDG style config dir
(setq package-user-dir (expand-file-name "elpa" xdg-cache-emacs))

;; Prevent undo tree files from polluting the filesystem (use XDG_STATE_HOME)
(setq undo-tree-history-directory-alist
      '(("." . (expand-file-name "undo" xdg-state-emacs))))

This should be included very early in init.el or early-init.el so that later configuration can use this:

(use-package xdg :ensure t)

The following XDG globals are defined:

emacs var ENV var Default (per spec) Default (MacOS) Default (Windows)
xdg-cache-home XDG_CACHE_HOME ~/.cache/
xdg-config-home XDG_CONFIG_HOME ~/.config/
xdg-data-home XDG_DATA_HOME ~/.local/share/
xdg-state-home XDG_STATE_HOME ~/.local/state/
xdg-desktop-dir XDG_DESKTOP_DIR ~/Desktop
xdg-download-dir XDG_DOWNLOAD_DIR ~/Downloads

Plus additional emacs specific subdir:

emacs var Notes
xdg-cache-emacs 'emacs' dir under xdg-cache-home
xdg-config-emacs 'emacs' dir under xdg-config-home
xdg-data-emacs 'emacs' dir under xdg-data-home
xdg-state-emacs 'emacs' dir under xdg-state-home

NOTE: This only works for Linux and MacOS currently. Windows is not supported.

See Also

About

XDG Base Directory Specification for Emacs

License:MIT License


Languages

Language:Emacs Lisp 100.0%