annotate lisp/doc-view.el @ 85087:1876f72f31dd

(follow-mode): Don't run hooks twice. Use `when'.
author Juanma Barranquero <lekktu@gmail.com>
date Mon, 08 Oct 2007 16:06:15 +0000
parents 63718012f1da
children 1fbaddcbc4ec
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
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
8 ;; Version: <2007-10-02 Tue 18:21>
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
29 ;; doc-view.el requires GNU Emacs 22.1 or newer. You also need GhostScript,
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
30 ;; `dvipdfm' which comes with TeTeX and `pdftotext', which comes with poppler
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
31 ;; (http://poppler.freedesktop.org/).
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 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
40 ;; To use it simply do
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
41 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
42 ;; M-x doc-view RET
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
43 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
44 ;; and you'll be queried for a document to open.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
45 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
46 ;; Since conversion may take some time all the PNG images are cached in a
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
47 ;; subdirectory of `doc-view-cache-directory' and reused when you want to view
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
48 ;; that file again. This reusing can be omitted if you provide a prefx
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
49 ;; argument to `doc-view'. To delete all cached files use
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
50 ;; `doc-view-clear-cache'. To open the cache with dired, so that you can tidy
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
51 ;; it out use `doc-view-dired-cache'.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
52 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
53 ;; When conversion in underway the first page will be displayed as soon as it
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
54 ;; is available and the available pages are refreshed every
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
55 ;; `doc-view-conversion-refresh-interval' seconds. If that variable is nil the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
56 ;; pages won't be displayed before conversion of the document finished
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
57 ;; completely.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
58 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
59 ;; DocView lets you select a slice of the displayed pages. This slice will be
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
60 ;; remembered and applied to all pages of the current document. This enables
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61 ;; you to cut away the margins of a document to save some space. To select a
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
62 ;; slice you can use `doc-view-set-slice' (bound to `s s') which will query you
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
63 ;; for the coordinates of the slice's top-left corner and its width and height.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
64 ;; A much more convenient way to do the same is offered by the command
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
65 ;; `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
66 ;; only have to press mouse-1 at the top-left corner and drag it to the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
67 ;; bottom-right corner of the desired slice. To reset the slice use
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68 ;; `doc-view-reset-slice' (bound to `s r').
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ;; Dired users should have a look at `doc-view-dired'.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72 ;; You can also search within the document. The command `doc-view-search'
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
73 ;; (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
74 ;; 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
75 ;; can jump to the next page containing a match with
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
76 ;; `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
77 ;; 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
78 ;; 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
79 ;; already exist the first invokation of `doc-view-search' starts the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
80 ;; conversion. When that finishes and you're still viewing the document
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
81 ;; (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
82 ;; then.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
83
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
84 ;;; Configuration:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
85
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86 ;; Basically doc-view should be quite usable with its standard settings, so
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
87 ;; putting
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 ;; (require 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
90 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
91 ;; into your `user-init-file' should be enough. If the images are too small or
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
92 ;; too big you should set the "-rXXX" option in `doc-view-ghostscript-options'
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
93 ;; to another value. (The bigger your screen, the higher the value.)
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"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
125 "-r100")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
126 "A list of options to give to ghostview."
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
204 ;;;; DocView Keymap
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
205
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
206 (defvar doc-view-mode-map
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
207 (let ((map (make-sparse-keymap)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
208 ;; Navigation in the document
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
209 (define-key map (kbd "n") 'doc-view-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
210 (define-key map (kbd "p") 'doc-view-previous-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
211 (define-key map (kbd "<next>") 'doc-view-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
212 (define-key map (kbd "<prior>") 'doc-view-previous-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
213 (define-key map (kbd "SPC") 'doc-view-scroll-up-or-next-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
214 (define-key map (kbd "DEL") 'doc-view-scroll-down-or-previous-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
215 (define-key map (kbd "M-<") 'doc-view-first-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
216 (define-key map (kbd "M->") 'doc-view-last-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
217 (define-key map (kbd "g") 'doc-view-goto-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
218 ;; Killing/burying the buffer (and the process)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
219 (define-key map (kbd "q") 'bury-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
220 (define-key map (kbd "k") 'doc-view-kill-proc-and-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
221 (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
222 ;; Slicing the image
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
223 (define-key map (kbd "s s") 'doc-view-set-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
224 (define-key map (kbd "s m") 'doc-view-set-slice-using-mouse)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
225 (define-key map (kbd "s r") 'doc-view-reset-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
226 ;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
227 (define-key map (kbd "C-s") 'doc-view-search)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
228 (define-key map (kbd "<find>") 'doc-view-search)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
229 (define-key map (kbd "C-S-n") 'doc-view-search-next-match)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
230 (define-key map (kbd "C-S-p") 'doc-view-search-previous-match)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
231 ;; Scrolling
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
232 (define-key map (kbd "C-v") 'scroll-up)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
233 (define-key map (kbd "<mouse-4>") 'mwheel-scroll)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
234 (define-key map (kbd "<mouse-5>") 'mwheel-scroll)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
235 (define-key map (kbd "M-v") 'scroll-down)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
236 ;; Show the tooltip
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
237 (define-key map (kbd "C-t") 'doc-view-show-tooltip)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
238 (suppress-keymap map)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
239 map)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
240 "Keymap used by `doc-view-mode'.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
241
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
242 ;;;; Navigation Commands
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
243
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
244 (defun doc-view-goto-page (page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
245 "View the page given by PAGE."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
246 (interactive "nPage: ")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
247 (let ((len (length doc-view-current-files)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
248 (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
249 (setq page 1)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
250 (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
251 (setq page len)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
252 (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
253 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
254 (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
255 (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
256 (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
257 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
258 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
259 ;; 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
260 (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
261 " (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
262 "\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
263 ;; 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
264 (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
265 (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
266 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
267 (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
268 (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
269 (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
270 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
271 (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
272 contexts)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
273 ;; Update the buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
274 (setq inhibit-read-only t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
275 (erase-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
276 (let ((beg (point)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
277 (doc-view-insert-image (nth (1- page) doc-view-current-files)
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
278 :pointer 'arrow)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
279 (put-text-property beg (point) 'help-echo doc-view-current-info))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
280 (insert "\n" doc-view-current-info)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
281 (goto-char (point-min))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
282 (forward-char)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
283 (setq inhibit-read-only nil)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
284
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
285 (defun doc-view-next-page (&optional arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
286 "Browse ARG pages forward."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
287 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
288 (doc-view-goto-page (+ doc-view-current-page (or arg 1))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
289
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
290 (defun doc-view-previous-page (&optional arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
291 "Browse ARG pages backward."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
292 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
293 (doc-view-goto-page (- doc-view-current-page (or arg 1))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
294
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
295 (defun doc-view-first-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
296 "View the first page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
297 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
298 (doc-view-goto-page 1))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
299
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
300 (defun doc-view-last-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
301 "View the last page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
302 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
303 (doc-view-goto-page (length doc-view-current-files)))
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-scroll-up-or-next-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
306 "Scroll page up if possible, else goto next page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
307 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
308 (condition-case nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
309 (scroll-up)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
310 (error (doc-view-next-page))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
311
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
312 (defun doc-view-scroll-down-or-previous-page ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
313 "Scroll page down if possible, else goto previous page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
314 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
315 (condition-case nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
316 (scroll-down)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
317 (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
318 (goto-char (point-max)))))
84422
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-kill-proc-and-buffer ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
321 "Kill the current converter process and buffer."
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 (when (eq major-mode 'doc-view-mode)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
324 (when doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
325 (kill-process doc-view-current-converter-process))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
326 (when doc-view-current-timer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
327 (cancel-timer doc-view-current-timer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
328 (setq doc-view-current-timer nil))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
329 (kill-buffer (current-buffer))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
330
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
331 ;;;; Conversion Functions
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
332
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
333 (defun doc-view-file-name-to-directory-name (file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
334 "Return the directory where the png files of FILE should be saved.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
335
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
336 It'a a subdirectory of `doc-view-cache-directory'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
337 (if doc-view-current-cache-dir
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
338 doc-view-current-cache-dir
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
339 (file-name-as-directory
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
340 (concat (file-name-as-directory doc-view-cache-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
341 (with-temp-buffer
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
342 (insert-file-contents-literally file)
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
343 (md5 (current-buffer)))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
344
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
345 (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
346 "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
347 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
348 (message "DocView: dvi->pdf process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
349 (set-buffer (process-get proc 'buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
350 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
351 (message "DocView: finished conversion from DVI to PDF!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
352 ;; Now go on converting this PDF to a set of PNG files.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
353 (let* ((pdf (process-get proc 'pdf-file))
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
354 (png (concat (doc-view-file-name-to-directory-name
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
355 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
356 "page-%d.png")))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
357 (doc-view-pdf/ps->png pdf png))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
358
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
359 (defun doc-view-dvi->pdf (dvi pdf)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
360 "Convert DVI to PDF asynchrounously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
361 (message "DocView: converting DVI to PDF now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
362 (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
363 (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
364 doc-view-dvipdfm-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
365 "-o" pdf dvi))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
366 (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
367 'doc-view-dvi->pdf-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
368 (process-put doc-view-current-converter-process 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
369 (process-put doc-view-current-converter-process 'pdf-file pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
370
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
371 (defun doc-view-pdf/ps->png-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
372 "If PDF/PS->PNG conversion was successful, update the display."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
373 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
374 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
375 (set-buffer (process-get proc 'buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
376 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
377 (when doc-view-current-timer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
378 (cancel-timer doc-view-current-timer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
379 (setq doc-view-current-timer nil))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
380 (message "DocView: finished conversion from PDF/PS to PNG!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
381 ;; Yippie, finished. Update the display!
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
382 (doc-view-display doc-view-current-doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
383
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
384 (defun doc-view-pdf/ps->png (pdf-ps png)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
385 "Convert PDF-PS to PNG asynchrounously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
386 (message "DocView: converting PDF or PS to PNG now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
387 (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
388 (apply 'start-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
389 (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
390 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
391 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
392 (list (concat "-sOutputFile=" png))
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
393 (list pdf-ps))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
394 (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
395 'buffer (current-buffer))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
396 (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
397 'doc-view-pdf/ps->png-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
398 (when doc-view-conversion-refresh-interval
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
399 (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
400 (run-at-time "1 secs" doc-view-conversion-refresh-interval
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
401 'doc-view-display
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
402 doc-view-current-doc))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
403
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
404 (defun doc-view-pdf->txt-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
405 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
406 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
407 (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
408 (proc-buffer (process-get proc 'buffer)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
409 (set-buffer proc-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
410 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
411 (message "DocView: finished conversion from PDF to TXT!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
412 ;; If the user looks at the DocView buffer where the conversion was
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
413 ;; performed, search anew. This time it will be queried for a regexp.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
414 (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
415 (doc-view-search)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
416
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
417 (defun doc-view-pdf->txt (pdf txt)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
418 "Convert PDF to TXT asynchrounously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
419 (message "DocView: converting PDF to TXT now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
420 (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
421 (start-process "doc-view-pdf->txt" doc-view-conversion-buffer
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
422 doc-view-pdftotext-program "-raw"
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
423 pdf txt))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
424 (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
425 'doc-view-pdf->txt-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
426 (process-put doc-view-current-converter-process 'buffer (current-buffer)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
427
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
428 (defun doc-view-ps->pdf-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
429 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
430 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
431 (set-buffer (process-get proc 'buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
432 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
433 (message "DocView: finished conversion from PS to PDF!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
434 ;; Now we can transform to plain text.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
435 (doc-view-pdf->txt (process-get proc 'pdf-file)
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
436 (concat (doc-view-file-name-to-directory-name
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
437 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
438 "doc.txt"))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
439
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
440 (defun doc-view-ps->pdf (ps pdf)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
441 "Convert PS to PDF asynchronously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
442 (message "DocView: converting PS to PDF now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
443 (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
444 (start-process "doc-view-ps->pdf" doc-view-conversion-buffer
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-ps2pdf-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
446 ps pdf))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
447 (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
448 'doc-view-ps->pdf-sentinel)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
449 (process-put doc-view-current-converter-process 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
450 (process-put doc-view-current-converter-process 'pdf-file pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
451
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
452 (defun doc-view-convert-doc (doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
453 "Convert DOC to a set of png files, one file per page.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
454
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
455 Those files are saved in the directory given by
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
456 `doc-view-file-name-to-directory-name'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
457 (clear-image-cache)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
458 (let* ((dir (doc-view-file-name-to-directory-name doc))
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 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
460 (when (file-exists-p dir)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
461 (dired-delete-file dir 'always))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
462 (make-directory dir t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
463 (if (not (string= (file-name-extension 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
464 ;; Convert to PNG images.
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
465 (doc-view-pdf/ps->png doc png-file)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
466 ;; DVI files have to be converted to PDF before GhostScript can process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
467 ;; it.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
468 (doc-view-dvi->pdf doc
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
469 (concat (file-name-as-directory dir)
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.pdf")))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
471
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
472 ;;;; DocView Mode
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
473
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
474 (define-derived-mode doc-view-mode nil "DocView"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
475 "Major mode in DocView buffers.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
476
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
477 \\{doc-view-mode-map}"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
478 :group 'doc-view
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
479 (setq buffer-read-only t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
480 (make-local-variable 'doc-view-current-files)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
481 (make-local-variable 'doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
482 (make-local-variable 'doc-view-current-image)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
483 (make-local-variable 'doc-view-current-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
484 (make-local-variable 'doc-view-current-converter-process)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
485 (make-local-variable 'doc-view-current-timer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
486 (make-local-variable 'doc-view-current-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
487 (make-local-variable 'doc-view-current-cache-dir)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
488 (make-local-variable 'doc-view-current-info)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
489 (make-local-variable 'doc-view-current-search-matches))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
490
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
491 ;;;; Slicing
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
492
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
493 (defun doc-view-set-slice (x y width height)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
494 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
495 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
496 margins of the document. It prompts for the top-left corner (X
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
497 and Y) of the slice to display and its WIDTH and HEIGHT.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
498
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
499 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
500 do that. To reset the slice use `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
501 (interactive
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
502 (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
503 (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
504 (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
505 (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
506 (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
507 (list a b c d)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
508 (setq doc-view-current-slice (list x y width height))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
509 ;; Redisplay
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
510 (doc-view-goto-page doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
511
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
512 (defun doc-view-set-slice-using-mouse ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
513 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
514 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
515 dragging it to its bottom-right corner. See also
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
516 `doc-view-set-slice' and `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
517 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
518 (let (x y w h done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
519 (while (not done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
520 (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
521 (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
522 "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
523 (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
524 (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
525 (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
526 (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
527 (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
528 (setq done t))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
529 (doc-view-set-slice x y w h)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
530
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
531 (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
532 "Reset the current slice.
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
533 After calling this function the whole pages will be visible
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
534 again."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
535 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
536 (setq doc-view-current-slice nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
537 ;; Redisplay
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
538 (doc-view-goto-page doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
539
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
540 ;;;; Display
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
541
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
542 (defun doc-view-insert-image (file &rest args)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
543 "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
544 ARGS is a list of image descriptors."
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
545 (let ((image (apply 'create-image file 'png nil args)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
546 (setq doc-view-current-image image)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
547 (insert-image image (concat "[" file "]") nil doc-view-current-slice)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
548
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
549 (defun doc-view-sort (a b)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
550 "Return non-nil if A should be sorted before B.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
551 Predicate for sorting `doc-view-current-files'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
552 (if (< (length a) (length b))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
553 t
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
554 (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
555 nil
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
556 (string< a b))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
557
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
558 (defun doc-view-display (doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
559 "Start viewing the document DOC."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
560 (let ((dir (doc-view-file-name-to-directory-name doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
561 (set-buffer (format "*DocView: %s*" doc))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
562 (setq doc-view-current-files
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
563 (sort (directory-files dir t "page-[0-9]+\\.png" 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
564 'doc-view-sort))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
565 (when (> (length doc-view-current-files) 0)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
566 (doc-view-goto-page doc-view-current-page))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
567
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
568 (defun doc-view-buffer-message ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
569 (setq inhibit-read-only t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
570 (erase-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
571 (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
572 "\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
573 "
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
574 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
575 view gets converted to PNG now and the conversion of the first
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
576 page hasn't finished yet or
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
577 `doc-view-conversion-refresh-interval' is set to nil.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
578
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
579 For now these keys are useful:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
580
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
581 `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
582 `k' : Kill the conversion process and this buffer.\n")
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
583 (setq inhibit-read-only nil))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
584
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
585 (defun doc-view-show-tooltip ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
586 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
587 (tooltip-show doc-view-current-info))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
588
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
589 ;;;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
590
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
591 (defun doc-view-search-internal (regexp file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
592 "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
593 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
594 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
595 (with-temp-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
596 (insert-file-contents file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
597 (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
598 (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
599 matches)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
600 (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
601 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
602 (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
603 (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
604 (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
605 (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
606 (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
607 (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
608 (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
609 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
610 (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
611 (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
612 (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
613 ;; 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
614 (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
615 ;; 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
616 (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
617 (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
618 (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
619 (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
620 (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
621 (setq lastpage page)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
622 (nreverse matches))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
623
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
624 (defun doc-view-search-no-of-matches (list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
625 "Extract the number of matches from the search result LIST."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
626 (let ((no 0))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
627 (dolist (p list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
628 (setq no (+ no (1- (length p)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
629 no))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
630
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
631 (defun doc-view-search ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
632 "Query for a regexp and search the current document.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
633 If the current document hasn't been transformed to plain text
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
634 till now do that first. You should try searching anew when the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
635 conversion finished."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
636 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
637 ;; New search, so forget the old results.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
638 (setq doc-view-current-search-matches nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
639 (let ((txt (concat (doc-view-file-name-to-directory-name
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
640 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
641 "doc.txt")))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
642 (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
643 (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
644 (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
645 (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
646 (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
647 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
648 (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
649 (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
650 doc-view-current-search-matches)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
651 ;; We must convert to TXT first!
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
652 (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
653 (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
654 (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
655 (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
656 ((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
657 ;; 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
658 (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
659 ((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
660 ;; 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
661 ;; 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
662 (doc-view-ps->pdf 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
663 (concat (doc-view-file-name-to-directory-name
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
664 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
665 "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
666 ((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
667 ;; 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
668 ;; cache subdirectory.
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
669 (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
06c04cf43e80 (doc-view): Don't ignore pdf and dvi files when completing filename.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 84450
diff changeset
670 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
671 "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
672 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
673 (t (error "DocView doesn't know what to do"))))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
674
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
675 (defun doc-view-search-next-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
676 "Go to the ARGth next matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
677 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
678 (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
679 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
680 (page (car (nth (1- arg) next-pages))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
681 (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
682 (doc-view-goto-page page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
683 (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
684 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
685 (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
686 (doc-view-goto-page (caar doc-view-current-search-matches))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
687
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
688 (defun doc-view-search-previous-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
689 "Go to the ARGth previous matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
690 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
691 (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
692 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
693 (page (car (nth (1- arg) (nreverse prev-pages)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
694 (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
695 (doc-view-goto-page page)
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
696 (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
697 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
698 (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
699 (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
700
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
701 ;;;; User Interface Commands
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
702
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
703 ;;;###autoload
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
704 (defun doc-view (no-cache &optional file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
705 "Convert FILE to png and start viewing it.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
706 If no FILE is given, query for on.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
707 If this FILE is still in the cache, don't convert and use the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
708 existing page files. With prefix arg NO-CACHE, don't use the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
709 cached files and convert anew."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
710 (interactive "P")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
711 (if (not (and (image-type-available-p 'png)
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
712 (display-images-p)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
713 (message "DocView: your emacs or display doesn't support png images.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
714 (let* ((doc (or file
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 (expand-file-name
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 (let ((completion-ignored-extensions
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 ;; Don't hide files doc-view can display
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 (remove-if (lambda (str)
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 (string-match "\\.\\(ps\\|pdf\\|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
720 str))
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 completion-ignored-extensions)))
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 (read-file-name "File: " nil 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
723 (buffer (get-buffer-create (format "*DocView: %s*" 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
724 (dir (doc-view-file-name-to-directory-name doc)))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
725 (switch-to-buffer buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
726 (doc-view-buffer-message)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
727 (doc-view-mode)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
728 (setq doc-view-current-doc doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
729 (setq doc-view-current-page 1)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
730 (if (not (and (file-exists-p 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
731 (not no-cache)))
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 (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
733 (setq doc-view-current-cache-dir nil)
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-convert-doc 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
735 (message "DocView: using cached files!")
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-view-display doc-view-current-doc)))))
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
737
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
738 (defun doc-view-dired (no-cache)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
739 "View the current dired file with doc-view.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
740 NO-CACHE is the same as in `doc-view'.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
741
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
742 You might want to bind this command to a dired key, e.g.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
743
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
744 (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
745 (interactive "P")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
746 (doc-view no-cache (dired-get-file-for-visit)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
747
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
748 (defun doc-view-clear-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
749 "Delete the whole cache (`doc-view-cache-directory')."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
750 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
751 (dired-delete-file doc-view-cache-directory 'always)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
752 (make-directory doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
753
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
754 (defun doc-view-dired-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
755 "Open `dired' in `doc-view-cache-directory'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
756 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
757 (dired doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
758
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
759 (provide 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
760
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
761 ;; Local Variables:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
762 ;; mode: outline-minor
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
763 ;; End:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
764
84450
a8fe8c64e5d0 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 84422
diff changeset
765 ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
766 ;;; doc-view.el ends here