diff options
| author | Tassilo Horn | 2010-12-30 14:45:09 +0100 |
|---|---|---|
| committer | Tassilo Horn | 2010-12-30 14:45:09 +0100 |
| commit | 95e16d17b79704085634aaa5b87db1b86ec7ba5f (patch) | |
| tree | e9007c514e062e43ff904639593326c06bf99ce9 | |
| parent | 5bbb4727aa8adca6e1dac35dd7c1ed21ffd24e02 (diff) | |
| download | emacs-95e16d17b79704085634aaa5b87db1b86ec7ba5f.tar.gz emacs-95e16d17b79704085634aaa5b87db1b86ec7ba5f.zip | |
* 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.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/doc-view.el | 60 |
2 files changed, 63 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 85a2b2114ec..e86f316ac22 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2010-12-30 Tassilo Horn <tassilo@member.fsf.org> | ||
| 2 | |||
| 3 | * doc-view.el: Implement viewing of OpenDocument (and Microsoft | ||
| 4 | Office) files. Not yet enabled via auto-mode-list. | ||
| 5 | (doc-view-unoconv-program): New custom variable. | ||
| 6 | (doc-view-mode-p): Handle new odf document type. | ||
| 7 | (doc-view-odf->pdf): New conversion function. | ||
| 8 | (doc-view-convert-current-doc): Call it for odf files. | ||
| 9 | (doc-view-mode): Recognize newly supported file extensions. | ||
| 10 | |||
| 1 | 2010-12-30 Michael Albinus <michael.albinus@gmx.de> | 11 | 2010-12-30 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 12 | ||
| 3 | * net/tramp.el (tramp-default-method-alist) | 13 | * net/tramp.el (tramp-default-method-alist) |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 4f183f4b9dc..9d0f6a3af63 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -190,6 +190,13 @@ If this and `doc-view-dvipdfm-program' are set, | |||
| 190 | :type 'file | 190 | :type 'file |
| 191 | :group 'doc-view) | 191 | :group 'doc-view) |
| 192 | 192 | ||
| 193 | (defcustom doc-view-unoconv-program (executable-find "unoconv") | ||
| 194 | "Program to convert any file type readable by OpenOffice.org to PDF. | ||
| 195 | |||
| 196 | Needed for viewing OpenOffice.org (and MS Office) files." | ||
| 197 | :type 'file | ||
| 198 | :group 'doc-view) | ||
| 199 | |||
| 193 | (defcustom doc-view-ps2pdf-program (executable-find "ps2pdf") | 200 | (defcustom doc-view-ps2pdf-program (executable-find "ps2pdf") |
| 194 | "Program to convert PS files to PDF. | 201 | "Program to convert PS files to PDF. |
| 195 | 202 | ||
| @@ -604,8 +611,9 @@ It's a subdirectory of `doc-view-cache-directory'." | |||
| 604 | 611 | ||
| 605 | ;;;###autoload | 612 | ;;;###autoload |
| 606 | (defun doc-view-mode-p (type) | 613 | (defun doc-view-mode-p (type) |
| 607 | "Return non-nil if image type TYPE is available for `doc-view'. | 614 | "Return non-nil if document type TYPE is available for `doc-view'. |
| 608 | Image types are symbols like `dvi', `postscript' or `pdf'." | 615 | Document types are symbols like `dvi', `ps', `pdf', or `odf' (any |
| 616 | OpenDocument format)." | ||
| 609 | (and (display-graphic-p) | 617 | (and (display-graphic-p) |
| 610 | (image-type-available-p 'png) | 618 | (image-type-available-p 'png) |
| 611 | (cond | 619 | (cond |
| @@ -619,6 +627,10 @@ Image types are symbols like `dvi', `postscript' or `pdf'." | |||
| 619 | (eq type 'pdf)) | 627 | (eq type 'pdf)) |
| 620 | (and doc-view-ghostscript-program | 628 | (and doc-view-ghostscript-program |
| 621 | (executable-find doc-view-ghostscript-program))) | 629 | (executable-find doc-view-ghostscript-program))) |
| 630 | ((eq type 'odf) | ||
| 631 | (and doc-view-unoconv-program | ||
| 632 | (executable-find doc-view-unoconv-program) | ||
| 633 | (doc-view-mode-p 'pdf))) | ||
| 622 | (t ;; unknown image type | 634 | (t ;; unknown image type |
| 623 | nil)))) | 635 | nil)))) |
| 624 | 636 | ||
| @@ -692,6 +704,13 @@ Should be invoked when the cached images aren't up-to-date." | |||
| 692 | (list "-o" pdf dvi) | 704 | (list "-o" pdf dvi) |
| 693 | callback))) | 705 | callback))) |
| 694 | 706 | ||
| 707 | (defun doc-view-odf->pdf (odf callback) | ||
| 708 | "Convert ODF to PDF asynchronously and call CALLBACK when finished. | ||
| 709 | The converted PDF is put into the current cache directory, and it | ||
| 710 | is named like ODF with the extension turned to pdf." | ||
| 711 | (doc-view-start-process "odf->pdf" doc-view-unoconv-program | ||
| 712 | (list "-f" "pdf" "-o" (doc-view-current-cache-dir) odf) | ||
| 713 | callback)) | ||
| 695 | 714 | ||
| 696 | (defun doc-view-pdf/ps->png (pdf-ps png) | 715 | (defun doc-view-pdf/ps->png (pdf-ps png) |
| 697 | "Convert PDF-PS to PNG asynchronously." | 716 | "Convert PDF-PS to PNG asynchronously." |
| @@ -838,6 +857,24 @@ Those files are saved in the directory given by the function | |||
| 838 | (png-file png-file)) | 857 | (png-file png-file)) |
| 839 | (doc-view-dvi->pdf doc-view-buffer-file-name pdf | 858 | (doc-view-dvi->pdf doc-view-buffer-file-name pdf |
| 840 | (lambda () (doc-view-pdf/ps->png pdf png-file))))) | 859 | (lambda () (doc-view-pdf/ps->png pdf png-file))))) |
| 860 | (odf | ||
| 861 | ;; ODF files have to be converted to PDF before Ghostscript can | ||
| 862 | ;; process it. | ||
| 863 | (lexical-let | ||
| 864 | ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir)) | ||
| 865 | (opdf (expand-file-name (concat (file-name-sans-extension | ||
| 866 | (file-name-nondirectory doc-view-buffer-file-name)) | ||
| 867 | ".pdf") | ||
| 868 | doc-view-current-cache-dir)) | ||
| 869 | (png-file png-file)) | ||
| 870 | ;; The unoconv tool only supports a output directory, but no | ||
| 871 | ;; file name. It's named like the input file with the | ||
| 872 | ;; extension replaced by pdf. | ||
| 873 | (doc-view-odf->pdf doc-view-buffer-file-name | ||
| 874 | (lambda () | ||
| 875 | ;; Rename to doc.pdf | ||
| 876 | (rename-file opdf pdf) | ||
| 877 | (doc-view-pdf/ps->png pdf png-file))))) | ||
| 841 | 878 | ||
| 842 | (let ((pages (doc-view-active-pages))) | 879 | (let ((pages (doc-view-active-pages))) |
| 843 | ;; Convert PDF to PNG images starting with the active pages. | 880 | ;; Convert PDF to PNG images starting with the active pages. |
| @@ -1236,11 +1273,20 @@ toggle between displaying the document or editing it as text. | |||
| 1236 | (let ((name-types | 1273 | (let ((name-types |
| 1237 | (when buffer-file-name | 1274 | (when buffer-file-name |
| 1238 | (cdr (assoc (file-name-extension buffer-file-name) | 1275 | (cdr (assoc (file-name-extension buffer-file-name) |
| 1239 | '(("dvi" dvi) | 1276 | '( |
| 1240 | ("pdf" pdf) | 1277 | ;; DVI |
| 1241 | ("epdf" pdf) | 1278 | ("dvi" dvi) |
| 1242 | ("ps" ps) | 1279 | |
| 1243 | ("eps" ps)))))) | 1280 | ("pdf" pdf) ("epdf" pdf) |
| 1281 | ;; PostScript | ||
| 1282 | ("ps" ps) ("eps" ps) | ||
| 1283 | ;; OpenDocument formats | ||
| 1284 | ("odt" odf) ("ods" odf) ("odp" odf) ("odg" odf) | ||
| 1285 | ("odc" odf) ("odi" odf) ("odm" odf) ("ott" odf) | ||
| 1286 | ("ots" odf) ("otp" odf) ("otg" odf) | ||
| 1287 | ;; Microsoft Office formats (also handled | ||
| 1288 | ;; by the odf conversion chain) | ||
| 1289 | ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)))))) | ||
| 1244 | (content-types | 1290 | (content-types |
| 1245 | (save-excursion | 1291 | (save-excursion |
| 1246 | (goto-char (point-min)) | 1292 | (goto-char (point-min)) |