emacs-devel
[Top][All Lists]
Advanced

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

[PATCH] Update compat


From: Nicolas Martyanoff
Subject: [PATCH] Update compat
Date: Wed, 25 Jan 2023 21:32:50 +0100

From: GNU ELPA Mirror Bot <emacs-devel@gnu.org>

Timestamp: 2022-11-23 00:00:55
GNU ELPA commit: c1e7d260a3e9305188aea0b5a372f4ccd4dfb22c
Emacs commit: 057901f55ad12ebbc9cf092dd6ad0f02539849f9
---
 compat-27.el | 11 +++++++++++
 compat.texi  |  8 ++++++++
 2 files changed, 19 insertions(+)

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 @@ defvar json-null)
         (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:
-- 
2.38.1




reply via email to

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