aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-03-12 15:26:49 +0000
committerStefan Monnier2008-03-12 15:26:49 +0000
commitb4cb319f0a5638aca3aaf655d6795c860e27c56f (patch)
tree63f9dfa723f30b67463bc17ac5fcbb1812b4b135
parent3c1beeeb873317b0e0b1e12b66e1afec4836003e (diff)
downloademacs-b4cb319f0a5638aca3aaf655d6795c860e27c56f.tar.gz
emacs-b4cb319f0a5638aca3aaf655d6795c860e27c56f.zip
Remove all cb-args, use closures instead.
(doc-view-sentinel): Merge doc-view-dvi->pdf-sentinel, doc-view-ps->pdf-sentinel, and doc-view-pdf->txt-sentinel (which was doing an incorrect check). Update all callers to use the new name. (doc-view-doc->txt): Add missing `txt' argument.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/doc-view.el137
2 files changed, 58 insertions, 87 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bceadaa6d86..ef3495eada7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12008-03-12 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * doc-view.el: Remove all cb-args, use closures instead.
4 (doc-view-sentinel): Merge doc-view-dvi->pdf-sentinel,
5 doc-view-ps->pdf-sentinel, and doc-view-pdf->txt-sentinel (which was
6 doing an incorrect check). Update all callers to use the new name.
7 (doc-view-doc->txt): Add missing `txt' argument.
8
12008-03-12 Tassilo Horn <tassilo@member.fsf.org> 92008-03-12 Tassilo Horn <tassilo@member.fsf.org>
2 10
3 * doc-view.el (doc-view-current-cache-dir): Set buffer used for 11 * doc-view.el (doc-view-current-cache-dir): Set buffer used for
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index a68e41e3b90..0ffc0471024 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -526,29 +526,26 @@ Should be invoked when the cached images aren't up-to-date."
526 (dired-delete-file (doc-view-current-cache-dir) 'always)) 526 (dired-delete-file (doc-view-current-cache-dir) 'always))
527 (doc-view-initiate-display)) 527 (doc-view-initiate-display))
528 528
529(defun doc-view-dvi->pdf-sentinel (proc event) 529(defun doc-view-sentinel (proc event)
530 "If DVI->PDF conversion was successful, convert the PDF to PNG now." 530 "Generic sentinel for doc-view conversion processes."
531 (if (not (string-match "finished" event)) 531 (if (not (string-match "finished" event))
532 (message "DocView: dvi->pdf process changed status to %s." event) 532 (message "DocView: process %s changed status to %s."
533 (process-name proc) event)
533 (with-current-buffer (process-get proc 'buffer) 534 (with-current-buffer (process-get proc 'buffer)
534 (let ((callback (process-get proc 'callback)) 535 (setq doc-view-current-converter-process nil
535 (cb-args (process-get proc 'cb-args))) 536 mode-line-process nil)
536 (setq doc-view-current-converter-process nil 537 (funcall (process-get proc 'callback)))))
537 mode-line-process nil) 538
538 (apply callback cb-args))))) 539(defun doc-view-dvi->pdf (dvi pdf callback)
539 540 "Convert DVI to PDF asynchronously and call CALLBACK when finished."
540(defun doc-view-dvi->pdf (dvi pdf callback &rest cb-args)
541 "Convert DVI to PDF asynchronously and call CALLBACK with CB-ARGS when finished."
542 (setq doc-view-current-converter-process 541 (setq doc-view-current-converter-process
543 (start-process "dvi->pdf" doc-view-conversion-buffer 542 (start-process "dvi->pdf" doc-view-conversion-buffer
544 doc-view-dvipdfm-program 543 doc-view-dvipdfm-program
545 "-o" pdf dvi) 544 "-o" pdf dvi)
546 mode-line-process (list (format ":%s" doc-view-current-converter-process))) 545 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
547 (set-process-sentinel doc-view-current-converter-process 546 (set-process-sentinel doc-view-current-converter-process 'doc-view-sentinel)
548 'doc-view-dvi->pdf-sentinel)
549 (process-put doc-view-current-converter-process 'buffer (current-buffer)) 547 (process-put doc-view-current-converter-process 'buffer (current-buffer))
550 (process-put doc-view-current-converter-process 'callback callback) 548 (process-put doc-view-current-converter-process 'callback callback))
551 (process-put doc-view-current-converter-process 'cb-args cb-args))
552 549
553(defun doc-view-pdf/ps->png-sentinel (proc event) 550(defun doc-view-pdf/ps->png-sentinel (proc event)
554 "If PDF/PS->PNG conversion was successful, update the display." 551 "If PDF/PS->PNG conversion was successful, update the display."
@@ -589,78 +586,44 @@ Should be invoked when the cached images aren't up-to-date."
589 'doc-view-display 586 'doc-view-display
590 (current-buffer))))) 587 (current-buffer)))))
591 588
592(defun doc-view-pdf->txt-sentinel (proc event) 589(defun doc-view-pdf->txt (pdf txt callback)
593 (if (not (string-match "finished" event)) 590 "Convert PDF to TXT asynchronously and call CALLBACK when finished."
594 (message "DocView: converter process changed status to %s." event)
595 (let ((current-buffer (current-buffer))
596 (proc-buffer (process-get proc 'buffer)))
597 (with-current-buffer proc-buffer
598 (let ((callback (process-get doc-view-current-converter-process 'callback))
599 (cb-args (process-get doc-view-current-converter-process 'cb-args)))
600 (setq doc-view-current-converter-process nil
601 mode-line-process nil)
602 ;; If the user looks at the DocView buffer where the conversion was
603 ;; performed, call callback.
604 (when (eq current-buffer proc-buffer)
605 (apply callback cb-args)))))))
606
607(defun doc-view-pdf->txt (pdf txt callback &rest cb-args)
608 "Convert PDF to TXT asynchronously and call CALLBACK with CB-ARGS when finished."
609 (setq doc-view-current-converter-process 591 (setq doc-view-current-converter-process
610 (start-process "pdf->txt" doc-view-conversion-buffer 592 (start-process "pdf->txt" doc-view-conversion-buffer
611 doc-view-pdftotext-program "-raw" 593 doc-view-pdftotext-program "-raw"
612 pdf txt) 594 pdf txt)
613 mode-line-process (list (format ":%s" doc-view-current-converter-process))) 595 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
614 (set-process-sentinel doc-view-current-converter-process 596 (set-process-sentinel doc-view-current-converter-process
615 'doc-view-pdf->txt-sentinel) 597 'doc-view-sentinel)
616 (process-put doc-view-current-converter-process 'buffer (current-buffer)) 598 (process-put doc-view-current-converter-process 'buffer (current-buffer))
617 (process-put doc-view-current-converter-process 'callback callback) 599 (process-put doc-view-current-converter-process 'callback callback))
618 (process-put doc-view-current-converter-process 'cb-args cb-args))
619 600
620(defun doc-view-doc->txt (callback &rest cb-args) 601(defun doc-view-doc->txt (txt callback)
621 "Convert the current document to text and call CALLBACK with CB-ARGS when done." 602 "Convert the current document to text and call CALLBACK when done."
622 (make-directory (doc-view-current-cache-dir)) 603 (make-directory (doc-view-current-cache-dir))
623 (let ((ext (file-name-extension doc-view-buffer-file-name))) 604 (case doc-view-doc-type
624 (case doc-view-doc-type 605 (pdf
625 (pdf 606 ;; Doc is a PDF, so convert it to TXT
626 ;; Doc is a PDF, so convert it to TXT 607 (doc-view-pdf->txt doc-view-buffer-file-name txt callback))
627 (if cb-args 608 (ps
628 (doc-view-pdf->txt doc-view-buffer-file-name txt callback cb-args) 609 ;; Doc is a PS, so convert it to PDF (which will be converted to
629 (doc-view-pdf->txt doc-view-buffer-file-name txt callback))) 610 ;; TXT thereafter).
630 (ps 611 (lexical-let ((pdf (expand-file-name "doc.pdf"
631 ;; Doc is a PS, so convert it to PDF (which will be converted to 612 (doc-view-current-cache-dir)))
632 ;; TXT thereafter). 613 (txt txt)
633 (let ((pdf (expand-file-name "doc.pdf" 614 (callback callback))
634 (doc-view-current-cache-dir)))) 615 (doc-view-ps->pdf doc-view-buffer-file-name pdf
635 (if cb-args 616 (lambda () (doc-view-pdf->txt pdf txt callback)))))
636 (doc-view-ps->pdf doc-view-buffer-file-name pdf 617 (dvi
637 'doc-view-pdf->txt 618 ;; Doc is a DVI. This means that a doc.pdf already exists in its
638 pdf txt callback cb-args) 619 ;; cache subdirectory.
639 (doc-view-ps->pdf doc-view-buffer-file-name pdf 620 (doc-view-pdf->txt (expand-file-name "doc.pdf"
640 'doc-view-pdf->txt 621 (doc-view-current-cache-dir))
641 pdf txt callback)))) 622 txt callback))
642 (dvi 623 (t (error "DocView doesn't know what to do"))))
643 ;; Doc is a DVI. This means that a doc.pdf already exists in its 624
644 ;; cache subdirectory. 625(defun doc-view-ps->pdf (ps pdf callback)
645 (if cb-args 626 "Convert PS to PDF asynchronously and call CALLBACK when finished."
646 (doc-view-pdf->txt (expand-file-name "doc.pdf"
647 (doc-view-current-cache-dir))
648 txt callback cb-args)
649 (doc-view-pdf->txt (expand-file-name "doc.pdf"
650 (doc-view-current-cache-dir))
651 txt callback)))
652 (t (error "DocView doesn't know what to do")))))
653
654(defun doc-view-ps->pdf-sentinel (proc event)
655 (if (not (string-match "finished" event))
656 (message "DocView: converter process changed status to %s." event)
657 (with-current-buffer (process-get proc 'buffer)
658 (setq doc-view-current-converter-process nil
659 mode-line-process nil)
660 (apply (process-get proc 'callback) (process-get proc 'cb-args)))))
661
662(defun doc-view-ps->pdf (ps pdf callback &rest cb-args)
663 "Convert PS to PDF asynchronously and call CALLBACK with CB-ARGS when finished."
664 (setq doc-view-current-converter-process 627 (setq doc-view-current-converter-process
665 (start-process "ps->pdf" doc-view-conversion-buffer 628 (start-process "ps->pdf" doc-view-conversion-buffer
666 doc-view-ps2pdf-program 629 doc-view-ps2pdf-program
@@ -670,11 +633,9 @@ Should be invoked when the cached images aren't up-to-date."
670 ;; in-file and out-file 633 ;; in-file and out-file
671 ps pdf) 634 ps pdf)
672 mode-line-process (list (format ":%s" doc-view-current-converter-process))) 635 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
673 (set-process-sentinel doc-view-current-converter-process 636 (set-process-sentinel doc-view-current-converter-process 'doc-view-sentinel)
674 'doc-view-ps->pdf-sentinel)
675 (process-put doc-view-current-converter-process 'buffer (current-buffer)) 637 (process-put doc-view-current-converter-process 'buffer (current-buffer))
676 (process-put doc-view-current-converter-process 'callback callback) 638 (process-put doc-view-current-converter-process 'callback callback))
677 (process-put doc-view-current-converter-process 'cb-args cb-args))
678 639
679(defun doc-view-convert-current-doc () 640(defun doc-view-convert-current-doc ()
680 "Convert `doc-view-buffer-file-name' to a set of png files, one file per page. 641 "Convert `doc-view-buffer-file-name' to a set of png files, one file per page.
@@ -693,9 +654,11 @@ Those files are saved in the directory given by the function
693 (dvi 654 (dvi
694 ;; DVI files have to be converted to PDF before Ghostscript can process 655 ;; DVI files have to be converted to PDF before Ghostscript can process
695 ;; it. 656 ;; it.
696 (let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))) 657 (lexical-let
697 (doc-view-dvi->pdf doc-view-buffer-file-name 658 ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))
698 pdf 'doc-view-pdf/ps->png pdf png-file))) 659 (png-file png-file))
660 (doc-view-dvi->pdf doc-view-buffer-file-name pdf
661 (lambda () (doc-view-pdf/ps->png pdf png-file)))))
699 (t 662 (t
700 ;; Convert to PNG images. 663 ;; Convert to PNG images.
701 (doc-view-pdf/ps->png doc-view-buffer-file-name png-file))))) 664 (doc-view-pdf/ps->png doc-view-buffer-file-name png-file)))))
@@ -849,7 +812,7 @@ For now these keys are useful:
849 (let ((txt (expand-file-name "doc.txt" (doc-view-current-cache-dir)))) 812 (let ((txt (expand-file-name "doc.txt" (doc-view-current-cache-dir))))
850 (if (file-readable-p txt) 813 (if (file-readable-p txt)
851 (find-file txt) 814 (find-file txt)
852 (doc-view-doc->txt 'doc-view-open-text))))) 815 (doc-view-doc->txt txt 'doc-view-open-text)))))
853 816
854;;;;; Toggle between editing and viewing 817;;;;; Toggle between editing and viewing
855 818
@@ -952,7 +915,7 @@ If BACKWARD is non-nil, jump to the previous match."
952 ;; We must convert to TXT first! 915 ;; We must convert to TXT first!
953 (if doc-view-current-converter-process 916 (if doc-view-current-converter-process
954 (message "DocView: please wait till conversion finished.") 917 (message "DocView: please wait till conversion finished.")
955 (doc-view-doc->txt 'doc-view-search nil)))))) 918 (doc-view-doc->txt txt (lambda () (doc-view-search nil))))))))
956 919
957(defun doc-view-search-next-match (arg) 920(defun doc-view-search-next-match (arg)
958 "Go to the ARGth next matching page." 921 "Go to the ARGth next matching page."