annotate lisp/doc-view.el @ 85410:f8c52ed3968f

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