From ea681cecebd157e23a6ebbae634a683dc26de4b1 Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Fri, 7 Feb 2020 12:44:40 +0800 Subject: [PATCH] Move polyfill into main file Prevents packaging mess --- org-roam-polyfill.el | 16 ---------------- org-roam.el | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/org-roam-polyfill.el b/org-roam-polyfill.el index 8515d2a..0c7d357 100644 --- a/org-roam-polyfill.el +++ b/org-roam-polyfill.el @@ -1,18 +1,2 @@ -;; 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) diff --git a/org-roam.el b/org-roam.el index 649e015..a8ce95c 100644 --- a/org-roam.el +++ b/org-roam.el @@ -4,7 +4,6 @@ ;; ;;; Code: -(require 'org-roam-polyfill) (require 'org-element) (require 'async) (require 'subr-x) @@ -61,6 +60,26 @@ Valid values are :type 'string :group 'org-roam) +;;; Polyfills +;; These are for functions I use that are only available in newer Emacs + +;; 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))) + ;;; Dynamic variables (defvar org-roam-update-timer nil "Variable containing the timer that periodically updates the buffer.")