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

View File

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