1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
|