Update xdg-paths.el to conform with the linter

This commit is contained in:
Gergely Polonkai 2020-10-16 15:50:37 +02:00
parent 4001fb3180
commit fe33e00f82
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
1 changed files with 37 additions and 38 deletions

View File

@ -40,7 +40,7 @@
;;; user-documents-directory ~/Documents
;;;
;;; Some convenience functions are defined to locate files in these
;;; directories and to add user lisp to load-path.
;;; directories and to add user Lisp to load-path.
;;;
;;; Some advantages are:
;;;
@ -114,28 +114,28 @@
;;; Code:
(eval-when-compile
(require 'cl))
(require 'cl-lib))
;;; Directories definition.
(defvar user-emacs-config-directory nil
"The directory where the emacs user configuration files are stored at.")
"The directory where the Emacs user configuration files are stored at.")
(defvar user-emacs-data-directory nil
"The directory where the emacs user data and lisp files are stored at.
"The directory where the Emacs user data and Lisp files are stored at.
\\[user-emacs-directory] is set to this directory.")
(defvar user-emacs-cache-directory nil
"The directory where the emacs user expendable files are stored at.
"The directory where the Emacs user expendable files are stored at.
Files stored here should not be missed when deleted, apart a
temporary loss in speed.")
(defvar user-emacs-lisp-directory nil
"The directory where the user lisp packages are stored at.
"The directory where the user Lisp packages are stored at.
This directory is added to \\[load-path].")
@ -146,72 +146,73 @@ This directory is added to \\[load-path].")
(defun xdg-user-dir (dirname)
"Given NAME, run 'xdg-user-dir NAME' and return the result in a string.
"Given DIRNAME, run 'xdg-user-dir DIRNAME' and return the result in a string.
If the command fails, return NIL."
(let ((command (concat "xdg-user-dir " dirname)))
(if (zerop (shell-command command))
(substring (shell-command-to-string command) 0 -1)
(substring (shell-command-to-string command) 0 -1)
nil)))
(defun locate-user-file (filename &optional type)
"Given a file, locate it in the user files.
"Given a file FILENAME, locate it in the user files.
If TYPE is NIL or 'data, the file will be located in user-emacs-data-directory.
If 'config, it will be located in user-emacs-config-directory.
If `config', it will be located in user-emacs-config-directory.
If 'cache, it will be located in user-emacs-cache-directory.
If `cache', it will be located in user-emacs-cache-directory.
If 'lisp, it will be located in user-emacs-lisp-directory.
If `lisp', it will be located in user-emacs-lisp-directory.
If 'documents, it will be located in user-documents-directory.
If `documents', it will be located in user-documents-directory.
If the category is wrong, an error will be signaled.
"
If the category is wrong, an error will be signaled."
(expand-file-name filename
(case type
((nil data) user-emacs-data-directory)
('config user-emacs-config-directory)
('lisp user-emacs-lisp-directory)
('cache user-emacs-cache-directory)
('documents user-documents-directory)
(t (error "The category %s is not valid" type)))))
(cond
((or (not type) (eq type 'data)) user-emacs-data-directory)
((eq type 'config) user-emacs-config-directory)
((eq type 'lisp) user-emacs-lisp-directory)
((eq type 'cache) user-emacs-cache-directory)
((eq type 'documents) user-documents-directory)
(t (error "The category %s is not valid" type)))))
(defun locate-user-config-file (filename)
"Given a file, locate it in `user-emacs-config-directory`."
"Given a file FILENAME, locate it in `user-emacs-config-directory`."
(locate-user-file filename 'config))
(defun locate-user-lisp (filename)
"Given a file, locate it in `user-emacs-lisp-directory`."
"Given a file FILENAME, locate it in `user-emacs-lisp-directory`."
(locate-user-file filename 'lisp))
(defun add-to-path (directory &optional append)
"Given DIRECTORY, it it exists and is indeed a directory, add
it to `load-path`."
"Given DIRECTORY, it it exists and is a directory, add it to `load-path`.
APPEND is passed verbatim to `add-to-list'."
(interactive "D")
(if (file-directory-p directory)
(add-to-list 'load-path directory append)
(error "The directory \"%s\" does not exist or isn't a directory." directory)))
(error "The directory \"%s\" does not exist or isn't a directory" directory)))
(defun add-user-lisp-to-path (directory &optional append)
"Given DIRECTORY, it it exists and is indeed a directory, add
it to `load-path`."
"Given DIRECTORY, if it exists and is a directory, add it to `load-path`.
APPEND is passed directly to `add-to-path'."
(interactive "D")
(add-to-path (locate-user-lisp directory) append))
;; Set the default variables if they have no name.
(macrolet ((setq-if-null (variable value)
`(if (null ,variable)
(setf ,variable ,value)))
(getdir (variable fallback)
`(expand-file-name "emacs/" (or (getenv ,variable) ,fallback))))
(cl-macrolet ((setq-if-null (variable value)
`(if (null ,variable)
(setf ,variable ,value)))
(getdir (variable fallback)
`(expand-file-name "emacs/" (or (getenv ,variable) ,fallback))))
(setq-if-null user-emacs-config-directory (getdir "XDG_CONFIG_HOME" "~/.config/"))
(setq-if-null user-emacs-data-directory (getdir "XDG_DATA_HOME" "~/.local/share/"))
(setq-if-null user-emacs-cache-directory (getdir "XDG_CACHE_HOME" "~/.cache/"))
@ -219,12 +220,10 @@ it to `load-path`."
(setq-if-null user-documents-directory (or (xdg-user-dir "DOCUMENTS") "~/Documents")))
;; Set the user-emacs-directory to user-emacs-data-directory.
;(setf user-emacs-directory user-emacs-data-directory)
;; Add the user lisp directory to path.
(add-to-list 'load-path user-emacs-lisp-directory)
(provide 'xdg-paths)
;;; xdg-paths.el ends here