diff options
| author | Stefan Monnier | 2008-03-12 14:50:36 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-03-12 14:50:36 +0000 |
| commit | eb79098b2bda5863112102d70fa372f788f7c85c (patch) | |
| tree | 0a8e6510c35f69a2b43efcc82fcbab1252cffc8f | |
| parent | 8e8b845d1d17da478bc971927641e3b831f980ac (diff) | |
| download | emacs-eb79098b2bda5863112102d70fa372f788f7c85c.tar.gz emacs-eb79098b2bda5863112102d70fa372f788f7c85c.zip | |
(doc-view-new-window-function): Add assertion.
(doc-view-doc-type): New var.
(doc-view-convert-current-doc, doc-view-doc->txt): Use it.
(doc-view-intersection): New fun.
(doc-view-mode): Use it to set the new var.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/doc-view.el | 62 |
2 files changed, 57 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2deb3d4c792..3518243b3ca 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2008-03-12 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * doc-view.el (doc-view-new-window-function): Add assertion. | ||
| 4 | (doc-view-doc-type): New var. | ||
| 5 | (doc-view-convert-current-doc, doc-view-doc->txt): Use it. | ||
| 6 | (doc-view-intersection): New fun. | ||
| 7 | (doc-view-mode): Use it to set the new var. | ||
| 8 | |||
| 1 | 2008-03-12 Tassilo Horn <tassilo@member.fsf.org> | 9 | 2008-03-12 Tassilo Horn <tassilo@member.fsf.org> |
| 2 | 10 | ||
| 3 | * lisp/doc-view.el (doc-view-doc->txt, doc-view-open-text) | 11 | * lisp/doc-view.el (doc-view-doc->txt, doc-view-open-text) |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 57a07eb9a93..01dd163ac80 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -103,7 +103,7 @@ | |||
| 103 | ;; - share more code with image-mode. | 103 | ;; - share more code with image-mode. |
| 104 | ;; - better menu. | 104 | ;; - better menu. |
| 105 | ;; - Bind slicing to a drag event. | 105 | ;; - Bind slicing to a drag event. |
| 106 | ;; - doc-view-fit-doc-to-window and doc-view-fit-window-to-doc. | 106 | ;; - doc-view-fit-doc-to-window and doc-view-fit-window-to-doc? |
| 107 | ;; - zoom the region around the cursor (like xdvi). | 107 | ;; - zoom the region around the cursor (like xdvi). |
| 108 | ;; - get rid of the silly arrow in the fringe. | 108 | ;; - get rid of the silly arrow in the fringe. |
| 109 | ;; - improve anti-aliasing (pdf-utils gets it better). | 109 | ;; - improve anti-aliasing (pdf-utils gets it better). |
| @@ -214,6 +214,7 @@ has finished." | |||
| 214 | (let ((ol (image-mode-window-get 'overlay winprops))) | 214 | (let ((ol (image-mode-window-get 'overlay winprops))) |
| 215 | (if ol | 215 | (if ol |
| 216 | (setq ol (copy-overlay ol)) | 216 | (setq ol (copy-overlay ol)) |
| 217 | (assert (not (get-char-property (point-min) 'display (car winprops)))) | ||
| 217 | (setq ol (make-overlay (point-min) (point-max) nil t)) | 218 | (setq ol (make-overlay (point-min) (point-max) nil t)) |
| 218 | (overlay-put ol 'doc-view t)) | 219 | (overlay-put ol 'doc-view t)) |
| 219 | (overlay-put ol 'window (car winprops)) | 220 | (overlay-put ol 'window (car winprops)) |
| @@ -248,6 +249,10 @@ files inside an archive it is a temporary copy of | |||
| 248 | the (uncompressed, extracted) file residing in | 249 | the (uncompressed, extracted) file residing in |
| 249 | `doc-view-cache-directory'.") | 250 | `doc-view-cache-directory'.") |
| 250 | 251 | ||
| 252 | (defvar doc-view-doc-type nil | ||
| 253 | "The type of document in the current buffer. | ||
| 254 | Can be `dvi', `pdf', or `ps'.") | ||
| 255 | |||
| 251 | ;;;; DocView Keymaps | 256 | ;;;; DocView Keymaps |
| 252 | 257 | ||
| 253 | (defvar doc-view-mode-map | 258 | (defvar doc-view-mode-map |
| @@ -615,13 +620,13 @@ Should be invoked when the cached images aren't up-to-date." | |||
| 615 | "Convert the current document to text and call CALLBACK with CB-ARGS when done." | 620 | "Convert the current document to text and call CALLBACK with CB-ARGS when done." |
| 616 | (make-directory (doc-view-current-cache-dir)) | 621 | (make-directory (doc-view-current-cache-dir)) |
| 617 | (let ((ext (file-name-extension doc-view-buffer-file-name))) | 622 | (let ((ext (file-name-extension doc-view-buffer-file-name))) |
| 618 | (cond | 623 | (case doc-view-doc-type |
| 619 | ((string= ext "pdf") | 624 | |
| 620 | ;; Doc is a PDF, so convert it to TXT | 625 | ;; Doc is a PDF, so convert it to TXT |
| 621 | (if cb-args | 626 | (if cb-args |
| 622 | (doc-view-pdf->txt doc-view-buffer-file-name txt callback cb-args) | 627 | (doc-view-pdf->txt doc-view-buffer-file-name txt callback cb-args) |
| 623 | (doc-view-pdf->txt doc-view-buffer-file-name txt callback))) | 628 | (doc-view-pdf->txt doc-view-buffer-file-name txt callback))) |
| 624 | ((string= ext "ps") | 629 | (ps |
| 625 | ;; Doc is a PS, so convert it to PDF (which will be converted to | 630 | ;; Doc is a PS, so convert it to PDF (which will be converted to |
| 626 | ;; TXT thereafter). | 631 | ;; TXT thereafter). |
| 627 | (let ((pdf (expand-file-name "doc.pdf" | 632 | (let ((pdf (expand-file-name "doc.pdf" |
| @@ -633,7 +638,7 @@ Should be invoked when the cached images aren't up-to-date." | |||
| 633 | (doc-view-ps->pdf doc-view-buffer-file-name pdf | 638 | (doc-view-ps->pdf doc-view-buffer-file-name pdf |
| 634 | 'doc-view-pdf->txt | 639 | 'doc-view-pdf->txt |
| 635 | pdf txt callback)))) | 640 | pdf txt callback)))) |
| 636 | ((string= ext "dvi") | 641 | (dvi |
| 637 | ;; Doc is a DVI. This means that a doc.pdf already exists in its | 642 | ;; Doc is a DVI. This means that a doc.pdf already exists in its |
| 638 | ;; cache subdirectory. | 643 | ;; cache subdirectory. |
| 639 | (if cb-args | 644 | (if cb-args |
| @@ -683,14 +688,16 @@ Those files are saved in the directory given by the function | |||
| 683 | (let ((png-file (expand-file-name "page-%d.png" | 688 | (let ((png-file (expand-file-name "page-%d.png" |
| 684 | (doc-view-current-cache-dir)))) | 689 | (doc-view-current-cache-dir)))) |
| 685 | (make-directory (doc-view-current-cache-dir)) | 690 | (make-directory (doc-view-current-cache-dir)) |
| 686 | (if (not (string= (file-name-extension doc-view-buffer-file-name) "dvi")) | 691 | (case doc-view-doc-type |
| 687 | ;; Convert to PNG images. | 692 | (dvi |
| 688 | (doc-view-pdf/ps->png doc-view-buffer-file-name png-file) | 693 | ;; DVI files have to be converted to PDF before Ghostscript can process |
| 689 | ;; DVI files have to be converted to PDF before Ghostscript can process | 694 | ;; it. |
| 690 | ;; it. | 695 | (let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))) |
| 691 | (let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))) | 696 | (doc-view-dvi->pdf doc-view-buffer-file-name |
| 692 | (doc-view-dvi->pdf doc-view-buffer-file-name | 697 | pdf 'doc-view-pdf/ps->png pdf png-file))) |
| 693 | pdf 'doc-view-pdf/ps->png pdf png-file))))) | 698 | (t |
| 699 | ;; Convert to PNG images. | ||
| 700 | (doc-view-pdf/ps->png doc-view-buffer-file-name png-file))))) | ||
| 694 | 701 | ||
| 695 | ;;;; Slicing | 702 | ;;;; Slicing |
| 696 | 703 | ||
| @@ -1023,6 +1030,11 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1023 | (remove-overlays (point-min) (point-max) 'doc-view t) | 1030 | (remove-overlays (point-min) (point-max) 'doc-view t) |
| 1024 | (if (consp image-mode-winprops-alist) (setq image-mode-winprops-alist nil))) | 1031 | (if (consp image-mode-winprops-alist) (setq image-mode-winprops-alist nil))) |
| 1025 | 1032 | ||
| 1033 | (defun doc-view-intersection (l1 l2) | ||
| 1034 | (let ((l ())) | ||
| 1035 | (dolist (x l1) (if (memq x l2) (push x l))) | ||
| 1036 | l)) | ||
| 1037 | |||
| 1026 | ;;;###autoload | 1038 | ;;;###autoload |
| 1027 | (defun doc-view-mode () | 1039 | (defun doc-view-mode () |
| 1028 | "Major mode in DocView buffers. | 1040 | "Major mode in DocView buffers. |
| @@ -1037,6 +1049,30 @@ toggle between displaying the document or editing it as text. | |||
| 1037 | (kill-all-local-variables) | 1049 | (kill-all-local-variables) |
| 1038 | (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) | 1050 | (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) |
| 1039 | 1051 | ||
| 1052 | ;; Figure out the document type. | ||
| 1053 | (let ((name-types | ||
| 1054 | (when buffer-file-name | ||
| 1055 | (cdr (assoc (file-name-extension buffer-file-name) | ||
| 1056 | '(("dvi" dvi) | ||
| 1057 | ("pdf" pdf) | ||
| 1058 | ("epdf" pdf) | ||
| 1059 | ("ps" ps) | ||
| 1060 | ("eps" ps)))))) | ||
| 1061 | (content-types | ||
| 1062 | (save-excursion | ||
| 1063 | (goto-char (point-min)) | ||
| 1064 | (cond | ||
| 1065 | ((looking-at "%!") '(ps)) | ||
| 1066 | ((looking-at "%PDF") '(pdf)) | ||
| 1067 | ((looking-at "\367\002") '(dvi)))))) | ||
| 1068 | (set (make-local-variable 'doc-view-doc-type) | ||
| 1069 | (car (or (doc-view-intersection name-types content-types) | ||
| 1070 | (when (and name-types content-types) | ||
| 1071 | (error "Conflicting types: name says %s but content says %s" | ||
| 1072 | name-types content-types)) | ||
| 1073 | name-types content-types | ||
| 1074 | (error "Cannot determine the document type"))))) | ||
| 1075 | |||
| 1040 | (doc-view-make-safe-dir doc-view-cache-directory) | 1076 | (doc-view-make-safe-dir doc-view-cache-directory) |
| 1041 | ;; Handle compressed files, remote files, files inside archives | 1077 | ;; Handle compressed files, remote files, files inside archives |
| 1042 | (set (make-local-variable 'doc-view-buffer-file-name) | 1078 | (set (make-local-variable 'doc-view-buffer-file-name) |