Mercurial > emacs
annotate lisp/doc-view.el @ 85410:f8c52ed3968f
(org-columns-eval): Use forward-line.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Thu, 18 Oct 2007 16:06:16 +0000 |
parents | 5b96a46cc08a |
children | 26dcc1207f42 |
rev | line source |
---|---|
84422 | 1 ;;; doc-view.el --- View PDF/PostScript/DVI files in Emacs |
2 | |
3 ;; Copyright (C) 2007 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: Tassilo Horn <tassilo@member.fsf.org> | |
6 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org> | |
7 ;; Keywords: files, pdf, ps, dvi | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
8 ;; Version: <2007-10-17 Wed 22:15> |
84422 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 3, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
25 ;; Boston, MA 02110-1301, USA. | |
26 | |
27 ;;; Requirements: | |
28 | |
85367
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
29 ;; 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
|
30 ;; `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
|
31 ;; (http://www.foolabs.com/xpdf/) or poppler (http://poppler.freedesktop.org/). |
84422 | 32 |
33 ;;; Commentary: | |
34 | |
35 ;; DocView is a document viewer for Emacs. It converts PDF, PS and DVI files | |
36 ;; to a set of PNG files, one PNG for each page, and displays the PNG images | |
37 ;; inside an Emacs buffer. This buffer uses `doc-view-mode' which provides | |
38 ;; convenient key bindings for browsing the document. | |
39 ;; | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
40 ;; 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
|
41 ;; |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
42 ;; C-x C-f ~/path/to/document RET |
84422 | 43 ;; |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
44 ;; 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
|
45 ;; images. With `C-c C-c' you can toggle between the rendered images |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
46 ;; representation and the source text representation of the document. With |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
47 ;; `C-c C-e' you can switch to an appropriate editing mode for the document. |
84422 | 48 ;; |
49 ;; Since conversion may take some time all the PNG images are cached in a | |
50 ;; 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
|
51 ;; 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
|
52 ;; when displaying the document. To delete all cached files use |
84422 | 53 ;; `doc-view-clear-cache'. To open the cache with dired, so that you can tidy |
54 ;; it out use `doc-view-dired-cache'. | |
55 ;; | |
56 ;; When conversion in underway the first page will be displayed as soon as it | |
57 ;; is available and the available pages are refreshed every | |
58 ;; `doc-view-conversion-refresh-interval' seconds. If that variable is nil the | |
59 ;; pages won't be displayed before conversion of the document finished | |
60 ;; completely. | |
61 ;; | |
62 ;; DocView lets you select a slice of the displayed pages. This slice will be | |
63 ;; remembered and applied to all pages of the current document. This enables | |
64 ;; you to cut away the margins of a document to save some space. To select a | |
65 ;; slice you can use `doc-view-set-slice' (bound to `s s') which will query you | |
66 ;; for the coordinates of the slice's top-left corner and its width and height. | |
67 ;; A much more convenient way to do the same is offered by the command | |
68 ;; `doc-view-set-slice-using-mouse' (bound to `s m'). After invokation you | |
69 ;; only have to press mouse-1 at the top-left corner and drag it to the | |
70 ;; bottom-right corner of the desired slice. To reset the slice use | |
71 ;; `doc-view-reset-slice' (bound to `s r'). | |
72 ;; | |
73 ;; You can also search within the document. The command `doc-view-search' | |
74 ;; (bound to `C-s') queries for a search regexp and initializes a list of all | |
75 ;; matching pages and messages how many match-pages were found. After that you | |
76 ;; can jump to the next page containing a match with | |
77 ;; `doc-view-search-next-match' (bound to `C-S-n') or to the previous matching | |
78 ;; page with `doc-view-search-previous-match' (bound to `C-S-p'). This works | |
79 ;; by searching a plain text representation of the document. If that doesn't | |
80 ;; already exist the first invokation of `doc-view-search' starts the | |
81 ;; conversion. When that finishes and you're still viewing the document | |
82 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp | |
83 ;; then. | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
84 ;; |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
85 ;; 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
|
86 ;; 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
|
87 ;; |
84422 | 88 |
89 ;;; Configuration: | |
90 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
91 ;; 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
|
92 ;; `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
|
93 ;; the higher the value.) |
84422 | 94 ;; |
95 ;; This and all other options can be set with the customization interface. | |
96 ;; Simply do | |
97 ;; | |
98 ;; M-x customize-group RET doc-view RET | |
99 ;; | |
100 ;; and modify them to your needs. | |
101 | |
102 ;;; Code: | |
103 | |
104 (require 'dired) | |
105 (eval-when-compile (require 'cl)) | |
106 | |
107 ;;;; Customization Options | |
108 | |
109 (defgroup doc-view nil | |
110 "In-buffer viewer for PDF, PostScript and DVI files." | |
111 :link '(function-link doc-view) | |
112 :version "22.2" | |
113 :group 'applications | |
114 :group 'multimedia | |
115 :prefix "doc-view-") | |
116 | |
117 (defcustom doc-view-ghostscript-program "gs" | |
118 "Program to convert PS and PDF files to PNG." | |
119 :type '(file) | |
120 :group 'doc-view) | |
121 | |
122 (defcustom doc-view-ghostscript-options | |
123 '("-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4" | |
124 "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET" | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
125 "-dSAFER" "-r100") |
85367
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
126 "A list of options to give to ghostscript." |
84422 | 127 :type '(sexp) |
128 :group 'doc-view) | |
129 | |
130 (defcustom doc-view-dvipdfm-program "dvipdfm" | |
131 "Program to convert DVI files to PDF. | |
132 | |
133 DVI file will be converted to PDF before the resulting PDF is | |
134 converted to PNG." | |
135 :type '(file) | |
136 :group 'doc-view) | |
137 | |
138 (defcustom doc-view-ps2pdf-program "ps2pdf" | |
139 "Program to convert PS files to PDF. | |
140 | |
141 PS files will be converted to PDF before searching is possible." | |
142 :type '(file) | |
143 :group 'doc-view) | |
144 | |
145 (defcustom doc-view-pdftotext-program "pdftotext" | |
146 "Program to convert PDF files to plain text. | |
147 | |
148 Needed for searching." | |
149 :type '(file) | |
150 :group 'doc-view) | |
151 | |
152 (defcustom doc-view-cache-directory (concat temporary-file-directory | |
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
|
153 "doc-view") |
84422 | 154 "The base directory, where the PNG images will be saved." |
155 :type '(directory) | |
156 :group 'doc-view) | |
157 | |
158 (defcustom doc-view-conversion-buffer "*doc-view conversion output*" | |
159 "The buffer where messages from the converter programs go to." | |
160 :type '(string) | |
161 :group 'doc-view) | |
162 | |
163 (defcustom doc-view-conversion-refresh-interval 3 | |
164 "Every how much seconds the DocView buffer gets refreshed while conversion. | |
165 After such an refresh newly converted pages will be available for | |
166 viewing. If set to nil there won't be any refreshes and the | |
167 pages won't be displayed before conversion of the whole document | |
168 has finished." | |
169 :type '(string) | |
170 :group 'doc-view) | |
171 | |
172 ;;;; Internal Variables | |
173 | |
174 (defvar doc-view-current-files nil | |
175 "Only used internally.") | |
176 | |
177 (defvar doc-view-current-page nil | |
178 "Only used internally.") | |
179 | |
180 (defvar doc-view-current-doc nil | |
181 "Only used internally.") | |
182 | |
183 (defvar doc-view-current-converter-process nil | |
184 "Only used internally.") | |
185 | |
186 (defvar doc-view-current-timer nil | |
187 "Only used internally.") | |
188 | |
189 (defvar doc-view-current-slice nil | |
190 "Only used internally.") | |
191 | |
192 (defvar doc-view-current-cache-dir nil | |
193 "Only used internally.") | |
194 | |
195 (defvar doc-view-current-search-matches nil | |
196 "Only used internally.") | |
197 | |
198 (defvar doc-view-current-image nil | |
199 "Only used internally.") | |
200 | |
201 (defvar doc-view-current-info nil | |
202 "Only used internally.") | |
203 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
204 (defvar doc-view-current-display nil |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
205 "Only used internally.") |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
206 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
207 ;;;; DocView Keymaps |
84422 | 208 |
209 (defvar doc-view-mode-map | |
210 (let ((map (make-sparse-keymap))) | |
211 ;; Navigation in the document | |
212 (define-key map (kbd "n") 'doc-view-next-page) | |
213 (define-key map (kbd "p") 'doc-view-previous-page) | |
214 (define-key map (kbd "<next>") 'doc-view-next-page) | |
215 (define-key map (kbd "<prior>") 'doc-view-previous-page) | |
216 (define-key map (kbd "SPC") 'doc-view-scroll-up-or-next-page) | |
217 (define-key map (kbd "DEL") 'doc-view-scroll-down-or-previous-page) | |
218 (define-key map (kbd "M-<") 'doc-view-first-page) | |
219 (define-key map (kbd "M->") 'doc-view-last-page) | |
220 (define-key map (kbd "g") 'doc-view-goto-page) | |
221 ;; Killing/burying the buffer (and the process) | |
222 (define-key map (kbd "q") 'bury-buffer) | |
223 (define-key map (kbd "k") 'doc-view-kill-proc-and-buffer) | |
224 (define-key map (kbd "C-x k") 'doc-view-kill-proc-and-buffer) | |
225 ;; Slicing the image | |
226 (define-key map (kbd "s s") 'doc-view-set-slice) | |
227 (define-key map (kbd "s m") 'doc-view-set-slice-using-mouse) | |
228 (define-key map (kbd "s r") 'doc-view-reset-slice) | |
229 ;; Searching | |
230 (define-key map (kbd "C-s") 'doc-view-search) | |
231 (define-key map (kbd "<find>") 'doc-view-search) | |
232 (define-key map (kbd "C-S-n") 'doc-view-search-next-match) | |
233 (define-key map (kbd "C-S-p") 'doc-view-search-previous-match) | |
234 ;; Scrolling | |
235 (define-key map (kbd "C-v") 'scroll-up) | |
236 (define-key map (kbd "<mouse-4>") 'mwheel-scroll) | |
237 (define-key map (kbd "<mouse-5>") 'mwheel-scroll) | |
238 (define-key map (kbd "M-v") 'scroll-down) | |
239 ;; Show the tooltip | |
240 (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
|
241 ;; 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
|
242 (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
|
243 (define-key map (kbd "C-c C-e") 'doc-view-edit-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
244 ;; Reconvert the current document |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
245 (define-key map (kbd "g") 'doc-view-reconvert-doc) |
84422 | 246 (suppress-keymap map) |
247 map) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
248 "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
|
249 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
250 (defvar doc-view-mode-text-map |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
251 (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
|
252 ;; 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
|
253 (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
|
254 (define-key map (kbd "C-c C-e") 'doc-view-edit-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
255 ;; Killing/burying the buffer (and the process) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
256 (define-key map (kbd "q") 'bury-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
257 (define-key map (kbd "k") 'doc-view-kill-proc-and-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
258 (define-key map (kbd "C-x k") 'doc-view-kill-proc-and-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
259 map) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
260 "Keymap used by `doc-view-mode' when displaying a document as text.") |
84422 | 261 |
262 ;;;; Navigation Commands | |
263 | |
264 (defun doc-view-goto-page (page) | |
265 "View the page given by PAGE." | |
266 (interactive "nPage: ") | |
267 (let ((len (length doc-view-current-files))) | |
268 (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
|
269 (setq page 1) |
84422 | 270 (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
|
271 (setq page len))) |
84422 | 272 (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
|
273 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
|
274 (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
|
275 (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
|
276 (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
|
277 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
|
278 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
|
279 ;; 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
|
280 (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
|
281 " (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
|
282 "\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
|
283 ;; 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
|
284 (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
|
285 (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
|
286 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
|
287 (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
|
288 (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
|
289 (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
|
290 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
|
291 (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
|
292 contexts))))) |
84422 | 293 ;; Update the buffer |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
294 (let ((inhibit-read-only t)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
295 (erase-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
296 (let ((beg (point))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
297 (doc-view-insert-image (nth (1- page) doc-view-current-files) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
298 :pointer 'arrow) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
299 (put-text-property beg (point) 'help-echo doc-view-current-info)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
300 (insert "\n" doc-view-current-info) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
301 (goto-char (point-min)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
302 (forward-char)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
303 (set-buffer-modified-p nil))) |
84422 | 304 |
305 (defun doc-view-next-page (&optional arg) | |
306 "Browse ARG pages forward." | |
307 (interactive "p") | |
308 (doc-view-goto-page (+ doc-view-current-page (or arg 1)))) | |
309 | |
310 (defun doc-view-previous-page (&optional arg) | |
311 "Browse ARG pages backward." | |
312 (interactive "p") | |
313 (doc-view-goto-page (- doc-view-current-page (or arg 1)))) | |
314 | |
315 (defun doc-view-first-page () | |
316 "View the first page." | |
317 (interactive) | |
318 (doc-view-goto-page 1)) | |
319 | |
320 (defun doc-view-last-page () | |
321 "View the last page." | |
322 (interactive) | |
323 (doc-view-goto-page (length doc-view-current-files))) | |
324 | |
325 (defun doc-view-scroll-up-or-next-page () | |
326 "Scroll page up if possible, else goto next page." | |
327 (interactive) | |
328 (condition-case nil | |
329 (scroll-up) | |
330 (error (doc-view-next-page)))) | |
331 | |
332 (defun doc-view-scroll-down-or-previous-page () | |
333 "Scroll page down if possible, else goto previous page." | |
334 (interactive) | |
335 (condition-case nil | |
336 (scroll-down) | |
337 (error (doc-view-previous-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
|
338 (goto-char (point-max))))) |
84422 | 339 |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
340 (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
|
341 "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
|
342 (interactive) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
343 (when doc-view-current-converter-process |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
344 (kill-process doc-view-current-converter-process)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
345 (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
|
346 (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
|
347 (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
|
348 (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
|
349 |
84422 | 350 (defun doc-view-kill-proc-and-buffer () |
351 "Kill the current converter process and buffer." | |
352 (interactive) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
353 (doc-view-kill-proc) |
84422 | 354 (when (eq major-mode 'doc-view-mode) |
355 (kill-buffer (current-buffer)))) | |
356 | |
357 ;;;; Conversion Functions | |
358 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
359 (defun doc-view-reconvert-doc (&rest args) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
360 "Reconvert the current document. |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
361 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
|
362 (interactive) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
363 (let ((inhibit-read-only t) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
364 (doc doc-view-current-doc)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
365 (doc-view-kill-proc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
366 ;; Clear the old cached files |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
367 (when (file-exists-p (doc-view-current-cache-dir)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
368 (dired-delete-file (doc-view-current-cache-dir) 'always)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
369 (doc-view-kill-proc-and-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
370 (find-file doc))) |
84422 | 371 |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
372 (defun doc-view-current-cache-dir () |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
373 "Return the directory where the png files of the current doc should be saved. |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
374 It's a subdirectory of `doc-view-cache-directory'." |
84422 | 375 (if doc-view-current-cache-dir |
376 doc-view-current-cache-dir | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
377 (setq doc-view-current-cache-dir |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
378 (file-name-as-directory |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
379 (concat (file-name-as-directory doc-view-cache-directory) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
380 (let ((doc doc-view-current-doc)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
381 (with-temp-buffer |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
382 (insert-file-contents-literally doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
383 (md5 (current-buffer))))))))) |
84422 | 384 |
385 (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
|
386 "If DVI->PDF conversion was successful, convert the PDF to PNG now." |
84422 | 387 (if (not (string-match "finished" event)) |
388 (message "DocView: dvi->pdf process changed status to %s." event) | |
389 (set-buffer (process-get proc 'buffer)) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
390 (setq doc-view-current-converter-process nil |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
391 mode-line-process nil) |
84422 | 392 (message "DocView: finished conversion from DVI to PDF!") |
393 ;; Now go on converting this PDF to a set of PNG files. | |
394 (let* ((pdf (process-get proc 'pdf-file)) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
395 (png (concat (doc-view-current-cache-dir) |
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
|
396 "page-%d.png"))) |
84422 | 397 (doc-view-pdf/ps->png pdf png)))) |
398 | |
399 (defun doc-view-dvi->pdf (dvi pdf) | |
400 "Convert DVI to PDF asynchrounously." | |
401 (message "DocView: converting DVI to PDF now!") | |
402 (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
|
403 (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
|
404 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
|
405 "-o" pdf dvi) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
406 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 407 (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
|
408 'doc-view-dvi->pdf-sentinel) |
84422 | 409 (process-put doc-view-current-converter-process 'buffer (current-buffer)) |
410 (process-put doc-view-current-converter-process 'pdf-file pdf)) | |
411 | |
412 (defun doc-view-pdf/ps->png-sentinel (proc event) | |
413 "If PDF/PS->PNG conversion was successful, update the display." | |
414 (if (not (string-match "finished" event)) | |
415 (message "DocView: converter process changed status to %s." event) | |
416 (set-buffer (process-get proc 'buffer)) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
417 (setq doc-view-current-converter-process nil |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
418 mode-line-process nil) |
84422 | 419 (when doc-view-current-timer |
420 (cancel-timer doc-view-current-timer) | |
421 (setq doc-view-current-timer nil)) | |
422 (message "DocView: finished conversion from PDF/PS to PNG!") | |
423 ;; Yippie, finished. Update the display! | |
424 (doc-view-display doc-view-current-doc))) | |
425 | |
426 (defun doc-view-pdf/ps->png (pdf-ps png) | |
427 "Convert PDF-PS to PNG asynchrounously." | |
428 (message "DocView: converting PDF or PS to PNG now!") | |
429 (setq 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
|
430 (apply 'start-process |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
431 (append (list "pdf/ps->png" 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
|
432 doc-view-ghostscript-program) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
433 doc-view-ghostscript-options |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
434 (list (concat "-sOutputFile=" png)) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
435 (list pdf-ps))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
436 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 437 (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
|
438 'buffer (current-buffer)) |
84422 | 439 (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
|
440 'doc-view-pdf/ps->png-sentinel) |
84422 | 441 (when doc-view-conversion-refresh-interval |
442 (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
|
443 (run-at-time "1 secs" doc-view-conversion-refresh-interval |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
444 'doc-view-display-maybe |
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
|
445 doc-view-current-doc)))) |
84422 | 446 |
447 (defun doc-view-pdf->txt-sentinel (proc event) | |
448 (if (not (string-match "finished" event)) | |
449 (message "DocView: converter process changed status to %s." event) | |
450 (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
|
451 (proc-buffer (process-get proc 'buffer))) |
84422 | 452 (set-buffer proc-buffer) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
453 (setq doc-view-current-converter-process nil |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
454 mode-line-process nil) |
84422 | 455 (message "DocView: finished conversion from PDF to TXT!") |
456 ;; If the user looks at the DocView buffer where the conversion was | |
457 ;; performed, search anew. This time it will be queried for a regexp. | |
458 (when (eq current-buffer proc-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
|
459 (doc-view-search))))) |
84422 | 460 |
461 (defun doc-view-pdf->txt (pdf txt) | |
462 "Convert PDF to TXT asynchrounously." | |
463 (message "DocView: converting PDF to TXT now!") | |
464 (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
|
465 (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
|
466 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
|
467 pdf txt) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
468 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 469 (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
|
470 'doc-view-pdf->txt-sentinel) |
84422 | 471 (process-put doc-view-current-converter-process 'buffer (current-buffer))) |
472 | |
473 (defun doc-view-ps->pdf-sentinel (proc event) | |
474 (if (not (string-match "finished" event)) | |
475 (message "DocView: converter process changed status to %s." event) | |
476 (set-buffer (process-get proc 'buffer)) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
477 (setq doc-view-current-converter-process nil |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
478 mode-line-process nil) |
84422 | 479 (message "DocView: finished conversion from PS to PDF!") |
480 ;; Now we can transform to plain text. | |
481 (doc-view-pdf->txt (process-get proc 'pdf-file) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
482 (concat (doc-view-current-cache-dir) |
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
|
483 "doc.txt")))) |
84422 | 484 |
485 (defun doc-view-ps->pdf (ps pdf) | |
486 "Convert PS to PDF asynchronously." | |
487 (message "DocView: converting PS to PDF now!") | |
488 (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
|
489 (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
|
490 doc-view-ps2pdf-program |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
491 ps pdf "-dSAFER") |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
492 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
84422 | 493 (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
|
494 'doc-view-ps->pdf-sentinel) |
84422 | 495 (process-put doc-view-current-converter-process 'buffer (current-buffer)) |
496 (process-put doc-view-current-converter-process 'pdf-file pdf)) | |
497 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
498 (defun doc-view-convert-current-doc () |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
499 "Convert `doc-view-current-doc' to a set of png files, one file per page. |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
500 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
|
501 `doc-view-current-cache-dir'." |
84422 | 502 (clear-image-cache) |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
503 (let ((png-file (concat (doc-view-current-cache-dir) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
504 "page-%d.png"))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
505 (make-directory doc-view-current-cache-dir t) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
506 (if (not (string= (file-name-extension doc-view-current-doc) "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
|
507 ;; Convert to PNG images. |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
508 (doc-view-pdf/ps->png doc-view-current-doc png-file) |
85367
1fbaddcbc4ec
Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85029
diff
changeset
|
509 ;; DVI files have to be converted to PDF before Ghostscript can process |
84422 | 510 ;; it. |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
511 (doc-view-dvi->pdf doc-view-current-doc |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
512 (concat (file-name-as-directory doc-view-current-cache-dir) |
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
|
513 "doc.pdf"))))) |
84422 | 514 |
515 ;;;; Slicing | |
516 | |
517 (defun doc-view-set-slice (x y width height) | |
518 "Set the slice of the images that should be displayed. | |
519 You can use this function to tell doc-view not to display the | |
520 margins of the document. It prompts for the top-left corner (X | |
521 and Y) of the slice to display and its WIDTH and HEIGHT. | |
522 | |
523 See `doc-view-set-slice-using-mouse' for a more convenient way to | |
524 do that. To reset the slice use `doc-view-reset-slice'." | |
525 (interactive | |
526 (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
|
527 (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
|
528 (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
|
529 (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
|
530 (d (read-number (format "Height (0..%d): " (- (cdr size) b))))) |
84422 | 531 (list a b c d))) |
532 (setq doc-view-current-slice (list x y width height)) | |
533 ;; Redisplay | |
534 (doc-view-goto-page doc-view-current-page)) | |
535 | |
536 (defun doc-view-set-slice-using-mouse () | |
537 "Set the slice of the images that should be displayed. | |
538 You set the slice by pressing mouse-1 at its top-left corner and | |
539 dragging it to its bottom-right corner. See also | |
540 `doc-view-set-slice' and `doc-view-reset-slice'." | |
541 (interactive) | |
542 (let (x y w h done) | |
543 (while (not done) | |
544 (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
|
545 (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
|
546 "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
|
547 (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
|
548 (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
|
549 (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
|
550 (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
|
551 (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
|
552 (setq done t)))) |
84422 | 553 (doc-view-set-slice x y w h))) |
554 | |
555 (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
|
556 "Reset the current slice. |
84422 | 557 After calling this function the whole pages will be visible |
558 again." | |
559 (interactive) | |
560 (setq doc-view-current-slice nil) | |
561 ;; Redisplay | |
562 (doc-view-goto-page doc-view-current-page)) | |
563 | |
564 ;;;; Display | |
565 | |
566 (defun doc-view-insert-image (file &rest args) | |
567 "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
|
568 ARGS is a list of image descriptors." |
84422 | 569 (let ((image (apply 'create-image file 'png nil args))) |
570 (setq doc-view-current-image image) | |
571 (insert-image image (concat "[" file "]") nil doc-view-current-slice))) | |
572 | |
573 (defun doc-view-sort (a b) | |
574 "Return non-nil if A should be sorted before B. | |
575 Predicate for sorting `doc-view-current-files'." | |
576 (if (< (length a) (length b)) | |
577 t | |
578 (if (> (length a) (length b)) | |
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
|
579 nil |
84422 | 580 (string< a b)))) |
581 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
582 (defun doc-view-display-maybe (doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
583 "Call `doc-view-display' iff we're in the image display." |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
584 (when (eq doc-view-current-display 'image) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
585 (doc-view-display doc))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
586 |
84422 | 587 (defun doc-view-display (doc) |
588 "Start viewing the document DOC." | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
589 (set-buffer (get-file-buffer doc)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
590 (setq doc-view-current-files |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
591 (sort (directory-files (doc-view-current-cache-dir) t |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
592 "page-[0-9]+\\.png" t) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
593 'doc-view-sort)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
594 (when (> (length doc-view-current-files) 0) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
595 (doc-view-goto-page doc-view-current-page))) |
84422 | 596 |
597 (defun doc-view-buffer-message () | |
598 (insert (propertize "Welcome to DocView!" 'face 'bold) | |
85027
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
599 "\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
|
600 " |
84422 | 601 If you see this buffer it means that the document you want to |
602 view gets converted to PNG now and the conversion of the first | |
603 page hasn't finished yet or | |
604 `doc-view-conversion-refresh-interval' is set to nil. | |
605 | |
606 For now these keys are useful: | |
607 | |
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
|
608 `q' : Bury this buffer. Conversion will go on in background. |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
609 `k' : Kill the conversion process and this buffer.\n") |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
610 (set-buffer-modified-p nil)) |
84422 | 611 |
612 (defun doc-view-show-tooltip () | |
613 (interactive) | |
614 (tooltip-show doc-view-current-info)) | |
615 | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
616 ;;;;; Toggle between text and image display |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
617 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
618 (defun doc-view-toggle-display () |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
619 "Start or stop displaying a document file 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
|
620 This command toggles between showing the text of the document |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
621 file and showing the document 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
|
622 (interactive) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
623 (if (get-text-property (point-min) 'display) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
624 ;; Switch to text display |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
625 (let ((inhibit-read-only t)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
626 (erase-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
627 (insert-file-contents doc-view-current-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
628 (use-local-map doc-view-mode-text-map) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
629 (setq mode-name "DocView[text]" |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
630 doc-view-current-display 'text) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
631 (if (called-interactively-p) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
632 (message "Repeat this command to go back to displaying the file as images"))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
633 ;; Switch to image display |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
634 (let ((inhibit-read-only t)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
635 (erase-buffer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
636 (doc-view-buffer-message) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
637 (setq doc-view-current-page (or doc-view-current-page 1)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
638 (if (file-exists-p (doc-view-current-cache-dir)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
639 (progn |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
640 (message "DocView: using cached files!") |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
641 (doc-view-display doc-view-current-doc)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
642 (doc-view-convert-current-doc)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
643 (use-local-map doc-view-mode-map) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
644 (setq mode-name (format "DocView") |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
645 doc-view-current-display 'image) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
646 (if (called-interactively-p) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
647 (message "Repeat this command to go back to displaying the file as text")))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
648 (set-buffer-modified-p nil)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
649 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
650 ;;;;; Leave doc-view-mode and open the file for edit |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
651 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
652 (defun doc-view-edit-doc () |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
653 "Leave `doc-view-mode' and open the current doc with an appropriate editing mode." |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
654 (interactive) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
655 (let ((filename doc-view-current-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
656 (auto-mode-alist (append '(("\\.[eE]?[pP][sS]\\'" . ps-mode) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
657 ("\\.\\(pdf\\|PDF\\|dvi\\|DVI\\)$" . fundamental-mode)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
658 auto-mode-alist))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
659 (kill-buffer (current-buffer)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
660 (find-file filename))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
661 |
84422 | 662 ;;;; Searching |
663 | |
664 (defun doc-view-search-internal (regexp file) | |
665 "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
|
666 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
|
667 the pagenumber and CONTEXTS are all lines of text containing a match." |
84422 | 668 (with-temp-buffer |
669 (insert-file-contents file) | |
670 (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
|
671 (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
|
672 matches) |
84422 | 673 (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
|
674 regexp "\\)\\)") nil t) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
675 (when (match-string 1) (incf 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
|
676 (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
|
677 (if (/= page lastpage) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
678 (setq matches (push (cons 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
|
679 (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
|
680 (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
|
681 (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
|
682 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
|
683 (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
|
684 (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
|
685 (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
|
686 ;; 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
|
687 (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
|
688 ;; 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
|
689 (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
|
690 (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
|
691 (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
|
692 (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
|
693 (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
|
694 (setq lastpage page))) |
84422 | 695 (nreverse matches)))) |
696 | |
697 (defun doc-view-search-no-of-matches (list) | |
698 "Extract the number of matches from the search result LIST." | |
699 (let ((no 0)) | |
700 (dolist (p list) | |
701 (setq no (+ no (1- (length p))))) | |
702 no)) | |
703 | |
704 (defun doc-view-search () | |
705 "Query for a regexp and search the current document. | |
706 If the current document hasn't been transformed to plain text | |
707 till now do that first. You should try searching anew when the | |
708 conversion finished." | |
709 (interactive) | |
710 ;; New search, so forget the old results. | |
711 (setq doc-view-current-search-matches nil) | |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
712 (let ((txt (concat (doc-view-current-cache-dir) |
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
|
713 "doc.txt"))) |
84422 | 714 (if (file-readable-p txt) |
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
|
715 (progn |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
716 (setq 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
|
717 (doc-view-search-internal |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
718 (read-from-minibuffer "Regexp: ") |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
719 txt)) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
720 (message "DocView: search yielded %d 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
|
721 (doc-view-search-no-of-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
|
722 doc-view-current-search-matches))) |
84422 | 723 ;; We must convert to TXT first! |
724 (if 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
|
725 (message "DocView: please wait till conversion finished.") |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
726 (let ((ext (file-name-extension doc-view-current-doc))) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
727 (cond |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
728 ((string= ext "pdf") |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
729 ;; Doc is a PDF, so convert it to TXT |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
730 (doc-view-pdf->txt doc-view-current-doc txt)) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
731 ((string= ext "ps") |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
732 ;; Doc is a PS, so convert it to PDF (which will be converted to |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
733 ;; TXT thereafter). |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
734 (doc-view-ps->pdf doc-view-current-doc |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
735 (concat (doc-view-current-cache-dir) |
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
|
736 "doc.pdf"))) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
737 ((string= ext "dvi") |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
738 ;; Doc is a DVI. This means that a doc.pdf already exists in its |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
739 ;; cache subdirectory. |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
740 (doc-view-pdf->txt (concat (doc-view-current-cache-dir) |
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
|
741 "doc.pdf") |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
742 txt)) |
06c04cf43e80
(doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents:
84450
diff
changeset
|
743 (t (error "DocView doesn't know what to do")))))))) |
84422 | 744 |
745 (defun doc-view-search-next-match (arg) | |
746 "Go to the ARGth next matching page." | |
747 (interactive "p") | |
748 (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-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
|
749 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
|
750 (page (car (nth (1- arg) next-pages)))) |
84422 | 751 (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
|
752 (doc-view-goto-page page) |
84422 | 753 (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
|
754 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
|
755 (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
|
756 (doc-view-goto-page (caar doc-view-current-search-matches)))))) |
84422 | 757 |
758 (defun doc-view-search-previous-match (arg) | |
759 "Go to the ARGth previous matching page." | |
760 (interactive "p") | |
761 (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-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
|
762 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
|
763 (page (car (nth (1- arg) (nreverse prev-pages))))) |
84422 | 764 (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
|
765 (doc-view-goto-page page) |
84422 | 766 (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
|
767 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
|
768 (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
|
769 (doc-view-goto-page (caar (last doc-view-current-search-matches))))))) |
84422 | 770 |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
771 ;;;; 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
|
772 |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
773 (put 'doc-view-mode 'mode-class 'special) |
84422 | 774 |
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
|
775 ;;;###autoload |
85369
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
776 (define-derived-mode doc-view-mode nil "DocView" |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
777 "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
|
778 You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
779 toggle between display as a set of images and display as text." |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
780 :group 'doc-view |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
781 (make-local-variable 'doc-view-current-files) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
782 (make-local-variable 'doc-view-current-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
783 (make-local-variable 'doc-view-current-image) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
784 (make-local-variable 'doc-view-current-page) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
785 (make-local-variable 'doc-view-current-converter-process) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
786 (make-local-variable 'doc-view-current-timer) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
787 (make-local-variable 'doc-view-current-slice) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
788 (make-local-variable 'doc-view-current-cache-dir) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
789 (make-local-variable 'doc-view-current-info) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
790 (make-local-variable 'doc-view-current-search-matches) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
791 (setq doc-view-current-doc (buffer-file-name)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
792 (insert-file-contents doc-view-current-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
793 (use-local-map doc-view-mode-text-map) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
794 (setq mode-name "DocView[text]" |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
795 doc-view-current-display 'text |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
796 buffer-read-only t |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
797 revert-buffer-function 'doc-view-reconvert-doc) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
798 ;; Switch to image display if possible |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
799 (if (and (display-images-p) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
800 (image-type-available-p 'png) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
801 (not (get-text-property (point-min) 'display))) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
802 (doc-view-toggle-display)) |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
803 (message |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
804 "%s" |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
805 (substitute-command-keys |
5b96a46cc08a
* bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents:
85367
diff
changeset
|
806 "Type \\[doc-view-toggle-display] to toggle between image and text display."))) |
84422 | 807 |
808 (defun doc-view-clear-cache () | |
809 "Delete the whole cache (`doc-view-cache-directory')." | |
810 (interactive) | |
811 (dired-delete-file doc-view-cache-directory 'always) | |
812 (make-directory doc-view-cache-directory)) | |
813 | |
814 (defun doc-view-dired-cache () | |
815 "Open `dired' in `doc-view-cache-directory'." | |
816 (interactive) | |
817 (dired doc-view-cache-directory)) | |
818 | |
819 (provide 'doc-view) | |
820 | |
821 ;; Local Variables: | |
822 ;; mode: outline-minor | |
823 ;; End: | |
824 | |
84450 | 825 ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be |
84422 | 826 ;;; doc-view.el ends here |