# HG changeset patch # User Stefan Monnier # Date 1196953469 0 # Node ID a99e0ba48aeb387dc52b459a3050bb1a375dbf19 # Parent 565c0401b7c2c68d23b88d79df6383791183fc6f (doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel) (doc-view-pdf->txt-sentinel, doc-view-ps->pdf-sentinel, doc-view-display): Don't change buffer within a sentinel or timer. (doc-view-display): Don't try to display before the requested page is available, unless told to do so explicitly. (doc-view-pdf/ps->png-sentinel, doc-view-initiate-display): Force display even if the requested page is not available. diff -r 565c0401b7c2 -r a99e0ba48aeb lisp/ChangeLog --- a/lisp/ChangeLog Thu Dec 06 13:30:14 2007 +0000 +++ b/lisp/ChangeLog Thu Dec 06 15:04:29 2007 +0000 @@ -1,3 +1,14 @@ +2007-12-06 Stefan Monnier + + * doc-view.el (doc-view-dvi->pdf-sentinel) + (doc-view-pdf/ps->png-sentinel, doc-view-pdf->txt-sentinel) + (doc-view-ps->pdf-sentinel, doc-view-display): Don't change buffer + within a sentinel or timer. + (doc-view-display): Don't try to display before the requested page + is available, unless told to do so explicitly. + (doc-view-pdf/ps->png-sentinel, doc-view-initiate-display): + Force display even if the requested page is not available. + 2007-12-06 Richard Stallman * help-fns.el (describe-function-1): Call ad-get-advice-info diff -r 565c0401b7c2 -r a99e0ba48aeb lisp/doc-view.el --- a/lisp/doc-view.el Thu Dec 06 13:30:14 2007 +0000 +++ b/lisp/doc-view.el Thu Dec 06 15:04:29 2007 +0000 @@ -508,14 +508,14 @@ "If DVI->PDF conversion was successful, convert the PDF to PNG now." (if (not (string-match "finished" event)) (message "DocView: dvi->pdf process changed status to %s." event) - (set-buffer (process-get proc 'buffer)) - (setq doc-view-current-converter-process nil - mode-line-process nil) - ;; Now go on converting this PDF to a set of PNG files. - (let* ((pdf (process-get proc 'pdf-file)) - (png (expand-file-name "page-%d.png" - (doc-view-current-cache-dir)))) - (doc-view-pdf/ps->png pdf png)))) + (with-current-buffer (process-get proc 'buffer) + (setq doc-view-current-converter-process nil + mode-line-process nil) + ;; Now go on converting this PDF to a set of PNG files. + (let* ((pdf (process-get proc 'pdf-file)) + (png (expand-file-name "page-%d.png" + (doc-view-current-cache-dir)))) + (doc-view-pdf/ps->png pdf png))))) (defun doc-view-dvi->pdf (dvi pdf) "Convert DVI to PDF asynchronously." @@ -533,14 +533,14 @@ "If PDF/PS->PNG conversion was successful, update the display." (if (not (string-match "finished" event)) (message "DocView: converter process changed status to %s." event) - (set-buffer (process-get proc 'buffer)) - (setq doc-view-current-converter-process nil - mode-line-process nil) - (when doc-view-current-timer - (cancel-timer doc-view-current-timer) - (setq doc-view-current-timer nil)) - ;; Yippie, finished. Update the display! - (doc-view-display buffer-file-name))) + (with-current-buffer (process-get proc 'buffer) + (setq doc-view-current-converter-process nil + mode-line-process nil) + (when doc-view-current-timer + (cancel-timer doc-view-current-timer) + (setq doc-view-current-timer nil)) + ;; Yippie, finished. Update the display! + (doc-view-display buffer-file-name 'force)))) (defun doc-view-pdf/ps->png (pdf-ps png) "Convert PDF-PS to PNG asynchronously." @@ -568,13 +568,13 @@ (message "DocView: converter process changed status to %s." event) (let ((current-buffer (current-buffer)) (proc-buffer (process-get proc 'buffer))) - (set-buffer proc-buffer) - (setq doc-view-current-converter-process nil - mode-line-process nil) - ;; If the user looks at the DocView buffer where the conversion was - ;; performed, search anew. This time it will be queried for a regexp. - (when (eq current-buffer proc-buffer) - (doc-view-search nil))))) + (with-current-buffer proc-buffer + (setq doc-view-current-converter-process nil + mode-line-process nil) + ;; If the user looks at the DocView buffer where the conversion was + ;; performed, search anew. This time it will be queried for a regexp. + (when (eq current-buffer proc-buffer) + (doc-view-search nil)))))) (defun doc-view-pdf->txt (pdf txt) "Convert PDF to TXT asynchronously." @@ -590,13 +590,13 @@ (defun doc-view-ps->pdf-sentinel (proc event) (if (not (string-match "finished" event)) (message "DocView: converter process changed status to %s." event) - (set-buffer (process-get proc 'buffer)) - (setq doc-view-current-converter-process nil - mode-line-process nil) - ;; Now we can transform to plain text. - (doc-view-pdf->txt (process-get proc 'pdf-file) - (expand-file-name "doc.txt" - (doc-view-current-cache-dir))))) + (with-current-buffer (process-get proc 'buffer) + (setq doc-view-current-converter-process nil + mode-line-process nil) + ;; Now we can transform to plain text. + (doc-view-pdf->txt (process-get proc 'pdf-file) + (expand-file-name "doc.txt" + (doc-view-current-cache-dir)))))) (defun doc-view-ps->pdf (ps pdf) "Convert PS to PDF asynchronously." @@ -707,15 +707,19 @@ (and (= (length a) (length b)) (string< a b)))) -(defun doc-view-display (doc) - "Start viewing the document DOC." - (set-buffer (get-file-buffer doc)) - (setq doc-view-current-files - (sort (directory-files (doc-view-current-cache-dir) t - "page-[0-9]+\\.png" t) - 'doc-view-sort)) - (when (> (length doc-view-current-files) 0) - (doc-view-goto-page doc-view-current-page))) +(defun doc-view-display (doc &optional force) + "Start viewing the document DOC. +If FORCE is non-nil, start viewing even if the document does not +have the page we want to view." + (with-current-buffer (get-file-buffer doc) + (setq doc-view-current-files + (sort (directory-files (doc-view-current-cache-dir) t + "page-[0-9]+\\.png" t) + 'doc-view-sort)) + (when (or force + (>= (length doc-view-current-files) + (or doc-view-current-page 1))) + (doc-view-goto-page doc-view-current-page)))) (defun doc-view-buffer-message () ;; Only show this message initially, not when refreshing the buffer (in which @@ -898,7 +902,7 @@ (if (file-exists-p (doc-view-current-cache-dir)) (progn (message "DocView: using cached files!") - (doc-view-display buffer-file-name)) + (doc-view-display buffer-file-name 'force)) (doc-view-convert-current-doc)) (message "%s"