annotate lisp/doc-view.el @ 112450:16ddab338c43

Remove HAVE_RAW_DECL_CHOWN etc. from config.h
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 23 Jan 2011 20:53:39 -0800
parents ef719132ddfa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1 ;;; doc-view.el --- View PDF/PostScript/DVI files in Emacs
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 107167
diff changeset
3 ;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
4 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
5 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
6 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
7 ;; Keywords: files, pdf, ps, dvi
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
8
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
10
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94443
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94443
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94443
diff changeset
14 ;; (at your option) any later version.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
15
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
20
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94443
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
23
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
24 ;;; Requirements:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
25
85367
1fbaddcbc4ec Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85029
diff changeset
26 ;; doc-view.el requires GNU Emacs 22.1 or newer. You also need Ghostscript,
94092
41edf72809eb Changed requirements section to tell that only one
Tassilo Horn <tassilo@member.fsf.org>
parents: 94080
diff changeset
27 ;; `dvipdf' (comes with Ghostscript) or `dvipdfm' (comes with teTeX or TeXLive)
41edf72809eb Changed requirements section to tell that only one
Tassilo Horn <tassilo@member.fsf.org>
parents: 94080
diff changeset
28 ;; and `pdftotext', which comes with xpdf (http://www.foolabs.com/xpdf/) or
41edf72809eb Changed requirements section to tell that only one
Tassilo Horn <tassilo@member.fsf.org>
parents: 94080
diff changeset
29 ;; poppler (http://poppler.freedesktop.org/).
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
30
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
31 ;;; Commentary:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
32
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
33 ;; DocView is a document viewer for Emacs. It converts PDF, PS and DVI files
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
34 ;; to a set of PNG files, one PNG for each page, and displays the PNG images
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
35 ;; inside an Emacs buffer. This buffer uses `doc-view-mode' which provides
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
36 ;; convenient key bindings for browsing the document.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
37 ;;
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
38 ;; To use it simply open a document file with
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
39 ;;
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
40 ;; C-x C-f ~/path/to/document RET
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
41 ;;
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
42 ;; and the document will be converted and displayed, if your emacs supports png
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
43 ;; images. With `C-c C-c' you can toggle between the rendered images
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
44 ;; representation and the source text representation of the document.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
45 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
46 ;; Since conversion may take some time all the PNG images are cached in a
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
47 ;; subdirectory of `doc-view-cache-directory' and reused when you want to view
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
48 ;; that file again. To reconvert a document hit `g' (`doc-view-reconvert-doc')
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
49 ;; when displaying the document. To delete all cached files use
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
50 ;; `doc-view-clear-cache'. To open the cache with dired, so that you can tidy
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
51 ;; it out use `doc-view-dired-cache'.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
52 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
53 ;; When conversion in underway the first page will be displayed as soon as it
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
54 ;; is available and the available pages are refreshed every
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
55 ;; `doc-view-conversion-refresh-interval' seconds. If that variable is nil the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
56 ;; pages won't be displayed before conversion of the document finished
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
57 ;; completely.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
58 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
59 ;; DocView lets you select a slice of the displayed pages. This slice will be
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
60 ;; remembered and applied to all pages of the current document. This enables
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61 ;; you to cut away the margins of a document to save some space. To select a
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
62 ;; slice you can use `doc-view-set-slice' (bound to `s s') which will query you
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
63 ;; for the coordinates of the slice's top-left corner and its width and height.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
64 ;; A much more convenient way to do the same is offered by the command
102358
07bc423d78f1 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 101909
diff changeset
65 ;; `doc-view-set-slice-using-mouse' (bound to `s m'). After invocation you
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
66 ;; only have to press mouse-1 at the top-left corner and drag it to the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
67 ;; bottom-right corner of the desired slice. To reset the slice use
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68 ;; `doc-view-reset-slice' (bound to `s r').
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ;; You can also search within the document. The command `doc-view-search'
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72 ;; matching pages and messages how many match-pages were found. After that you
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
73 ;; can jump to the next page containing a match with an additional `C-s'. With
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
74 ;; `C-r' you can do the same, but backwards. To search for a new regexp give a
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
75 ;; prefix arg to one of the search functions, e.g. by typing `C-u C-s'. The
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
76 ;; searching works by using a plain text representation of the document. If
102358
07bc423d78f1 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 101909
diff changeset
77 ;; that doesn't already exist the first invocation of `doc-view-search' (or
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
78 ;; `doc-view-search-backward') starts the conversion. When that finishes and
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
79 ;; you're still viewing the document (i.e. you didn't switch to another buffer)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
80 ;; you're queried for the regexp then.
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
81 ;;
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
82 ;; Dired users can simply hit `v' on a document file. If it's a PS, PDF or DVI
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
83 ;; it will be opened using `doc-view-mode'.
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
84 ;;
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
85
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86 ;;; Configuration:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
87
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
88 ;; If the images are too small or too big you should set the "-rXXX" option in
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
89 ;; `doc-view-ghostscript-options' to another value. (The bigger your screen,
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
90 ;; the higher the value.)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
91 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
92 ;; This and all other options can be set with the customization interface.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
93 ;; Simply do
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
94 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
95 ;; M-x customize-group RET doc-view RET
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
96 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
97 ;; and modify them to your needs.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
98
86035
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
99 ;;; Todo:
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
100
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
101 ;; - add print command.
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
102 ;; - share more code with image-mode.
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
103 ;; - better menu.
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
104 ;; - Bind slicing to a drag event.
92759
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
105 ;; - doc-view-fit-doc-to-window and doc-view-fit-window-to-doc?
87842
3a98637489f5 (doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87697
diff changeset
106 ;; - zoom the region around the cursor (like xdvi).
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
107 ;; - get rid of the silly arrow in the fringe.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
108 ;; - improve anti-aliasing (pdf-utils gets it better).
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
109
86035
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
110 ;;;; About isearch support
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
111
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
112 ;; I tried implementing isearch by setting
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
113 ;; `isearch-search-fun-function' buffer-locally, but that didn't
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
114 ;; work too good. The function doing the real search was called
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
115 ;; endlessly somehow. But even if we'd get that working no real
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
116 ;; isearch feeling comes up due to the missing match highlighting.
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
117 ;; Currently I display all lines containing a match in a tooltip and
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
118 ;; each C-s or C-r jumps directly to the next/previous page with a
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
119 ;; match. With isearch we could only display the current match. So
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
120 ;; we had to decide if another C-s jumps to the next page with a
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
121 ;; match (thus only the first match in a page will be displayed in a
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
122 ;; tooltip) or to the next match, which would do nothing visible
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
123 ;; (except the tooltip) if the next match is on the same page.
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
124
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
125 ;; And it's much slower than the current search facility, because
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
126 ;; isearch really searches for each step forward or backward wheras
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
127 ;; the current approach searches once and then it knows to which
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
128 ;; pages to jump.
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
129
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
130 ;; Anyway, if someone with better isearch knowledge wants to give it a try,
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
131 ;; feel free to do it. --Tassilo
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
132
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
133 ;;; Code:
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
134
93048
7a4d478a79d1 (require): Require cl at compile time because
Tassilo Horn <tassilo@member.fsf.org>
parents: 93004
diff changeset
135 (eval-when-compile (require 'cl))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
136 (require 'dired)
85420
de8f3f575afc (doc-view-mode-map): Use the image-mode scrolling commands. Don't rebind C-x k.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85419
diff changeset
137 (require 'image-mode)
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
138 (require 'jka-compr)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
139
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
140 ;;;; Customization Options
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
141
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
142 (defgroup doc-view nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
143 "In-buffer viewer for PDF, PostScript and DVI files."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
144 :link '(function-link doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
145 :version "22.2"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
146 :group 'applications
107167
f6b8c73548b3 Minor tweaks to custom groups.
Chong Yidong <cyd@stupidchicken.com>
parents: 107096
diff changeset
147 :group 'data
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
148 :group 'multimedia
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
149 :prefix "doc-view-")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
150
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
151 (defcustom doc-view-ghostscript-program (executable-find "gs")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
152 "Program to convert PS and PDF files to PNG."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
153 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
154 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
155
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
156 (defcustom doc-view-ghostscript-options
85418
26dcc1207f42 (doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85369
diff changeset
157 '("-dSAFER" ;; Avoid security problems when rendering files from untrusted
26dcc1207f42 (doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85369
diff changeset
158 ;; sources.
26dcc1207f42 (doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85369
diff changeset
159 "-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4"
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
160 "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET")
85367
1fbaddcbc4ec Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85029
diff changeset
161 "A list of options to give to ghostscript."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
162 :type '(repeat string)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
163 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
164
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
165 (defcustom doc-view-resolution 100
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
166 "Dots per inch resolution used to render the documents.
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
167 Higher values result in larger images."
86154
1cdfc94602cb * smime.el (from):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 86119
diff changeset
168 :type 'number
1cdfc94602cb * smime.el (from):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 86119
diff changeset
169 :group 'doc-view)
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
170
112126
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
171 (defcustom doc-view-image-width 850
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
172 "Default image width.
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
173 Has only an effect if imagemagick support is compiled into emacs."
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
174 :type 'number
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
175 :group 'doc-view)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
176
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
177 (defcustom doc-view-dvipdfm-program (executable-find "dvipdfm")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
178 "Program to convert DVI files to PDF.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
179
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
180 DVI file will be converted to PDF before the resulting PDF is
94075
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
181 converted to PNG.
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
182
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
183 If this and `doc-view-dvipdf-program' are set,
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
184 `doc-view-dvipdf-program' will be preferred."
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
185 :type 'file
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
186 :group 'doc-view)
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
187
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
188 (defcustom doc-view-dvipdf-program (executable-find "dvipdf")
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
189 "Program to convert DVI files to PDF.
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
190
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
191 DVI file will be converted to PDF before the resulting PDF is
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
192 converted to PNG.
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
193
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
194 If this and `doc-view-dvipdfm-program' are set,
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
195 `doc-view-dvipdf-program' will be preferred."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
196 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
197 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
198
112034
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
199 (defcustom doc-view-unoconv-program (executable-find "unoconv")
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
200 "Program to convert any file type readable by OpenOffice.org to PDF.
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
201
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
202 Needed for viewing OpenOffice.org (and MS Office) files."
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
203 :type 'file
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
204 :group 'doc-view)
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
205
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
206 (defcustom doc-view-ps2pdf-program (executable-find "ps2pdf")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
207 "Program to convert PS files to PDF.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
208
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
209 PS files will be converted to PDF before searching is possible."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
210 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
211 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
212
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
213 (defcustom doc-view-pdftotext-program (executable-find "pdftotext")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
214 "Program to convert PDF files to plain text.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
215
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
216 Needed for searching."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
217 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
218 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
219
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
220 (defcustom doc-view-cache-directory
85856
a26944b15c75 (doc-view-cache-directory): Remove superfluous concat.
Glenn Morris <rgm@gnu.org>
parents: 85844
diff changeset
221 (expand-file-name (format "docview%d" (user-uid))
85844
cf0d3de08293 * doc-view.el (doc-view-cache-directory): Fix bug where an integer
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85843
diff changeset
222 temporary-file-directory)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
223 "The base directory, where the PNG images will be saved."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
224 :type 'directory
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
225 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
226
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
227 (defvar doc-view-conversion-buffer " *doc-view conversion output*"
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
228 "The buffer where messages from the converter programs go to.")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
229
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
230 (defcustom doc-view-conversion-refresh-interval 1
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
231 "Interval in seconds between refreshes of the DocView buffer while converting.
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
232 After such a refresh newly converted pages will be available for
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
233 viewing. If set to nil there won't be any refreshes and the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
234 pages won't be displayed before conversion of the whole document
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
235 has finished."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
236 :type 'integer
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
237 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
238
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
239 (defcustom doc-view-continuous nil
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
240 "In Continuous mode reaching the page edge advances to next/previous page.
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
241 When non-nil, scrolling a line upward at the bottom edge of the page
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
242 moves to the next page, and scrolling a line downward at the top edge
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
243 of the page moves to the previous page."
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
244 :type 'boolean
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
245 :group 'doc-view
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
246 :version "23.2")
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
247
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
248 ;;;; Internal Variables
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
249
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
250 (defun doc-view-new-window-function (winprops)
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
251 (let ((ol (image-mode-window-get 'overlay winprops)))
107069
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
252 (when (and ol (not (overlay-buffer ol)))
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
253 ;; I've seen `ol' be a dead overlay. I do not yet know how this
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
254 ;; happened, so maybe the bug is elsewhere, but in the mean time,
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
255 ;; this seems like a safe approach.
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
256 (setq ol nil))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
257 (if ol
107069
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
258 (progn
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
259 (assert (eq (overlay-buffer ol) (current-buffer)))
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
260 (setq ol (copy-overlay ol)))
94443
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
261 (assert (not (get-char-property (point-min) 'display)))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
262 (setq ol (make-overlay (point-min) (point-max) nil t))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
263 (overlay-put ol 'doc-view t))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
264 (overlay-put ol 'window (car winprops))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
265 (image-mode-window-put 'overlay ol winprops)))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
266
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
267 (defvar doc-view-current-files nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
268 "Only used internally.")
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
269 (make-variable-buffer-local 'doc-view-current-files)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
270
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
271 (defvar doc-view-current-converter-processes nil
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
272 "Only used internally.")
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
273 (make-variable-buffer-local 'doc-view-current-converter-processes)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
274
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
275 (defvar doc-view-current-timer nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
276 "Only used internally.")
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
277 (make-variable-buffer-local 'doc-view-current-timer)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
278
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
279 (defvar doc-view-current-cache-dir nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
280 "Only used internally.")
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
281 (make-variable-buffer-local 'doc-view-current-cache-dir)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
282
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
283 (defvar doc-view-current-search-matches nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
284 "Only used internally.")
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
285 (make-variable-buffer-local 'doc-view-current-search-matches)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
286
87006
a15ce3ca213a (doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86441
diff changeset
287 (defvar doc-view-pending-cache-flush nil
a15ce3ca213a (doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86441
diff changeset
288 "Only used internally.")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
289
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
290 (defvar doc-view-previous-major-mode nil
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
291 "Only used internally.")
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
292
87697
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
293 (defvar doc-view-buffer-file-name nil
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
294 "Only used internally.
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
295 The file name used for conversion. Normally it's the same as
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
296 `buffer-file-name', but for remote files, compressed files and
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
297 files inside an archive it is a temporary copy of
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
298 the (uncompressed, extracted) file residing in
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
299 `doc-view-cache-directory'.")
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
300
92759
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
301 (defvar doc-view-doc-type nil
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
302 "The type of document in the current buffer.
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
303 Can be `dvi', `pdf', or `ps'.")
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
304
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
305 ;;;; DocView Keymaps
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
306
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
307 (defvar doc-view-mode-map
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
308 (let ((map (make-sparse-keymap)))
95508
88781ac6a1be * image-mode.el (image-mode-map): Suppress key map and bind `q'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95363
diff changeset
309 (set-keymap-parent map image-mode-map)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
310 ;; Navigation in the document
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
311 (define-key map (kbd "n") 'doc-view-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
312 (define-key map (kbd "p") 'doc-view-previous-page)
85444
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
313 (define-key map (kbd "<next>") 'forward-page)
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
314 (define-key map (kbd "<prior>") 'backward-page)
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
315 (define-key map [remap forward-page] 'doc-view-next-page)
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
316 (define-key map [remap backward-page] 'doc-view-previous-page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
317 (define-key map (kbd "SPC") 'doc-view-scroll-up-or-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
318 (define-key map (kbd "DEL") 'doc-view-scroll-down-or-previous-page)
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
319 (define-key map (kbd "C-n") 'doc-view-next-line-or-next-page)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
320 (define-key map (kbd "<down>") 'doc-view-next-line-or-next-page)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
321 (define-key map (kbd "C-p") 'doc-view-previous-line-or-previous-page)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
322 (define-key map (kbd "<up>") 'doc-view-previous-line-or-previous-page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
323 (define-key map (kbd "M-<") 'doc-view-first-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
324 (define-key map (kbd "M->") 'doc-view-last-page)
85843
05357c175a50 (doc-view-mode-map): Bind doc-view-goto-page to the keys
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85815
diff changeset
325 (define-key map [remap goto-line] 'doc-view-goto-page)
102541
cdeea75795b2 (doc-view-mode-map): Bind RET to image-next-line.
Tassilo Horn <tassilo@member.fsf.org>
parents: 102470
diff changeset
326 (define-key map (kbd "RET") 'image-next-line)
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
327 ;; Zoom in/out.
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
328 (define-key map "+" 'doc-view-enlarge)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
329 (define-key map "-" 'doc-view-shrink)
95508
88781ac6a1be * image-mode.el (image-mode-map): Suppress key map and bind `q'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95363
diff changeset
330 ;; Killing the buffer (and the process)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
331 (define-key map (kbd "k") 'doc-view-kill-proc-and-buffer)
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
332 (define-key map (kbd "K") 'doc-view-kill-proc)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
333 ;; Slicing the image
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
334 (define-key map (kbd "s s") 'doc-view-set-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
335 (define-key map (kbd "s m") 'doc-view-set-slice-using-mouse)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
336 (define-key map (kbd "s r") 'doc-view-reset-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
337 ;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
338 (define-key map (kbd "C-s") 'doc-view-search)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
339 (define-key map (kbd "<find>") 'doc-view-search)
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
340 (define-key map (kbd "C-r") 'doc-view-search-backward)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
341 ;; Show the tooltip
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
342 (define-key map (kbd "C-t") 'doc-view-show-tooltip)
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
343 ;; Toggle between text and image display or editing
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
344 (define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
345 ;; Open a new buffer with doc's text contents
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
346 (define-key map (kbd "C-c C-t") 'doc-view-open-text)
107069
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
347 ;; Reconvert the current document. Don't just use revert-buffer
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
348 ;; because that resets the scale factor, the page number, ...
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
349 (define-key map (kbd "g") 'doc-view-revert-buffer)
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
350 (define-key map (kbd "r") 'doc-view-revert-buffer)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
351 map)
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
352 "Keymap used by `doc-view-mode' when displaying a doc as a set of images.")
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
353
107069
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
354 (defun doc-view-revert-buffer (&optional ignore-auto noconfirm)
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
355 "Like `revert-buffer', but preserves the buffer's current modes."
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
356 ;; FIXME: this should probably be moved to files.el and used for
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
357 ;; most/all "g" bindings to revert-buffer.
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
358 (interactive (list (not current-prefix-arg)))
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
359 (revert-buffer ignore-auto noconfirm 'preserve-modes))
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
360
3ce5dcdece39 (doc-view-new-window-function): Be a bit more defensive.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
361
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
362 (easy-menu-define doc-view-menu doc-view-mode-map
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
363 "Menu for Doc View mode."
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
364 '("DocView"
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
365 ["Toggle display" doc-view-toggle-display]
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
366 ("Continuous"
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
367 ["Off" (setq doc-view-continuous nil)
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
368 :style radio :selected (eq doc-view-continuous nil)]
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
369 ["On" (setq doc-view-continuous t)
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
370 :style radio :selected (eq doc-view-continuous t)]
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
371 "---"
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
372 ["Save as Default"
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
373 (customize-save-variable 'doc-view-continuous doc-view-continuous) t]
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
374 )
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
375 "---"
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
376 ["Set Slice" doc-view-set-slice-using-mouse]
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
377 ["Set Slice (manual)" doc-view-set-slice]
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
378 ["Reset Slice" doc-view-reset-slice]
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
379 "---"
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
380 ["Search" doc-view-search]
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
381 ["Search Backwards" doc-view-search-backward]
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
382 ))
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
383
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
384 (defvar doc-view-minor-mode-map
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
385 (let ((map (make-sparse-keymap)))
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
386 ;; Toggle between text and image display or editing
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
387 (define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
388 map)
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
389 "Keymap used by `doc-minor-view-mode'.")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
390
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
391 ;;;; Navigation Commands
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
392
92224
5f0de7ccefc4 (doc-view-current-page): Add a `win' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92220
diff changeset
393 (defmacro doc-view-current-page (&optional win)
5f0de7ccefc4 (doc-view-current-page): Add a `win' argument.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92220
diff changeset
394 `(image-mode-window-get 'page ,win))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
395 (defmacro doc-view-current-info () `(image-mode-window-get 'info))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
396 (defmacro doc-view-current-overlay () `(image-mode-window-get 'overlay))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
397 (defmacro doc-view-current-image () `(image-mode-window-get 'image))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
398 (defmacro doc-view-current-slice () `(image-mode-window-get 'slice))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
399
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
400 (defun doc-view-last-page-number ()
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
401 (length doc-view-current-files))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
402
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
403 (defun doc-view-goto-page (page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
404 "View the page given by PAGE."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
405 (interactive "nPage: ")
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
406 (let ((len (doc-view-last-page-number))
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
407 (hscroll (window-hscroll)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
408 (if (< page 1)
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
409 (setq page 1)
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
410 (when (and (> page len)
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
411 ;; As long as the converter is running, we don't know
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
412 ;; how many pages will be available.
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
413 (null doc-view-current-converter-processes))
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
414 (setq page len)))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
415 (setf (doc-view-current-page) page
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
416 (doc-view-current-info)
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
417 (concat
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
418 (propertize
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
419 (format "Page %d of %d." page len) 'face 'bold)
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
420 ;; Tell user if converting isn't finished yet
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
421 (if doc-view-current-converter-processes
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
422 " (still converting...)\n"
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
423 "\n")
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
424 ;; Display context infos if this page matches the last search
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
425 (when (and doc-view-current-search-matches
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
426 (assq page doc-view-current-search-matches))
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
427 (concat (propertize "Search matches:\n" 'face 'bold)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
428 (let ((contexts ""))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
429 (dolist (m (cdr (assq page
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
430 doc-view-current-search-matches)))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
431 (setq contexts (concat contexts " - \"" m "\"\n")))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
432 contexts)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
433 ;; Update the buffer
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
434 ;; We used to find the file name from doc-view-current-files but
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
435 ;; that's not right if the pages are not generated sequentially
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
436 ;; or if the page isn't in doc-view-current-files yet.
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
437 (let ((file (expand-file-name (format "page-%d.png" page)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
438 (doc-view-current-cache-dir))))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
439 (doc-view-insert-image file :pointer 'arrow)
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
440 (set-window-hscroll (selected-window) hscroll)
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
441 (when (and (not (file-exists-p file))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
442 doc-view-current-converter-processes)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
443 ;; The PNG file hasn't been generated yet.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
444 (doc-view-pdf->png-1 doc-view-buffer-file-name file page
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
445 (lexical-let ((page page)
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
446 (win (selected-window))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
447 (file file))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
448 (lambda ()
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
449 (and (eq (current-buffer) (window-buffer win))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
450 ;; If we changed page in the mean
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
451 ;; time, don't mess things up.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
452 (eq (doc-view-current-page win) page)
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
453 ;; Make sure we don't infloop.
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
454 (file-readable-p file)
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
455 (with-selected-window win
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
456 (doc-view-goto-page page))))))))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
457 (overlay-put (doc-view-current-overlay)
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
458 'help-echo (doc-view-current-info))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
459
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
460 (defun doc-view-next-page (&optional arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
461 "Browse ARG pages forward."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
462 (interactive "p")
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
463 (doc-view-goto-page (+ (doc-view-current-page) (or arg 1))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
464
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
465 (defun doc-view-previous-page (&optional arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
466 "Browse ARG pages backward."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
467 (interactive "p")
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
468 (doc-view-goto-page (- (doc-view-current-page) (or arg 1))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
469
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
470 (defun doc-view-first-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
471 "View the first page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
472 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
473 (doc-view-goto-page 1))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
474
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
475 (defun doc-view-last-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
476 "View the last page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
477 (interactive)
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
478 (doc-view-goto-page (doc-view-last-page-number)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
479
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
480 (defun doc-view-scroll-up-or-next-page (&optional arg)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
481 "Scroll page up ARG lines if possible, else goto next page.
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
482 When `doc-view-continuous' is non-nil, scrolling upward
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
483 at the bottom edge of the page moves to the next page.
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
484 Otherwise, goto next page only on typing SPC (ARG is nil)."
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
485 (interactive "P")
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
486 (if (or doc-view-continuous (null arg))
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
487 (let ((hscroll (window-hscroll))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
488 (cur-page (doc-view-current-page)))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
489 (when (= (window-vscroll) (image-scroll-up arg))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
490 (doc-view-next-page)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
491 (when (/= cur-page (doc-view-current-page))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
492 (image-bob)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
493 (image-bol 1))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
494 (set-window-hscroll (selected-window) hscroll)))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
495 (image-scroll-up arg)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
496
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
497 (defun doc-view-scroll-down-or-previous-page (&optional arg)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
498 "Scroll page down ARG lines if possible, else goto previous page.
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
499 When `doc-view-continuous' is non-nil, scrolling downward
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
500 at the top edge of the page moves to the previous page.
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
501 Otherwise, goto previous page only on typing DEL (ARG is nil)."
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
502 (interactive "P")
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
503 (if (or doc-view-continuous (null arg))
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
504 (let ((hscroll (window-hscroll))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
505 (cur-page (doc-view-current-page)))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
506 (when (= (window-vscroll) (image-scroll-down arg))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
507 (doc-view-previous-page)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
508 (when (/= cur-page (doc-view-current-page))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
509 (image-eob)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
510 (image-bol 1))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
511 (set-window-hscroll (selected-window) hscroll)))
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
512 (image-scroll-down arg)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
513
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
514 (defun doc-view-next-line-or-next-page (&optional arg)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
515 "Scroll upward by ARG lines if possible, else goto next page.
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
516 When `doc-view-continuous' is non-nil, scrolling a line upward
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
517 at the bottom edge of the page moves to the next page."
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
518 (interactive "p")
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
519 (if doc-view-continuous
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
520 (let ((hscroll (window-hscroll))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
521 (cur-page (doc-view-current-page)))
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
522 (when (= (window-vscroll) (image-next-line arg))
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
523 (doc-view-next-page)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
524 (when (/= cur-page (doc-view-current-page))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
525 (image-bob)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
526 (image-bol 1))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
527 (set-window-hscroll (selected-window) hscroll)))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
528 (image-next-line 1)))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
529
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
530 (defun doc-view-previous-line-or-previous-page (&optional arg)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
531 "Scroll downward by ARG lines if possible, else goto previous page.
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
532 When `doc-view-continuous' is non-nil, scrolling a line downward
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
533 at the top edge of the page moves to the previous page."
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
534 (interactive "p")
106327
8cb95e673f03 (doc-view-continuous):
Juri Linkov <juri@jurta.org>
parents: 106242
diff changeset
535 (if doc-view-continuous
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
536 (let ((hscroll (window-hscroll))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
537 (cur-page (doc-view-current-page)))
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
538 (when (= (window-vscroll) (image-previous-line arg))
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
539 (doc-view-previous-page)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
540 (when (/= cur-page (doc-view-current-page))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
541 (image-eob)
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
542 (image-bol 1))
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
543 (set-window-hscroll (selected-window) hscroll)))
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
544 (image-previous-line arg)))
106207
936dfb675acf Implement DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 103948
diff changeset
545
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
546 ;;;; Utility Functions
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
547
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
548 (defun doc-view-kill-proc ()
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
549 "Kill the current converter process(es)."
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
550 (interactive)
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
551 (while (consp doc-view-current-converter-processes)
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
552 (ignore-errors ;; Maybe it's dead already?
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
553 (kill-process (pop doc-view-current-converter-processes))))
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
554 (when doc-view-current-timer
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
555 (cancel-timer doc-view-current-timer)
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
556 (setq doc-view-current-timer nil))
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
557 (setq mode-line-process nil))
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
558
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
559 (defun doc-view-kill-proc-and-buffer ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
560 "Kill the current converter process and buffer."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
561 (interactive)
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
562 (doc-view-kill-proc)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
563 (when (eq major-mode 'doc-view-mode)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
564 (kill-buffer (current-buffer))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
565
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
566 (defun doc-view-make-safe-dir (dir)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
567 (condition-case nil
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
568 (let ((umask (default-file-modes)))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
569 (unwind-protect
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
570 (progn
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
571 ;; Create temp files with strict access rights. It's easy to
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
572 ;; loosen them later, whereas it's impossible to close the
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
573 ;; time-window of loose permissions otherwise.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
574 (set-default-file-modes #o0700)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
575 (make-directory dir))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
576 ;; Reset the umask.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
577 (set-default-file-modes umask)))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
578 (file-already-exists
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
579 (if (file-symlink-p dir)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
580 (error "Danger: %s points to a symbolic link" dir))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
581 ;; In case it was created earlier with looser rights.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
582 ;; We could check the mode info returned by file-attributes, but it's
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
583 ;; a pain to parse and it may not tell you what we want under
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
584 ;; non-standard file-systems. So let's just say what we want and let
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
585 ;; the underlying C code and file-system figure it out.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
586 ;; This also ends up checking a bunch of useful conditions: it makes
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
587 ;; sure we have write-access to the directory and that we own it, thus
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
588 ;; closing a bunch of security holes.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
589 (set-file-modes dir #o0700))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
590
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
591 (defun doc-view-current-cache-dir ()
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
592 "Return the directory where the png files of the current doc should be saved.
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
593 It's a subdirectory of `doc-view-cache-directory'."
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
594 (if doc-view-current-cache-dir
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
595 doc-view-current-cache-dir
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
596 ;; Try and make sure doc-view-cache-directory exists and is safe.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
597 (doc-view-make-safe-dir doc-view-cache-directory)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
598 ;; Now compute the subdirectory to use.
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
599 (setq doc-view-current-cache-dir
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
600 (file-name-as-directory
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
601 (expand-file-name
106467
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
602 (concat (file-name-nondirectory doc-view-buffer-file-name)
87697
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
603 "-"
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
604 (let ((file doc-view-buffer-file-name))
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
605 (with-temp-buffer
92760
0275e742e0a1 (doc-view-current-cache-dir): Set buffer used for
Tassilo Horn <tassilo@member.fsf.org>
parents: 92759
diff changeset
606 (set-buffer-multibyte nil)
87697
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
607 (insert-file-contents-literally file)
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
608 (md5 (current-buffer)))))
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
609 doc-view-cache-directory)))))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
610
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
611 (defun doc-view-remove-if (predicate list)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
612 "Return LIST with all items removed that satisfy PREDICATE."
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
613 (let (new-list)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
614 (dolist (item list (nreverse new-list))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
615 (when (not (funcall predicate item))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
616 (setq new-list (cons item new-list))))))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
617
86441
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
618 ;;;###autoload
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
619 (defun doc-view-mode-p (type)
112034
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
620 "Return non-nil if document type TYPE is available for `doc-view'.
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
621 Document types are symbols like `dvi', `ps', `pdf', or `odf' (any
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
622 OpenDocument format)."
86441
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
623 (and (display-graphic-p)
112167
40ab7b8eb7a4 * doc-view.el (doc-view-mode-p): Check for png or imagemagick
Tassilo Horn <tassilo@member.fsf.org>
parents: 112127
diff changeset
624 (or (image-type-available-p 'imagemagick)
40ab7b8eb7a4 * doc-view.el (doc-view-mode-p): Check for png or imagemagick
Tassilo Horn <tassilo@member.fsf.org>
parents: 112127
diff changeset
625 (image-type-available-p 'png))
86441
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
626 (cond
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
627 ((eq type 'dvi)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
628 (and (doc-view-mode-p 'pdf)
94075
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
629 (or (and doc-view-dvipdf-program
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
630 (executable-find doc-view-dvipdf-program))
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
631 (and doc-view-dvipdfm-program
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
632 (executable-find doc-view-dvipdfm-program)))))
87681
92ee34bb9001 2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87580
diff changeset
633 ((or (eq type 'postscript) (eq type 'ps) (eq type 'eps)
86441
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
634 (eq type 'pdf))
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
635 (and doc-view-ghostscript-program
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
636 (executable-find doc-view-ghostscript-program)))
112034
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
637 ((eq type 'odf)
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
638 (and doc-view-unoconv-program
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
639 (executable-find doc-view-unoconv-program)
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
640 (doc-view-mode-p 'pdf)))
86441
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
641 (t ;; unknown image type
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
642 nil))))
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
643
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
644 ;;;; Conversion Functions
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
645
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
646 (defvar doc-view-shrink-factor 1.125)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
647
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
648 (defun doc-view-enlarge (factor)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
649 "Enlarge the document."
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
650 (interactive (list doc-view-shrink-factor))
112126
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
651 (if (eq (plist-get (cdr (doc-view-current-image)) :type)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
652 'imagemagick)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
653 ;; ImageMagick supports on-the-fly-rescaling
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
654 (progn
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
655 (set (make-local-variable 'doc-view-image-width)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
656 (ceiling (* factor doc-view-image-width)))
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
657 (doc-view-insert-image (plist-get (cdr (doc-view-current-image)) :file)
112127
25ff862568d0 Fix bug in doc-view-enlarge.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112126
diff changeset
658 :width doc-view-image-width))
112126
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
659 (set (make-local-variable 'doc-view-resolution)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
660 (ceiling (* factor doc-view-resolution)))
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
661 (doc-view-reconvert-doc)))
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
662
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
663 (defun doc-view-shrink (factor)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
664 "Shrink the document."
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
665 (interactive (list doc-view-shrink-factor))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
666 (doc-view-enlarge (/ 1.0 factor)))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
667
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
668 (defun doc-view-reconvert-doc ()
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
669 "Reconvert the current document.
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
670 Should be invoked when the cached images aren't up-to-date."
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
671 (interactive)
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
672 (doc-view-kill-proc)
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
673 ;; Clear the old cached files
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
674 (when (file-exists-p (doc-view-current-cache-dir))
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
675 (delete-directory (doc-view-current-cache-dir) 'recursive))
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
676 (doc-view-initiate-display))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
677
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
678 (defun doc-view-sentinel (proc event)
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
679 "Generic sentinel for doc-view conversion processes."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
680 (if (not (string-match "finished" event))
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
681 (message "DocView: process %s changed status to %s."
102545
061690191e25 (doc-view-sentinel): Strip trailing newline from event message.
Chong Yidong <cyd@stupidchicken.com>
parents: 102541
diff changeset
682 (process-name proc)
061690191e25 (doc-view-sentinel): Strip trailing newline from event message.
Chong Yidong <cyd@stupidchicken.com>
parents: 102541
diff changeset
683 (if (string-match "\\(.+\\)\n?\\'" event)
061690191e25 (doc-view-sentinel): Strip trailing newline from event message.
Chong Yidong <cyd@stupidchicken.com>
parents: 102541
diff changeset
684 (match-string 1 event)
061690191e25 (doc-view-sentinel): Strip trailing newline from event message.
Chong Yidong <cyd@stupidchicken.com>
parents: 102541
diff changeset
685 event))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
686 (when (buffer-live-p (process-get proc 'buffer))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
687 (with-current-buffer (process-get proc 'buffer)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
688 (setq doc-view-current-converter-processes
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
689 (delq proc doc-view-current-converter-processes))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
690 (setq mode-line-process
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
691 (if doc-view-current-converter-processes
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
692 (format ":%s" (car doc-view-current-converter-processes))))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
693 (funcall (process-get proc 'callback))))))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
694
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
695 (defun doc-view-start-process (name program args callback)
94073
747b5b0190df (doc-view-start-process): Don't set
Tassilo Horn <tassilo@member.fsf.org>
parents: 93460
diff changeset
696 ;; Make sure the process is started in an existing directory, (rather than
747b5b0190df (doc-view-start-process): Don't set
Tassilo Horn <tassilo@member.fsf.org>
parents: 93460
diff changeset
697 ;; some file-name-handler-managed dir, for example).
747b5b0190df (doc-view-start-process): Don't set
Tassilo Horn <tassilo@member.fsf.org>
parents: 93460
diff changeset
698 (let* ((default-directory (if (file-readable-p default-directory)
747b5b0190df (doc-view-start-process): Don't set
Tassilo Horn <tassilo@member.fsf.org>
parents: 93460
diff changeset
699 default-directory
747b5b0190df (doc-view-start-process): Don't set
Tassilo Horn <tassilo@member.fsf.org>
parents: 93460
diff changeset
700 (expand-file-name "~/")))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
701 (proc (apply 'start-process name doc-view-conversion-buffer
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
702 program args)))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
703 (push proc doc-view-current-converter-processes)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
704 (setq mode-line-process (list (format ":%s" proc)))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
705 (set-process-sentinel proc 'doc-view-sentinel)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
706 (process-put proc 'buffer (current-buffer))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
707 (process-put proc 'callback callback)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
708
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
709 (defun doc-view-dvi->pdf (dvi pdf callback)
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
710 "Convert DVI to PDF asynchronously and call CALLBACK when finished."
94075
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
711 ;; Prefer dvipdf over dvipdfm, because the latter has problems if the DVI
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
712 ;; references and includes other PS files.
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
713 (if (and doc-view-dvipdf-program
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
714 (executable-find doc-view-dvipdf-program))
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
715 (doc-view-start-process "dvi->pdf" doc-view-dvipdf-program
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
716 (list dvi pdf)
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
717 callback)
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
718 (doc-view-start-process "dvi->pdf" doc-view-dvipdfm-program
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
719 (list "-o" pdf dvi)
b31c348d0336 * doc-view.el (doc-view-dvipdf-program): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 94073
diff changeset
720 callback)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
721
112034
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
722 (defun doc-view-odf->pdf (odf callback)
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
723 "Convert ODF to PDF asynchronously and call CALLBACK when finished.
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
724 The converted PDF is put into the current cache directory, and it
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
725 is named like ODF with the extension turned to pdf."
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
726 (doc-view-start-process "odf->pdf" doc-view-unoconv-program
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
727 (list "-f" "pdf" "-o" (doc-view-current-cache-dir) odf)
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
728 callback))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
729
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
730 (defun doc-view-pdf/ps->png (pdf-ps png)
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
731 "Convert PDF-PS to PNG asynchronously."
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
732 (doc-view-start-process
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
733 "pdf/ps->png" doc-view-ghostscript-program
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
734 (append doc-view-ghostscript-options
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
735 (list (format "-r%d" (round doc-view-resolution))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
736 (concat "-sOutputFile=" png)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
737 pdf-ps))
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
738 (lexical-let ((resolution doc-view-resolution))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
739 (lambda ()
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
740 ;; Only create the resolution file when it's all done, so it also
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
741 ;; serves as a witness that the conversion is complete.
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
742 (write-region (prin1-to-string resolution) nil
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
743 (expand-file-name "resolution.el"
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
744 (doc-view-current-cache-dir))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
745 nil 'silently)
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
746 (when doc-view-current-timer
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
747 (cancel-timer doc-view-current-timer)
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
748 (setq doc-view-current-timer nil))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
749 (doc-view-display (current-buffer) 'force))))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
750 ;; Update the displayed pages as soon as they're done generating.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
751 (when doc-view-conversion-refresh-interval
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
752 (setq doc-view-current-timer
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
753 (run-at-time "1 secs" doc-view-conversion-refresh-interval
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
754 'doc-view-display
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
755 (current-buffer)))))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
756
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
757 (defun doc-view-pdf->png-1 (pdf png page callback)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
758 "Convert a PAGE of a PDF file to PNG asynchronously.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
759 Call CALLBACK with no arguments when done."
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
760 (doc-view-start-process
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
761 "pdf->png-1" doc-view-ghostscript-program
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
762 (append doc-view-ghostscript-options
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
763 (list (format "-r%d" (round doc-view-resolution))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
764 ;; Sadly, `gs' only supports the page-range
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
765 ;; for PDF files.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
766 (format "-dFirstPage=%d" page)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
767 (format "-dLastPage=%d" page)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
768 (concat "-sOutputFile=" png)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
769 pdf))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
770 callback))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
771
95841
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 95508
diff changeset
772 (declare-function clear-image-cache "image.c" (&optional filter))
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 95508
diff changeset
773
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
774 (defun doc-view-pdf->png (pdf png pages)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
775 "Convert a PDF file to PNG asynchronously.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
776 Start by converting PAGES, and then the rest."
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
777 (if (null pages)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
778 (doc-view-pdf/ps->png pdf png)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
779 ;; We could render several `pages' with a single process if they're
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
780 ;; (almost) consecutive, but since in 99% of the cases, there'll be only
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
781 ;; a single page anyway, and of the remaining 1%, few cases will have
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
782 ;; consecutive pages, it's not worth the trouble.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
783 (lexical-let ((pdf pdf) (png png) (rest (cdr pages)))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
784 (doc-view-pdf->png-1
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
785 pdf (format png (car pages)) (car pages)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
786 (lambda ()
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
787 (if rest
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
788 (doc-view-pdf->png pdf png rest)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
789 ;; Yippie, the important pages are done, update the display.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
790 (clear-image-cache)
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
791 ;; For the windows that have a message (like "Welcome to
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
792 ;; DocView") display property, clearing the image cache is
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
793 ;; not sufficient.
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
794 (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
795 (with-selected-window win
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
796 (when (stringp (get-char-property (point-min) 'display))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
797 (doc-view-goto-page (doc-view-current-page)))))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
798 ;; Convert the rest of the pages.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
799 (doc-view-pdf/ps->png pdf png)))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
800
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
801 (defun doc-view-pdf->txt (pdf txt callback)
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
802 "Convert PDF to TXT asynchronously and call CALLBACK when finished."
98845
5eadfa7d3021 (doc-view-pdf->txt, doc-view-ps->pdf): Give an error if the needed
Glenn Morris <rgm@gnu.org>
parents: 98160
diff changeset
803 (or doc-view-pdftotext-program
5eadfa7d3021 (doc-view-pdf->txt, doc-view-ps->pdf): Give an error if the needed
Glenn Morris <rgm@gnu.org>
parents: 98160
diff changeset
804 (error "You need the `pdftotext' program to convert a PDF to text"))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
805 (doc-view-start-process "pdf->txt" doc-view-pdftotext-program
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
806 (list "-raw" pdf txt)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
807 callback))
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
808
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
809 (defun doc-view-doc->txt (txt callback)
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
810 "Convert the current document to text and call CALLBACK when done."
93004
c378e060aab3 (doc-view-doc->txt, doc-view-convert-current-doc):
Tassilo Horn <tassilo@member.fsf.org>
parents: 92879
diff changeset
811 (make-directory (doc-view-current-cache-dir) t)
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
812 (case doc-view-doc-type
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
813 (pdf
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
814 ;; Doc is a PDF, so convert it to TXT
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
815 (doc-view-pdf->txt doc-view-buffer-file-name txt callback))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
816 (ps
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
817 ;; Doc is a PS, so convert it to PDF (which will be converted to
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
818 ;; TXT thereafter).
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
819 (lexical-let ((pdf (expand-file-name "doc.pdf"
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
820 (doc-view-current-cache-dir)))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
821 (txt txt)
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
822 (callback callback))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
823 (doc-view-ps->pdf doc-view-buffer-file-name pdf
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
824 (lambda () (doc-view-pdf->txt pdf txt callback)))))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
825 (dvi
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
826 ;; Doc is a DVI. This means that a doc.pdf already exists in its
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
827 ;; cache subdirectory.
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
828 (doc-view-pdf->txt (expand-file-name "doc.pdf"
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
829 (doc-view-current-cache-dir))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
830 txt callback))
112035
33f84f010bcb * doc-view.el (doc-view-doc->txt): Handle OpenDocument (or MS Office) files also for searching.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112034
diff changeset
831 (odf
33f84f010bcb * doc-view.el (doc-view-doc->txt): Handle OpenDocument (or MS Office) files also for searching.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112034
diff changeset
832 ;; Doc is some ODF (or MS Office) doc. This means that a doc.pdf
33f84f010bcb * doc-view.el (doc-view-doc->txt): Handle OpenDocument (or MS Office) files also for searching.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112034
diff changeset
833 ;; already exists in its cache subdirectory.
33f84f010bcb * doc-view.el (doc-view-doc->txt): Handle OpenDocument (or MS Office) files also for searching.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112034
diff changeset
834 (doc-view-pdf->txt (expand-file-name "doc.pdf"
33f84f010bcb * doc-view.el (doc-view-doc->txt): Handle OpenDocument (or MS Office) files also for searching.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112034
diff changeset
835 (doc-view-current-cache-dir))
33f84f010bcb * doc-view.el (doc-view-doc->txt): Handle OpenDocument (or MS Office) files also for searching.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112034
diff changeset
836 txt callback))
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
837 (t (error "DocView doesn't know what to do"))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
838
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
839 (defun doc-view-ps->pdf (ps pdf callback)
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
840 "Convert PS to PDF asynchronously and call CALLBACK when finished."
98845
5eadfa7d3021 (doc-view-pdf->txt, doc-view-ps->pdf): Give an error if the needed
Glenn Morris <rgm@gnu.org>
parents: 98160
diff changeset
841 (or doc-view-ps2pdf-program
5eadfa7d3021 (doc-view-pdf->txt, doc-view-ps->pdf): Give an error if the needed
Glenn Morris <rgm@gnu.org>
parents: 98160
diff changeset
842 (error "You need the `ps2pdf' program to convert PS to PDF"))
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
843 (doc-view-start-process "ps->pdf" doc-view-ps2pdf-program
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
844 (list
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
845 ;; Avoid security problems when rendering files from
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
846 ;; untrusted sources.
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
847 "-dSAFER"
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
848 ;; in-file and out-file
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
849 ps pdf)
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
850 callback))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
851
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
852 (defun doc-view-active-pages ()
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
853 (let ((pages ()))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
854 (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
855 (let ((page (image-mode-window-get 'page win)))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
856 (unless (memq page pages) (push page pages))))
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
857 pages))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
858
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
859 (defun doc-view-convert-current-doc ()
87697
e0467846347e 2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87693
diff changeset
860 "Convert `doc-view-buffer-file-name' to a set of png files, one file per page.
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
861 Those files are saved in the directory given by the function
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
862 `doc-view-current-cache-dir'."
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
863 ;; Let stale files still display while we recompute the new ones, so only
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
864 ;; flush the cache when the conversion is over. One of the reasons why it
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
865 ;; is important to keep displaying the stale page is so that revert-buffer
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
866 ;; preserves the horizontal/vertical scroll settings (which are otherwise
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
867 ;; resets during the redisplay).
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
868 (setq doc-view-pending-cache-flush t)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
869 (let ((png-file (expand-file-name "page-%d.png"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
870 (doc-view-current-cache-dir))))
93004
c378e060aab3 (doc-view-doc->txt, doc-view-convert-current-doc):
Tassilo Horn <tassilo@member.fsf.org>
parents: 92879
diff changeset
871 (make-directory (doc-view-current-cache-dir) t)
92759
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
872 (case doc-view-doc-type
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
873 (dvi
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
874 ;; DVI files have to be converted to PDF before Ghostscript can process
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
875 ;; it.
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
876 (lexical-let
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
877 ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
878 (png-file png-file))
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
879 (doc-view-dvi->pdf doc-view-buffer-file-name pdf
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
880 (lambda () (doc-view-pdf/ps->png pdf png-file)))))
112034
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
881 (odf
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
882 ;; ODF files have to be converted to PDF before Ghostscript can
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
883 ;; process it.
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
884 (lexical-let
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
885 ((pdf (expand-file-name "doc.pdf" doc-view-current-cache-dir))
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
886 (opdf (expand-file-name (concat (file-name-sans-extension
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
887 (file-name-nondirectory doc-view-buffer-file-name))
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
888 ".pdf")
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
889 doc-view-current-cache-dir))
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
890 (png-file png-file))
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
891 ;; The unoconv tool only supports a output directory, but no
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
892 ;; file name. It's named like the input file with the
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
893 ;; extension replaced by pdf.
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
894 (doc-view-odf->pdf doc-view-buffer-file-name
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
895 (lambda ()
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
896 ;; Rename to doc.pdf
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
897 (rename-file opdf pdf)
6957ace4e43f * doc-view.el: Implement viewing of OpenDocument (and Microsoft Office) files.
Tassilo Horn <tassilo@member.fsf.org>
parents: 109395
diff changeset
898 (doc-view-pdf/ps->png pdf png-file)))))
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
899 (pdf
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
900 (let ((pages (doc-view-active-pages)))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
901 ;; Convert PDF to PNG images starting with the active pages.
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
902 (doc-view-pdf->png doc-view-buffer-file-name png-file pages)))
92759
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
903 (t
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
904 ;; Convert to PNG images.
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
905 (doc-view-pdf/ps->png doc-view-buffer-file-name png-file)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
906
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
907 ;;;; Slicing
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
908
95841
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 95508
diff changeset
909 (declare-function image-size "image.c" (spec &optional pixels frame))
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 95508
diff changeset
910
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
911 (defun doc-view-set-slice (x y width height)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
912 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
913 You can use this function to tell doc-view not to display the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
914 margins of the document. It prompts for the top-left corner (X
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
915 and Y) of the slice to display and its WIDTH and HEIGHT.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
916
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
917 See `doc-view-set-slice-using-mouse' for a more convenient way to
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
918 do that. To reset the slice use `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
919 (interactive
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
920 (let* ((size (image-size (doc-view-current-image) t))
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
921 (a (read-number (format "Top-left X (0..%d): " (car size))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
922 (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
923 (c (read-number (format "Width (0..%d): " (- (car size) a))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
924 (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
925 (list a b c d)))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
926 (setf (doc-view-current-slice) (list x y width height))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
927 ;; Redisplay
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
928 (doc-view-goto-page (doc-view-current-page)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
929
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
930 (defun doc-view-set-slice-using-mouse ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
931 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
932 You set the slice by pressing mouse-1 at its top-left corner and
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
933 dragging it to its bottom-right corner. See also
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
934 `doc-view-set-slice' and `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
935 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
936 (let (x y w h done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
937 (while (not done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
938 (let ((e (read-event
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
939 (concat "Press mouse-1 at the top-left corner and "
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
940 "drag it to the bottom-right corner!"))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
941 (when (eq (car e) 'drag-mouse-1)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
942 (setq x (car (posn-object-x-y (event-start e))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
943 (setq y (cdr (posn-object-x-y (event-start e))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
944 (setq w (- (car (posn-object-x-y (event-end e))) x))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
945 (setq h (- (cdr (posn-object-x-y (event-end e))) y))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
946 (setq done t))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
947 (doc-view-set-slice x y w h)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
948
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
949 (defun doc-view-reset-slice ()
85029
63718012f1da (doc-view-dvi->pdf-sentinel, doc-view-reset-slice)
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 85027
diff changeset
950 "Reset the current slice.
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
951 After calling this function whole pages will be visible again."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
952 (interactive)
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
953 (setf (doc-view-current-slice) nil)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
954 ;; Redisplay
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
955 (doc-view-goto-page (doc-view-current-page)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
956
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
957 ;;;; Display
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
958
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
959 (defun doc-view-insert-image (file &rest args)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
960 "Insert the given png FILE.
85029
63718012f1da (doc-view-dvi->pdf-sentinel, doc-view-reset-slice)
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 85027
diff changeset
961 ARGS is a list of image descriptors."
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
962 (when doc-view-pending-cache-flush
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
963 (clear-image-cache)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
964 (setq doc-view-pending-cache-flush nil))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
965 (let ((ol (doc-view-current-overlay))
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
966 (image (if (and file (file-readable-p file))
112126
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
967 (if (not (fboundp 'imagemagick-types))
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
968 (apply 'create-image file 'png nil args)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
969 (unless (member :width args)
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
970 (setq args (append args (list :width doc-view-image-width))))
afc7f5e3ff12 * doc-view.el (doc-view-image-width): New variable.
Tassilo Horn <tassilo@member.fsf.org>
parents: 112039
diff changeset
971 (apply 'create-image file 'imagemagick nil args))))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
972 (slice (doc-view-current-slice)))
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
973 (setf (doc-view-current-image) image)
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
974 (move-overlay ol (point-min) (point-max))
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
975 (overlay-put ol 'display
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
976 (cond
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
977 (image
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
978 (if slice
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
979 (list (cons 'slice slice) image)
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
980 image))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
981 ;; We're trying to display a page that doesn't exist.
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
982 (doc-view-current-converter-processes
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
983 ;; Maybe the page doesn't exist *yet*.
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
984 "Cannot display this page (yet)!")
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
985 (t
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
986 ;; Typically happens if the conversion process somehow
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
987 ;; failed. Better not signal an error here because it
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
988 ;; could prevent a subsequent reconversion from fixing
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
989 ;; the problem.
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
990 (concat "Cannot display this page!\n"
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
991 "Maybe because of a conversion failure!"))))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
992 (let ((win (overlay-get ol 'window)))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
993 (if (stringp (overlay-get ol 'display))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
994 (progn ;Make sure the text is not scrolled out of view.
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
995 (set-window-hscroll win 0)
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
996 (set-window-vscroll win 0))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
997 (let ((hscroll (image-mode-window-get 'hscroll win))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
998 (vscroll (image-mode-window-get 'vscroll win)))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
999 ;; Reset scroll settings, in case they were changed.
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1000 (if hscroll (set-window-hscroll win hscroll))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1001 (if vscroll (set-window-vscroll win vscroll)))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1002
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1003 (defun doc-view-sort (a b)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1004 "Return non-nil if A should be sorted before B.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1005 Predicate for sorting `doc-view-current-files'."
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
1006 (or (< (length a) (length b))
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
1007 (and (= (length a) (length b))
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
1008 (string< a b))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1009
91789
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1010 (defun doc-view-display (buffer &optional force)
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1011 "Start viewing the document in BUFFER.
87133
a99e0ba48aeb (doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87006
diff changeset
1012 If FORCE is non-nil, start viewing even if the document does not
a99e0ba48aeb (doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87006
diff changeset
1013 have the page we want to view."
91789
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1014 (with-current-buffer buffer
92220
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1015 (let ((prev-pages doc-view-current-files))
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1016 (setq doc-view-current-files
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1017 (sort (directory-files (doc-view-current-cache-dir) t
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1018 "page-[0-9]+\\.png" t)
9976b0faa96a (doc-view-conversion-buffer): Give it an internal name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92004
diff changeset
1019 'doc-view-sort))
94443
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1020 (dolist (win (or (get-buffer-window-list buffer nil t)
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1021 (list (selected-window))))
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1022 (let* ((page (doc-view-current-page win))
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1023 (pagefile (expand-file-name (format "page-%d.png" page)
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1024 (doc-view-current-cache-dir))))
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1025 (when (or force
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1026 (and (not (member pagefile prev-pages))
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1027 (member pagefile doc-view-current-files)))
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1028 (with-selected-window win
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1029 (assert (eq (current-buffer) buffer))
f41f8f74c3cb (doc-view-new-window-function): Avoid using WINDOW
Chong Yidong <cyd@stupidchicken.com>
parents: 94236
diff changeset
1030 (doc-view-goto-page page))))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1031
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1032 (defun doc-view-buffer-message ()
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1033 ;; Only show this message initially, not when refreshing the buffer (in which
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1034 ;; case it's better to keep displaying the "stale" page while computing
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1035 ;; the fresh new ones).
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1036 (unless (overlay-get (doc-view-current-overlay) 'display)
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1037 (overlay-put (doc-view-current-overlay) 'display
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1038 (concat (propertize "Welcome to DocView!" 'face 'bold)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1039 "\n"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1040 "
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
1041 If you see this buffer it means that the document you want to view is being
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
1042 converted to PNG and the conversion of the first page hasn't finished yet or
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1043 `doc-view-conversion-refresh-interval' is set to nil.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1044
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1045 For now these keys are useful:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1046
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1047 `q' : Bury this buffer. Conversion will go on in background.
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1048 `k' : Kill the conversion process and this buffer.
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1049 `K' : Kill the conversion process.\n"))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1050
95841
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 95508
diff changeset
1051 (declare-function tooltip-show "tooltip" (text &optional use-echo-area))
b4e36ff621b3 Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents: 95508
diff changeset
1052
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1053 (defun doc-view-show-tooltip ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1054 (interactive)
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1055 (tooltip-show (doc-view-current-info)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1056
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1057 (defun doc-view-open-text ()
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1058 "Open a buffer with the current doc's contents as text."
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1059 (interactive)
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
1060 (if doc-view-current-converter-processes
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1061 (message "DocView: please wait till conversion finished.")
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1062 (let ((txt (expand-file-name "doc.txt" (doc-view-current-cache-dir))))
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1063 (if (file-readable-p txt)
112208
f78d631cd428 * doc-view.el (doc-view-open-text): Use meaningful text buffer
Tassilo Horn <tassilo@member.fsf.org>
parents: 112167
diff changeset
1064 (let ((name (concat "Text contents of "
f78d631cd428 * doc-view.el (doc-view-open-text): Use meaningful text buffer
Tassilo Horn <tassilo@member.fsf.org>
parents: 112167
diff changeset
1065 (file-name-nondirectory buffer-file-name)))
f78d631cd428 * doc-view.el (doc-view-open-text): Use meaningful text buffer
Tassilo Horn <tassilo@member.fsf.org>
parents: 112167
diff changeset
1066 (dir (file-name-directory buffer-file-name)))
f78d631cd428 * doc-view.el (doc-view-open-text): Use meaningful text buffer
Tassilo Horn <tassilo@member.fsf.org>
parents: 112167
diff changeset
1067 (with-current-buffer (find-file txt)
f78d631cd428 * doc-view.el (doc-view-open-text): Use meaningful text buffer
Tassilo Horn <tassilo@member.fsf.org>
parents: 112167
diff changeset
1068 (rename-buffer name)
f78d631cd428 * doc-view.el (doc-view-open-text): Use meaningful text buffer
Tassilo Horn <tassilo@member.fsf.org>
parents: 112167
diff changeset
1069 (setq default-directory dir)))
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
1070 (doc-view-doc->txt txt 'doc-view-open-text)))))
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1071
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1072 ;;;;; Toggle between editing and viewing
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1073
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1074 (defun doc-view-toggle-display ()
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1075 "Toggle between editing a document as text or viewing it."
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1076 (interactive)
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1077 (if (eq major-mode 'doc-view-mode)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1078 ;; Switch to editing mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1079 (progn
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1080 (doc-view-kill-proc)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1081 (setq buffer-read-only nil)
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1082 (remove-overlays (point-min) (point-max) 'doc-view t)
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1083 (set (make-local-variable 'image-mode-winprops-alist) t)
112036
f559229a64b8 * doc-view.el (doc-view-mode, doc-view-toggle-display): Use
Tassilo Horn <tassilo@member.fsf.org>
parents: 112035
diff changeset
1084 ;; Switch to the previously used major mode or fall back to
f559229a64b8 * doc-view.el (doc-view-mode, doc-view-toggle-display): Use
Tassilo Horn <tassilo@member.fsf.org>
parents: 112035
diff changeset
1085 ;; normal mode.
112039
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1086 (doc-view-fallback-mode)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1087 (doc-view-minor-mode 1))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1088 ;; Switch to doc-view-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1089 (when (and (buffer-modified-p)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1090 (y-or-n-p "The buffer has been modified. Save the changes? "))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1091 (save-buffer))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1092 (doc-view-mode)))
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1093
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1094 ;;;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1095
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1096
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1097 (defun doc-view-search-internal (regexp file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1098 "Return a list of FILE's pages that contain text matching REGEXP.
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1099 The value is an alist of the form (PAGE CONTEXTS) where PAGE is
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1100 the pagenumber and CONTEXTS are all lines of text containing a match."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1101 (with-temp-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1102 (insert-file-contents file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1103 (let ((page 1)
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1104 (lastpage 1)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1105 matches)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1106 (while (re-search-forward (concat "\\(?:\\([ ]\\)\\|\\("
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1107 regexp "\\)\\)") nil t)
87556
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1108 (when (match-string 1) (setq page (1+ page)))
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1109 (when (match-string 2)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1110 (if (/= page lastpage)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1111 (push (cons page
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1112 (list (buffer-substring
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1113 (line-beginning-position)
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1114 (line-end-position))))
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1115 matches)
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1116 (setq matches (cons
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1117 (append
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1118 (or
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1119 ;; This page already is a match.
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1120 (car matches)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1121 ;; This is the first match on page.
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1122 (list page))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1123 (list (buffer-substring
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1124 (line-beginning-position)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1125 (line-end-position))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1126 (cdr matches))))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1127 (setq lastpage page)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1128 (nreverse matches))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1129
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1130 (defun doc-view-search-no-of-matches (list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1131 "Extract the number of matches from the search result LIST."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1132 (let ((no 0))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1133 (dolist (p list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1134 (setq no (+ no (1- (length p)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1135 no))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1136
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1137 (defun doc-view-search-backward (new-query)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1138 "Call `doc-view-search' for backward search.
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1139 If prefix NEW-QUERY is given, ask for a new regexp."
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1140 (interactive "P")
86156
d98fdcca854b * doc-view.el (doc-view-search-backward, doc-view-search): Fix
Dan Nicolaescu <dann@ics.uci.edu>
parents: 86154
diff changeset
1141 (doc-view-search new-query t))
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1142
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1143 (defun doc-view-search (new-query &optional backward)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1144 "Jump to the next match or initiate a new search if NEW-QUERY is given.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1145 If the current document hasn't been transformed to plain text
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1146 till now do that first.
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1147 If BACKWARD is non-nil, jump to the previous match."
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1148 (interactive "P")
86156
d98fdcca854b * doc-view.el (doc-view-search-backward, doc-view-search): Fix
Dan Nicolaescu <dann@ics.uci.edu>
parents: 86154
diff changeset
1149 (if (and (not new-query)
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1150 doc-view-current-search-matches)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1151 (if backward
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1152 (doc-view-search-previous-match 1)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1153 (doc-view-search-next-match 1))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1154 ;; New search, so forget the old results.
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1155 (setq doc-view-current-search-matches nil)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1156 (let ((txt (expand-file-name "doc.txt"
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1157 (doc-view-current-cache-dir))))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1158 (if (file-readable-p txt)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1159 (progn
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1160 (setq doc-view-current-search-matches
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1161 (doc-view-search-internal
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1162 (read-from-minibuffer "Regexp: ")
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1163 txt))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1164 (message "DocView: search yielded %d matches."
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1165 (doc-view-search-no-of-matches
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1166 doc-view-current-search-matches)))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1167 ;; We must convert to TXT first!
93460
1f7e9d28dedf Compute displayed pages first (in PDF).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93050
diff changeset
1168 (if doc-view-current-converter-processes
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
1169 (message "DocView: please wait till conversion finished.")
92763
5d8ccd2d65e2 Remove all cb-args, use closures instead.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92760
diff changeset
1170 (doc-view-doc->txt txt (lambda () (doc-view-search nil))))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1171
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1172 (defun doc-view-search-next-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1173 "Go to the ARGth next matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1174 (interactive "p")
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1175 (let* ((next-pages (doc-view-remove-if
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1176 (lambda (i) (<= (car i) (doc-view-current-page)))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1177 doc-view-current-search-matches))
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1178 (page (car (nth (1- arg) next-pages))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1179 (if page
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1180 (doc-view-goto-page page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1181 (when (and
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1182 doc-view-current-search-matches
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1183 (y-or-n-p "No more matches after current page. Wrap to first match? "))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1184 (doc-view-goto-page (caar doc-view-current-search-matches))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1185
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1186 (defun doc-view-search-previous-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1187 "Go to the ARGth previous matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1188 (interactive "p")
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1189 (let* ((prev-pages (doc-view-remove-if
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1190 (lambda (i) (>= (car i) (doc-view-current-page)))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1191 doc-view-current-search-matches))
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1192 (page (car (nth (1- arg) (nreverse prev-pages)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1193 (if page
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1194 (doc-view-goto-page page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1195 (when (and
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1196 doc-view-current-search-matches
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1197 (y-or-n-p "No more matches before current page. Wrap to last match? "))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1198 (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1199
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1200 ;;;; User interface commands and the mode
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1201
107096
31db1aaeac2d * doc-view.el (doc-view-mode):
Juri Linkov <juri@jurta.org>
parents: 107087
diff changeset
1202 (put 'doc-view-mode 'mode-class 'special)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1203
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1204 (defun doc-view-already-converted-p ()
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1205 "Return non-nil if the current doc was already converted."
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1206 (and (file-exists-p (doc-view-current-cache-dir))
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1207 ;; Check that the resolution info is there, otherwise it means
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1208 ;; the conversion is incomplete.
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1209 (file-readable-p (expand-file-name "resolution.el"
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1210 (doc-view-current-cache-dir)))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1211 (> (length (directory-files (doc-view-current-cache-dir)
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1212 nil "\\.png\\'"))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1213 0)))
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1214
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1215 (defun doc-view-initiate-display ()
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1216 ;; Switch to image display if possible
93050
831841710ce9 (doc-view-initiate-display): Use doc-view-doc-type
Tassilo Horn <tassilo@member.fsf.org>
parents: 93048
diff changeset
1217 (if (doc-view-mode-p doc-view-doc-type)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1218 (progn
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1219 (doc-view-buffer-message)
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1220 (setf (doc-view-current-page) (or (doc-view-current-page) 1))
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1221 (if (doc-view-already-converted-p)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1222 (progn
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1223 (message "DocView: using cached files!")
102413
feece1082bed (doc-view-convert-current-doc): Save the current
Tassilo Horn <tassilo@member.fsf.org>
parents: 102358
diff changeset
1224 ;; Load the saved resolution
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1225 (let* ((res-file (expand-file-name "resolution.el"
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1226 (doc-view-current-cache-dir)))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1227 (res
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1228 (with-temp-buffer
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1229 (when (file-readable-p res-file)
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1230 (insert-file-contents res-file)
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1231 (read (current-buffer))))))
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1232 (when (numberp res)
102413
feece1082bed (doc-view-convert-current-doc): Save the current
Tassilo Horn <tassilo@member.fsf.org>
parents: 102358
diff changeset
1233 (set (make-local-variable 'doc-view-resolution) res)))
91789
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1234 (doc-view-display (current-buffer) 'force))
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1235 (doc-view-convert-current-doc))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1236 (message
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1237 "%s"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1238 (substitute-command-keys
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1239 (concat "Type \\[doc-view-toggle-display] to toggle between "
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1240 "editing or viewing the document."))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1241 (message
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
1242 "%s"
103948
53e13148fb68 * doc-view.el (doc-view-initiate-display): Add yes-or-no-p if
Chong Yidong <cyd@stupidchicken.com>
parents: 102824
diff changeset
1243 (concat "No PNG support is available, or some conversion utility for "
53e13148fb68 * doc-view.el (doc-view-initiate-display): Add yes-or-no-p if
Chong Yidong <cyd@stupidchicken.com>
parents: 102824
diff changeset
1244 (file-name-extension doc-view-buffer-file-name)
53e13148fb68 * doc-view.el (doc-view-initiate-display): Add yes-or-no-p if
Chong Yidong <cyd@stupidchicken.com>
parents: 102824
diff changeset
1245 " files is missing."))
112209
4a44f74c4f7c (doc-view-initiate-display): Fall back to normal mode when
Tassilo Horn <tassilo@member.fsf.org>
parents: 112208
diff changeset
1246 (when (and (executable-find doc-view-pdftotext-program)
4a44f74c4f7c (doc-view-initiate-display): Fall back to normal mode when
Tassilo Horn <tassilo@member.fsf.org>
parents: 112208
diff changeset
1247 (y-or-n-p
4a44f74c4f7c (doc-view-initiate-display): Fall back to normal mode when
Tassilo Horn <tassilo@member.fsf.org>
parents: 112208
diff changeset
1248 "Unable to render file. View extracted text instead? "))
4a44f74c4f7c (doc-view-initiate-display): Fall back to normal mode when
Tassilo Horn <tassilo@member.fsf.org>
parents: 112208
diff changeset
1249 (doc-view-open-text))
4a44f74c4f7c (doc-view-initiate-display): Fall back to normal mode when
Tassilo Horn <tassilo@member.fsf.org>
parents: 112208
diff changeset
1250 (doc-view-toggle-display)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1251
92556
5944be8c8211 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 92224
diff changeset
1252 (defvar bookmark-make-record-function)
87556
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1253
91789
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1254 (defun doc-view-clone-buffer-hook ()
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1255 ;; FIXME: There are several potential problems linked with reconversion
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1256 ;; and auto-revert when we have indirect buffers because they share their
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1257 ;; /tmp cache directory. This sharing is good (you'd rather not reconvert
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1258 ;; for each clone), but that means that clones need to collaborate a bit.
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1259 ;; I guess it mostly means: detect when a reconversion process is already
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1260 ;; running, and run the sentinel in all clones.
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1261 ;;
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1262 ;; Maybe the clones should really have a separate /tmp directory
91789
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1263 ;; so they could have a different resolution and you could use clones
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1264 ;; for zooming.
92004
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1265 (remove-overlays (point-min) (point-max) 'doc-view t)
db743b98a24b Allow different windows to show different pages.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91789
diff changeset
1266 (if (consp image-mode-winprops-alist) (setq image-mode-winprops-alist nil)))
91789
0048d198c131 (doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91715
diff changeset
1267
92759
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
1268 (defun doc-view-intersection (l1 l2)
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
1269 (let ((l ()))
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
1270 (dolist (x l1) (if (memq x l2) (push x l)))
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
1271 l))
01d116e7fb72 (doc-view-new-window-function): Add assertion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92752
diff changeset
1272
112039
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1273 (defun doc-view-set-doc-type ()
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1274 "Figure out the current document type (`doc-view-doc-type')."
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1275 (let ((name-types
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1276 (when buffer-file-name
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1277 (cdr (assoc (file-name-extension buffer-file-name)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1278 '(
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1279 ;; DVI
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1280 ("dvi" dvi)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1281 ;; PDF
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1282 ("pdf" pdf) ("epdf" pdf)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1283 ;; PostScript
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1284 ("ps" ps) ("eps" ps)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1285 ;; OpenDocument formats
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1286 ("odt" odf) ("ods" odf) ("odp" odf) ("odg" odf)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1287 ("odc" odf) ("odi" odf) ("odm" odf) ("ott" odf)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1288 ("ots" odf) ("otp" odf) ("otg" odf)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1289 ;; Microsoft Office formats (also handled
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1290 ;; by the odf conversion chain)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1291 ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1292 ("ppt" odf) ("pptx" odf))))))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1293 (content-types
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1294 (save-excursion
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1295 (goto-char (point-min))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1296 (cond
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1297 ((looking-at "%!") '(ps))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1298 ((looking-at "%PDF") '(pdf))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1299 ((looking-at "\367\002") '(dvi))))))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1300 (set (make-local-variable 'doc-view-doc-type)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1301 (car (or (doc-view-intersection name-types content-types)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1302 (when (and name-types content-types)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1303 (error "Conflicting types: name says %s but content says %s"
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1304 name-types content-types))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1305 name-types content-types
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1306 (error "Cannot determine the document type"))))))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1307
85027
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
1308 ;;;###autoload
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1309 (defun doc-view-mode ()
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1310 "Major mode in DocView buffers.
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1311
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1312 DocView Mode is an Emacs document viewer. It displays PDF, PS
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1313 and DVI files (as PNG images) in Emacs buffers.
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1314
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
1315 You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
88105
44fd682c485a (doc-view-mode): Improve docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88063
diff changeset
1316 toggle between displaying the document or editing it as text.
44fd682c485a (doc-view-mode): Improve docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 88063
diff changeset
1317 \\{doc-view-mode-map}"
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1318 (interactive)
87681
92ee34bb9001 2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87580
diff changeset
1319
102824
607b4f5da59c (doc-view-mode): Don't give up if the file doesn't exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 102545
diff changeset
1320 (if (= (point-min) (point-max))
101623
0974e3e4aca7 (doc-view-mode): Don't use string-match and file
Tassilo Horn <tassilo@member.fsf.org>
parents: 101575
diff changeset
1321 ;; The doc is empty or doesn't exist at all, so fallback to
102824
607b4f5da59c (doc-view-mode): Don't give up if the file doesn't exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 102545
diff changeset
1322 ;; another mode. We used to also check file-exists-p, but this
607b4f5da59c (doc-view-mode): Don't give up if the file doesn't exist.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 102545
diff changeset
1323 ;; returns nil for tar members.
112039
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1324 (doc-view-fallback-mode)
92879
4486b0175a46 (doc-view-doc->txt, doc-view-convert-current-doc):
Tassilo Horn <tassilo@member.fsf.org>
parents: 92763
diff changeset
1325
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1326 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1327 doc-view-previous-major-mode
112039
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1328 (when (not (memq major-mode
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1329 '(doc-view-mode fundamental-mode)))
112036
f559229a64b8 * doc-view.el (doc-view-mode, doc-view-toggle-display): Use
Tassilo Horn <tassilo@member.fsf.org>
parents: 112035
diff changeset
1330 major-mode))))
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1331 (kill-all-local-variables)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1332 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
1333
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1334 ;; Figure out the document type.
112039
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1335 (unless doc-view-doc-type
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1336 (doc-view-set-doc-type))
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
1337
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1338 (doc-view-make-safe-dir doc-view-cache-directory)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1339 ;; Handle compressed files, remote files, files inside archives
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1340 (set (make-local-variable 'doc-view-buffer-file-name)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1341 (cond
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1342 (jka-compr-really-do-compress
106467
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1343 ;; FIXME: there's a risk of name conflicts here.
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1344 (expand-file-name
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1345 (file-name-nondirectory
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1346 (file-name-sans-extension buffer-file-name))
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1347 doc-view-cache-directory))
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1348 ;; Is the file readable by local processes?
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1349 ;; We used to use `file-remote-p' but it's unclear what it's
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1350 ;; supposed to return nil for things like local files accessed via
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1351 ;; `su' or via file://...
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1352 ((let ((file-name-handler-alist nil))
106467
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1353 (not (and buffer-file-name (file-readable-p buffer-file-name))))
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1354 ;; FIXME: there's a risk of name conflicts here.
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1355 (expand-file-name
106467
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1356 (if buffer-file-name
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1357 (file-name-nondirectory buffer-file-name)
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1358 (buffer-name))
0314d1c68b88 Make it work for non-file buffers (bug#5102).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106327
diff changeset
1359 doc-view-cache-directory))
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1360 (t buffer-file-name)))
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1361 (when (not (string= doc-view-buffer-file-name buffer-file-name))
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1362 (write-region nil nil doc-view-buffer-file-name))
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
1363
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1364 (add-hook 'change-major-mode-hook
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1365 (lambda ()
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1366 (doc-view-kill-proc)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1367 (remove-overlays (point-min) (point-max) 'doc-view t))
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1368 nil t)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1369 (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1370 (add-hook 'kill-buffer-hook 'doc-view-kill-proc nil t)
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
1371
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1372 (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case.
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1373 ;; Keep track of display info ([vh]scroll, page number, overlay,
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1374 ;; ...) for each window in which this document is shown.
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1375 (add-hook 'image-mode-new-window-functions
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1376 'doc-view-new-window-function nil t)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1377 (image-mode-setup-winprops)
101909
b62aecf6b1db (doc-view-scroll-up-or-next-page)
Tassilo Horn <tassilo@member.fsf.org>
parents: 101623
diff changeset
1378
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1379 (set (make-local-variable 'mode-line-position)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1380 '(" P" (:eval (number-to-string (doc-view-current-page)))
107087
392cb4c24760 Fix up various corner case problems.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 107069
diff changeset
1381 "/" (:eval (number-to-string (doc-view-last-page-number)))))
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1382 ;; Don't scroll unless the user specifically asked for it.
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1383 (set (make-local-variable 'auto-hscroll-mode) nil)
106241
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
1384 (set (make-local-variable 'mwheel-scroll-up-function)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
1385 'doc-view-scroll-up-or-next-page)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
1386 (set (make-local-variable 'mwheel-scroll-down-function)
7ce04dfc904d Mouse-wheel scrolling for DocView Continuous mode. (Bug#4896)
Juri Linkov <juri@jurta.org>
parents: 106214
diff changeset
1387 'doc-view-scroll-down-or-previous-page)
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1388 (set (make-local-variable 'cursor-type) nil)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1389 (use-local-map doc-view-mode-map)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1390 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1391 (set (make-local-variable 'bookmark-make-record-function)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1392 'doc-view-bookmark-make-record)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1393 (setq mode-name "DocView"
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1394 buffer-read-only t
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1395 major-mode 'doc-view-mode)
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1396 (doc-view-initiate-display)
106214
8653ee602137 * doc-view.el (doc-view-mode): Switch off view-mode explicitly,
Tassilo Horn <tassilo@member.fsf.org>
parents: 106207
diff changeset
1397 ;; Switch off view-mode explicitly, because doc-view-mode is the
8653ee602137 * doc-view.el (doc-view-mode): Switch off view-mode explicitly,
Tassilo Horn <tassilo@member.fsf.org>
parents: 106207
diff changeset
1398 ;; canonical view mode for PDF/PS/DVI files. This could be
8653ee602137 * doc-view.el (doc-view-mode): Switch off view-mode explicitly,
Tassilo Horn <tassilo@member.fsf.org>
parents: 106207
diff changeset
1399 ;; switched on automatically depending on the value of
8653ee602137 * doc-view.el (doc-view-mode): Switch off view-mode explicitly,
Tassilo Horn <tassilo@member.fsf.org>
parents: 106207
diff changeset
1400 ;; `view-read-only'.
106242
fb2730a2950b (doc-view-mode): Set buffer-local `view-read-only' to nil
Juri Linkov <juri@jurta.org>
parents: 106241
diff changeset
1401 (set (make-local-variable 'view-read-only) nil)
101573
6c0c4dcde904 (doc-view-mode): Enhance docstring and fallback to
Tassilo Horn <tassilo@member.fsf.org>
parents: 100908
diff changeset
1402 (run-mode-hooks 'doc-view-mode-hook)))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1403
112039
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1404 (defun doc-view-fallback-mode ()
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1405 "Fallback to the previous or next best major mode."
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1406 (if doc-view-previous-major-mode
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1407 (funcall doc-view-previous-major-mode)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1408 (let ((auto-mode-alist (rassq-delete-all
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1409 'doc-view-mode-maybe
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1410 (rassq-delete-all 'doc-view-mode
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1411 (copy-alist auto-mode-alist)))))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1412 (normal-mode))))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1413
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1414 ;;;###autoload
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1415 (defun doc-view-mode-maybe ()
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1416 "Switch to `doc-view-mode' if possible.
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1417 If the required external tools are not available, then fallback
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1418 to the next best mode."
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1419 (condition-case nil
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1420 (doc-view-set-doc-type)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1421 (error (doc-view-fallback-mode)))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1422 (if (doc-view-mode-p doc-view-doc-type)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1423 (doc-view-mode)
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1424 (doc-view-fallback-mode)))
2fef20daac2b * doc-view.el (doc-view-set-doc-type): New function refactored
Tassilo Horn <tassilo@member.fsf.org>
parents: 112037
diff changeset
1425
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1426 ;;;###autoload
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1427 (define-minor-mode doc-view-minor-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1428 "Toggle Doc view minor mode.
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1429 With arg, turn Doc view minor mode on if arg is positive, off otherwise.
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1430 See the command `doc-view-mode' for more information on this mode."
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1431 nil " DocView" doc-view-minor-mode-map
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1432 :group 'doc-view
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1433 (when doc-view-minor-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1434 (add-hook 'change-major-mode-hook (lambda () (doc-view-minor-mode -1)) nil t)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1435 (message
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1436 "%s"
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1437 (substitute-command-keys
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
1438 "Type \\[doc-view-toggle-display] to toggle between editing or viewing the document."))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1439
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1440 (defun doc-view-clear-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1441 "Delete the whole cache (`doc-view-cache-directory')."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1442 (interactive)
92752
7f212bec15c4 (doc-view-doc->txt, doc-view-open-text)
Tassilo Horn <tassilo@member.fsf.org>
parents: 92691
diff changeset
1443 (dired-delete-file doc-view-cache-directory 'always))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1444
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1445 (defun doc-view-dired-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1446 "Open `dired' in `doc-view-cache-directory'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1447 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1448 (dired doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1449
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1450
87411
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1451 ;;;; Bookmark integration
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1452
109395
fa4400531412 Preparation for setting bookmarks in Gnus article buffers (Bug#5975).
Karl Fogel <kfogel@red-bean.com>
parents: 107167
diff changeset
1453 (declare-function bookmark-make-record-default
fa4400531412 Preparation for setting bookmarks in Gnus article buffers (Bug#5975).
Karl Fogel <kfogel@red-bean.com>
parents: 107167
diff changeset
1454 "bookmark" (&optional no-file no-context posn))
92691
0574109ed8bc (bookmark-buffer-file-name, bookmark-prop-get): Declare.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92674
diff changeset
1455 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
96280
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1456 (declare-function bookmark-default-handler "bookmark" (bmk))
92691
0574109ed8bc (bookmark-buffer-file-name, bookmark-prop-get): Declare.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92674
diff changeset
1457
92674
ac3c6c3e119c * bookmark.el (bookmark-make): Don't pass the `annotation' to the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92563
diff changeset
1458 (defun doc-view-bookmark-make-record ()
96280
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1459 (nconc (bookmark-make-record-default)
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1460 `((page . ,(doc-view-current-page))
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1461 (handler . doc-view-bookmark-jump))))
87411
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1462
87556
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1463
87411
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1464 ;;;###autoload
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1465 (defun doc-view-bookmark-jump (bmk)
87521
0140d3ebb262 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 87412
diff changeset
1466 ;; This implements the `handler' function interface for record type
92556
5944be8c8211 Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents: 92224
diff changeset
1467 ;; returned by `doc-view-bookmark-make-record', which see.
96280
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1468 (prog1 (bookmark-default-handler bmk)
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1469 (let ((page (bookmark-prop-get bmk 'page)))
87411
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1470 (when (not (eq major-mode 'doc-view-mode))
96280
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1471 (doc-view-toggle-display))
92691
0574109ed8bc (bookmark-buffer-file-name, bookmark-prop-get): Declare.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92674
diff changeset
1472 (with-selected-window
0574109ed8bc (bookmark-buffer-file-name, bookmark-prop-get): Declare.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92674
diff changeset
1473 (or (get-buffer-window (current-buffer) 0)
0574109ed8bc (bookmark-buffer-file-name, bookmark-prop-get): Declare.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 92674
diff changeset
1474 (selected-window))
96280
bfca3297fa0b * bookmark.el (bookmark-alist): Allow the 2 slightly different formats
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 95841
diff changeset
1475 (doc-view-goto-page page)))))
87411
9ac481bc897b 2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents: 87133
diff changeset
1476
87556
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1477
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1478 (provide 'doc-view)
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1479
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1480 ;; Local Variables:
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1481 ;; mode: outline-minor
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1482 ;; End:
39204305bf6f (doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents: 87522
diff changeset
1483
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1484 ;;; doc-view.el ends here