annotate lisp/doc-view.el @ 84951:55a892948dea

* indent.h: * indent.c: Use EMACS_INT for ints coming from Elisp data.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 27 Sep 2007 18:49:57 +0000
parents a8fe8c64e5d0
children 06c04cf43e80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1 ;;; doc-view.el --- View PDF/PostScript/DVI files in Emacs
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
3 ;; Copyright (C) 2007 Free Software Foundation, Inc.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
4 ;;
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
5 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
6 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
7 ;; Keywords: files, pdf, ps, dvi
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
8 ;; Version: <2007-09-07 Fri 15:28>
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
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
153 "doc-view")
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)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
249 (setq page 1)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
250 (when (> page len)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
251 (setq page len)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
252 (setq doc-view-current-page page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
253 doc-view-current-info
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
254 (concat
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
255 (propertize
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
256 (format "Page %d of %d."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
257 doc-view-current-page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
258 len) 'face 'bold)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
259 ;; Tell user if converting isn't finished yet
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
260 (if doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
261 " (still converting...)\n"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
262 "\n")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
263 ;; Display context infos if this page matches the last search
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
264 (when (and doc-view-current-search-matches
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
265 (assq doc-view-current-page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
266 doc-view-current-search-matches))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
267 (concat (propertize "Search matches:\n" 'face 'bold)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
268 (let ((contexts ""))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
269 (dolist (m (cdr (assq doc-view-current-page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
270 doc-view-current-search-matches)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
271 (setq contexts (concat contexts " - \"" m "\"\n")))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
272 contexts)))))
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)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
278 :pointer 'arrow)
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)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
318 (goto-char (point-max)))))
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)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
341 (with-temp-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
342 (insert-file-contents-literally file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
343 (md5 (current-buffer)))))))
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)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
346 "If DVI->PDF conversion was successful, convert the PDF to PNG
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
347 now."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
348 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
349 (message "DocView: dvi->pdf process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
350 (set-buffer (process-get proc 'buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
351 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
352 (message "DocView: finished conversion from DVI to PDF!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
353 ;; Now go on converting this PDF to a set of PNG files.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
354 (let* ((pdf (process-get proc 'pdf-file))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
355 (png (concat (doc-view-file-name-to-directory-name
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
356 doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
357 "page-%d.png")))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
358 (doc-view-pdf/ps->png pdf png))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
359
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
360 (defun doc-view-dvi->pdf (dvi pdf)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
361 "Convert DVI to PDF asynchrounously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
362 (message "DocView: converting DVI to PDF now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
363 (setq doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
364 (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
365 doc-view-dvipdfm-program
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
366 "-o" pdf dvi))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
367 (set-process-sentinel doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
368 'doc-view-dvi->pdf-sentinel)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
369 (process-put doc-view-current-converter-process 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
370 (process-put doc-view-current-converter-process 'pdf-file pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
371
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
372 (defun doc-view-pdf/ps->png-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
373 "If PDF/PS->PNG conversion was successful, update the display."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
374 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
375 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
376 (set-buffer (process-get proc 'buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
377 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
378 (when doc-view-current-timer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
379 (cancel-timer doc-view-current-timer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
380 (setq doc-view-current-timer nil))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
381 (message "DocView: finished conversion from PDF/PS to PNG!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
382 ;; Yippie, finished. Update the display!
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
383 (doc-view-display doc-view-current-doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
384
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
385 (defun doc-view-pdf/ps->png (pdf-ps png)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
386 "Convert PDF-PS to PNG asynchrounously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
387 (message "DocView: converting PDF or PS to PNG now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
388 (setq doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
389 (apply 'start-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
390 (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
391 doc-view-ghostscript-program)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
392 doc-view-ghostscript-options
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
393 (list (concat "-sOutputFile=" png))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
394 (list pdf-ps))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
395 (process-put doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
396 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
397 (set-process-sentinel doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
398 'doc-view-pdf/ps->png-sentinel)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
399 (when doc-view-conversion-refresh-interval
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
400 (setq doc-view-current-timer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
401 (run-at-time "1 secs" doc-view-conversion-refresh-interval
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
402 'doc-view-display
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
403 doc-view-current-doc))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
404
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
405 (defun doc-view-pdf->txt-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
406 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
407 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
408 (let ((current-buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
409 (proc-buffer (process-get proc 'buffer)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
410 (set-buffer proc-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
411 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
412 (message "DocView: finished conversion from PDF to TXT!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
413 ;; If the user looks at the DocView buffer where the conversion was
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
414 ;; performed, search anew. This time it will be queried for a regexp.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
415 (when (eq current-buffer proc-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
416 (doc-view-search)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
417
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
418 (defun doc-view-pdf->txt (pdf txt)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
419 "Convert PDF to TXT asynchrounously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
420 (message "DocView: converting PDF to TXT now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
421 (setq doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
422 (start-process "doc-view-pdf->txt" doc-view-conversion-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
423 doc-view-pdftotext-program "-raw"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
424 pdf txt))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
425 (set-process-sentinel doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
426 'doc-view-pdf->txt-sentinel)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
427 (process-put doc-view-current-converter-process 'buffer (current-buffer)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
428
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
429 (defun doc-view-ps->pdf-sentinel (proc event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
430 (if (not (string-match "finished" event))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
431 (message "DocView: converter process changed status to %s." event)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
432 (set-buffer (process-get proc 'buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
433 (setq doc-view-current-converter-process nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
434 (message "DocView: finished conversion from PS to PDF!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
435 ;; Now we can transform to plain text.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
436 (doc-view-pdf->txt (process-get proc 'pdf-file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
437 (concat (doc-view-file-name-to-directory-name
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
438 doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
439 "doc.txt"))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
440
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
441 (defun doc-view-ps->pdf (ps pdf)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
442 "Convert PS to PDF asynchronously."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
443 (message "DocView: converting PS to PDF now!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
444 (setq doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
445 (start-process "doc-view-ps->pdf" doc-view-conversion-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
446 doc-view-ps2pdf-program
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
447 ps pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
448 (set-process-sentinel doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
449 'doc-view-ps->pdf-sentinel)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
450 (process-put doc-view-current-converter-process 'buffer (current-buffer))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
451 (process-put doc-view-current-converter-process 'pdf-file pdf))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
452
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
453 (defun doc-view-convert-doc (doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
454 "Convert DOC to a set of png files, one file per page.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
455
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
456 Those files are saved in the directory given by
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
457 `doc-view-file-name-to-directory-name'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
458 (clear-image-cache)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
459 (let* ((dir (doc-view-file-name-to-directory-name doc))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
460 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
461 (when (file-exists-p dir)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
462 (dired-delete-file dir 'always))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
463 (make-directory dir t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
464 (if (not (string= (file-name-extension doc) "dvi"))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
465 ;; Convert to PNG images.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
466 (doc-view-pdf/ps->png doc png-file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
467 ;; DVI files have to be converted to PDF before GhostScript can process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
468 ;; it.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
469 (doc-view-dvi->pdf doc
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
470 (concat (file-name-as-directory dir)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
471 "doc.pdf")))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
472
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
473 ;;;; DocView Mode
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
474
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
475 (define-derived-mode doc-view-mode nil "DocView"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
476 "Major mode in DocView buffers.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
477
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
478 \\{doc-view-mode-map}"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
479 :group 'doc-view
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
480 (setq buffer-read-only t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
481 (make-local-variable 'doc-view-current-files)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
482 (make-local-variable 'doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
483 (make-local-variable 'doc-view-current-image)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
484 (make-local-variable 'doc-view-current-page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
485 (make-local-variable 'doc-view-current-converter-process)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
486 (make-local-variable 'doc-view-current-timer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
487 (make-local-variable 'doc-view-current-slice)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
488 (make-local-variable 'doc-view-current-cache-dir)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
489 (make-local-variable 'doc-view-current-info)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
490 (make-local-variable 'doc-view-current-search-matches))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
491
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
492 ;;;; Slicing
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
493
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
494 (defun doc-view-set-slice (x y width height)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
495 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
496 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
497 margins of the document. It prompts for the top-left corner (X
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
498 and Y) of the slice to display and its WIDTH and HEIGHT.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
499
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
500 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
501 do that. To reset the slice use `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
502 (interactive
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
503 (let* ((size (image-size doc-view-current-image t))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
504 (a (read-number (format "Top-left X (0..%d): " (car size))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
505 (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
506 (c (read-number (format "Width (0..%d): " (- (car size) a))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
507 (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
508 (list a b c d)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
509 (setq doc-view-current-slice (list x y width height))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
510 ;; Redisplay
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
511 (doc-view-goto-page doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
512
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
513 (defun doc-view-set-slice-using-mouse ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
514 "Set the slice of the images that should be displayed.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
515 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
516 dragging it to its bottom-right corner. See also
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
517 `doc-view-set-slice' and `doc-view-reset-slice'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
518 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
519 (let (x y w h done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
520 (while (not done)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
521 (let ((e (read-event
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
522 (concat "Press mouse-1 at the top-left corner and "
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
523 "drag it to the bottom-right corner!"))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
524 (when (eq (car e) 'drag-mouse-1)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
525 (setq x (car (posn-object-x-y (event-start e))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
526 (setq y (cdr (posn-object-x-y (event-start e))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
527 (setq w (- (car (posn-object-x-y (event-end e))) x))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
528 (setq h (- (cdr (posn-object-x-y (event-end e))) y))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
529 (setq done t))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
530 (doc-view-set-slice x y w h)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
531
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
532 (defun doc-view-reset-slice ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
533 "Resets the current slice.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
534 After calling this function the whole pages will be visible
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
535 again."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
536 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
537 (setq doc-view-current-slice nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
538 ;; Redisplay
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
539 (doc-view-goto-page doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
540
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
541 ;;;; Display
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
542
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
543 (defun doc-view-insert-image (file &rest args)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
544 "Insert the given png FILE.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
545 ARGs is a list of image descriptors."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
546 (let ((image (apply 'create-image file 'png nil args)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
547 (setq doc-view-current-image image)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
548 (insert-image image (concat "[" file "]") nil doc-view-current-slice)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
549
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
550 (defun doc-view-sort (a b)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
551 "Return non-nil if A should be sorted before B.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
552 Predicate for sorting `doc-view-current-files'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
553 (if (< (length a) (length b))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
554 t
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
555 (if (> (length a) (length b))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
556 nil
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
557 (string< a b))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
558
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
559 (defun doc-view-display (doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
560 "Start viewing the document DOC."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
561 (let ((dir (doc-view-file-name-to-directory-name doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
562 (set-buffer (format "*DocView: %s*" doc))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
563 (setq doc-view-current-files
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
564 (sort (directory-files dir t "page-[0-9]+\\.png" t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
565 'doc-view-sort))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
566 (when (> (length doc-view-current-files) 0)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
567 (doc-view-goto-page doc-view-current-page))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
568
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
569 (defun doc-view-buffer-message ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
570 (setq inhibit-read-only t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
571 (erase-buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
572 (insert (propertize "Welcome to DocView!" 'face 'bold)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
573 "\n"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
574 "
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
575 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
576 view gets converted to PNG now and the conversion of the first
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
577 page hasn't finished yet or
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
578 `doc-view-conversion-refresh-interval' is set to nil.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
579
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
580 For now these keys are useful:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
581
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
582 `q' : Bury this buffer. Conversion will go on in background.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
583 `k' : Kill the conversion process and this buffer.\n")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
584 (setq inhibit-read-only nil))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
585
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
586 (defun doc-view-show-tooltip ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
587 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
588 (tooltip-show doc-view-current-info))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
589
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
590 ;;;; Searching
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
591
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
592 (defun doc-view-search-internal (regexp file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
593 "Return a list of FILE's pages that contain text matching REGEXP.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
594 The value is an alist of the form
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
595
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
596 (PAGE CONTEXTS)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
597
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
598 where PAGE is the pagenumber and CONTEXTS are the lines
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
599 containing the match."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
600 (with-temp-buffer
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
601 (insert-file-contents file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
602 (let ((page 1)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
603 (lastpage 1)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
604 matches)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
605 (while (re-search-forward (concat "\\(?:\\([ ]\\)\\|\\("
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
606 regexp "\\)\\)") nil t)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
607 (when (match-string 1) (incf page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
608 (when (match-string 2)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
609 (if (/= page lastpage)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
610 (setq matches (push (cons page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
611 (list (buffer-substring
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
612 (line-beginning-position)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
613 (line-end-position))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
614 matches))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
615 (setq matches (cons
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
616 (append
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
617 (or
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
618 ;; This page already is a match.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
619 (car matches)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
620 ;; This is the first match on page.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
621 (list page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
622 (list (buffer-substring
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
623 (line-beginning-position)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
624 (line-end-position))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
625 (cdr matches))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
626 (setq lastpage page)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
627 (nreverse matches))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
628
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
629 (defun doc-view-search-no-of-matches (list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
630 "Extract the number of matches from the search result LIST."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
631 (let ((no 0))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
632 (dolist (p list)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
633 (setq no (+ no (1- (length p)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
634 no))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
635
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
636 (defun doc-view-search ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
637 "Query for a regexp and search the current document.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
638 If the current document hasn't been transformed to plain text
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
639 till now do that first. You should try searching anew when the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
640 conversion finished."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
641 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
642 ;; New search, so forget the old results.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
643 (setq doc-view-current-search-matches nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
644 (let ((txt (concat (doc-view-file-name-to-directory-name
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
645 doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
646 "doc.txt")))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
647 (if (file-readable-p txt)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
648 (progn
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
649 (setq doc-view-current-search-matches
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
650 (doc-view-search-internal
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
651 (read-from-minibuffer "Regexp: ")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
652 txt))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
653 (message "DocView: search yielded %d matches."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
654 (doc-view-search-no-of-matches
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
655 doc-view-current-search-matches)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
656 ;; We must convert to TXT first!
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
657 (if doc-view-current-converter-process
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
658 (message "DocView: please wait till conversion finished.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
659 (let ((ext (file-name-extension doc-view-current-doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
660 (cond
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
661 ((string= ext "pdf")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
662 ;; Doc is a PDF, so convert it to TXT
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
663 (doc-view-pdf->txt doc-view-current-doc txt))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
664 ((string= ext "ps")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
665 ;; Doc is a PS, so convert it to PDF (which will be converted to
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
666 ;; TXT thereafter).
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
667 (doc-view-ps->pdf doc-view-current-doc
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
668 (concat (doc-view-file-name-to-directory-name
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
669 doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
670 "doc.pdf")))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
671 ((string= ext "dvi")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
672 ;; Doc is a DVI. This means that a doc.pdf already exists in its
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
673 ;; cache subdirectory.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
674 (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
675 doc-view-current-doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
676 "doc.pdf")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
677 txt))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
678 (t (error "DocView doesn't know what to do"))))))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
679
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
680 (defun doc-view-search-next-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
681 "Go to the ARGth next matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
682 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
683 (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
684 doc-view-current-search-matches))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
685 (page (car (nth (1- arg) next-pages))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
686 (if page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
687 (doc-view-goto-page page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
688 (when (and
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
689 doc-view-current-search-matches
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
690 (y-or-n-p "No more matches after current page. Wrap to first match? "))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
691 (doc-view-goto-page (caar doc-view-current-search-matches))))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
692
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
693 (defun doc-view-search-previous-match (arg)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
694 "Go to the ARGth previous matching page."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
695 (interactive "p")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
696 (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
697 doc-view-current-search-matches))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
698 (page (car (nth (1- arg) (nreverse prev-pages)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
699 (if page
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
700 (doc-view-goto-page page)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
701 (when (and
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
702 doc-view-current-search-matches
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
703 (y-or-n-p "No more matches before current page. Wrap to last match? "))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
704 (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
705
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
706 ;;;; User Interface Commands
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
707
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
708 (defun doc-view (no-cache &optional file)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
709 "Convert FILE to png and start viewing it.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
710 If no FILE is given, query for on.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
711 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
712 existing page files. With prefix arg NO-CACHE, don't use the
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
713 cached files and convert anew."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
714 (interactive "P")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
715 (if (not (and (image-type-available-p 'png)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
716 (display-images-p)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
717 (message "DocView: your emacs or display doesn't support png images.")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
718 (let* ((doc (or file
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
719 (expand-file-name (read-file-name "File: " nil nil t))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
720 (buffer (get-buffer-create (format "*DocView: %s*" doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
721 (dir (doc-view-file-name-to-directory-name doc)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
722 (switch-to-buffer buffer)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
723 (doc-view-buffer-message)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
724 (doc-view-mode)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
725 (setq doc-view-current-doc doc)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
726 (setq doc-view-current-page 1)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
727 (if (not (and (file-exists-p dir)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
728 (not no-cache)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
729 (progn
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
730 (setq doc-view-current-cache-dir nil)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
731 (doc-view-convert-doc doc-view-current-doc))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
732 (message "DocView: using cached files!")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
733 (doc-view-display doc-view-current-doc)))))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
734
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
735 (defun doc-view-dired (no-cache)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
736 "View the current dired file with doc-view.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
737 NO-CACHE is the same as in `doc-view'.
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
738
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
739 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
740
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
741 (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
742 (interactive "P")
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
743 (doc-view no-cache (dired-get-file-for-visit)))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
744
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
745 (defun doc-view-clear-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
746 "Delete the whole cache (`doc-view-cache-directory')."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
747 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
748 (dired-delete-file doc-view-cache-directory 'always)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
749 (make-directory doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
750
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
751 (defun doc-view-dired-cache ()
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
752 "Open `dired' in `doc-view-cache-directory'."
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
753 (interactive)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
754 (dired doc-view-cache-directory))
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
755
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
756 (provide 'doc-view)
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
757
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
758 ;; Local Variables:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
759 ;; mode: outline-minor
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
760 ;; End:
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
761
84450
a8fe8c64e5d0 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 84422
diff changeset
762 ;; arch-tag: 5d6e5c5e-095f-489e-b4e4-1ca90a7d79be
84422
67c730c1c685 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
763 ;;; doc-view.el ends here