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