Mercurial > emacs
changeset 112034:6957ace4e43f
* doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Not yet enabled via auto-mode-list.
(doc-view-unoconv-program): New custom variable.
(doc-view-mode-p): Handle new odf document type.
(doc-view-odf->pdf): New conversion function.
(doc-view-convert-current-doc): Call it for odf files.
(doc-view-mode): Recognize newly supported file extensions.
author | Tassilo Horn <tassilo@member.fsf.org> |
---|---|
date | Thu, 30 Dec 2010 14:45:09 +0100 |
parents | a80c1e8d9df4 |
children | 33f84f010bcb |
files | lisp/ChangeLog lisp/doc-view.el |
diffstat | 2 files changed, 63 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Thu Dec 30 12:30:55 2010 +0100 +++ b/lisp/ChangeLog Thu Dec 30 14:45:09 2010 +0100 @@ -1,3 +1,13 @@ +2010-12-30 Tassilo Horn <tassilo@member.fsf.org> + + * doc-view.el: Implement viewing of OpenDocument (and Microsoft + Office) files. Not yet enabled via auto-mode-list. + (doc-view-unoconv-program): New custom variable. + (doc-view-mode-p): Handle new odf document type. + (doc-view-odf->pdf): New conversion function. + (doc-view-convert-current-doc): Call it for odf files. + (doc-view-mode): Recognize newly supported file extensions. + 2010-12-30 Michael Albinus <michael.albinus@gmx.de> * net/tramp.el (tramp-default-method-alist)
--- a/lisp/doc-view.el Thu Dec 30 12:30:55 2010 +0100 +++ b/lisp/doc-view.el Thu Dec 30 14:45:09 2010 +0100 @@ -190,6 +190,13 @@ :type 'file :group 'doc-view) +(defcustom doc-view-unoconv-program (executable-find "unoconv") + "Program to convert any file type readable by OpenOffice.org to PDF. + +Needed for viewing OpenOffice.org (and MS Office) files." + :type 'file + :group 'doc-view) + (defcustom doc-view-ps2pdf-program (executable-find "ps2pdf") "Program to convert PS files to PDF. @@ -604,8 +611,9 @@ ;;;###autoload (defun doc-view-mode-p (type) - "Return non-nil if image type TYPE is available for `doc-view'. -Image types are symbols like `dvi', `postscript' or `pdf'." + "Return non-nil if document type TYPE is available for `doc-view'. +Document types are symbols like `dvi', `ps', `pdf', or `odf' (any +OpenDocument format)." (and (display-graphic-p) (image-type-available-p 'png) (cond @@ -619,6 +627,10 @@ (eq type 'pdf)) (and doc-view-ghostscript-program (executable-find doc-view-ghostscript-program))) + ((eq type 'odf) + (and doc-view-unoconv-program + (executable-find doc-view-unoconv-program) + (doc-view-mode-p 'pdf))) (t ;; unknown image type nil)))) @@ -692,6 +704,13 @@ (list "-o" pdf dvi) callback))) +(defun doc-view-odf->pdf (odf callback) + "Convert ODF to PDF asynchronously and call CALLBACK when finished. +The converted PDF is put into the current cache directory, and it +is named like ODF with the extension turned to pdf." + (doc-view-start-process "odf->pdf" doc-view-unoconv-program + (list "-f" "pdf" "-o" (doc-view-current-cache-dir) odf) + callback)) (defun doc-view-pdf/ps->png (pdf-ps png) "Convert PDF-PS to PNG asynchronously." @@ -838,6 +857,24 @@ (png-file png-file)) (doc-view-dvi->pdf doc-view-buffer-file-name pdf (lambda () (doc-view-pdf/ps->png pdf png-file))))) + (odf + ;; ODF files have to be converted to PDF before Ghostscript can + ;; process it. + (lexical-let + ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir)) + (opdf (expand-file-name (concat (file-name-sans-extension + (file-name-nondirectory doc-view-buffer-file-name)) + ".pdf") + doc-view-current-cache-dir)) + (png-file png-file)) + ;; The unoconv tool only supports a output directory, but no + ;; file name. It's named like the input file with the + ;; extension replaced by pdf. + (doc-view-odf->pdf doc-view-buffer-file-name + (lambda () + ;; Rename to doc.pdf + (rename-file opdf pdf) + (doc-view-pdf/ps->png pdf png-file))))) (pdf (let ((pages (doc-view-active-pages))) ;; Convert PDF to PNG images starting with the active pages. @@ -1236,11 +1273,20 @@ (let ((name-types (when buffer-file-name (cdr (assoc (file-name-extension buffer-file-name) - '(("dvi" dvi) - ("pdf" pdf) - ("epdf" pdf) - ("ps" ps) - ("eps" ps)))))) + '( + ;; DVI + ("dvi" dvi) + ;; PDF + ("pdf" pdf) ("epdf" pdf) + ;; PostScript + ("ps" ps) ("eps" ps) + ;; OpenDocument formats + ("odt" odf) ("ods" odf) ("odp" odf) ("odg" odf) + ("odc" odf) ("odi" odf) ("odm" odf) ("ott" odf) + ("ots" odf) ("otp" odf) ("otg" odf) + ;; Microsoft Office formats (also handled + ;; by the odf conversion chain) + ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)))))) (content-types (save-excursion (goto-char (point-min))