diff options
| author | Stefan Monnier | 2010-02-04 20:53:40 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-02-04 20:53:40 -0500 |
| commit | bdd428996e3c2cc58ffcde8b0cb2215e2e2b247c (patch) | |
| tree | 8e0ee2729ad7c5f26e337a7161967da6f2450566 | |
| parent | dd969a56a57ce94dca1b61b25c8cc4ad102112f7 (diff) | |
| download | emacs-bdd428996e3c2cc58ffcde8b0cb2215e2e2b247c.tar.gz emacs-bdd428996e3c2cc58ffcde8b0cb2215e2e2b247c.zip | |
Fix up various corner case problems.
* doc-view.el (doc-view-last-page-number): New function.
(doc-view-mode, doc-view-last-page, doc-view-goto-page): Use it.
(doc-view-goto-page): Avoid inf-loops when the conversion fails.
(doc-view-kill-proc): Avoid inf-loop in freak cases.
(doc-view-reconvert-doc): Use the new recursive delete-directory.
(doc-view-convert-current-doc): Don't create the resolution.el file
here any more.
(doc-view-pdf/ps->png): Do it here instead.
(doc-view-already-converted-p): Check that resolution.el is present.
(doc-view-pdf->png): Don't rely on doc-view-pdf/ps->png for the few
windows that are not yet showing images.
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/doc-view.el | 84 |
2 files changed, 65 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0e831a4be72..0d1538c0136 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2010-02-05 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | Fix up various corner case problems. | ||
| 4 | * doc-view.el (doc-view-last-page-number): New function. | ||
| 5 | (doc-view-mode, doc-view-last-page, doc-view-goto-page): Use it. | ||
| 6 | (doc-view-goto-page): Avoid inf-loops when the conversion fails. | ||
| 7 | (doc-view-kill-proc): Avoid inf-loop in freak cases. | ||
| 8 | (doc-view-reconvert-doc): Use the new recursive delete-directory. | ||
| 9 | (doc-view-convert-current-doc): Don't create the resolution.el file | ||
| 10 | here any more. | ||
| 11 | (doc-view-pdf/ps->png): Do it here instead. | ||
| 12 | (doc-view-already-converted-p): Check that resolution.el is present. | ||
| 13 | (doc-view-pdf->png): Don't rely on doc-view-pdf/ps->png for the few | ||
| 14 | windows that are not yet showing images. | ||
| 15 | |||
| 1 | 2010-02-04 Alan Mackenzie <acm@muc.de> | 16 | 2010-02-04 Alan Mackenzie <acm@muc.de> |
| 2 | 17 | ||
| 3 | Change strategy for marking < and > as template delimiters: mark | 18 | Change strategy for marking < and > as template delimiters: mark |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index d8a2e909732..5b84fc3e0d1 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -383,10 +383,13 @@ Can be `dvi', `pdf', or `ps'.") | |||
| 383 | (defmacro doc-view-current-image () `(image-mode-window-get 'image)) | 383 | (defmacro doc-view-current-image () `(image-mode-window-get 'image)) |
| 384 | (defmacro doc-view-current-slice () `(image-mode-window-get 'slice)) | 384 | (defmacro doc-view-current-slice () `(image-mode-window-get 'slice)) |
| 385 | 385 | ||
| 386 | (defun doc-view-last-page-number () | ||
| 387 | (length doc-view-current-files)) | ||
| 388 | |||
| 386 | (defun doc-view-goto-page (page) | 389 | (defun doc-view-goto-page (page) |
| 387 | "View the page given by PAGE." | 390 | "View the page given by PAGE." |
| 388 | (interactive "nPage: ") | 391 | (interactive "nPage: ") |
| 389 | (let ((len (length doc-view-current-files)) | 392 | (let ((len (doc-view-last-page-number)) |
| 390 | (hscroll (window-hscroll))) | 393 | (hscroll (window-hscroll))) |
| 391 | (if (< page 1) | 394 | (if (< page 1) |
| 392 | (setq page 1) | 395 | (setq page 1) |
| @@ -426,12 +429,15 @@ Can be `dvi', `pdf', or `ps'.") | |||
| 426 | ;; The PNG file hasn't been generated yet. | 429 | ;; The PNG file hasn't been generated yet. |
| 427 | (doc-view-pdf->png-1 doc-view-buffer-file-name file page | 430 | (doc-view-pdf->png-1 doc-view-buffer-file-name file page |
| 428 | (lexical-let ((page page) | 431 | (lexical-let ((page page) |
| 429 | (win (selected-window))) | 432 | (win (selected-window)) |
| 433 | (file file)) | ||
| 430 | (lambda () | 434 | (lambda () |
| 431 | (and (eq (current-buffer) (window-buffer win)) | 435 | (and (eq (current-buffer) (window-buffer win)) |
| 432 | ;; If we changed page in the mean | 436 | ;; If we changed page in the mean |
| 433 | ;; time, don't mess things up. | 437 | ;; time, don't mess things up. |
| 434 | (eq (doc-view-current-page win) page) | 438 | (eq (doc-view-current-page win) page) |
| 439 | ;; Make sure we don't infloop. | ||
| 440 | (file-readable-p file) | ||
| 435 | (with-selected-window win | 441 | (with-selected-window win |
| 436 | (doc-view-goto-page page)))))))) | 442 | (doc-view-goto-page page)))))))) |
| 437 | (overlay-put (doc-view-current-overlay) | 443 | (overlay-put (doc-view-current-overlay) |
| @@ -455,7 +461,7 @@ Can be `dvi', `pdf', or `ps'.") | |||
| 455 | (defun doc-view-last-page () | 461 | (defun doc-view-last-page () |
| 456 | "View the last page." | 462 | "View the last page." |
| 457 | (interactive) | 463 | (interactive) |
| 458 | (doc-view-goto-page (length doc-view-current-files))) | 464 | (doc-view-goto-page (doc-view-last-page-number))) |
| 459 | 465 | ||
| 460 | (defun doc-view-scroll-up-or-next-page (&optional arg) | 466 | (defun doc-view-scroll-up-or-next-page (&optional arg) |
| 461 | "Scroll page up ARG lines if possible, else goto next page. | 467 | "Scroll page up ARG lines if possible, else goto next page. |
| @@ -528,7 +534,7 @@ at the top edge of the page moves to the previous page." | |||
| 528 | (defun doc-view-kill-proc () | 534 | (defun doc-view-kill-proc () |
| 529 | "Kill the current converter process(es)." | 535 | "Kill the current converter process(es)." |
| 530 | (interactive) | 536 | (interactive) |
| 531 | (while doc-view-current-converter-processes | 537 | (while (consp doc-view-current-converter-processes) |
| 532 | (ignore-errors ;; Maybe it's dead already? | 538 | (ignore-errors ;; Maybe it's dead already? |
| 533 | (kill-process (pop doc-view-current-converter-processes)))) | 539 | (kill-process (pop doc-view-current-converter-processes)))) |
| 534 | (when doc-view-current-timer | 540 | (when doc-view-current-timer |
| @@ -638,7 +644,7 @@ Should be invoked when the cached images aren't up-to-date." | |||
| 638 | (doc-view-kill-proc) | 644 | (doc-view-kill-proc) |
| 639 | ;; Clear the old cached files | 645 | ;; Clear the old cached files |
| 640 | (when (file-exists-p (doc-view-current-cache-dir)) | 646 | (when (file-exists-p (doc-view-current-cache-dir)) |
| 641 | (dired-delete-file (doc-view-current-cache-dir) 'always)) | 647 | (delete-directory (doc-view-current-cache-dir) 'recursive)) |
| 642 | (doc-view-initiate-display)) | 648 | (doc-view-initiate-display)) |
| 643 | 649 | ||
| 644 | (defun doc-view-sentinel (proc event) | 650 | (defun doc-view-sentinel (proc event) |
| @@ -694,11 +700,18 @@ Should be invoked when the cached images aren't up-to-date." | |||
| 694 | (list (format "-r%d" (round doc-view-resolution)) | 700 | (list (format "-r%d" (round doc-view-resolution)) |
| 695 | (concat "-sOutputFile=" png) | 701 | (concat "-sOutputFile=" png) |
| 696 | pdf-ps)) | 702 | pdf-ps)) |
| 697 | (lambda () | 703 | (lexical-let ((resolution doc-view-resolution)) |
| 698 | (when doc-view-current-timer | 704 | (lambda () |
| 699 | (cancel-timer doc-view-current-timer) | 705 | ;; Only create the resolution file when it's all done, so it also |
| 700 | (setq doc-view-current-timer nil)) | 706 | ;; serves as a witness that the conversion is complete. |
| 701 | (doc-view-display (current-buffer) 'force))) | 707 | (write-region (prin1-to-string resolution) nil |
| 708 | (expand-file-name "resolution.el" | ||
| 709 | (doc-view-current-cache-dir)) | ||
| 710 | nil 'silently) | ||
| 711 | (when doc-view-current-timer | ||
| 712 | (cancel-timer doc-view-current-timer) | ||
| 713 | (setq doc-view-current-timer nil)) | ||
| 714 | (doc-view-display (current-buffer) 'force)))) | ||
| 702 | ;; Update the displayed pages as soon as they're done generating. | 715 | ;; Update the displayed pages as soon as they're done generating. |
| 703 | (when doc-view-conversion-refresh-interval | 716 | (when doc-view-conversion-refresh-interval |
| 704 | (setq doc-view-current-timer | 717 | (setq doc-view-current-timer |
| @@ -740,6 +753,13 @@ Start by converting PAGES, and then the rest." | |||
| 740 | (doc-view-pdf->png pdf png rest) | 753 | (doc-view-pdf->png pdf png rest) |
| 741 | ;; Yippie, the important pages are done, update the display. | 754 | ;; Yippie, the important pages are done, update the display. |
| 742 | (clear-image-cache) | 755 | (clear-image-cache) |
| 756 | ;; For the windows that have a message (like "Welcome to | ||
| 757 | ;; DocView") display property, clearing the image cache is | ||
| 758 | ;; not sufficient. | ||
| 759 | (dolist (win (get-buffer-window-list (current-buffer) nil 'visible)) | ||
| 760 | (with-selected-window win | ||
| 761 | (when (stringp (get-char-property (point-min) 'display)) | ||
| 762 | (doc-view-goto-page (doc-view-current-page))))) | ||
| 743 | ;; Convert the rest of the pages. | 763 | ;; Convert the rest of the pages. |
| 744 | (doc-view-pdf/ps->png pdf png))))))) | 764 | (doc-view-pdf/ps->png pdf png))))))) |
| 745 | 765 | ||
| @@ -806,18 +826,8 @@ Those files are saved in the directory given by the function | |||
| 806 | ;; resets during the redisplay). | 826 | ;; resets during the redisplay). |
| 807 | (setq doc-view-pending-cache-flush t) | 827 | (setq doc-view-pending-cache-flush t) |
| 808 | (let ((png-file (expand-file-name "page-%d.png" | 828 | (let ((png-file (expand-file-name "page-%d.png" |
| 809 | (doc-view-current-cache-dir))) | ||
| 810 | (res-file (expand-file-name "resolution.el" | ||
| 811 | (doc-view-current-cache-dir)))) | 829 | (doc-view-current-cache-dir)))) |
| 812 | (make-directory (doc-view-current-cache-dir) t) | 830 | (make-directory (doc-view-current-cache-dir) t) |
| 813 | ;; Save the used resolution so that it can be restored when | ||
| 814 | ;; reading the cached files. | ||
| 815 | (let ((res doc-view-resolution)) | ||
| 816 | (with-temp-buffer | ||
| 817 | (princ res (current-buffer)) | ||
| 818 | ;; Don't use write-file, so as to avoid prompts for `require-newline', | ||
| 819 | ;; or for pre-existing buffers with the same name, ... | ||
| 820 | (write-region nil nil res-file nil 'silently))) | ||
| 821 | (case doc-view-doc-type | 831 | (case doc-view-doc-type |
| 822 | (dvi | 832 | (dvi |
| 823 | ;; DVI files have to be converted to PDF before Ghostscript can process | 833 | ;; DVI files have to be converted to PDF before Ghostscript can process |
| @@ -827,10 +837,10 @@ Those files are saved in the directory given by the function | |||
| 827 | (png-file png-file)) | 837 | (png-file png-file)) |
| 828 | (doc-view-dvi->pdf doc-view-buffer-file-name pdf | 838 | (doc-view-dvi->pdf doc-view-buffer-file-name pdf |
| 829 | (lambda () (doc-view-pdf/ps->png pdf png-file))))) | 839 | (lambda () (doc-view-pdf/ps->png pdf png-file))))) |
| 830 | 840 | ||
| 831 | (let ((pages (doc-view-active-pages))) | 841 | (let ((pages (doc-view-active-pages))) |
| 832 | ;; Convert PDF to PNG images starting with the active pages. | 842 | ;; Convert PDF to PNG images starting with the active pages. |
| 833 | (doc-view-pdf->png doc-view-buffer-file-name png-file pages))) | 843 | (doc-view-pdf->png doc-view-buffer-file-name png-file pages))) |
| 834 | (t | 844 | (t |
| 835 | ;; Convert to PNG images. | 845 | ;; Convert to PNG images. |
| 836 | (doc-view-pdf/ps->png doc-view-buffer-file-name png-file))))) | 846 | (doc-view-pdf/ps->png doc-view-buffer-file-name png-file))))) |
| @@ -1129,7 +1139,13 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1129 | (defun doc-view-already-converted-p () | 1139 | (defun doc-view-already-converted-p () |
| 1130 | "Return non-nil if the current doc was already converted." | 1140 | "Return non-nil if the current doc was already converted." |
| 1131 | (and (file-exists-p (doc-view-current-cache-dir)) | 1141 | (and (file-exists-p (doc-view-current-cache-dir)) |
| 1132 | (> (length (directory-files (doc-view-current-cache-dir) nil "\\.png$")) 0))) | 1142 | ;; Check that the resolution info is there, otherwise it means |
| 1143 | ;; the conversion is incomplete. | ||
| 1144 | (file-readable-p (expand-file-name "resolution.el" | ||
| 1145 | (doc-view-current-cache-dir))) | ||
| 1146 | (> (length (directory-files (doc-view-current-cache-dir) | ||
| 1147 | nil "\\.png\\'")) | ||
| 1148 | 0))) | ||
| 1133 | 1149 | ||
| 1134 | (defun doc-view-initiate-display () | 1150 | (defun doc-view-initiate-display () |
| 1135 | ;; Switch to image display if possible | 1151 | ;; Switch to image display if possible |
| @@ -1141,14 +1157,14 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1141 | (progn | 1157 | (progn |
| 1142 | (message "DocView: using cached files!") | 1158 | (message "DocView: using cached files!") |
| 1143 | ;; Load the saved resolution | 1159 | ;; Load the saved resolution |
| 1144 | (let ((res-file (expand-file-name "resolution.el" | 1160 | (let* ((res-file (expand-file-name "resolution.el" |
| 1145 | (doc-view-current-cache-dir))) | 1161 | (doc-view-current-cache-dir))) |
| 1146 | (res doc-view-resolution)) | 1162 | (res |
| 1147 | (with-temp-buffer | 1163 | (with-temp-buffer |
| 1148 | (when (file-exists-p res-file) | 1164 | (when (file-readable-p res-file) |
| 1149 | (insert-file-contents res-file) | 1165 | (insert-file-contents res-file) |
| 1150 | (setq res (read (current-buffer))))) | 1166 | (read (current-buffer)))))) |
| 1151 | (when (numberp res) | 1167 | (when (numberp res) |
| 1152 | (set (make-local-variable 'doc-view-resolution) res))) | 1168 | (set (make-local-variable 'doc-view-resolution) res))) |
| 1153 | (doc-view-display (current-buffer) 'force)) | 1169 | (doc-view-display (current-buffer) 'force)) |
| 1154 | (doc-view-convert-current-doc)) | 1170 | (doc-view-convert-current-doc)) |
| @@ -1282,7 +1298,7 @@ toggle between displaying the document or editing it as text. | |||
| 1282 | 1298 | ||
| 1283 | (set (make-local-variable 'mode-line-position) | 1299 | (set (make-local-variable 'mode-line-position) |
| 1284 | '(" P" (:eval (number-to-string (doc-view-current-page))) | 1300 | '(" P" (:eval (number-to-string (doc-view-current-page))) |
| 1285 | "/" (:eval (number-to-string (length doc-view-current-files))))) | 1301 | "/" (:eval (number-to-string (doc-view-last-page-number))))) |
| 1286 | ;; Don't scroll unless the user specifically asked for it. | 1302 | ;; Don't scroll unless the user specifically asked for it. |
| 1287 | (set (make-local-variable 'auto-hscroll-mode) nil) | 1303 | (set (make-local-variable 'auto-hscroll-mode) nil) |
| 1288 | (set (make-local-variable 'mwheel-scroll-up-function) | 1304 | (set (make-local-variable 'mwheel-scroll-up-function) |