;;; acdw.el --- various meta-whatevers -*- lexical-binding: t -*- ;;; Commentary: ;; What's that saying about how the hardest things in computer science ;; are naming and off-by-one errors? Well, the naming one I know very ;; well. I've been trying to figure out a good way to prefix my ;; bespoke functions, other stuff I found online, and various emacs ;; lisp detritus for quite some time (I reckon at over a year, as of ;; 2021-11-02). Finally, I found the answer in the writings of Daniel ;; Mendler: I'll prefix everything with a `+' ! ;; To that end, pretty much everything in lisp/ will have a filename ;; like "+org.el", except of course this file, and maybe a few ;; /actually original/ libraries I haven't had the wherewithal to ;; package out properly yet. ;; Is it perfect? No. Is it fine? Yes. Here it is. ;;; Code: ;;; Define a directory and an expanding function (defmacro +define-dir (name directory &optional docstring inhibit-mkdir) "Define a variable and function NAME expanding to DIRECTORY. DOCSTRING is applied to the variable. Ensure DIRECTORY exists in the filesystem, unless INHIBIT-MKDIR is non-nil." (declare (indent 2)) (unless inhibit-mkdir (make-directory (eval directory) :parents)) `(progn (defvar ,name ,directory ,(concat docstring (when docstring "\n") "Defined by `/define-dir'.")) (defun ,name (file &optional mkdir) ,(concat "Expand FILE relative to variable `" (symbol-name name) "'.\n" "If MKDIR is non-nil, the directory is created.\n" "Defined by `/define-dir'.") (let ((file-name (expand-file-name (convert-standard-filename file) ,name))) (when mkdir (make-directory (file-name-directory file-name) :parents)) file-name)))) (provide 'acdw) ;;; acdw.el ends here