From 107eab7ef6311a5b5f9c85c179ae83b2e3204094 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 8 Jan 2023 18:19:04 -0600 Subject: myeahhhhhh --- lisp/acdw.el | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lisp/acdw.el (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el new file mode 100644 index 0000000..f16a679 --- /dev/null +++ b/lisp/acdw.el @@ -0,0 +1,39 @@ +;;; acdw.el --- My Emacs extras -*- lexical-binding: t; -*- + +;;; Code: + +(defmacro defdir (name directory &optional docstring makedir) + "Define a variable and a function NAME expanding to DIRECTORY. +DOCSTRING is applied to the variable; its default is DIRECTORY's +path. If MAKEDIR is non-nil, the directory and its parents will +be created." + (declare (indent 2) (doc-string 3)) + `(progn + (defvar ,name (expand-file-name ,directory) + ,(concat (or docstring (format "%s" directory)) "\n" + "Defined by `defdir'.")) + (defun ,name (file &optional mkdir) + ,(concat "Expand FILE relative to variable `" (symbol-name name) "'.\n" + "If MKDIR is non-nil, parent directories are created.\n" + "Defined by `defdir'.") + (let ((file-name (expand-file-name + (convert-standard-filename file) ,name))) + (when mkdir + (make-directory (file-name-directory file-name) :parents)) + file-name)) + ,(if makedir + `(make-directory ,directory :parents) + `(unless (file-exists-p ,directory) + (warn "Directory `%s' doesn't exist." ,directory))))) + +(defun choose-executable (&rest programs) + "Return the first of PROGRAMS that exists in the system's $PATH. +Each of PROGRAMS can be a single string, or a list. If it's a list then its car +will be tested with `executable-find', and the entire list returned. This +enables passing arguments to a calling function." + (seq-find (lambda (x) + (executable-find (car (ensure-list x)))) + programs)) + +(provide 'acdw) +;;; acdw.el ends here -- cgit 1.4.1-21-gabe81