From 81eb8c5f9e4e8fe7e97c7358691edad7e694372b Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Tue, 10 Aug 2021 22:02:40 +0200 Subject: [PATCH] attach: Fix for Emacs<28 * lisp/org-compat.el: Introduce org-directory-empty-p which is directory-empty-p from Emacs 28. * lisp/org-attach.el (org-attach-sync): Use org-directory-empty-p instead of directory-empty-p. * etc/ORG-NEWS: Note about org-directory-empty-p. Thanks Kyle identifying the issue. Thanks Arthur for suggesting a fix. --- etc/ORG-NEWS | 2 ++ lisp/org-attach.el | 2 +- lisp/org-compat.el | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 78a57ba90..83a67da96 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -421,6 +421,8 @@ Tag completion now uses =completing-read-multiple= with a simple completion table, which should allow better interoperability with custom completion functions. +*** Providing =directory-empty-p= from Emacs 28 as =org-directory-empty-p= + * Version 9.4 ** Incompatible changes *** Possibly broken internal file links: please check and fix diff --git a/lisp/org-attach.el b/lisp/org-attach.el index e8e8ade83..f18453103 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -622,7 +622,7 @@ empty attachment directories." (let ((files (org-attach-file-list attach-dir))) (org-attach-tag (not files))) (when org-attach-sync-delete-empty-dir - (when (and (directory-empty-p attach-dir) + (when (and (org-directory-empty-p attach-dir) (if (eq 'query org-attach-sync-delete-empty-dir) (yes-or-no-p "Attachment directory is empty. Delete?") t)) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index ff992f344..866e2c300 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -71,6 +71,16 @@ (defvar org-table-tab-recognizes-table.el) (defvar org-table1-hline-regexp) + +;;; Emacs < 28.1 compatibility + +(if (version< emacs-version "28") + (defun org-directory-empty-p (dir) + "Return t if DIR names an existing directory containing no other files." + (and (file-directory-p dir) + (null (directory-files dir nil directory-files-no-dot-files-regexp t 1)))) + (defalias 'org-directory-empty-p #'directory-empty-p)) + ;;; Emacs < 27.1 compatibility