mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-11 09:20:51 +00:00
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.
This commit is contained in:
parent
3c1beeeb87
commit
b4cb319f0a
@ -1,3 +1,11 @@
|
|||||||
|
2008-03-12 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||||
|
|
||||||
|
* doc-view.el: 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.
|
||||||
|
|
||||||
2008-03-12 Tassilo Horn <tassilo@member.fsf.org>
|
2008-03-12 Tassilo Horn <tassilo@member.fsf.org>
|
||||||
|
|
||||||
* doc-view.el (doc-view-current-cache-dir): Set buffer used for
|
* doc-view.el (doc-view-current-cache-dir): Set buffer used for
|
||||||
|
105
lisp/doc-view.el
105
lisp/doc-view.el
@ -526,29 +526,26 @@ Should be invoked when the cached images aren't up-to-date."
|
|||||||
(dired-delete-file (doc-view-current-cache-dir) 'always))
|
(dired-delete-file (doc-view-current-cache-dir) 'always))
|
||||||
(doc-view-initiate-display))
|
(doc-view-initiate-display))
|
||||||
|
|
||||||
(defun doc-view-dvi->pdf-sentinel (proc event)
|
(defun doc-view-sentinel (proc event)
|
||||||
"If DVI->PDF conversion was successful, convert the PDF to PNG now."
|
"Generic sentinel for doc-view conversion processes."
|
||||||
(if (not (string-match "finished" event))
|
(if (not (string-match "finished" event))
|
||||||
(message "DocView: dvi->pdf process changed status to %s." event)
|
(message "DocView: process %s changed status to %s."
|
||||||
|
(process-name proc) event)
|
||||||
(with-current-buffer (process-get proc 'buffer)
|
(with-current-buffer (process-get proc 'buffer)
|
||||||
(let ((callback (process-get proc 'callback))
|
|
||||||
(cb-args (process-get proc 'cb-args)))
|
|
||||||
(setq doc-view-current-converter-process nil
|
(setq doc-view-current-converter-process nil
|
||||||
mode-line-process nil)
|
mode-line-process nil)
|
||||||
(apply callback cb-args)))))
|
(funcall (process-get proc 'callback)))))
|
||||||
|
|
||||||
(defun doc-view-dvi->pdf (dvi pdf callback &rest cb-args)
|
(defun doc-view-dvi->pdf (dvi pdf callback)
|
||||||
"Convert DVI to PDF asynchronously and call CALLBACK with CB-ARGS when finished."
|
"Convert DVI to PDF asynchronously and call CALLBACK when finished."
|
||||||
(setq doc-view-current-converter-process
|
(setq doc-view-current-converter-process
|
||||||
(start-process "dvi->pdf" doc-view-conversion-buffer
|
(start-process "dvi->pdf" doc-view-conversion-buffer
|
||||||
doc-view-dvipdfm-program
|
doc-view-dvipdfm-program
|
||||||
"-o" pdf dvi)
|
"-o" pdf dvi)
|
||||||
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
|
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
|
||||||
(set-process-sentinel doc-view-current-converter-process
|
(set-process-sentinel doc-view-current-converter-process 'doc-view-sentinel)
|
||||||
'doc-view-dvi->pdf-sentinel)
|
|
||||||
(process-put doc-view-current-converter-process 'buffer (current-buffer))
|
(process-put doc-view-current-converter-process 'buffer (current-buffer))
|
||||||
(process-put doc-view-current-converter-process 'callback callback)
|
(process-put doc-view-current-converter-process 'callback callback))
|
||||||
(process-put doc-view-current-converter-process 'cb-args cb-args))
|
|
||||||
|
|
||||||
(defun doc-view-pdf/ps->png-sentinel (proc event)
|
(defun doc-view-pdf/ps->png-sentinel (proc event)
|
||||||
"If PDF/PS->PNG conversion was successful, update the display."
|
"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."
|
|||||||
'doc-view-display
|
'doc-view-display
|
||||||
(current-buffer)))))
|
(current-buffer)))))
|
||||||
|
|
||||||
(defun doc-view-pdf->txt-sentinel (proc event)
|
(defun doc-view-pdf->txt (pdf txt callback)
|
||||||
(if (not (string-match "finished" event))
|
"Convert PDF to TXT asynchronously and call CALLBACK when finished."
|
||||||
(message "DocView: converter process changed status to %s." event)
|
|
||||||
(let ((current-buffer (current-buffer))
|
|
||||||
(proc-buffer (process-get proc 'buffer)))
|
|
||||||
(with-current-buffer proc-buffer
|
|
||||||
(let ((callback (process-get doc-view-current-converter-process 'callback))
|
|
||||||
(cb-args (process-get doc-view-current-converter-process 'cb-args)))
|
|
||||||
(setq doc-view-current-converter-process nil
|
|
||||||
mode-line-process nil)
|
|
||||||
;; If the user looks at the DocView buffer where the conversion was
|
|
||||||
;; performed, call callback.
|
|
||||||
(when (eq current-buffer proc-buffer)
|
|
||||||
(apply callback cb-args)))))))
|
|
||||||
|
|
||||||
(defun doc-view-pdf->txt (pdf txt callback &rest cb-args)
|
|
||||||
"Convert PDF to TXT asynchronously and call CALLBACK with CB-ARGS when finished."
|
|
||||||
(setq doc-view-current-converter-process
|
(setq doc-view-current-converter-process
|
||||||
(start-process "pdf->txt" doc-view-conversion-buffer
|
(start-process "pdf->txt" doc-view-conversion-buffer
|
||||||
doc-view-pdftotext-program "-raw"
|
doc-view-pdftotext-program "-raw"
|
||||||
pdf txt)
|
pdf txt)
|
||||||
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
|
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
|
||||||
(set-process-sentinel doc-view-current-converter-process
|
(set-process-sentinel doc-view-current-converter-process
|
||||||
'doc-view-pdf->txt-sentinel)
|
'doc-view-sentinel)
|
||||||
(process-put doc-view-current-converter-process 'buffer (current-buffer))
|
(process-put doc-view-current-converter-process 'buffer (current-buffer))
|
||||||
(process-put doc-view-current-converter-process 'callback callback)
|
(process-put doc-view-current-converter-process 'callback callback))
|
||||||
(process-put doc-view-current-converter-process 'cb-args cb-args))
|
|
||||||
|
|
||||||
(defun doc-view-doc->txt (callback &rest cb-args)
|
(defun doc-view-doc->txt (txt callback)
|
||||||
"Convert the current document to text and call CALLBACK with CB-ARGS when done."
|
"Convert the current document to text and call CALLBACK when done."
|
||||||
(make-directory (doc-view-current-cache-dir))
|
(make-directory (doc-view-current-cache-dir))
|
||||||
(let ((ext (file-name-extension doc-view-buffer-file-name)))
|
|
||||||
(case doc-view-doc-type
|
(case doc-view-doc-type
|
||||||
(pdf
|
(pdf
|
||||||
;; Doc is a PDF, so convert it to TXT
|
;; Doc is a PDF, so convert it to TXT
|
||||||
(if cb-args
|
(doc-view-pdf->txt doc-view-buffer-file-name txt callback))
|
||||||
(doc-view-pdf->txt doc-view-buffer-file-name txt callback cb-args)
|
|
||||||
(doc-view-pdf->txt doc-view-buffer-file-name txt callback)))
|
|
||||||
(ps
|
(ps
|
||||||
;; Doc is a PS, so convert it to PDF (which will be converted to
|
;; Doc is a PS, so convert it to PDF (which will be converted to
|
||||||
;; TXT thereafter).
|
;; TXT thereafter).
|
||||||
(let ((pdf (expand-file-name "doc.pdf"
|
(lexical-let ((pdf (expand-file-name "doc.pdf"
|
||||||
(doc-view-current-cache-dir))))
|
(doc-view-current-cache-dir)))
|
||||||
(if cb-args
|
(txt txt)
|
||||||
|
(callback callback))
|
||||||
(doc-view-ps->pdf doc-view-buffer-file-name pdf
|
(doc-view-ps->pdf doc-view-buffer-file-name pdf
|
||||||
'doc-view-pdf->txt
|
(lambda () (doc-view-pdf->txt pdf txt callback)))))
|
||||||
pdf txt callback cb-args)
|
|
||||||
(doc-view-ps->pdf doc-view-buffer-file-name pdf
|
|
||||||
'doc-view-pdf->txt
|
|
||||||
pdf txt callback))))
|
|
||||||
(dvi
|
(dvi
|
||||||
;; Doc is a DVI. This means that a doc.pdf already exists in its
|
;; Doc is a DVI. This means that a doc.pdf already exists in its
|
||||||
;; cache subdirectory.
|
;; cache subdirectory.
|
||||||
(if cb-args
|
|
||||||
(doc-view-pdf->txt (expand-file-name "doc.pdf"
|
(doc-view-pdf->txt (expand-file-name "doc.pdf"
|
||||||
(doc-view-current-cache-dir))
|
(doc-view-current-cache-dir))
|
||||||
txt callback cb-args)
|
txt callback))
|
||||||
(doc-view-pdf->txt (expand-file-name "doc.pdf"
|
(t (error "DocView doesn't know what to do"))))
|
||||||
(doc-view-current-cache-dir))
|
|
||||||
txt callback)))
|
|
||||||
(t (error "DocView doesn't know what to do")))))
|
|
||||||
|
|
||||||
(defun doc-view-ps->pdf-sentinel (proc event)
|
(defun doc-view-ps->pdf (ps pdf callback)
|
||||||
(if (not (string-match "finished" event))
|
"Convert PS to PDF asynchronously and call CALLBACK when finished."
|
||||||
(message "DocView: converter process changed status to %s." event)
|
|
||||||
(with-current-buffer (process-get proc 'buffer)
|
|
||||||
(setq doc-view-current-converter-process nil
|
|
||||||
mode-line-process nil)
|
|
||||||
(apply (process-get proc 'callback) (process-get proc 'cb-args)))))
|
|
||||||
|
|
||||||
(defun doc-view-ps->pdf (ps pdf callback &rest cb-args)
|
|
||||||
"Convert PS to PDF asynchronously and call CALLBACK with CB-ARGS when finished."
|
|
||||||
(setq doc-view-current-converter-process
|
(setq doc-view-current-converter-process
|
||||||
(start-process "ps->pdf" doc-view-conversion-buffer
|
(start-process "ps->pdf" doc-view-conversion-buffer
|
||||||
doc-view-ps2pdf-program
|
doc-view-ps2pdf-program
|
||||||
@ -670,11 +633,9 @@ Should be invoked when the cached images aren't up-to-date."
|
|||||||
;; in-file and out-file
|
;; in-file and out-file
|
||||||
ps pdf)
|
ps pdf)
|
||||||
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
|
mode-line-process (list (format ":%s" doc-view-current-converter-process)))
|
||||||
(set-process-sentinel doc-view-current-converter-process
|
(set-process-sentinel doc-view-current-converter-process 'doc-view-sentinel)
|
||||||
'doc-view-ps->pdf-sentinel)
|
|
||||||
(process-put doc-view-current-converter-process 'buffer (current-buffer))
|
(process-put doc-view-current-converter-process 'buffer (current-buffer))
|
||||||
(process-put doc-view-current-converter-process 'callback callback)
|
(process-put doc-view-current-converter-process 'callback callback))
|
||||||
(process-put doc-view-current-converter-process 'cb-args cb-args))
|
|
||||||
|
|
||||||
(defun doc-view-convert-current-doc ()
|
(defun doc-view-convert-current-doc ()
|
||||||
"Convert `doc-view-buffer-file-name' to a set of png files, one file per page.
|
"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
|
|||||||
(dvi
|
(dvi
|
||||||
;; DVI files have to be converted to PDF before Ghostscript can process
|
;; DVI files have to be converted to PDF before Ghostscript can process
|
||||||
;; it.
|
;; it.
|
||||||
(let ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir)))
|
(lexical-let
|
||||||
(doc-view-dvi->pdf doc-view-buffer-file-name
|
((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))
|
||||||
pdf 'doc-view-pdf/ps->png pdf png-file)))
|
(png-file png-file))
|
||||||
|
(doc-view-dvi->pdf doc-view-buffer-file-name pdf
|
||||||
|
(lambda () (doc-view-pdf/ps->png pdf png-file)))))
|
||||||
(t
|
(t
|
||||||
;; Convert to PNG images.
|
;; Convert to PNG images.
|
||||||
(doc-view-pdf/ps->png doc-view-buffer-file-name png-file)))))
|
(doc-view-pdf/ps->png doc-view-buffer-file-name png-file)))))
|
||||||
@ -849,7 +812,7 @@ For now these keys are useful:
|
|||||||
(let ((txt (expand-file-name "doc.txt" (doc-view-current-cache-dir))))
|
(let ((txt (expand-file-name "doc.txt" (doc-view-current-cache-dir))))
|
||||||
(if (file-readable-p txt)
|
(if (file-readable-p txt)
|
||||||
(find-file txt)
|
(find-file txt)
|
||||||
(doc-view-doc->txt 'doc-view-open-text)))))
|
(doc-view-doc->txt txt 'doc-view-open-text)))))
|
||||||
|
|
||||||
;;;;; Toggle between editing and viewing
|
;;;;; Toggle between editing and viewing
|
||||||
|
|
||||||
@ -952,7 +915,7 @@ If BACKWARD is non-nil, jump to the previous match."
|
|||||||
;; We must convert to TXT first!
|
;; We must convert to TXT first!
|
||||||
(if doc-view-current-converter-process
|
(if doc-view-current-converter-process
|
||||||
(message "DocView: please wait till conversion finished.")
|
(message "DocView: please wait till conversion finished.")
|
||||||
(doc-view-doc->txt 'doc-view-search nil))))))
|
(doc-view-doc->txt txt (lambda () (doc-view-search nil))))))))
|
||||||
|
|
||||||
(defun doc-view-search-next-match (arg)
|
(defun doc-view-search-next-match (arg)
|
||||||
"Go to the ARGth next matching page."
|
"Go to the ARGth next matching page."
|
||||||
|
Loading…
Reference in New Issue
Block a user