Mercurial > emacs
comparison lisp/doc-view.el @ 87133:a99e0ba48aeb
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 06 Dec 2007 15:04:29 +0000 |
parents | a15ce3ca213a |
children | 9ac481bc897b |
comparison
equal
deleted
inserted
replaced
87132:565c0401b7c2 | 87133:a99e0ba48aeb |
---|---|
506 | 506 |
507 (defun doc-view-dvi->pdf-sentinel (proc event) | 507 (defun doc-view-dvi->pdf-sentinel (proc event) |
508 "If DVI->PDF conversion was successful, convert the PDF to PNG now." | 508 "If DVI->PDF conversion was successful, convert the PDF to PNG now." |
509 (if (not (string-match "finished" event)) | 509 (if (not (string-match "finished" event)) |
510 (message "DocView: dvi->pdf process changed status to %s." event) | 510 (message "DocView: dvi->pdf process changed status to %s." event) |
511 (set-buffer (process-get proc 'buffer)) | 511 (with-current-buffer (process-get proc 'buffer) |
512 (setq doc-view-current-converter-process nil | 512 (setq doc-view-current-converter-process nil |
513 mode-line-process nil) | 513 mode-line-process nil) |
514 ;; Now go on converting this PDF to a set of PNG files. | 514 ;; Now go on converting this PDF to a set of PNG files. |
515 (let* ((pdf (process-get proc 'pdf-file)) | 515 (let* ((pdf (process-get proc 'pdf-file)) |
516 (png (expand-file-name "page-%d.png" | 516 (png (expand-file-name "page-%d.png" |
517 (doc-view-current-cache-dir)))) | 517 (doc-view-current-cache-dir)))) |
518 (doc-view-pdf/ps->png pdf png)))) | 518 (doc-view-pdf/ps->png pdf png))))) |
519 | 519 |
520 (defun doc-view-dvi->pdf (dvi pdf) | 520 (defun doc-view-dvi->pdf (dvi pdf) |
521 "Convert DVI to PDF asynchronously." | 521 "Convert DVI to PDF asynchronously." |
522 (setq doc-view-current-converter-process | 522 (setq doc-view-current-converter-process |
523 (start-process "dvi->pdf" doc-view-conversion-buffer | 523 (start-process "dvi->pdf" doc-view-conversion-buffer |
531 | 531 |
532 (defun doc-view-pdf/ps->png-sentinel (proc event) | 532 (defun doc-view-pdf/ps->png-sentinel (proc event) |
533 "If PDF/PS->PNG conversion was successful, update the display." | 533 "If PDF/PS->PNG conversion was successful, update the display." |
534 (if (not (string-match "finished" event)) | 534 (if (not (string-match "finished" event)) |
535 (message "DocView: converter process changed status to %s." event) | 535 (message "DocView: converter process changed status to %s." event) |
536 (set-buffer (process-get proc 'buffer)) | 536 (with-current-buffer (process-get proc 'buffer) |
537 (setq doc-view-current-converter-process nil | 537 (setq doc-view-current-converter-process nil |
538 mode-line-process nil) | 538 mode-line-process nil) |
539 (when doc-view-current-timer | 539 (when doc-view-current-timer |
540 (cancel-timer doc-view-current-timer) | 540 (cancel-timer doc-view-current-timer) |
541 (setq doc-view-current-timer nil)) | 541 (setq doc-view-current-timer nil)) |
542 ;; Yippie, finished. Update the display! | 542 ;; Yippie, finished. Update the display! |
543 (doc-view-display buffer-file-name))) | 543 (doc-view-display buffer-file-name 'force)))) |
544 | 544 |
545 (defun doc-view-pdf/ps->png (pdf-ps png) | 545 (defun doc-view-pdf/ps->png (pdf-ps png) |
546 "Convert PDF-PS to PNG asynchronously." | 546 "Convert PDF-PS to PNG asynchronously." |
547 (setq doc-view-current-converter-process | 547 (setq doc-view-current-converter-process |
548 (apply 'start-process | 548 (apply 'start-process |
566 (defun doc-view-pdf->txt-sentinel (proc event) | 566 (defun doc-view-pdf->txt-sentinel (proc event) |
567 (if (not (string-match "finished" event)) | 567 (if (not (string-match "finished" event)) |
568 (message "DocView: converter process changed status to %s." event) | 568 (message "DocView: converter process changed status to %s." event) |
569 (let ((current-buffer (current-buffer)) | 569 (let ((current-buffer (current-buffer)) |
570 (proc-buffer (process-get proc 'buffer))) | 570 (proc-buffer (process-get proc 'buffer))) |
571 (set-buffer proc-buffer) | 571 (with-current-buffer proc-buffer |
572 (setq doc-view-current-converter-process nil | 572 (setq doc-view-current-converter-process nil |
573 mode-line-process nil) | 573 mode-line-process nil) |
574 ;; If the user looks at the DocView buffer where the conversion was | 574 ;; If the user looks at the DocView buffer where the conversion was |
575 ;; performed, search anew. This time it will be queried for a regexp. | 575 ;; performed, search anew. This time it will be queried for a regexp. |
576 (when (eq current-buffer proc-buffer) | 576 (when (eq current-buffer proc-buffer) |
577 (doc-view-search nil))))) | 577 (doc-view-search nil)))))) |
578 | 578 |
579 (defun doc-view-pdf->txt (pdf txt) | 579 (defun doc-view-pdf->txt (pdf txt) |
580 "Convert PDF to TXT asynchronously." | 580 "Convert PDF to TXT asynchronously." |
581 (setq doc-view-current-converter-process | 581 (setq doc-view-current-converter-process |
582 (start-process "pdf->txt" doc-view-conversion-buffer | 582 (start-process "pdf->txt" doc-view-conversion-buffer |
588 (process-put doc-view-current-converter-process 'buffer (current-buffer))) | 588 (process-put doc-view-current-converter-process 'buffer (current-buffer))) |
589 | 589 |
590 (defun doc-view-ps->pdf-sentinel (proc event) | 590 (defun doc-view-ps->pdf-sentinel (proc event) |
591 (if (not (string-match "finished" event)) | 591 (if (not (string-match "finished" event)) |
592 (message "DocView: converter process changed status to %s." event) | 592 (message "DocView: converter process changed status to %s." event) |
593 (set-buffer (process-get proc 'buffer)) | 593 (with-current-buffer (process-get proc 'buffer) |
594 (setq doc-view-current-converter-process nil | 594 (setq doc-view-current-converter-process nil |
595 mode-line-process nil) | 595 mode-line-process nil) |
596 ;; Now we can transform to plain text. | 596 ;; Now we can transform to plain text. |
597 (doc-view-pdf->txt (process-get proc 'pdf-file) | 597 (doc-view-pdf->txt (process-get proc 'pdf-file) |
598 (expand-file-name "doc.txt" | 598 (expand-file-name "doc.txt" |
599 (doc-view-current-cache-dir))))) | 599 (doc-view-current-cache-dir)))))) |
600 | 600 |
601 (defun doc-view-ps->pdf (ps pdf) | 601 (defun doc-view-ps->pdf (ps pdf) |
602 "Convert PS to PDF asynchronously." | 602 "Convert PS to PDF asynchronously." |
603 (setq doc-view-current-converter-process | 603 (setq doc-view-current-converter-process |
604 (start-process "ps->pdf" doc-view-conversion-buffer | 604 (start-process "ps->pdf" doc-view-conversion-buffer |
705 Predicate for sorting `doc-view-current-files'." | 705 Predicate for sorting `doc-view-current-files'." |
706 (or (< (length a) (length b)) | 706 (or (< (length a) (length b)) |
707 (and (= (length a) (length b)) | 707 (and (= (length a) (length b)) |
708 (string< a b)))) | 708 (string< a b)))) |
709 | 709 |
710 (defun doc-view-display (doc) | 710 (defun doc-view-display (doc &optional force) |
711 "Start viewing the document DOC." | 711 "Start viewing the document DOC. |
712 (set-buffer (get-file-buffer doc)) | 712 If FORCE is non-nil, start viewing even if the document does not |
713 (setq doc-view-current-files | 713 have the page we want to view." |
714 (sort (directory-files (doc-view-current-cache-dir) t | 714 (with-current-buffer (get-file-buffer doc) |
715 "page-[0-9]+\\.png" t) | 715 (setq doc-view-current-files |
716 'doc-view-sort)) | 716 (sort (directory-files (doc-view-current-cache-dir) t |
717 (when (> (length doc-view-current-files) 0) | 717 "page-[0-9]+\\.png" t) |
718 (doc-view-goto-page doc-view-current-page))) | 718 'doc-view-sort)) |
719 (when (or force | |
720 (>= (length doc-view-current-files) | |
721 (or doc-view-current-page 1))) | |
722 (doc-view-goto-page doc-view-current-page)))) | |
719 | 723 |
720 (defun doc-view-buffer-message () | 724 (defun doc-view-buffer-message () |
721 ;; Only show this message initially, not when refreshing the buffer (in which | 725 ;; Only show this message initially, not when refreshing the buffer (in which |
722 ;; case it's better to keep displaying the "stale" page while computing | 726 ;; case it's better to keep displaying the "stale" page while computing |
723 ;; the fresh new ones). | 727 ;; the fresh new ones). |
896 (doc-view-buffer-message) | 900 (doc-view-buffer-message) |
897 (setq doc-view-current-page (or doc-view-current-page 1)) | 901 (setq doc-view-current-page (or doc-view-current-page 1)) |
898 (if (file-exists-p (doc-view-current-cache-dir)) | 902 (if (file-exists-p (doc-view-current-cache-dir)) |
899 (progn | 903 (progn |
900 (message "DocView: using cached files!") | 904 (message "DocView: using cached files!") |
901 (doc-view-display buffer-file-name)) | 905 (doc-view-display buffer-file-name 'force)) |
902 (doc-view-convert-current-doc)) | 906 (doc-view-convert-current-doc)) |
903 (message | 907 (message |
904 "%s" | 908 "%s" |
905 (substitute-command-keys | 909 (substitute-command-keys |
906 (concat "Type \\[doc-view-toggle-display] to toggle between " | 910 (concat "Type \\[doc-view-toggle-display] to toggle between " |