emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 6b7a3513dc: Add make-empty-file defined in Emacs


From: ELPA Syncer
Subject: [elpa] externals/compat 6b7a3513dc: Add make-empty-file defined in Emacs 27
Date: Tue, 22 Nov 2022 11:57:28 -0500 (EST)

branch: externals/compat
commit 6b7a3513dc9dce2e59ef8e11f73f2a011ea1ffeb
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add make-empty-file defined in Emacs 27
---
 compat-27.el | 11 +++++++++++
 compat.texi  |  8 ++++++++
 2 files changed, 19 insertions(+)

diff --git a/compat-27.el b/compat-27.el
index 04abe6e86d..714df89618 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 f19d27f449..47625ed179 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 deffn
+
 @subsection Prefixed Definitions
 These functions are prefixed with @code{compat} prefix, and are only
 loaded when @code{compat-27} is required:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]