Add polyfill for make-empty-file

make-empty-file was only introduced in Emacs 27, which some people are
not yet running
This commit is contained in:
Jethro Kuan
2020-02-06 16:05:22 +08:00
parent 8fda90b3aa
commit f49c1837f3
2 changed files with 19 additions and 0 deletions

18
org-roam-polyfill.el Normal file
View File

@ -0,0 +1,18 @@
;; Introduced in Emacs 27.1
(unless (fboundp 'make-empty-file)
(defun make-empty-file (filename &optional parents)
"Create an empty file FILENAME.
Optional arg PARENTS, if non-nil then creates parent dirs as needed.
If called interactively, then PARENTS is non-nil."
(interactive
(let ((filename (read-file-name "Create empty file: ")))
(list filename t)))
(when (and (file-exists-p filename) (null parents))
(signal 'file-already-exists `("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)))
(provide'org-roam-polyfill)

View File

@ -5,6 +5,7 @@
;;; Code:
(require 'deft)
(require 'org-roam-polyfill)
(require 'org-element)
(require 'async)
(require 'subr-x)