emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r102725: * doc-view.el: Implement vie


From: Tassilo Horn
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r102725: * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Date: Thu, 30 Dec 2010 14:45:09 +0100
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 102725
committer: Tassilo Horn <address@hidden>
branch nick: trunk
timestamp: Thu 2010-12-30 14:45:09 +0100
message:
  * 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.
modified:
  lisp/ChangeLog
  lisp/doc-view.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-12-30 09:04:15 +0000
+++ b/lisp/ChangeLog    2010-12-30 13:45:09 +0000
@@ -1,3 +1,13 @@
+2010-12-30  Tassilo Horn  <address@hidden>
+
+       * 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  <address@hidden>
 
        * net/tramp.el (tramp-default-method-alist)

=== modified file 'lisp/doc-view.el'
--- a/lisp/doc-view.el  2010-07-14 15:57:54 +0000
+++ b/lisp/doc-view.el  2010-12-30 13:45:09 +0000
@@ -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))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]