Mercurial > emacs
annotate lisp/doc-view.el @ 91802:3a35316b344f
(sgml-html-meta-auto-coding-function): Make sure the search limit is ahead.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 12 Feb 2008 21:21:02 +0000 |
parents | 0048d198c131 |
children | db743b98a24b |
rev | line source |
---|---|
84422 | 1 ;;; doc-view.el --- View PDF/PostScript/DVI files in Emacs |
2 | |
87556
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc. |
84422 | 4 ;; |
5 ;; Author: Tassilo Horn <tassilo@member.fsf.org> | |
6 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org> | |
7 ;; Keywords: files, pdf, ps, dvi | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 3, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
24 ;; Boston, MA 02110-1301, USA. | |
25 | |
26 ;;; Requirements: | |
27 | |
85367
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
28 ;; doc-view.el requires GNU Emacs 22.1 or newer. You also need Ghostscript, |
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
29 ;; `dvipdfm' which comes with teTeX and `pdftotext', which comes with xpdf |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
30 ;; (http://www.foolabs.com/xpdf/) or poppler (http://poppler.freedesktop.org/). |
84422 | 31 |
32 ;;; Commentary: | |
33 | |
34 ;; DocView is a document viewer for Emacs. It converts PDF, PS and DVI files | |
35 ;; to a set of PNG files, one PNG for each page, and displays the PNG images | |
36 ;; inside an Emacs buffer. This buffer uses `doc-view-mode' which provides | |
37 ;; convenient key bindings for browsing the document. | |
38 ;; | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
39 ;; 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
|
40 ;; |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
41 ;; C-x C-f ~/path/to/document RET |
84422 | 42 ;; |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
43 ;; 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
|
44 ;; 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
|
45 ;; representation and the source text representation of the document. |
84422 | 46 ;; |
47 ;; Since conversion may take some time all the PNG images are cached in a | |
48 ;; 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
|
49 ;; 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
|
50 ;; when displaying the document. To delete all cached files use |
84422 | 51 ;; `doc-view-clear-cache'. To open the cache with dired, so that you can tidy |
52 ;; it out use `doc-view-dired-cache'. | |
53 ;; | |
54 ;; When conversion in underway the first page will be displayed as soon as it | |
55 ;; is available and the available pages are refreshed every | |
56 ;; `doc-view-conversion-refresh-interval' seconds. If that variable is nil the | |
57 ;; pages won't be displayed before conversion of the document finished | |
58 ;; completely. | |
59 ;; | |
60 ;; DocView lets you select a slice of the displayed pages. This slice will be | |
61 ;; remembered and applied to all pages of the current document. This enables | |
62 ;; you to cut away the margins of a document to save some space. To select a | |
63 ;; slice you can use `doc-view-set-slice' (bound to `s s') which will query you | |
64 ;; for the coordinates of the slice's top-left corner and its width and height. | |
65 ;; A much more convenient way to do the same is offered by the command | |
66 ;; `doc-view-set-slice-using-mouse' (bound to `s m'). After invokation you | |
67 ;; only have to press mouse-1 at the top-left corner and drag it to the | |
68 ;; bottom-right corner of the desired slice. To reset the slice use | |
69 ;; `doc-view-reset-slice' (bound to `s r'). | |
70 ;; | |
71 ;; You can also search within the document. The command `doc-view-search' | |
72 ;; (bound to `C-s') queries for a search regexp and initializes a list of all | |
73 ;; 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
|
74 ;; 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
|
75 ;; `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
|
76 ;; 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
|
77 ;; searching works by using a plain text representation of the document. If |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
78 ;; that doesn't already exist the first invokation of `doc-view-search' (or |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
79 ;; `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
|
80 ;; 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
|
81 ;; 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
|
82 ;; |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
83 ;; 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
|
84 ;; 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
|
85 ;; |
84422 | 86 |
87 ;;; Configuration: | |
88 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
89 ;; 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
|
90 ;; `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
|
91 ;; the higher the value.) |
84422 | 92 ;; |
93 ;; This and all other options can be set with the customization interface. | |
94 ;; Simply do | |
95 ;; | |
96 ;; M-x customize-group RET doc-view RET | |
97 ;; | |
98 ;; and modify them to your needs. | |
99 | |
86035
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
100 ;;; Todo: |
84422 | 101 |
91715
66471668862f
Add todo entries.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
88105
diff
changeset
|
102 ;; - fix behavior with clone-indirect-buffer |
66471668862f
Add todo entries.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
88105
diff
changeset
|
103 ;; - allow different windows showing the same buffer to change pages |
66471668862f
Add todo entries.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
88105
diff
changeset
|
104 ;; independently. |
87850
dd673d4bceda
(doc-view-goto-page): Don't move point any more, now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87842
diff
changeset
|
105 ;; - share more code with image-mode again. |
85801
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
106 ;; - 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
|
107 ;; - Bind slicing to a drag event. |
86119
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
108 ;; - 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
|
109 ;; - 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
|
110 ;; - 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
|
111 ;; - 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
|
112 |
86035
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
113 ;;;; About isearch support |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
114 |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
115 ;; I tried implementing isearch by setting |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
116 ;; `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
|
117 ;; 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
|
118 ;; 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
|
119 ;; 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
|
120 ;; 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
|
121 ;; 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
|
122 ;; 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
|
123 ;; 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
|
124 ;; 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
|
125 ;; 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
|
126 ;; (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
|
127 |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
128 ;; 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
|
129 ;; 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
|
130 ;; 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
|
131 ;; pages to jump. |
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 ;; 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
|
134 ;; feel free to do it. --Tassilo |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
135 |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
136 ;;; Code: |
d3745283de5f
Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents:
86025
diff
changeset
|
137 |
84422 | 138 (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
|
139 (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
|
140 (require 'jka-compr) |
84422 | 141 |
142 ;;;; Customization Options | |
143 | |
144 (defgroup doc-view nil | |
145 "In-buffer viewer for PDF, PostScript and DVI files." | |
146 :link '(function-link doc-view) | |
147 :version "22.2" | |
148 :group 'applications | |
149 :group 'multimedia | |
150 :prefix "doc-view-") | |
151 | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
152 (defcustom doc-view-ghostscript-program (executable-find "gs") |
84422 | 153 "Program to convert PS and PDF files to PNG." |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
154 :type 'file |
84422 | 155 :group 'doc-view) |
156 | |
157 (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
|
158 '("-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
|
159 ;; sources. |
26dcc1207f42
(doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85369
diff
changeset
|
160 "-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4" |
86119
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
161 "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET") |
85367
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
162 "A list of options to give to ghostscript." |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
163 :type '(repeat string) |
84422 | 164 :group 'doc-view) |
165 | |
86119
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
166 (defcustom doc-view-resolution 100 |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
167 "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
|
168 Higher values result in larger images." |
86154 | 169 :type 'number |
170 :group 'doc-view) | |
86119
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
171 |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
172 (defcustom doc-view-dvipdfm-program (executable-find "dvipdfm") |
84422 | 173 "Program to convert DVI files to PDF. |
174 | |
175 DVI file will be converted to PDF before the resulting PDF is | |
176 converted to PNG." | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
177 :type 'file |
84422 | 178 :group 'doc-view) |
179 | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
180 (defcustom doc-view-ps2pdf-program (executable-find "ps2pdf") |
84422 | 181 "Program to convert PS files to PDF. |
182 | |
183 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
|
184 :type 'file |
84422 | 185 :group 'doc-view) |
186 | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
187 (defcustom doc-view-pdftotext-program (executable-find "pdftotext") |
84422 | 188 "Program to convert PDF files to plain text. |
189 | |
190 Needed for searching." | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
191 :type 'file |
84422 | 192 :group 'doc-view) |
193 | |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
194 (defcustom doc-view-cache-directory |
85856
a26944b15c75
(doc-view-cache-directory): Remove superfluous concat.
Glenn Morris <rgm@gnu.org>
parents:
85844
diff
changeset
|
195 (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
|
196 temporary-file-directory) |
84422 | 197 "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
|
198 :type 'directory |
84422 | 199 :group 'doc-view) |
200 | |
201 (defcustom doc-view-conversion-buffer "*doc-view conversion output*" | |
202 "The buffer where messages from the converter programs go to." | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
203 :type 'string |
84422 | 204 :group 'doc-view) |
205 | |
206 (defcustom doc-view-conversion-refresh-interval 3 | |
85815
960b3c592913
(doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents:
85805
diff
changeset
|
207 "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
|
208 After such a refresh newly converted pages will be available for |
84422 | 209 viewing. If set to nil there won't be any refreshes and the |
210 pages won't be displayed before conversion of the whole document | |
211 has finished." | |
85421
fbc2287ee475
Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85420
diff
changeset
|
212 :type 'integer |
84422 | 213 :group 'doc-view) |
214 | |
215 ;;;; Internal Variables | |
216 | |
217 (defvar doc-view-current-files nil | |
218 "Only used internally.") | |
219 | |
220 (defvar doc-view-current-page nil | |
221 "Only used internally.") | |
222 | |
223 (defvar doc-view-current-converter-process nil | |
224 "Only used internally.") | |
225 | |
226 (defvar doc-view-current-timer nil | |
227 "Only used internally.") | |
228 | |
229 (defvar doc-view-current-slice nil | |
230 "Only used internally.") | |
231 | |
232 (defvar doc-view-current-cache-dir nil | |
233 "Only used internally.") | |
234 | |
235 (defvar doc-view-current-search-matches nil | |
236 "Only used internally.") | |
237 | |
238 (defvar doc-view-current-image nil | |
239 "Only used internally.") | |
87006
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
240 |
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
241 (defvar doc-view-current-overlay nil |
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
242 "Only used internally.") |
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
243 |
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
244 (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
|
245 "Only used internally.") |
84422 | 246 |
247 (defvar doc-view-current-info nil | |
248 "Only used internally.") | |
249 | |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
250 (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
|
251 "Only used internally.") |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
252 |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
253 (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
|
254 "Only used internally. |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
255 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
|
256 `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
|
257 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
|
258 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
|
259 `doc-view-cache-directory'.") |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
260 |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
261 ;;;; DocView Keymaps |
84422 | 262 |
263 (defvar doc-view-mode-map | |
264 (let ((map (make-sparse-keymap))) | |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
265 (suppress-keymap map) |
84422 | 266 ;; Navigation in the document |
267 (define-key map (kbd "n") 'doc-view-next-page) | |
268 (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
|
269 (define-key map (kbd "<next>") 'forward-page) |
a3364ed63fcd
(doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85421
diff
changeset
|
270 (define-key map (kbd "<prior>") 'backward-page) |
a3364ed63fcd
(doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85421
diff
changeset
|
271 (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
|
272 (define-key map [remap backward-page] 'doc-view-previous-page) |
84422 | 273 (define-key map (kbd "SPC") 'doc-view-scroll-up-or-next-page) |
274 (define-key map (kbd "DEL") 'doc-view-scroll-down-or-previous-page) | |
275 (define-key map (kbd "M-<") 'doc-view-first-page) | |
276 (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
|
277 (define-key map [remap goto-line] 'doc-view-goto-page) |
87575
f637e8101ba1
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87572
diff
changeset
|
278 (define-key map [remap scroll-up] 'image-scroll-up) |
f637e8101ba1
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87572
diff
changeset
|
279 (define-key map [remap scroll-down] 'image-scroll-down) |
86119
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
280 ;; Zoom in/out. |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
281 (define-key map "+" 'doc-view-enlarge) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
282 (define-key map "-" 'doc-view-shrink) |
84422 | 283 ;; Killing/burying the buffer (and the process) |
284 (define-key map (kbd "q") 'bury-buffer) | |
285 (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
|
286 (define-key map (kbd "K") 'doc-view-kill-proc) |
84422 | 287 ;; Slicing the image |
288 (define-key map (kbd "s s") 'doc-view-set-slice) | |
289 (define-key map (kbd "s m") 'doc-view-set-slice-using-mouse) | |
290 (define-key map (kbd "s r") 'doc-view-reset-slice) | |
291 ;; Searching | |
292 (define-key map (kbd "C-s") 'doc-view-search) | |
293 (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
|
294 (define-key map (kbd "C-r") 'doc-view-search-backward) |
84422 | 295 ;; Scrolling |
85444
a3364ed63fcd
(doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85421
diff
changeset
|
296 (define-key map [remap forward-char] 'image-forward-hscroll) |
a3364ed63fcd
(doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85421
diff
changeset
|
297 (define-key map [remap backward-char] 'image-backward-hscroll) |
a3364ed63fcd
(doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85421
diff
changeset
|
298 (define-key map [remap next-line] 'image-next-line) |
a3364ed63fcd
(doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85421
diff
changeset
|
299 (define-key map [remap previous-line] 'image-previous-line) |
84422 | 300 ;; Show the tooltip |
301 (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
|
302 ;; 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
|
303 (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
|
304 ;; Reconvert the current document |
85843
05357c175a50
(doc-view-mode-map): Bind doc-view-goto-page to the keys
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85815
diff
changeset
|
305 (define-key map (kbd "g") 'revert-buffer) |
05357c175a50
(doc-view-mode-map): Bind doc-view-goto-page to the keys
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85815
diff
changeset
|
306 (define-key map (kbd "r") 'revert-buffer) |
84422 | 307 map) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
308 "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
|
309 |
85801
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
310 (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
|
311 "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
|
312 '("DocView" |
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
313 ["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
|
314 ["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
|
315 ["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
|
316 "---" |
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
317 ["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
|
318 ["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
|
319 ["Toggle display" doc-view-toggle-display] |
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
320 )) |
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
321 |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
322 (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
|
323 (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
|
324 ;; 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
|
325 (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
|
326 map) |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
327 "Keymap used by `doc-minor-view-mode'.") |
84422 | 328 |
329 ;;;; Navigation Commands | |
330 | |
331 (defun doc-view-goto-page (page) | |
332 "View the page given by PAGE." | |
333 (interactive "nPage: ") | |
334 (let ((len (length doc-view-current-files))) | |
335 (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
|
336 (setq page 1) |
84422 | 337 (when (> page len) |
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
|
338 (setq page len))) |
84422 | 339 (setq doc-view-current-page 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
|
340 doc-view-current-info |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
341 (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
|
342 (propertize |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
343 (format "Page %d of %d." |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
344 doc-view-current-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
|
345 len) '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
|
346 ;; Tell user if converting isn't finished yet |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
347 (if doc-view-current-converter-process |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
348 " (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
|
349 "\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
|
350 ;; 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
|
351 (when (and 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
|
352 (assq doc-view-current-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
|
353 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
|
354 (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
|
355 (let ((contexts "")) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
356 (dolist (m (cdr (assq doc-view-current-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
|
357 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
|
358 (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
|
359 contexts))))) |
84422 | 360 ;; Update the buffer |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
361 (doc-view-insert-image (nth (1- page) doc-view-current-files) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
362 :pointer 'arrow) |
87850
dd673d4bceda
(doc-view-goto-page): Don't move point any more, now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87842
diff
changeset
|
363 (overlay-put doc-view-current-overlay 'help-echo doc-view-current-info))) |
84422 | 364 |
365 (defun doc-view-next-page (&optional arg) | |
366 "Browse ARG pages forward." | |
367 (interactive "p") | |
368 (doc-view-goto-page (+ doc-view-current-page (or arg 1)))) | |
369 | |
370 (defun doc-view-previous-page (&optional arg) | |
371 "Browse ARG pages backward." | |
372 (interactive "p") | |
373 (doc-view-goto-page (- doc-view-current-page (or arg 1)))) | |
374 | |
375 (defun doc-view-first-page () | |
376 "View the first page." | |
377 (interactive) | |
378 (doc-view-goto-page 1)) | |
379 | |
380 (defun doc-view-last-page () | |
381 "View the last page." | |
382 (interactive) | |
383 (doc-view-goto-page (length doc-view-current-files))) | |
384 | |
385 (defun doc-view-scroll-up-or-next-page () | |
386 "Scroll page up if possible, else goto next page." | |
387 (interactive) | |
87572
0e44918a91f4
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87556
diff
changeset
|
388 (when (= (window-vscroll) (image-scroll-up nil)) |
87580
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
389 (let ((cur-page doc-view-current-page)) |
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
390 (doc-view-next-page) |
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
391 (when (/= cur-page doc-view-current-page) |
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
392 (set-window-vscroll nil 0))))) |
84422 | 393 |
394 (defun doc-view-scroll-down-or-previous-page () | |
395 "Scroll page down if possible, else goto previous page." | |
396 (interactive) | |
87572
0e44918a91f4
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87556
diff
changeset
|
397 (when (= (window-vscroll) (image-scroll-down nil)) |
87580
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
398 (let ((cur-page doc-view-current-page)) |
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
399 (doc-view-previous-page) |
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
400 (when (/= cur-page doc-view-current-page) |
c47e66c6d239
2008-01-04 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87575
diff
changeset
|
401 (image-scroll-up nil))))) |
84422 | 402 |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
403 ;;;; Utility Functions |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
404 |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
405 (defun doc-view-kill-proc () |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
406 "Kill the current converter process." |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
407 (interactive) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
408 (when doc-view-current-converter-process |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
409 (kill-process doc-view-current-converter-process) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
410 (setq doc-view-current-converter-process nil)) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
411 (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
|
412 (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
|
413 (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
|
414 (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
|
415 |
84422 | 416 (defun doc-view-kill-proc-and-buffer () |
417 "Kill the current converter process and buffer." | |
418 (interactive) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
419 (doc-view-kill-proc) |
84422 | 420 (when (eq major-mode 'doc-view-mode) |
421 (kill-buffer (current-buffer)))) | |
422 | |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
423 (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
|
424 (condition-case nil |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
425 (let ((umask (default-file-modes))) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
426 (unwind-protect |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
427 (progn |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
428 ;; 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
|
429 ;; 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
|
430 ;; time-window of loose permissions otherwise. |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
431 (set-default-file-modes #o0700) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
432 (make-directory dir)) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
433 ;; Reset the umask. |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
434 (set-default-file-modes umask))) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
435 (file-already-exists |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
436 (if (file-symlink-p dir) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
437 (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
|
438 ;; 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
|
439 ;; 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
|
440 ;; 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
|
441 ;; 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
|
442 ;; 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
|
443 ;; 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
|
444 ;; 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
|
445 ;; closing a bunch of security holes. |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
446 (set-file-modes dir #o0700)))) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
447 |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
448 (defun doc-view-current-cache-dir () |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
449 "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
|
450 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
|
451 (if doc-view-current-cache-dir |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
452 doc-view-current-cache-dir |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
453 ;; 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
|
454 (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
|
455 ;; Now compute the subdirectory to use. |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
456 (setq doc-view-current-cache-dir |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
457 (file-name-as-directory |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
458 (expand-file-name |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
459 (concat (file-name-nondirectory buffer-file-name) |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
460 "-" |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
461 (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
|
462 (with-temp-buffer |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
463 (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
|
464 (md5 (current-buffer))))) |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
465 doc-view-cache-directory))))) |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
466 |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
467 (defun doc-view-remove-if (predicate list) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
468 "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
|
469 (let (new-list) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
470 (dolist (item list (nreverse new-list)) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
471 (when (not (funcall predicate item)) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
472 (setq new-list (cons item new-list)))))) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
473 |
86441
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
474 ;;;###autoload |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
475 (defun doc-view-mode-p (type) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
476 "Return non-nil if image type TYPE is available for `doc-view'. |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
477 Image types are symbols like `dvi', `postscript' or `pdf'." |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
478 (and (display-graphic-p) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
479 (image-type-available-p 'png) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
480 (cond |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
481 ((eq type 'dvi) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
482 (and (doc-view-mode-p 'pdf) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
483 doc-view-dvipdfm-program |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
484 (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
|
485 ((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
|
486 (eq type 'pdf)) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
487 (and doc-view-ghostscript-program |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
488 (executable-find doc-view-ghostscript-program))) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
489 (t ;; unknown image type |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
490 nil)))) |
6934c0956614
(doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86156
diff
changeset
|
491 |
84422 | 492 ;;;; Conversion Functions |
493 | |
86119
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
494 (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
|
495 |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
496 (defun doc-view-enlarge (factor) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
497 "Enlarge the document." |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
498 (interactive (list doc-view-shrink-factor)) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
499 (set (make-local-variable 'doc-view-resolution) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
500 (* factor doc-view-resolution)) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
501 (doc-view-reconvert-doc)) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
502 |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
503 (defun doc-view-shrink (factor) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
504 "Shrink the document." |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
505 (interactive (list doc-view-shrink-factor)) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
506 (doc-view-enlarge (/ 1.0 factor))) |
5b6715f2ee11
(doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
86035
diff
changeset
|
507 |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
508 (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
|
509 "Reconvert the current document. |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
510 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
|
511 (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
|
512 (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
|
513 ;; 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
|
514 (when (file-exists-p (doc-view-current-cache-dir)) |
9b97166d0c6c
(doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85784
diff
changeset
|
515 (dired-delete-file (doc-view-current-cache-dir) 'always)) |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
516 (doc-view-initiate-display)) |
84422 | 517 |
518 (defun doc-view-dvi->pdf-sentinel (proc event) | |
85029
63718012f1da
(doc-view-dvi->pdf-sentinel, doc-view-reset-slice)
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
85027
diff
changeset
|
519 "If DVI->PDF conversion was successful, convert the PDF to PNG now." |
84422 | 520 (if (not (string-match "finished" event)) |
521 (message "DocView: dvi->pdf process changed status to %s." event) | |
87133
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
522 (with-current-buffer (process-get proc 'buffer) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
523 (setq doc-view-current-converter-process nil |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
524 mode-line-process nil) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
525 ;; Now go on converting this PDF to a set of PNG files. |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
526 (let* ((pdf (process-get proc 'pdf-file)) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
527 (png (expand-file-name "page-%d.png" |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
528 (doc-view-current-cache-dir)))) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
529 (doc-view-pdf/ps->png pdf png))))) |
84422 | 530 |
531 (defun doc-view-dvi->pdf (dvi pdf) | |
85815
960b3c592913
(doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents:
85805
diff
changeset
|
532 "Convert DVI to PDF asynchronously." |
84422 | 533 (setq doc-view-current-converter-process |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
534 (start-process "dvi->pdf" doc-view-conversion-buffer |
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
|
535 doc-view-dvipdfm-program |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
536 "-o" pdf dvi) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
537 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 538 (set-process-sentinel doc-view-current-converter-process |
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
|
539 'doc-view-dvi->pdf-sentinel) |
84422 | 540 (process-put doc-view-current-converter-process 'buffer (current-buffer)) |
541 (process-put doc-view-current-converter-process 'pdf-file pdf)) | |
542 | |
543 (defun doc-view-pdf/ps->png-sentinel (proc event) | |
544 "If PDF/PS->PNG conversion was successful, update the display." | |
545 (if (not (string-match "finished" event)) | |
546 (message "DocView: converter process changed status to %s." event) | |
87133
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
547 (with-current-buffer (process-get proc 'buffer) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
548 (setq doc-view-current-converter-process nil |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
549 mode-line-process nil) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
550 (when doc-view-current-timer |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
551 (cancel-timer doc-view-current-timer) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
552 (setq doc-view-current-timer nil)) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
553 ;; Yippie, finished. Update the display! |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
554 (doc-view-display (current-buffer) 'force)))) |
84422 | 555 |
556 (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
|
557 "Convert PDF-PS to PNG asynchronously." |
84422 | 558 (setq doc-view-current-converter-process |
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
|
559 ;; Make sure the process is started in an existing directory, |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
560 ;; (rather than some file-name-handler-managed dir, for example). |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
561 (let ((default-directory (file-name-directory pdf-ps))) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
562 (apply 'start-process |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
563 (append (list "pdf/ps->png" doc-view-conversion-buffer |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
564 doc-view-ghostscript-program) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
565 doc-view-ghostscript-options |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
566 (list (format "-r%d" (round doc-view-resolution))) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
567 (list (concat "-sOutputFile=" png)) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
568 (list pdf-ps)))) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
569 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 570 (process-put doc-view-current-converter-process |
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
|
571 'buffer (current-buffer)) |
84422 | 572 (set-process-sentinel doc-view-current-converter-process |
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
|
573 'doc-view-pdf/ps->png-sentinel) |
84422 | 574 (when doc-view-conversion-refresh-interval |
575 (setq doc-view-current-timer | |
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
|
576 (run-at-time "1 secs" doc-view-conversion-refresh-interval |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
577 'doc-view-display |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
578 (current-buffer))))) |
84422 | 579 |
580 (defun doc-view-pdf->txt-sentinel (proc event) | |
581 (if (not (string-match "finished" event)) | |
582 (message "DocView: converter process changed status to %s." event) | |
583 (let ((current-buffer (current-buffer)) | |
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
|
584 (proc-buffer (process-get proc 'buffer))) |
87133
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
585 (with-current-buffer proc-buffer |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
586 (setq doc-view-current-converter-process nil |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
587 mode-line-process nil) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
588 ;; If the user looks at the DocView buffer where the conversion was |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
589 ;; performed, search anew. This time it will be queried for a regexp. |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
590 (when (eq current-buffer proc-buffer) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
591 (doc-view-search nil)))))) |
84422 | 592 |
593 (defun doc-view-pdf->txt (pdf txt) | |
85815
960b3c592913
(doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents:
85805
diff
changeset
|
594 "Convert PDF to TXT asynchronously." |
84422 | 595 (setq doc-view-current-converter-process |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
596 (start-process "pdf->txt" doc-view-conversion-buffer |
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
|
597 doc-view-pdftotext-program "-raw" |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
598 pdf txt) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
599 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 600 (set-process-sentinel doc-view-current-converter-process |
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
|
601 'doc-view-pdf->txt-sentinel) |
84422 | 602 (process-put doc-view-current-converter-process 'buffer (current-buffer))) |
603 | |
604 (defun doc-view-ps->pdf-sentinel (proc event) | |
605 (if (not (string-match "finished" event)) | |
606 (message "DocView: converter process changed status to %s." event) | |
87133
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
607 (with-current-buffer (process-get proc 'buffer) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
608 (setq doc-view-current-converter-process nil |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
609 mode-line-process nil) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
610 ;; Now we can transform to plain text. |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
611 (doc-view-pdf->txt (process-get proc 'pdf-file) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
612 (expand-file-name "doc.txt" |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
613 (doc-view-current-cache-dir)))))) |
84422 | 614 |
615 (defun doc-view-ps->pdf (ps pdf) | |
616 "Convert PS to PDF asynchronously." | |
617 (setq doc-view-current-converter-process | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
618 (start-process "ps->pdf" doc-view-conversion-buffer |
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
|
619 doc-view-ps2pdf-program |
85418
26dcc1207f42
(doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85369
diff
changeset
|
620 ;; Avoid security problems when rendering files from |
26dcc1207f42
(doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85369
diff
changeset
|
621 ;; untrusted sources. |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
622 "-dSAFER" |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
623 ;; in-file and out-file |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
624 ps pdf) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
625 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 626 (set-process-sentinel doc-view-current-converter-process |
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
|
627 'doc-view-ps->pdf-sentinel) |
84422 | 628 (process-put doc-view-current-converter-process 'buffer (current-buffer)) |
629 (process-put doc-view-current-converter-process 'pdf-file pdf)) | |
630 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
631 (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
|
632 "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
|
633 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
|
634 `doc-view-current-cache-dir'." |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
635 ;; 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
|
636 ;; 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
|
637 ;; 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
|
638 ;; 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
|
639 ;; resets during the redisplay). |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
640 (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
|
641 (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
|
642 (doc-view-current-cache-dir)))) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
643 (make-directory (doc-view-current-cache-dir)) |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
644 (if (not (string= (file-name-extension doc-view-buffer-file-name) "dvi")) |
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
|
645 ;; Convert to PNG images. |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
646 (doc-view-pdf/ps->png doc-view-buffer-file-name png-file) |
85367
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
647 ;; DVI files have to be converted to PDF before Ghostscript can process |
84422 | 648 ;; it. |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
649 (doc-view-dvi->pdf doc-view-buffer-file-name |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
650 (expand-file-name "doc.pdf" |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
651 doc-view-current-cache-dir))))) |
84422 | 652 |
653 ;;;; Slicing | |
654 | |
655 (defun doc-view-set-slice (x y width height) | |
656 "Set the slice of the images that should be displayed. | |
657 You can use this function to tell doc-view not to display the | |
658 margins of the document. It prompts for the top-left corner (X | |
659 and Y) of the slice to display and its WIDTH and HEIGHT. | |
660 | |
661 See `doc-view-set-slice-using-mouse' for a more convenient way to | |
662 do that. To reset the slice use `doc-view-reset-slice'." | |
663 (interactive | |
664 (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
|
665 (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
|
666 (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
|
667 (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
|
668 (d (read-number (format "Height (0..%d): " (- (cdr size) b))))) |
84422 | 669 (list a b c d))) |
670 (setq doc-view-current-slice (list x y width height)) | |
671 ;; Redisplay | |
672 (doc-view-goto-page doc-view-current-page)) | |
673 | |
674 (defun doc-view-set-slice-using-mouse () | |
675 "Set the slice of the images that should be displayed. | |
676 You set the slice by pressing mouse-1 at its top-left corner and | |
677 dragging it to its bottom-right corner. See also | |
678 `doc-view-set-slice' and `doc-view-reset-slice'." | |
679 (interactive) | |
680 (let (x y w h done) | |
681 (while (not done) | |
682 (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
|
683 (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
|
684 "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
|
685 (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
|
686 (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
|
687 (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
|
688 (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
|
689 (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
|
690 (setq done t)))) |
84422 | 691 (doc-view-set-slice x y w h))) |
692 | |
693 (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
|
694 "Reset the current slice. |
85815
960b3c592913
(doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents:
85805
diff
changeset
|
695 After calling this function whole pages will be visible again." |
84422 | 696 (interactive) |
697 (setq doc-view-current-slice nil) | |
698 ;; Redisplay | |
699 (doc-view-goto-page doc-view-current-page)) | |
700 | |
701 ;;;; Display | |
702 | |
703 (defun doc-view-insert-image (file &rest args) | |
704 "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
|
705 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
|
706 (when doc-view-pending-cache-flush |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
707 (clear-image-cache) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
708 (setq doc-view-pending-cache-flush nil)) |
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
|
709 (if (null file) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
710 ;; We're trying to display a page that doesn't exist. Typically happens |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
711 ;; if the conversion process somehow failed. Better not signal an |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
712 ;; error here because it could prevent a subsequent reconversion from |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
713 ;; fixing the problem. |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
714 (progn |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
715 (setq doc-view-current-image nil) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
716 (move-overlay doc-view-current-overlay (point-min) (point-max)) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
717 (overlay-put doc-view-current-overlay 'display |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
718 "Cannot display this page! Probably a conversion failure!")) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
719 (let ((image (apply 'create-image file 'png nil args))) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
720 (setq doc-view-current-image image) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
721 (move-overlay doc-view-current-overlay (point-min) (point-max)) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
722 (overlay-put doc-view-current-overlay 'display |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
723 (if doc-view-current-slice |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
724 (list (cons 'slice doc-view-current-slice) image) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
725 image))))) |
84422 | 726 |
727 (defun doc-view-sort (a b) | |
728 "Return non-nil if A should be sorted before B. | |
729 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
|
730 (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
|
731 (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
|
732 (string< a b)))) |
84422 | 733 |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
734 (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
|
735 "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
|
736 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
|
737 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
|
738 (with-current-buffer buffer |
87133
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
739 (setq doc-view-current-files |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
740 (sort (directory-files (doc-view-current-cache-dir) t |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
741 "page-[0-9]+\\.png" t) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
742 'doc-view-sort)) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
743 (when (or force |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
744 (>= (length doc-view-current-files) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
745 (or doc-view-current-page 1))) |
a99e0ba48aeb
(doc-view-dvi->pdf-sentinel, doc-view-pdf/ps->png-sentinel)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87006
diff
changeset
|
746 (doc-view-goto-page doc-view-current-page)))) |
84422 | 747 |
748 (defun doc-view-buffer-message () | |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
749 ;; 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
|
750 ;; 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
|
751 ;; the fresh new ones). |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
752 (unless (overlay-get doc-view-current-overlay 'display) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
753 (overlay-put doc-view-current-overlay 'display |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
754 (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
|
755 "\n" |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
756 " |
85815
960b3c592913
(doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents:
85805
diff
changeset
|
757 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
|
758 converted to PNG and the conversion of the first page hasn't finished yet or |
84422 | 759 `doc-view-conversion-refresh-interval' is set to nil. |
760 | |
761 For now these keys are useful: | |
762 | |
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
|
763 `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
|
764 `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
|
765 `K' : Kill the conversion process.\n")))) |
84422 | 766 |
767 (defun doc-view-show-tooltip () | |
768 (interactive) | |
769 (tooltip-show doc-view-current-info)) | |
770 | |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
771 ;;;;; 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
|
772 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
773 (defun doc-view-toggle-display () |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
774 "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
|
775 (interactive) |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
776 (if (eq major-mode 'doc-view-mode) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
777 ;; Switch to editing mode |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
778 (progn |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
779 (doc-view-kill-proc) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
780 (setq buffer-read-only nil) |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
781 (remove-overlays (point-min) (point-max) 'doc-view) |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
782 ;; Switch to the previously used major mode or fall back to fundamental |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
783 ;; mode. |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
784 (if doc-view-previous-major-mode |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
785 (funcall doc-view-previous-major-mode) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
786 (fundamental-mode)) |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
787 (doc-view-minor-mode 1)) |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
788 ;; Switch to doc-view-mode |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
789 (when (and (buffer-modified-p) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
790 (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
|
791 (save-buffer)) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
792 (doc-view-mode))) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
793 |
84422 | 794 ;;;; Searching |
795 | |
796 (defun doc-view-search-internal (regexp file) | |
797 "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
|
798 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
|
799 the pagenumber and CONTEXTS are all lines of text containing a match." |
84422 | 800 (with-temp-buffer |
801 (insert-file-contents file) | |
802 (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
|
803 (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
|
804 matches) |
84422 | 805 (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
|
806 regexp "\\)\\)") nil t) |
87556
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
807 (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
|
808 (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
|
809 (if (/= page lastpage) |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
810 (push (cons page |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
811 (list (buffer-substring |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
812 (line-beginning-position) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
813 (line-end-position)))) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
814 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
|
815 (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
|
816 (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
|
817 (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
|
818 ;; 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
|
819 (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
|
820 ;; 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
|
821 (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
|
822 (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
|
823 (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
|
824 (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
|
825 (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
|
826 (setq lastpage page))) |
84422 | 827 (nreverse matches)))) |
828 | |
829 (defun doc-view-search-no-of-matches (list) | |
830 "Extract the number of matches from the search result LIST." | |
831 (let ((no 0)) | |
832 (dolist (p list) | |
833 (setq no (+ no (1- (length p))))) | |
834 no)) | |
835 | |
86025
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
836 (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
|
837 "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
|
838 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
|
839 (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
|
840 (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
|
841 |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
842 (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
|
843 "Jump to the next match or initiate a new search if NEW-QUERY is given. |
84422 | 844 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
|
845 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
|
846 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
|
847 (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
|
848 (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
|
849 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
|
850 (if backward |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
851 (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
|
852 (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
|
853 ;; 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
|
854 (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
|
855 (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
|
856 (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
|
857 (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
|
858 (progn |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
859 (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
|
860 (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
|
861 (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
|
862 txt)) |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
863 (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
|
864 (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
|
865 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
|
866 ;; We must convert to TXT first! |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
867 (if doc-view-current-converter-process |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
868 (message "DocView: please wait till conversion finished.") |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
869 (let ((ext (file-name-extension doc-view-buffer-file-name))) |
86025
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
870 (cond |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
871 ((string= ext "pdf") |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
872 ;; Doc is a PDF, so convert it to TXT |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
873 (doc-view-pdf->txt doc-view-buffer-file-name txt)) |
86025
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
874 ((string= ext "ps") |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
875 ;; Doc is a PS, so convert it to PDF (which will be converted to |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
876 ;; TXT thereafter). |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
877 (doc-view-ps->pdf doc-view-buffer-file-name |
86025
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
878 (expand-file-name "doc.pdf" |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
879 (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
|
880 ((string= ext "dvi") |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
881 ;; Doc is a DVI. This means that a doc.pdf already exists in its |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
882 ;; cache subdirectory. |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
883 (doc-view-pdf->txt (expand-file-name "doc.pdf" |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
884 (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
|
885 txt)) |
19784f7db0ef
(doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents:
85856
diff
changeset
|
886 (t (error "DocView doesn't know what to do"))))))))) |
84422 | 887 |
888 (defun doc-view-search-next-match (arg) | |
889 "Go to the ARGth next matching page." | |
890 (interactive "p") | |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
891 (let* ((next-pages (doc-view-remove-if |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
892 (lambda (i) (<= (car i) doc-view-current-page)) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
893 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
|
894 (page (car (nth (1- arg) next-pages)))) |
84422 | 895 (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
|
896 (doc-view-goto-page page) |
84422 | 897 (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
|
898 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
|
899 (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
|
900 (doc-view-goto-page (caar doc-view-current-search-matches)))))) |
84422 | 901 |
902 (defun doc-view-search-previous-match (arg) | |
903 "Go to the ARGth previous matching page." | |
904 (interactive "p") | |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
905 (let* ((prev-pages (doc-view-remove-if |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
906 (lambda (i) (>= (car i) doc-view-current-page)) |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
907 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
|
908 (page (car (nth (1- arg) (nreverse prev-pages))))) |
84422 | 909 (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
|
910 (doc-view-goto-page page) |
84422 | 911 (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
|
912 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
|
913 (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
|
914 (doc-view-goto-page (caar (last doc-view-current-search-matches))))))) |
84422 | 915 |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
916 ;;;; 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
|
917 |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
918 ;; (put 'doc-view-mode 'mode-class 'special) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
919 |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
920 (defun doc-view-initiate-display () |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
921 ;; Switch to image display if possible |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
922 (if (doc-view-mode-p (intern (file-name-extension doc-view-buffer-file-name))) |
85805
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
923 (progn |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
924 (doc-view-buffer-message) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
925 (setq doc-view-current-page (or doc-view-current-page 1)) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
926 (if (file-exists-p (doc-view-current-cache-dir)) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
927 (progn |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
928 (message "DocView: using cached files!") |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
929 (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
|
930 (doc-view-convert-current-doc)) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
931 (message |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
932 "%s" |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
933 (substitute-command-keys |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
934 (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
|
935 "editing or viewing the document.")))) |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
936 (message |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
937 "%s" |
1d1d43e36948
Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85801
diff
changeset
|
938 (substitute-command-keys |
87006
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
939 (concat "No image (png) support available or some conversion utility for " |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
940 (file-name-extension doc-view-buffer-file-name)" files is missing. " |
87006
a15ce3ca213a
(doc-view-initiate-display): Use `doc-view-mode-p'.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
86441
diff
changeset
|
941 "Type \\[doc-view-toggle-display] to switch to an editing mode."))))) |
84422 | 942 |
87556
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
943 (defvar bookmark-make-cell-function) |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
944 |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
945 (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
|
946 ;; 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
|
947 ;; 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
|
948 ;; /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
|
949 ;; 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
|
950 ;; 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
|
951 ;; running, and run the sentinel in all clones. |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
952 ;; Not sure how important it is to fix it: a better target would be to |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
953 ;; allow a single buffer (without cloning) to display different pages in |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
954 ;; different windows. |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
955 ;; Maybe then the clones should really have a separate /tmp directory |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
956 ;; 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
|
957 ;; for zooming. |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
958 (dolist (ol (overlays-in (point-min) (point-max))) |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
959 ;; The overlay was copied by the cloning, so we just need to find it |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
960 ;; and put it in doc-view-current-overlay. |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
961 (if (overlay-get ol 'doc-view) (setq doc-view-current-overlay ol)))) |
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
962 |
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
|
963 ;;;###autoload |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
964 (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
|
965 "Major mode in DocView buffers. |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
966 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
|
967 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
|
968 \\{doc-view-mode-map}" |
85784
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
969 (interactive) |
87681
92ee34bb9001
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87580
diff
changeset
|
970 |
87685
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
971 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
972 doc-view-previous-major-mode |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
973 major-mode))) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
974 (kill-all-local-variables) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
975 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) |
87681
92ee34bb9001
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87580
diff
changeset
|
976 |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
977 ;; Handle compressed files, remote files, files inside archives |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
978 (set (make-local-variable '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
|
979 (cond |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
980 (jka-compr-really-do-compress |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
981 (expand-file-name |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
982 (file-name-nondirectory |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
983 (file-name-sans-extension buffer-file-name)) |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
984 doc-view-cache-directory)) |
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
|
985 ;; Is the file readable by local processes? |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
986 ;; We used to use `file-remote-p' but it's unclear what it's |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
987 ;; supposed to return nil for things like local files accessed via |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
988 ;; `su' or via file://... |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
989 ((let ((file-name-handler-alist nil)) |
3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87697
diff
changeset
|
990 (not (file-readable-p buffer-file-name))) |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
991 (expand-file-name |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
992 (file-name-nondirectory buffer-file-name) |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
993 doc-view-cache-directory)) |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
994 (t buffer-file-name))) |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
995 (when (not (string= doc-view-buffer-file-name buffer-file-name)) |
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
996 (write-region nil nil 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
|
997 |
87685
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
998 (make-local-variable 'doc-view-current-files) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
999 (make-local-variable 'doc-view-current-image) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1000 (make-local-variable 'doc-view-current-page) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1001 (make-local-variable 'doc-view-current-converter-process) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1002 (make-local-variable 'doc-view-current-timer) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1003 (make-local-variable 'doc-view-current-slice) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1004 (make-local-variable 'doc-view-current-cache-dir) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1005 (make-local-variable 'doc-view-current-info) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1006 (make-local-variable 'doc-view-current-search-matches) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1007 (set (make-local-variable 'doc-view-current-overlay) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1008 (make-overlay (point-min) (point-max) nil t)) |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
1009 (overlay-put doc-view-current-overlay 'doc-view t) |
87685
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1010 (add-hook 'change-major-mode-hook |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
1011 (lambda () (remove-overlays (point-min) (point-max) 'doc-view)) |
87685
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1012 nil t) |
91789
0048d198c131
(doc-view-display): Change file arg to buffer arg, so it
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91715
diff
changeset
|
1013 (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t) |
88058
fd7dd85405fc
2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87850
diff
changeset
|
1014 |
fd7dd85405fc
2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87850
diff
changeset
|
1015 ;; Keep track of [vh]scroll when switching buffers |
88063
656f1559e088
* doc-view.el (doc-view-mode): Adapt to i-m-current-[vh]scroll
Tassilo Horn <tassilo@member.fsf.org>
parents:
88058
diff
changeset
|
1016 (make-local-variable 'image-mode-current-hscroll) |
656f1559e088
* doc-view.el (doc-view-mode): Adapt to i-m-current-[vh]scroll
Tassilo Horn <tassilo@member.fsf.org>
parents:
88058
diff
changeset
|
1017 (make-local-variable 'image-mode-current-vscroll) |
656f1559e088
* doc-view.el (doc-view-mode): Adapt to i-m-current-[vh]scroll
Tassilo Horn <tassilo@member.fsf.org>
parents:
88058
diff
changeset
|
1018 (image-set-window-hscroll (selected-window) (window-hscroll)) |
656f1559e088
* doc-view.el (doc-view-mode): Adapt to i-m-current-[vh]scroll
Tassilo Horn <tassilo@member.fsf.org>
parents:
88058
diff
changeset
|
1019 (image-set-window-vscroll (selected-window) (window-vscroll)) |
88058
fd7dd85405fc
2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87850
diff
changeset
|
1020 (add-hook 'window-configuration-change-hook |
fd7dd85405fc
2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87850
diff
changeset
|
1021 'image-reset-current-vhscroll nil t) |
fd7dd85405fc
2008-01-29 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87850
diff
changeset
|
1022 |
87685
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1023 (set (make-local-variable 'mode-line-position) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1024 '(" P" (:eval (number-to-string doc-view-current-page)) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1025 "/" (:eval (number-to-string (length doc-view-current-files))))) |
87850
dd673d4bceda
(doc-view-goto-page): Don't move point any more, now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87842
diff
changeset
|
1026 ;; Don't scroll unless the user specifically asked for it. |
dd673d4bceda
(doc-view-goto-page): Don't move point any more, now that
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87842
diff
changeset
|
1027 (set (make-local-variable 'auto-hscroll-mode) nil) |
87685
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1028 (set (make-local-variable 'cursor-type) nil) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1029 (use-local-map doc-view-mode-map) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1030 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1031 (set (make-local-variable 'bookmark-make-cell-function) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1032 'doc-view-bookmark-make-cell) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1033 (setq mode-name "DocView" |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1034 buffer-read-only t |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1035 major-mode 'doc-view-mode) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1036 (doc-view-initiate-display) |
9b8e42b90c3b
2008-01-09 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87681
diff
changeset
|
1037 (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
|
1038 |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1039 ;;;###autoload |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1040 (define-minor-mode doc-view-minor-mode |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1041 "Toggle Doc view minor mode. |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1042 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
|
1043 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
|
1044 nil " DocView" doc-view-minor-mode-map |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1045 :group 'doc-view |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1046 (when doc-view-minor-mode |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1047 (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
|
1048 (message |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1049 "%s" |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1050 (substitute-command-keys |
b0dc7772c4dc
Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents:
85444
diff
changeset
|
1051 "Type \\[doc-view-toggle-display] to toggle between editing or viewing the document.")))) |
84422 | 1052 |
1053 (defun doc-view-clear-cache () | |
1054 "Delete the whole cache (`doc-view-cache-directory')." | |
1055 (interactive) | |
1056 (dired-delete-file doc-view-cache-directory 'always) | |
1057 (make-directory doc-view-cache-directory)) | |
1058 | |
1059 (defun doc-view-dired-cache () | |
1060 "Open `dired' in `doc-view-cache-directory'." | |
1061 (interactive) | |
1062 (dired doc-view-cache-directory)) | |
1063 | |
1064 | |
87411
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1065 ;;;; Bookmark integration |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1066 |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1067 (defun doc-view-bookmark-make-cell (annotation &rest args) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1068 (let ((the-record |
87697
e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87693
diff
changeset
|
1069 `((filename . ,buffer-file-name) |
87411
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1070 (page . ,doc-view-current-page) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1071 (handler . doc-view-bookmark-jump)))) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1072 |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1073 ;; Take no chances with text properties |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1074 (set-text-properties 0 (length annotation) nil annotation) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1075 |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1076 (when annotation |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1077 (nconc the-record (list (cons 'annotation annotation)))) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1078 |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1079 ;; Finally, return the completed record. |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1080 the-record)) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1081 |
87556
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1082 |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1083 (declare-function bookmark-get-filename "bookmark" (bookmark)) |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1084 (declare-function bookmark-get-bookmark-record "bookmark" (bookmark)) |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1085 |
87411
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1086 ;;;###autoload |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1087 (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
|
1088 ;; This implements the `handler' function interface for record type |
0140d3ebb262
Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents:
87412
diff
changeset
|
1089 ;; returned by `bookmark-make-cell-function', which see. |
87411
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1090 (save-window-excursion |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1091 (let ((filename (bookmark-get-filename bmk)) |
87412
f6ce12419345
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87411
diff
changeset
|
1092 (page (cdr (assq 'page (bookmark-get-bookmark-record bmk))))) |
87411
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1093 (find-file filename) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1094 (when (not (eq major-mode 'doc-view-mode)) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1095 (doc-view-toggle-display)) |
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1096 (doc-view-goto-page page) |
87521
0140d3ebb262
Change a return type, for greater extensibility. See
Karl Fogel <kfogel@red-bean.com>
parents:
87412
diff
changeset
|
1097 `((buffer ,(current-buffer)) (position ,1))))) |
87411
9ac481bc897b
2007-12-26 Tassilo Horn <tassilo@member.fsf.org>
Tassilo Horn <tassilo@member.fsf.org>
parents:
87133
diff
changeset
|
1098 |
87556
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1099 |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1100 (provide 'doc-view) |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1101 |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1102 ;; Local Variables: |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1103 ;; mode: outline-minor |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1104 ;; End: |
39204305bf6f
(doc-view-search-internal): Don't use `incf'.
Glenn Morris <rgm@gnu.org>
parents:
87522
diff
changeset
|
1105 |
87522 | 1106 ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be |
84422 | 1107 ;;; doc-view.el ends here |