Przeglądaj źródła

org-e-odt.el (org-e-odt--export-wrap): Use `condition-case'

* org-e-odt.el (org-e-odt--export-wrap): Use `condition-case'.
Bastien Guerry 12 lat temu
rodzic
commit
35f944aaf0
1 zmienionych plików z 88 dodań i 88 usunięć
  1. 88 88
      contrib/lisp/org-e-odt.el

+ 88 - 88
contrib/lisp/org-e-odt.el

@@ -3434,94 +3434,94 @@ contextual information."
 	      ;; Delete temporary directory and also other embedded
 	      ;; files that get copied there.
 	      (delete-directory org-e-odt-zip-dir t)))))
-     (org-condition-case-unless-debug
-      err
-      (progn
-	(unless (executable-find "zip")
-	  ;; Not at all OSes ship with zip by default
-	  (error "Executable \"zip\" needed for creating OpenDocument files"))
-	;; Do export.  This creates a bunch of xml files ready to be
-	;; saved and zipped.
-	(progn ,@body)
-	;; Create a manifest entry for content.xml.
-	(org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
-
-	;; Write mimetype file
-	(let* ((mimetypes
-		'(("odt" . "application/vnd.oasis.opendocument.text")
-		  ("odf" .  "application/vnd.oasis.opendocument.formula")))
-	       (mimetype (cdr (assoc-string out-file-type mimetypes t))))
-	  (unless mimetype
-	    (error "Unknown OpenDocument backend %S" out-file-type))
-	  (write-region mimetype nil (concat org-e-odt-zip-dir "mimetype"))
-	  (org-e-odt-create-manifest-file-entry mimetype "/" "1.2"))
-	;; Write out the manifest entries before zipping
-	(org-e-odt-write-manifest-file)
-	;; Save all XML files.
-	(mapc (lambda (file)
-		(let ((buf (get-file-buffer (concat org-e-odt-zip-dir file))))
-		  (when buf
-		    (with-current-buffer buf
-		      ;; Prettify output if needed.
-		      (when org-e-odt-prettify-xml
-			(indent-region (point-min) (point-max)))
-		      (save-buffer 0)))))
-	      org-e-odt-xml-files)
-	;; Run zip.
-	(let* ((target --out-file)
-	       (target-name (file-name-nondirectory target))
-	       (target-dir (file-name-directory target))
-	       (cmds `(("zip" "-mX0" ,target-name "mimetype")
-		       ("zip" "-rmTq" ,target-name "."))))
-	  ;; If a file with same name as the desired output file
-	  ;; exists, remove it.
-	  (when (file-exists-p target)
-	    (delete-file target))
-	  ;; Zip up the xml files.
-	  (let ((coding-system-for-write 'no-conversion) exitcode err-string)
-	    (message "Creating ODT file...")
-	    ;; Switch temporarily to content.xml.  This way Zip
-	    ;; process will inherit `org-e-odt-zip-dir' as the current
-	    ;; directory.
-	    (with-current-buffer
-		(find-file-noselect (concat org-e-odt-zip-dir "content.xml") t)
-	      (mapc
-	       (lambda (cmd)
-		 (message "Running %s" (mapconcat 'identity cmd " "))
-		 (setq err-string
-		       (with-output-to-string
-			 (setq exitcode
-			       (apply 'call-process (car cmd)
-				      nil standard-output nil (cdr cmd)))))
-		 (or (zerop exitcode)
-		     (error (concat "Unable to create OpenDocument file."
-				    (format "  Zip failed with error (%s)"
-					    err-string)))))
-	       cmds)
-	      ;; Zip file is now in the rightful place.
-	      (rename-file target-name target)))
-	  (message "Created %s" target)
-	  ;; Cleanup work directory and work files.
-	  (funcall --cleanup-xml-buffers)
-	  ;; Open the OpenDocument file in archive-mode for
-	  ;; examination.
-	  (find-file-noselect target t)
-	  ;; Return exported file.
-	  (cond
-	   ;; Case 1: Conversion desired on exported file.  Run the
-	   ;; converter on the OpenDocument file.  Return the
-	   ;; converted file.
-	   (org-e-odt-preferred-output-format
-	    (or (org-e-odt-convert target org-e-odt-preferred-output-format)
-		target))
-	   ;; Case 2: No further conversion.  Return exported
-	   ;; OpenDocument file.
-	   (t target))))
-      ((quit error)
-       ;; Cleanup work directory and work files.
-       (funcall --cleanup-xml-buffers)
-       (message "OpenDocument export failed: %s"
-		(error-message-string err))))))
+     (condition-case
+	 err
+	 (progn
+	   (unless (executable-find "zip")
+	     ;; Not at all OSes ship with zip by default
+	     (error "Executable \"zip\" needed for creating OpenDocument files"))
+	   ;; Do export.  This creates a bunch of xml files ready to be
+	   ;; saved and zipped.
+	   (progn ,@body)
+	   ;; Create a manifest entry for content.xml.
+	   (org-e-odt-create-manifest-file-entry "text/xml" "content.xml")
+
+	   ;; Write mimetype file
+	   (let* ((mimetypes
+		   '(("odt" . "application/vnd.oasis.opendocument.text")
+		     ("odf" .  "application/vnd.oasis.opendocument.formula")))
+		  (mimetype (cdr (assoc-string out-file-type mimetypes t))))
+	     (unless mimetype
+	       (error "Unknown OpenDocument backend %S" out-file-type))
+	     (write-region mimetype nil (concat org-e-odt-zip-dir "mimetype"))
+	     (org-e-odt-create-manifest-file-entry mimetype "/" "1.2"))
+	   ;; Write out the manifest entries before zipping
+	   (org-e-odt-write-manifest-file)
+	   ;; Save all XML files.
+	   (mapc (lambda (file)
+		   (let ((buf (get-file-buffer (concat org-e-odt-zip-dir file))))
+		     (when buf
+		       (with-current-buffer buf
+			 ;; Prettify output if needed.
+			 (when org-e-odt-prettify-xml
+			   (indent-region (point-min) (point-max)))
+			 (save-buffer 0)))))
+		 org-e-odt-xml-files)
+	   ;; Run zip.
+	   (let* ((target --out-file)
+		  (target-name (file-name-nondirectory target))
+		  (target-dir (file-name-directory target))
+		  (cmds `(("zip" "-mX0" ,target-name "mimetype")
+			  ("zip" "-rmTq" ,target-name "."))))
+	     ;; If a file with same name as the desired output file
+	     ;; exists, remove it.
+	     (when (file-exists-p target)
+	       (delete-file target))
+	     ;; Zip up the xml files.
+	     (let ((coding-system-for-write 'no-conversion) exitcode err-string)
+	       (message "Creating ODT file...")
+	       ;; Switch temporarily to content.xml.  This way Zip
+	       ;; process will inherit `org-e-odt-zip-dir' as the current
+	       ;; directory.
+	       (with-current-buffer
+		   (find-file-noselect (concat org-e-odt-zip-dir "content.xml") t)
+		 (mapc
+		  (lambda (cmd)
+		    (message "Running %s" (mapconcat 'identity cmd " "))
+		    (setq err-string
+			  (with-output-to-string
+			    (setq exitcode
+				  (apply 'call-process (car cmd)
+					 nil standard-output nil (cdr cmd)))))
+		    (or (zerop exitcode)
+			(error (concat "Unable to create OpenDocument file."
+				       (format "  Zip failed with error (%s)"
+					       err-string)))))
+		  cmds)
+		 ;; Zip file is now in the rightful place.
+		 (rename-file target-name target)))
+	     (message "Created %s" target)
+	     ;; Cleanup work directory and work files.
+	     (funcall --cleanup-xml-buffers)
+	     ;; Open the OpenDocument file in archive-mode for
+	     ;; examination.
+	     (find-file-noselect target t)
+	     ;; Return exported file.
+	     (cond
+	      ;; Case 1: Conversion desired on exported file.  Run the
+	      ;; converter on the OpenDocument file.  Return the
+	      ;; converted file.
+	      (org-e-odt-preferred-output-format
+	       (or (org-e-odt-convert target org-e-odt-preferred-output-format)
+		   target))
+	      ;; Case 2: No further conversion.  Return exported
+	      ;; OpenDocument file.
+	      (t target))))
+       ((quit error)
+	;; Cleanup work directory and work files.
+	(funcall --cleanup-xml-buffers)
+	(message "OpenDocument export failed: %s"
+		 (error-message-string err))))))