From 58999598edf58805760ec3b81370b1dc68a5adcc Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Mon, 24 Dec 2012 13:51:48 +0100 Subject: [PATCH 1/2] New compatibility function `org-delete-directory' * org-compat.el (org-delete-directory): New compatibility function for Emacs 22, where `delete-directory' does not support recursive deletion. * org-odt.el (org-odt-cleanup-xml-buffers): Use the new compatibility function. Thanks to Achim and Jambunathan for suggesting this. --- lisp/org-compat.el | 22 +++++++++++++++++++++- lisp/org-odt.el | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 022f85e98..ea3e852d6 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -256,7 +256,6 @@ Works on both Emacs and XEmacs." (when (boundp 'zmacs-regions) (setq zmacs-regions t))))) - ;; Invisibility compatibility (defun org-remove-from-invisibility-spec (arg) @@ -455,6 +454,27 @@ With two arguments, return floor and remainder of their quotient." 'condition-case-no-debug) 'condition-case)) +;; RECURSIVE has been introduced with Emacs 23.2. +;; This is copying and adapted from `tramp-compat-delete-directory' +(defun org-delete-directory (directory &optional recursive) + "Compatibility function for `delete-directory'." + (if (null recursive) + (delete-directory directory) + (condition-case nil + (funcall 'delete-directory directory recursive) + ;; This Emacs version does not support the RECURSIVE flag. We + ;; use the implementation from Emacs 23.2. + (wrong-number-of-arguments + (setq directory (directory-file-name (expand-file-name directory))) + (if (not (file-symlink-p directory)) + (mapc (lambda (file) + (if (eq t (car (file-attributes file))) + (org-delete-directory file recursive) + (delete-file file))) + (directory-files + directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))) + (delete-directory directory))))) + ;;;###autoload (defmacro org-check-version () "Try very hard to provide sensible version strings." diff --git a/lisp/org-odt.el b/lisp/org-odt.el index f9fd6a2b9..63814811b 100644 --- a/lisp/org-odt.el +++ b/lisp/org-odt.el @@ -446,7 +446,7 @@ values. See Info node `(emacs) File Variables'." (kill-buffer))) xml-files)) ;; delete temporary directory. - (delete-directory org-odt-zip-dir t))))) + (org-delete-directory org-odt-zip-dir t))))) (org-condition-case-unless-debug err (prog1 (progn ,@body) (funcall --cleanup-xml-buffers)) From b63275350f524df5e33c2aa915de4415f312f409 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Wed, 19 Dec 2012 19:35:19 +0100 Subject: [PATCH 2/2] Backwards compatibility: don't defalias special forms * lisp/org-compat.el (org-condition-case-unless-debug): Do not use defalias for special forms, the Emacs 22 byte-compiler does not recognize them correctly when compiling macros. Use a macro instead and rely on macro expansion. That however makes the decision at compile time, which should be acceptable in this case since it only affects debugging. --- lisp/org-compat.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 022f85e98..74d56113c 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -448,12 +448,13 @@ With two arguments, return floor and remainder of their quotient." ;; `condition-case-unless-debug' has been introduced in Emacs 24.1 ;; `condition-case-no-debug' has been introduced in Emacs 23.1 -(defalias 'org-condition-case-unless-debug +(defmacro org-condition-case-unless-debug (var bodyform &rest handlers) + (declare (debug condition-case) (indent 2)) (or (and (fboundp 'condition-case-unless-debug) - 'condition-case-unless-debug) + `(condition-case-unless-debug ,var ,bodyform ,@handlers)) (and (fboundp 'condition-case-no-debug) - 'condition-case-no-debug) - 'condition-case)) + `(condition-case-no-debug ,var ,bodyform ,@handlers)) + `(condition-case ,var ,bodyform ,@handlers))) ;;;###autoload (defmacro org-check-version ()