annotate lisp/doc-view.el @ 86926:9b76416252fe

(top-level): Always require url-parse, not just when compiling.
author Glenn Morris <rgm@gnu.org>
date Sat, 01 Dec 2007 22:04:51 +0000
parents 6934c0956614
children a15ce3ca213a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1 ;;; doc-view.el --- View PDF/PostScript/DVI files in Emacs
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
3 ;; Copyright (C) 2007 Free Software Foundation, Inc.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
4 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
5 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
6 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
7 ;; Keywords: files, pdf, ps, dvi
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
8
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
10
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
14 ;; any later version.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
15
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
20
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
24 ;; Boston, MA 02110-1301, USA.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
25
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
26 ;;; Requirements:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
31
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
32 ;;; Commentary:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
33
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
34 ;; DocView is a document viewer for Emacs. It converts PDF, PS and DVI files
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
35 ;; to a set of PNG files, one PNG for each page, and displays the PNG images
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
36 ;; inside an Emacs buffer. This buffer uses `doc-view-mode' which provides
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
37 ;; convenient key bindings for browsing the document.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
46 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
47 ;; Since conversion may take some time all the PNG images are cached in a
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
51 ;; `doc-view-clear-cache'. To open the cache with dired, so that you can tidy
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
52 ;; it out use `doc-view-dired-cache'.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
53 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
54 ;; When conversion in underway the first page will be displayed as soon as it
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
55 ;; is available and the available pages are refreshed every
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
56 ;; `doc-view-conversion-refresh-interval' seconds. If that variable is nil the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
57 ;; pages won't be displayed before conversion of the document finished
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
58 ;; completely.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
59 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
60 ;; DocView lets you select a slice of the displayed pages. This slice will be
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61 ;; remembered and applied to all pages of the current document. This enables
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
62 ;; you to cut away the margins of a document to save some space. To select a
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
63 ;; slice you can use `doc-view-set-slice' (bound to `s s') which will query you
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
64 ;; for the coordinates of the slice's top-left corner and its width and height.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
65 ;; A much more convenient way to do the same is offered by the command
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
66 ;; `doc-view-set-slice-using-mouse' (bound to `s m'). After invokation you
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
67 ;; only have to press mouse-1 at the top-left corner and drag it to the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68 ;; bottom-right corner of the desired slice. To reset the slice use
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69 ;; `doc-view-reset-slice' (bound to `s r').
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71 ;; You can also search within the document. The command `doc-view-search'
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
87 ;;; Configuration:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
92 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
93 ;; This and all other options can be set with the customization interface.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
94 ;; Simply do
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
95 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
96 ;; M-x customize-group RET doc-view RET
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
97 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
98 ;; and modify them to your needs.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
99
86035
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
100 ;;; Todo:
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
101
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
102 ;; - 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
103 ;; - don't use `find-file'.
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
104 ;; - Bind slicing to a drag event.
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
105 ;; - doc-view-fit-doc-to-window and doc-view-fit-window-to-doc.
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
106 ;; - zoom a the region around the cursor (like xdvi).
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
107 ;; - get rid of the silly arrow in the fringe.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
108 ;; - improve anti-aliasing (pdf-utils gets it better).
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
109
86035
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
110 ;;;; About isearch support
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
111
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
112 ;; I tried implementing isearch by setting
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
113 ;; `isearch-search-fun-function' buffer-locally, but that didn't
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
114 ;; work too good. The function doing the real search was called
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
115 ;; endlessly somehow. But even if we'd get that working no real
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
116 ;; isearch feeling comes up due to the missing match highlighting.
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
117 ;; Currently I display all lines containing a match in a tooltip and
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
118 ;; each C-s or C-r jumps directly to the next/previous page with a
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
119 ;; match. With isearch we could only display the current match. So
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
120 ;; we had to decide if another C-s jumps to the next page with a
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
121 ;; match (thus only the first match in a page will be displayed in a
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
122 ;; tooltip) or to the next match, which would do nothing visible
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
123 ;; (except the tooltip) if the next match is on the same page.
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
124
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
125 ;; And it's much slower than the current search facility, because
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
126 ;; isearch really searches for each step forward or backward wheras
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
127 ;; the current approach searches once and then it knows to which
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
128 ;; pages to jump.
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
129
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
130 ;; Anyway, if someone with better isearch knowledge wants to give it a try,
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
131 ;; feel free to do it. --Tassilo
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
132
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
133 ;;; Code:
d3745283de5f Add comments about isearch support.
Juri Linkov <juri@jurta.org>
parents: 86025
diff changeset
134
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
135 (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
136 (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
137 (require 'jka-compr)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
138
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
139 ;;;; Customization Options
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
140
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
141 (defgroup doc-view nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
142 "In-buffer viewer for PDF, PostScript and DVI files."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
143 :link '(function-link doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
144 :version "22.2"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
145 :group 'applications
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
146 :group 'multimedia
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
147 :prefix "doc-view-")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
148
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
149 (defcustom doc-view-ghostscript-program (executable-find "gs")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
150 "Program to convert PS and PDF files to PNG."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
151 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
152 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
153
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
154 (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
155 '("-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
156 ;; sources.
26dcc1207f42 (doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85369
diff changeset
157 "-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4"
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
158 "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET")
85367
1fbaddcbc4ec Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85029
diff changeset
159 "A list of options to give to ghostscript."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
160 :type '(repeat string)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
161 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
162
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
163 (defcustom doc-view-resolution 100
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
164 "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
165 Higher values result in larger images."
86154
1cdfc94602cb * smime.el (from):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 86119
diff changeset
166 :type 'number
1cdfc94602cb * smime.el (from):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 86119
diff changeset
167 :group 'doc-view)
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
168
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
169 (defcustom doc-view-dvipdfm-program (executable-find "dvipdfm")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
170 "Program to convert DVI files to PDF.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
171
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
172 DVI file will be converted to PDF before the resulting PDF is
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
173 converted to PNG."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
174 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
175 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
176
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
177 (defcustom doc-view-ps2pdf-program (executable-find "ps2pdf")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
178 "Program to convert PS files to PDF.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
179
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
180 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
181 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
182 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
183
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
184 (defcustom doc-view-pdftotext-program (executable-find "pdftotext")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
185 "Program to convert PDF files to plain text.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
186
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
187 Needed for searching."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
188 :type 'file
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
189 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
190
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
191 (defcustom doc-view-cache-directory
85856
a26944b15c75 (doc-view-cache-directory): Remove superfluous concat.
Glenn Morris <rgm@gnu.org>
parents: 85844
diff changeset
192 (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
193 temporary-file-directory)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
194 "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
195 :type 'directory
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
196 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
197
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
198 (defcustom doc-view-conversion-buffer "*doc-view conversion output*"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
199 "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
200 :type 'string
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
201 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
202
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
203 (defcustom doc-view-conversion-refresh-interval 3
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
204 "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
205 After such a refresh newly converted pages will be available for
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
206 viewing. If set to nil there won't be any refreshes and the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
207 pages won't be displayed before conversion of the whole document
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
208 has finished."
85421
fbc2287ee475 Remove version keyword.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85420
diff changeset
209 :type 'integer
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
210 :group 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
211
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
212 ;;;; Internal Variables
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
213
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
214 (defvar doc-view-current-files nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
215 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
216
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
217 (defvar doc-view-current-page nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
218 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
219
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
220 (defvar doc-view-current-converter-process nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
221 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
222
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
223 (defvar doc-view-current-timer nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
224 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
225
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
226 (defvar doc-view-current-slice nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
227 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
228
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
229 (defvar doc-view-current-cache-dir nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
230 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
231
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
232 (defvar doc-view-current-search-matches nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
233 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
234
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
235 (defvar doc-view-current-image nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
236 "Only used internally.")
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
237 (defvar doc-view-current-overlay)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
238 (defvar doc-view-pending-cache-flush nil)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
239
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
240 (defvar doc-view-current-info nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
241 "Only used internally.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
242
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
243 (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
244 "Only used internally.")
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
245
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
246 ;;;; DocView Keymaps
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
247
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
248 (defvar doc-view-mode-map
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
249 (let ((map (make-sparse-keymap)))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
250 (suppress-keymap map)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
251 ;; Navigation in the document
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
252 (define-key map (kbd "n") 'doc-view-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
253 (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
254 (define-key map (kbd "<next>") 'forward-page)
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
255 (define-key map (kbd "<prior>") 'backward-page)
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
256 (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
257 (define-key map [remap backward-page] 'doc-view-previous-page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
258 (define-key map (kbd "SPC") 'doc-view-scroll-up-or-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
259 (define-key map (kbd "DEL") 'doc-view-scroll-down-or-previous-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
260 (define-key map (kbd "M-<") 'doc-view-first-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
261 (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
262 (define-key map [remap goto-line] 'doc-view-goto-page)
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
263 ;; Zoom in/out.
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
264 (define-key map "+" 'doc-view-enlarge)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
265 (define-key map "-" 'doc-view-shrink)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
266 ;; Killing/burying the buffer (and the process)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
267 (define-key map (kbd "q") 'bury-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
268 (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
269 (define-key map (kbd "K") 'doc-view-kill-proc)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
270 ;; Slicing the image
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
271 (define-key map (kbd "s s") 'doc-view-set-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
272 (define-key map (kbd "s m") 'doc-view-set-slice-using-mouse)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
273 (define-key map (kbd "s r") 'doc-view-reset-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
274 ;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
275 (define-key map (kbd "C-s") 'doc-view-search)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
276 (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
277 (define-key map (kbd "C-r") 'doc-view-search-backward)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
278 ;; Scrolling
85444
a3364ed63fcd (doc-view-mode-map): Use remapping.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85421
diff changeset
279 (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
280 (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
281 (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
282 (define-key map [remap previous-line] 'image-previous-line)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
283 ;; Show the tooltip
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
284 (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
285 ;; 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
286 (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
287 ;; 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
288 (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
289 (define-key map (kbd "r") 'revert-buffer)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
290 map)
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
291 "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
292
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
293 (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
294 "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
295 '("DocView"
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
296 ["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
297 ["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
298 ["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
299 "---"
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
300 ["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
301 ["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
302 ["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
303 ))
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
304
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
305 (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
306 (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
307 ;; 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
308 (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
309 map)
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
310 "Keymap used by `doc-minor-view-mode'.")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
311
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
312 ;;;; Navigation Commands
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
313
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
314 (defun doc-view-goto-page (page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
315 "View the page given by PAGE."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
316 (interactive "nPage: ")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
317 (let ((len (length doc-view-current-files)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
318 (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
319 (setq page 1)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
320 (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
321 (setq page len)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
322 (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
323 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
324 (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
325 (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
326 (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
327 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
328 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
329 ;; 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
330 (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
331 " (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
332 "\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
333 ;; 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
334 (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
335 (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
336 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
337 (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
338 (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
339 (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
340 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
341 (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
342 contexts)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
343 ;; Update the buffer
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
344 (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
345 :pointer 'arrow)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
346 (overlay-put doc-view-current-overlay 'help-echo doc-view-current-info)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
347 (goto-char (point-min))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
348 ;; This seems to be needed for set-window-hscroll (in
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
349 ;; image-forward-hscroll) to do something useful, I don't have time to
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
350 ;; debug this now. :-( --Stef
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
351 (forward-char)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
352
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
353 (defun doc-view-next-page (&optional arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
354 "Browse ARG pages forward."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
355 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
356 (doc-view-goto-page (+ doc-view-current-page (or arg 1))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
357
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
358 (defun doc-view-previous-page (&optional arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
359 "Browse ARG pages backward."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
360 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
361 (doc-view-goto-page (- doc-view-current-page (or arg 1))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
362
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
363 (defun doc-view-first-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
364 "View the first page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
365 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
366 (doc-view-goto-page 1))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
367
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
368 (defun doc-view-last-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
369 "View the last page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
370 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
371 (doc-view-goto-page (length doc-view-current-files)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
372
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
373 (defun doc-view-scroll-up-or-next-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
374 "Scroll page up if possible, else goto next page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
375 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
376 (condition-case nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
377 (scroll-up)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
378 (error (doc-view-next-page))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
379
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
380 (defun doc-view-scroll-down-or-previous-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
381 "Scroll page down if possible, else goto previous page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
382 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
383 (condition-case nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
384 (scroll-down)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
385 (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
386 (goto-char (point-max)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
387
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
388 ;;;; Utility Functions
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
389
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
390 (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
391 "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
392 (interactive)
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
393 (when doc-view-current-converter-process
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
394 (kill-process doc-view-current-converter-process)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
395 (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
396 (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
397 (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
398 (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
399 (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
400
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
401 (defun doc-view-kill-proc-and-buffer ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
402 "Kill the current converter process and buffer."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
403 (interactive)
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
404 (doc-view-kill-proc)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
405 (when (eq major-mode 'doc-view-mode)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
406 (kill-buffer (current-buffer))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
407
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
408 (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
409 (condition-case nil
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
410 (let ((umask (default-file-modes)))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
411 (unwind-protect
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
412 (progn
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
413 ;; 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
414 ;; 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
415 ;; time-window of loose permissions otherwise.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
416 (set-default-file-modes #o0700)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
417 (make-directory dir))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
418 ;; Reset the umask.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
419 (set-default-file-modes umask)))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
420 (file-already-exists
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
421 (if (file-symlink-p dir)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
422 (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
423 ;; 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
424 ;; 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
425 ;; 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
426 ;; 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
427 ;; 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
428 ;; 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
429 ;; 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
430 ;; closing a bunch of security holes.
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
431 (set-file-modes dir #o0700))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
432
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
433 (defun doc-view-current-cache-dir ()
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
434 "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
435 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
436 (if doc-view-current-cache-dir
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
437 doc-view-current-cache-dir
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
438 ;; 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
439 (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
440 ;; Now compute the subdirectory to use.
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
441 (setq doc-view-current-cache-dir
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
442 (file-name-as-directory
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
443 (expand-file-name
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
444 (let ((doc buffer-file-name))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
445 (concat (file-name-nondirectory doc)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
446 "-"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
447 (with-temp-buffer
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
448 (insert-file-contents-literally doc)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
449 (md5 (current-buffer)))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
450 doc-view-cache-directory)))))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
451
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
452 (defun doc-view-remove-if (predicate list)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
453 "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
454 (let (new-list)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
455 (dolist (item list (nreverse new-list))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
456 (when (not (funcall predicate item))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
457 (setq new-list (cons item new-list))))))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
458
86441
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
459 ;;;###autoload
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
460 (defun doc-view-mode-p (type)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
461 "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
462 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
463 (and (display-graphic-p)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
464 (image-type-available-p 'png)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
465 (cond
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
466 ((eq type 'dvi)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
467 (and (doc-view-mode-p 'pdf)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
468 doc-view-dvipdfm-program
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
469 (executable-find doc-view-dvipdfm-program)))
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
470 ((or (eq type 'postscript) (eq type 'ps)
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
471 (eq type 'pdf))
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
472 (and doc-view-ghostscript-program
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
473 (executable-find doc-view-ghostscript-program)))
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
474 (t ;; unknown image type
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
475 nil))))
6934c0956614 (doc-view-mode-p): New function.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 86156
diff changeset
476
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
477 ;;;; Conversion Functions
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
478
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
479 (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
480
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
481 (defun doc-view-enlarge (factor)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
482 "Enlarge the document."
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
483 (interactive (list doc-view-shrink-factor))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
484 (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
485 (* factor doc-view-resolution))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
486 (doc-view-reconvert-doc))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
487
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
488 (defun doc-view-shrink (factor)
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
489 "Shrink the document."
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
490 (interactive (list doc-view-shrink-factor))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
491 (doc-view-enlarge (/ 1.0 factor)))
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
492
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
493 (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
494 "Reconvert the current document.
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
495 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
496 (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
497 (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
498 ;; 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
499 (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
500 (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
501 (doc-view-initiate-display))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
502
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
503 (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
504 "If DVI->PDF conversion was successful, convert the PDF to PNG now."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
505 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
506 (message "DocView: dvi->pdf process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
507 (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
508 (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
509 mode-line-process nil)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
510 ;; Now go on converting this PDF to a set of PNG files.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
511 (let* ((pdf (process-get proc 'pdf-file))
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
512 (png (expand-file-name "page-%d.png"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
513 (doc-view-current-cache-dir))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
514 (doc-view-pdf/ps->png pdf png))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
515
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
516 (defun doc-view-dvi->pdf (dvi pdf)
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
517 "Convert DVI to PDF asynchronously."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
518 (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
519 (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
520 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
521 "-o" pdf dvi)
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
522 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
523 (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
524 'doc-view-dvi->pdf-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
525 (process-put doc-view-current-converter-process 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
526 (process-put doc-view-current-converter-process 'pdf-file pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
527
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
528 (defun doc-view-pdf/ps->png-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
529 "If PDF/PS->PNG conversion was successful, update the display."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
530 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
531 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
532 (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
533 (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
534 mode-line-process nil)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
535 (when doc-view-current-timer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
536 (cancel-timer doc-view-current-timer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
537 (setq doc-view-current-timer nil))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
538 ;; Yippie, finished. Update the display!
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
539 (doc-view-display buffer-file-name)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
540
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
541 (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
542 "Convert PDF-PS to PNG asynchronously."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
543 (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
544 (apply 'start-process
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
545 (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
546 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
547 doc-view-ghostscript-options
86119
5b6715f2ee11 (doc-view-ghostscript-options): Remove resolution arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 86035
diff changeset
548 (list (format "-r%d" (round doc-view-resolution)))
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
549 (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
550 (list pdf-ps)))
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
551 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
552 (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
553 'buffer (current-buffer))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
554 (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
555 'doc-view-pdf/ps->png-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
556 (when doc-view-conversion-refresh-interval
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
557 (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
558 (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
559 'doc-view-display
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
560 buffer-file-name))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
561
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
562 (defun doc-view-pdf->txt-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
563 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
564 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
565 (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
566 (proc-buffer (process-get proc 'buffer)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
567 (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
568 (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
569 mode-line-process nil)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
570 ;; If the user looks at the DocView buffer where the conversion was
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
571 ;; performed, search anew. This time it will be queried for a regexp.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
572 (when (eq current-buffer proc-buffer)
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
573 (doc-view-search nil)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
574
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
575 (defun doc-view-pdf->txt (pdf txt)
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
576 "Convert PDF to TXT asynchronously."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
577 (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
578 (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
579 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
580 pdf txt)
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
581 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
582 (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
583 'doc-view-pdf->txt-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
584 (process-put doc-view-current-converter-process 'buffer (current-buffer)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
585
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
586 (defun doc-view-ps->pdf-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
587 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
588 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
589 (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
590 (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
591 mode-line-process nil)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
592 ;; Now we can transform to plain text.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
593 (doc-view-pdf->txt (process-get proc 'pdf-file)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
594 (expand-file-name "doc.txt"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
595 (doc-view-current-cache-dir)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
596
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
597 (defun doc-view-ps->pdf (ps pdf)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
598 "Convert PS to PDF asynchronously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
599 (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
600 (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
601 doc-view-ps2pdf-program
85418
26dcc1207f42 (doc-view-ghostscript-options, doc-view-ps->pdf):
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85369
diff changeset
602 ;; 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
603 ;; untrusted sources.
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
604 "-dSAFER"
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
605 ;; in-file and out-file
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
606 ps pdf)
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
607 mode-line-process (list (format ":%s" doc-view-current-converter-process)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
608 (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
609 'doc-view-ps->pdf-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
610 (process-put doc-view-current-converter-process 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
611 (process-put doc-view-current-converter-process 'pdf-file pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
612
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
613 (defun doc-view-convert-current-doc ()
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
614 "Convert `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
615 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
616 `doc-view-current-cache-dir'."
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
617 ;; 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
618 ;; 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
619 ;; 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
620 ;; 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
621 ;; resets during the redisplay).
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
622 (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
623 (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
624 (doc-view-current-cache-dir))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
625 (make-directory (doc-view-current-cache-dir))
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
626 (if (not (string= (file-name-extension 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
627 ;; Convert to PNG images.
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
628 (doc-view-pdf/ps->png buffer-file-name png-file)
85367
1fbaddcbc4ec Mention xpdf. Fix spelling of Ghostscript.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85029
diff changeset
629 ;; DVI files have to be converted to PDF before Ghostscript can process
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
630 ;; it.
85801
9b97166d0c6c (doc-view-current-doc): Remove. Replace all uses by buffer-file-name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85784
diff changeset
631 (doc-view-dvi->pdf buffer-file-name
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
632 (expand-file-name "doc.pdf"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
633 doc-view-current-cache-dir)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
634
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
635 ;;;; Slicing
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
636
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
637 (defun doc-view-set-slice (x y width height)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
638 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
639 You can use this function to tell doc-view not to display the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
640 margins of the document. It prompts for the top-left corner (X
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
641 and Y) of the slice to display and its WIDTH and HEIGHT.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
642
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
643 See `doc-view-set-slice-using-mouse' for a more convenient way to
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
644 do that. To reset the slice use `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
645 (interactive
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
646 (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
647 (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
648 (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
649 (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
650 (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
651 (list a b c d)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
652 (setq doc-view-current-slice (list x y width height))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
653 ;; Redisplay
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
654 (doc-view-goto-page doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
655
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
656 (defun doc-view-set-slice-using-mouse ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
657 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
658 You set the slice by pressing mouse-1 at its top-left corner and
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
659 dragging it to its bottom-right corner. See also
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
660 `doc-view-set-slice' and `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
661 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
662 (let (x y w h done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
663 (while (not done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
664 (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
665 (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
666 "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
667 (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
668 (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
669 (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
670 (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
671 (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
672 (setq done t))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
673 (doc-view-set-slice x y w h)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
674
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
675 (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
676 "Reset the current slice.
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
677 After calling this function whole pages will be visible again."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
678 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
679 (setq doc-view-current-slice nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
680 ;; Redisplay
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
681 (doc-view-goto-page doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
682
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
683 ;;;; Display
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
684
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
685 (defun doc-view-insert-image (file &rest args)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
686 "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
687 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
688 (when doc-view-pending-cache-flush
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
689 (clear-image-cache)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
690 (setq doc-view-pending-cache-flush nil))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
691 (let ((image (apply 'create-image file 'png nil args)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
692 (setq doc-view-current-image image)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
693 (move-overlay doc-view-current-overlay (point-min) (point-max))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
694 (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
695 (if doc-view-current-slice
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
696 (list (cons 'slice doc-view-current-slice) image)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
697 image))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
698
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
699 (defun doc-view-sort (a b)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
700 "Return non-nil if A should be sorted before B.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
701 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
702 (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
703 (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
704 (string< a b))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
705
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
706 (defun doc-view-display (doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
707 "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
708 (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
709 (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
710 (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
711 "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
712 'doc-view-sort))
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
713 (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
714 (doc-view-goto-page doc-view-current-page)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
715
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
716 (defun doc-view-buffer-message ()
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
717 ;; 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
718 ;; 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
719 ;; the fresh new ones).
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
720 (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
721 (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
722 (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
723 "\n"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
724 "
85815
960b3c592913 (doc-view-conversion-refresh-interval)
Glenn Morris <rgm@gnu.org>
parents: 85805
diff changeset
725 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
726 converted to PNG and the conversion of the first page hasn't finished yet or
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
727 `doc-view-conversion-refresh-interval' is set to nil.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
728
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
729 For now these keys are useful:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
730
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
731 `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
732 `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
733 `K' : Kill the conversion process.\n"))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
734
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
735 (defun doc-view-show-tooltip ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
736 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
737 (tooltip-show doc-view-current-info))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
738
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
739 ;;;;; 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
740
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
741 (defun doc-view-toggle-display ()
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
742 "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
743 (interactive)
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
744 (if (eq major-mode 'doc-view-mode)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
745 ;; Switch to editing mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
746 (progn
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
747 (doc-view-kill-proc)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
748 (setq buffer-read-only nil)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
749 (delete-overlay doc-view-current-overlay)
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
750 ;; 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
751 ;; mode.
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
752 (if doc-view-previous-major-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
753 (funcall doc-view-previous-major-mode)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
754 (fundamental-mode))
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
755 (doc-view-minor-mode 1))
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
756 ;; Switch to doc-view-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
757 (when (and (buffer-modified-p)
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
758 (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
759 (save-buffer))
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
760 (doc-view-mode)))
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
761
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
762 ;;;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
763
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
764 (defun doc-view-search-internal (regexp file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
765 "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
766 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
767 the pagenumber and CONTEXTS are all lines of text containing a match."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
768 (with-temp-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
769 (insert-file-contents file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
770 (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
771 (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
772 matches)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
773 (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
774 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
775 (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
776 (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
777 (if (/= page lastpage)
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
778 (push (cons page
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
779 (list (buffer-substring
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
780 (line-beginning-position)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
781 (line-end-position))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
782 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
783 (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
784 (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
785 (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
786 ;; 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
787 (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
788 ;; 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
789 (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
790 (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
791 (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
792 (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
793 (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
794 (setq lastpage page)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
795 (nreverse matches))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
796
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
797 (defun doc-view-search-no-of-matches (list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
798 "Extract the number of matches from the search result LIST."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
799 (let ((no 0))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
800 (dolist (p list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
801 (setq no (+ no (1- (length p)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
802 no))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
803
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
804 (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
805 "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
806 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
807 (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
808 (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
809
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
810 (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
811 "Jump to the next match or initiate a new search if NEW-QUERY is given.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
812 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
813 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
814 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
815 (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
816 (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
817 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
818 (if backward
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
819 (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
820 (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
821 ;; 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
822 (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
823 (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
824 (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
825 (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
826 (progn
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
827 (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
828 (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
829 (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
830 txt))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
831 (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
832 (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
833 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
834 ;; 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
835 (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
836 (message "DocView: please wait till conversion finished.")
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
837 (let ((ext (file-name-extension buffer-file-name)))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
838 (cond
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
839 ((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
840 ;; Doc is a PDF, so convert it to TXT
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
841 (doc-view-pdf->txt buffer-file-name txt))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
842 ((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
843 ;; 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
844 ;; TXT thereafter).
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
845 (doc-view-ps->pdf buffer-file-name
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
846 (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
847 (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
848 ((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
849 ;; 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
850 ;; cache subdirectory.
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-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
852 (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
853 txt))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
854 (t (error "DocView doesn't know what to do")))))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
855
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
856 (defun doc-view-search-next-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
857 "Go to the ARGth next matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
858 (interactive "p")
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
859 (let* ((next-pages (doc-view-remove-if
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
860 (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
861 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
862 (page (car (nth (1- arg) next-pages))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
863 (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
864 (doc-view-goto-page page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
865 (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
866 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
867 (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
868 (doc-view-goto-page (caar doc-view-current-search-matches))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
869
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
870 (defun doc-view-search-previous-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
871 "Go to the ARGth previous matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
872 (interactive "p")
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
873 (let* ((prev-pages (doc-view-remove-if
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
874 (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
875 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
876 (page (car (nth (1- arg) (nreverse prev-pages)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
877 (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
878 (doc-view-goto-page page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
879 (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
880 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
881 (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
882 (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
883
85369
5b96a46cc08a * bindings.el (completion-ignored-extensions): Remove pdf and dvi
Reiner Steib <Reiner.Steib@gmx.de>
parents: 85367
diff changeset
884 ;;;; 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
885
85805
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
886 ;; (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
887
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
888 (defun doc-view-initiate-display ()
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
889 ;; Switch to image display if possible
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
890 (if (and (display-images-p)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
891 (image-type-available-p 'png))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
892 (progn
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
893 (doc-view-buffer-message)
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
894 (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
895 (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
896 (progn
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
897 (message "DocView: using cached files!")
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
898 (doc-view-display buffer-file-name))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
899 (doc-view-convert-current-doc))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
900 (message
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
901 "%s"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
902 (substitute-command-keys
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
903 (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
904 "editing or viewing the document."))))
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
905 (message
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
906 "%s"
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
907 (substitute-command-keys
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
908 (concat "No image (png) support available. Type \\[doc-view-toggle-display] "
1d1d43e36948 Use expand-file-name rather than concat.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 85801
diff changeset
909 "to switch to an editing mode.")))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
910
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
911 ;;;###autoload
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
912 (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
913 "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
914 You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
85784
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
915 toggle between displaying the document or editing it as text."
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
916 (interactive)
86025
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
917 (if jka-compr-really-do-compress
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
918 ;; This is a compressed file uncompressed by auto-compression-mode.
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
919 (when (y-or-n-p (concat "DocView: Cannot convert compressed file. "
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
920 "Save it uncompressed first? "))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
921 (let ((file (read-file-name
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
922 "File: "
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
923 (file-name-directory buffer-file-name))))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
924 (write-region (point-min) (point-max) file)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
925 (kill-buffer nil)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
926 (find-file file)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
927 (doc-view-mode)))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
928 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
929 doc-view-previous-major-mode
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
930 major-mode)))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
931 (kill-all-local-variables)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
932 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
933 (make-local-variable 'doc-view-current-files)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
934 (make-local-variable 'doc-view-current-image)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
935 (make-local-variable 'doc-view-current-page)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
936 (make-local-variable '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
937 (make-local-variable 'doc-view-current-timer)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
938 (make-local-variable 'doc-view-current-slice)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
939 (make-local-variable '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
940 (make-local-variable 'doc-view-current-info)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
941 (make-local-variable '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
942 (set (make-local-variable 'doc-view-current-overlay)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
943 (make-overlay (point-min) (point-max) nil t))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
944 (add-hook 'change-major-mode-hook
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
945 (lambda () (delete-overlay doc-view-current-overlay))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
946 nil t)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
947 (set (make-local-variable 'mode-line-position)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
948 '(" P" (:eval (number-to-string doc-view-current-page))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
949 "/" (:eval (number-to-string (length doc-view-current-files)))))
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
950 (set (make-local-variable 'cursor-type) nil)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
951 (use-local-map doc-view-mode-map)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
952 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
953 (setq mode-name "DocView"
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
954 buffer-read-only t
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
955 major-mode 'doc-view-mode)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
956 (doc-view-initiate-display)
19784f7db0ef (doc-view-mode-map, doc-view-menu, doc-view-pdf->txt-sentinel):
Juri Linkov <juri@jurta.org>
parents: 85856
diff changeset
957 (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
958
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
959 ;;;###autoload
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
960 (define-minor-mode doc-view-minor-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
961 "Toggle Doc view minor mode.
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
962 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
963 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
964 nil " DocView" doc-view-minor-mode-map
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
965 :group 'doc-view
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
966 (when doc-view-minor-mode
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
967 (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
968 (message
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
969 "%s"
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
970 (substitute-command-keys
b0dc7772c4dc Tassilo Horn <tassilo at member.fsf.org>
Glenn Morris <rgm@gnu.org>
parents: 85444
diff changeset
971 "Type \\[doc-view-toggle-display] to toggle between editing or viewing the document."))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
972
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
973 (defun doc-view-clear-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
974 "Delete the whole cache (`doc-view-cache-directory')."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
975 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
976 (dired-delete-file doc-view-cache-directory 'always)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
977 (make-directory doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
978
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
979 (defun doc-view-dired-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
980 "Open `dired' in `doc-view-cache-directory'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
981 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
982 (dired doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
983
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
984 (provide 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
985
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
986 ;; Local Variables:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
987 ;; mode: outline-minor
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
988 ;; End:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
989
84450
a8fe8c64e5d0 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 84422
diff changeset
990 ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
991 ;;; doc-view.el ends here