diff --git a/compat-27.el b/compat-27.el index 04abe6e..714df89 100644 --- a/compat-27.el +++ b/compat-27.el @@ -662,6 +662,17 @@ REMOTE is non-nil, search on the remote host indicated by (when (stringp res) (compat--file-local-name res))) (executable-find command))) +;;*UNTESTED +(compat-defun make-empty-file (filename &optional parents) + "Create an empty file FILENAME. +Optional arg PARENTS, if non-nil then creates parent dirs as needed." + (when (and (file-exists-p filename) (null parents)) + (signal 'file-already-exists (list "File exists" filename))) + (let ((paren-dir (file-name-directory filename))) + (when (and paren-dir (not (file-exists-p paren-dir))) + (make-directory paren-dir parents))) + (write-region "" nil filename nil 0)) + ;; TODO provide advice for directory-files-recursively ;;;; Defined in format-spec.el diff --git a/compat.texi b/compat.texi index f19d27f..9953269 100644 --- a/compat.texi +++ b/compat.texi @@ -1482,6 +1482,14 @@ derived from any of the major modes given by the symbols @var{modes}. @xref{Derived Modes,,,elisp}. @end defun +@c based on lispref/files.texi +@defun make-empty-file filename &optional parents +This function creates an empty file named @var{filename}. As +@code{make-directory}, this function creates parent directories if +@var{parents} is non-@code{nil}. If @var{filename} already exists, this +function signals an error. +@end defun + @subsection Prefixed Definitions These functions are prefixed with @code{compat} prefix, and are only loaded when @code{compat-27} is required: