diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/acdw.el | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ | |||
1 | ;;; acdw.el --- My Emacs extras -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | (defmacro defdir (name directory &optional docstring makedir) | ||
6 | "Define a variable and a function NAME expanding to DIRECTORY. | ||
7 | DOCSTRING is applied to the variable; its default is DIRECTORY's | ||
8 | path. If MAKEDIR is non-nil, the directory and its parents will | ||
9 | be created." | ||
10 | (declare (indent 2) (doc-string 3)) | ||
11 | `(progn | ||
12 | (defvar ,name (expand-file-name ,directory) | ||
13 | ,(concat (or docstring (format "%s" directory)) "\n" | ||
14 | "Defined by `defdir'.")) | ||
15 | (defun ,name (file &optional mkdir) | ||
16 | ,(concat "Expand FILE relative to variable `" (symbol-name name) "'.\n" | ||
17 | "If MKDIR is non-nil, parent directories are created.\n" | ||
18 | "Defined by `defdir'.") | ||
19 | (let ((file-name (expand-file-name | ||
20 | (convert-standard-filename file) ,name))) | ||
21 | (when mkdir | ||
22 | (make-directory (file-name-directory file-name) :parents)) | ||
23 | file-name)) | ||
24 | ,(if makedir | ||
25 | `(make-directory ,directory :parents) | ||
26 | `(unless (file-exists-p ,directory) | ||
27 | (warn "Directory `%s' doesn't exist." ,directory))))) | ||
28 | |||
29 | (defun choose-executable (&rest programs) | ||
30 | "Return the first of PROGRAMS that exists in the system's $PATH. | ||
31 | Each of PROGRAMS can be a single string, or a list. If it's a list then its car | ||
32 | will be tested with `executable-find', and the entire list returned. This | ||
33 | enables passing arguments to a calling function." | ||
34 | (seq-find (lambda (x) | ||
35 | (executable-find (car (ensure-list x)))) | ||
36 | programs)) | ||
37 | |||
38 | (provide 'acdw) | ||
39 | ;;; acdw.el ends here | ||