aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-02-25 20:04:59 +0000
committerStefan Monnier2008-02-25 20:04:59 +0000
commit56741510ef72437d6a9ce28b26b06d3693d9a0ce (patch)
tree9ac8251422954c1e39dd90cc2c28f0ea2a63e101
parentc48f463bdb6f9d8021c23c48136631869fd151f1 (diff)
downloademacs-56741510ef72437d6a9ce28b26b06d3693d9a0ce.tar.gz
emacs-56741510ef72437d6a9ce28b26b06d3693d9a0ce.zip
(doc-view-conversion-buffer): Give it an internal name.
Demote it to plain defvar. (doc-view-conversion-refresh-interval): Reduce interval. (doc-view-goto-page): Allow moving to pages not yet rendered. (doc-view-goto-page): Construct a file name rather than extracting it from doc-view-current-files. (doc-view-kill-proc): Ignore errors from kill-process. (doc-view-pdf/ps->png-sentinel): Die gracefully if the buffer is dead. (doc-view-insert-image): Use appropriate text if the page hasn't been rendered yet. Adjust scrolling so the text is displayed. (doc-view-display): Detect not just that a page is available, but also that it wasn't available before, to avoid refreshing all pages repeatedly. (doc-view-mode): Make doc-view-cache-directory if needed.
-rw-r--r--lisp/ChangeLog23
-rw-r--r--lisp/doc-view.el107
2 files changed, 89 insertions, 41 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c10fc02103f..89fd026d647 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,8 +1,25 @@
12008-02-25 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * doc-view.el (doc-view-conversion-buffer): Give it an internal name.
4 Demote it to plain defvar.
5 (doc-view-conversion-refresh-interval): Reduce interval.
6 (doc-view-goto-page): Allow moving to pages not yet rendered.
7 (doc-view-goto-page): Construct a file name rather than extracting it
8 from doc-view-current-files.
9 (doc-view-kill-proc): Ignore errors from kill-process.
10 (doc-view-pdf/ps->png-sentinel): Die gracefully if the buffer is dead.
11 (doc-view-insert-image): Use appropriate text if the page hasn't been
12 rendered yet. Adjust scrolling so the text is displayed.
13 (doc-view-display): Detect not just that a page is available, but also
14 that it wasn't available before, so as to avoid refreshing all pages
15 repeatedly.
16 (doc-view-mode): Make doc-view-cache-directory if needed.
17
12008-02-25 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> 182008-02-25 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
2 19
3 * textmodes/bibtex.el (bibtex-format-entry): Handle error message 20 * textmodes/bibtex.el (bibtex-format-entry): Handle error message
4 refering to a missing required field with the OPT prefix. Make 21 refering to a missing required field with the OPT prefix.
5 unwindform more robust. 22 Make unwindform more robust.
6 23
72008-02-25 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> 242008-02-25 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
8 25
@@ -10,7 +27,7 @@
10 it duplicates the bibtex support in progmodes/hideshow.el. 27 it duplicates the bibtex support in progmodes/hideshow.el.
11 * progmodes/hideshow.el (hs-special-modes-alist): Allow bibtex 28 * progmodes/hideshow.el (hs-special-modes-alist): Allow bibtex
12 entries that do not start at the beginning of a line. 29 entries that do not start at the beginning of a line.
13 30
142008-02-25 Chong Yidong <cyd@stupidchicken.com> 312008-02-25 Chong Yidong <cyd@stupidchicken.com>
15 32
16 * files.el (shell-quote-wildcard-pattern): Quote ' and " as well. 33 * files.el (shell-quote-wildcard-pattern): Quote ' and " as well.
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index c3ec4372920..1923c4f2d4f 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -99,10 +99,8 @@
99 99
100;;; Todo: 100;;; Todo:
101 101
102;; - fix behavior with clone-indirect-buffer 102;; - add print command.
103;; - allow different windows showing the same buffer to change pages 103;; - share more code with image-mode.
104;; independently.
105;; - share more code with image-mode again.
106;; - better menu. 104;; - better menu.
107;; - Bind slicing to a drag event. 105;; - Bind slicing to a drag event.
108;; - 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.
@@ -198,12 +196,10 @@ Needed for searching."
198 :type 'directory 196 :type 'directory
199 :group 'doc-view) 197 :group 'doc-view)
200 198
201(defcustom doc-view-conversion-buffer "*doc-view conversion output*" 199(defvar doc-view-conversion-buffer " *doc-view conversion output*"
202 "The buffer where messages from the converter programs go to." 200 "The buffer where messages from the converter programs go to.")
203 :type 'string
204 :group 'doc-view)
205 201
206(defcustom doc-view-conversion-refresh-interval 3 202(defcustom doc-view-conversion-refresh-interval 1
207 "Interval in seconds between refreshes of the DocView buffer while converting. 203 "Interval in seconds between refreshes of the DocView buffer while converting.
208After such a refresh newly converted pages will be available for 204After such a refresh newly converted pages will be available for
209viewing. If set to nil there won't be any refreshes and the 205viewing. If set to nil there won't be any refreshes and the
@@ -334,7 +330,10 @@ the (uncompressed, extracted) file residing in
334 (let ((len (length doc-view-current-files))) 330 (let ((len (length doc-view-current-files)))
335 (if (< page 1) 331 (if (< page 1)
336 (setq page 1) 332 (setq page 1)
337 (when (> page len) 333 (when (and (> page len)
334 ;; As long as the converter is running, we don't know
335 ;; how many pages will be available.
336 (null doc-view-current-converter-process))
338 (setq page len))) 337 (setq page len)))
339 (setf (doc-view-current-page) page 338 (setf (doc-view-current-page) page
340 (doc-view-current-info) 339 (doc-view-current-info)
@@ -355,7 +354,11 @@ the (uncompressed, extracted) file residing in
355 (setq contexts (concat contexts " - \"" m "\"\n"))) 354 (setq contexts (concat contexts " - \"" m "\"\n")))
356 contexts))))) 355 contexts)))))
357 ;; Update the buffer 356 ;; Update the buffer
358 (doc-view-insert-image (nth (1- page) doc-view-current-files) 357 ;; We used to find the file name from doc-view-current-files but
358 ;; that's not right if the pages are not generated sequentially
359 ;; or if the page isn't in doc-view-current-files yet.
360 (doc-view-insert-image (expand-file-name (format "page-%d.png" page)
361 (doc-view-current-cache-dir))
359 :pointer 'arrow) 362 :pointer 'arrow)
360 (overlay-put (doc-view-current-overlay) 363 (overlay-put (doc-view-current-overlay)
361 'help-echo (doc-view-current-info)))) 364 'help-echo (doc-view-current-info))))
@@ -404,7 +407,8 @@ the (uncompressed, extracted) file residing in
404 "Kill the current converter process." 407 "Kill the current converter process."
405 (interactive) 408 (interactive)
406 (when doc-view-current-converter-process 409 (when doc-view-current-converter-process
407 (kill-process doc-view-current-converter-process) 410 (ignore-errors ;; Maybe it's dead already?
411 (kill-process doc-view-current-converter-process))
408 (setq doc-view-current-converter-process nil)) 412 (setq doc-view-current-converter-process nil))
409 (when doc-view-current-timer 413 (when doc-view-current-timer
410 (cancel-timer doc-view-current-timer) 414 (cancel-timer doc-view-current-timer)
@@ -542,14 +546,16 @@ Should be invoked when the cached images aren't up-to-date."
542 "If PDF/PS->PNG conversion was successful, update the display." 546 "If PDF/PS->PNG conversion was successful, update the display."
543 (if (not (string-match "finished" event)) 547 (if (not (string-match "finished" event))
544 (message "DocView: converter process changed status to %s." event) 548 (message "DocView: converter process changed status to %s." event)
545 (with-current-buffer (process-get proc 'buffer) 549 ;; FIXME: kill the process if we kill the buffer?
546 (setq doc-view-current-converter-process nil 550 (when (buffer-live-p (process-get proc 'buffer))
547 mode-line-process nil) 551 (with-current-buffer (process-get proc 'buffer)
548 (when doc-view-current-timer 552 (setq doc-view-current-converter-process nil
549 (cancel-timer doc-view-current-timer) 553 mode-line-process nil)
550 (setq doc-view-current-timer nil)) 554 (when doc-view-current-timer
551 ;; Yippie, finished. Update the display! 555 (cancel-timer doc-view-current-timer)
552 (doc-view-display (current-buffer) 'force)))) 556 (setq doc-view-current-timer nil))
557 ;; Yippie, finished. Update the display!
558 (doc-view-display (current-buffer) 'force)))))
553 559
554(defun doc-view-pdf/ps->png (pdf-ps png) 560(defun doc-view-pdf/ps->png (pdf-ps png)
555 "Convert PDF-PS to PNG asynchronously." 561 "Convert PDF-PS to PNG asynchronously."
@@ -705,21 +711,38 @@ ARGS is a list of image descriptors."
705 (clear-image-cache) 711 (clear-image-cache)
706 (setq doc-view-pending-cache-flush nil)) 712 (setq doc-view-pending-cache-flush nil))
707 (let ((ol (doc-view-current-overlay)) 713 (let ((ol (doc-view-current-overlay))
708 (image (if file (apply 'create-image file 'png nil args))) 714 (image (if (and file (file-readable-p file))
715 (apply 'create-image file 'png nil args)))
709 (slice (doc-view-current-slice))) 716 (slice (doc-view-current-slice)))
710 (setf (doc-view-current-image) image) 717 (setf (doc-view-current-image) image)
711 (move-overlay ol (point-min) (point-max)) ;Probably redundant. 718 (move-overlay ol (point-min) (point-max))
712 (overlay-put ol 'display 719 (overlay-put ol 'display
713 (if (null image) 720 (cond
714 ;; We're trying to display a page that doesn't exist. 721 (image
715 ;; Typically happens if the conversion process somehow
716 ;; failed. Better not signal an error here because it
717 ;; could prevent a subsequent reconversion from fixing
718 ;; the problem.
719 "Cannot display this page! Probably a conversion failure!"
720 (if slice 722 (if slice
721 (list (cons 'slice slice) image) 723 (list (cons 'slice slice) image)
722 image))))) 724 image))
725 ;; We're trying to display a page that doesn't exist.
726 (doc-view-current-converter-process
727 ;; Maybe the page doesn't exist *yet*.
728 "Cannot display this page (yet)!")
729 (t
730 ;; Typically happens if the conversion process somehow
731 ;; failed. Better not signal an error here because it
732 ;; could prevent a subsequent reconversion from fixing
733 ;; the problem.
734 (concat "Cannot display this page!\n"
735 "Maybe because of a conversion failure!"))))
736 (let ((win (overlay-get ol 'window)))
737 (if (stringp (overlay-get ol 'display))
738 (progn ;Make sure the text is not scrolled out of view.
739 (set-window-hscroll win 0)
740 (set-window-vscroll win 0))
741 (let ((hscroll (image-mode-window-get 'hscroll win))
742 (vscroll (image-mode-window-get 'vscroll win)))
743 ;; Reset scroll settings, in case they were changed.
744 (if hscroll (set-window-hscroll win hscroll))
745 (if vscroll (set-window-vscroll win vscroll)))))))
723 746
724(defun doc-view-sort (a b) 747(defun doc-view-sort (a b)
725 "Return non-nil if A should be sorted before B. 748 "Return non-nil if A should be sorted before B.
@@ -733,14 +756,21 @@ Predicate for sorting `doc-view-current-files'."
733If FORCE is non-nil, start viewing even if the document does not 756If FORCE is non-nil, start viewing even if the document does not
734have the page we want to view." 757have the page we want to view."
735 (with-current-buffer buffer 758 (with-current-buffer buffer
736 (setq doc-view-current-files 759 (let ((prev-pages doc-view-current-files))
737 (sort (directory-files (doc-view-current-cache-dir) t 760 (setq doc-view-current-files
738 "page-[0-9]+\\.png" t) 761 (sort (directory-files (doc-view-current-cache-dir) t
739 'doc-view-sort)) 762 "page-[0-9]+\\.png" t)
740 (let ((page (doc-view-current-page))) 763 'doc-view-sort))
741 (when (or force 764 (dolist (win (get-buffer-window-list buffer nil t))
742 (>= (length doc-view-current-files) (or page 1))) 765 (let* ((page (doc-view-current-page win))
743 (doc-view-goto-page page))))) 766 (pagefile (expand-file-name (format "page-%d.png" page)
767 (doc-view-current-cache-dir))))
768 (when (or force
769 (and (not (member pagefile prev-pages))
770 (member pagefile doc-view-current-files)))
771 (with-selected-window win
772 (assert (eq (current-buffer) buffer))
773 (doc-view-goto-page page))))))))
744 774
745(defun doc-view-buffer-message () 775(defun doc-view-buffer-message ()
746 ;; Only show this message initially, not when refreshing the buffer (in which 776 ;; Only show this message initially, not when refreshing the buffer (in which
@@ -968,6 +998,7 @@ toggle between displaying the document or editing it as text.
968 (kill-all-local-variables) 998 (kill-all-local-variables)
969 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) 999 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
970 1000
1001 (doc-view-make-safe-dir doc-view-cache-directory)
971 ;; Handle compressed files, remote files, files inside archives 1002 ;; Handle compressed files, remote files, files inside archives
972 (set (make-local-variable 'doc-view-buffer-file-name) 1003 (set (make-local-variable 'doc-view-buffer-file-name)
973 (cond 1004 (cond