aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-01-10 00:05:24 -0500
committerStefan Monnier2013-01-10 00:05:24 -0500
commitbbc7ff25888a28c2c489cd3cb641d9c3e47a1488 (patch)
treef4e292759f2af7427cf296ac0f6d17493126b11c
parent31045a5b61d54617cf6cc76e8991bc41d7853c65 (diff)
downloademacs-bbc7ff25888a28c2c489cd3cb641d9c3e47a1488.tar.gz
emacs-bbc7ff25888a28c2c489cd3cb641d9c3e47a1488.zip
* lisp/doc-view.el (doc-view-pdfdraw-program): Allow "pdfdraw" name.
(doc-view-pdf->png-converter-function): Use mupdf if available. (doc-view-djvu->png-converter-function) (doc-view-ps->png-converter-function): Remove. (doc-view--image-file-pattern): Replace doc-view--image-file-extension. (doc-view-goto-page, doc-view-convert-current-doc, doc-view-display) (doc-view-already-converted-p): Adjust accordingly. (doc-view-mode-p): Simplify. (doc-view-enlarge): Use setq-local. (doc-view-pdf->png-converter-ghostscript) (doc-view-djvu->png-converter-ddjvu) (doc-view-pdf->png-converter-mupdf): Rework to call doc-view-start-process directly. (doc-view-pdf/ps->png): Simplify accordingly. (doc-view-pdf->png-1, doc-view-djvu->png-1): Remove. (doc-view-document->bitmap): Rename from doc-view-document->png. (doc-view-convert-current-doc): Merge pdf and djvu cases. (doc-view-set-slice-from-bounding-box): Fix completion table. (doc-view-mode): Use add-hook for after-revert-hook.
-rw-r--r--lisp/ChangeLog22
-rw-r--r--lisp/doc-view.el235
2 files changed, 122 insertions, 135 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b9f35e6567c..8611edd3bfc 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,25 @@
12013-01-10 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * doc-view.el (doc-view-pdfdraw-program): Allow "pdfdraw" name.
4 (doc-view-pdf->png-converter-function): Use mupdf if available.
5 (doc-view-djvu->png-converter-function)
6 (doc-view-ps->png-converter-function): Remove.
7 (doc-view--image-file-pattern): Replace doc-view--image-file-extension.
8 (doc-view-goto-page, doc-view-convert-current-doc, doc-view-display)
9 (doc-view-already-converted-p): Adjust accordingly.
10 (doc-view-mode-p): Simplify.
11 (doc-view-enlarge): Use setq-local.
12 (doc-view-pdf->png-converter-ghostscript)
13 (doc-view-djvu->png-converter-ddjvu)
14 (doc-view-pdf->png-converter-mupdf): Rework to call
15 doc-view-start-process directly.
16 (doc-view-pdf/ps->png): Simplify accordingly.
17 (doc-view-pdf->png-1, doc-view-djvu->png-1): Remove.
18 (doc-view-document->bitmap): Rename from doc-view-document->png.
19 (doc-view-convert-current-doc): Merge pdf and djvu cases.
20 (doc-view-set-slice-from-bounding-box): Fix completion table.
21 (doc-view-mode): Use add-hook for after-revert-hook.
22
12013-01-10 Glenn Morris <rgm@gnu.org> 232013-01-10 Glenn Morris <rgm@gnu.org>
2 24
3 * emacs-lisp/authors.el (authors-ignored-files) 25 * emacs-lisp/authors.el (authors-ignored-files)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 0658a11c30a..9748a5f5f72 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -158,13 +158,18 @@
158 :type 'file 158 :type 'file
159 :group 'doc-view) 159 :group 'doc-view)
160 160
161(defcustom doc-view-pdfdraw-program "mudraw" 161(defcustom doc-view-pdfdraw-program
162 "Program to convert PDF files to PNG." 162 (cond
163 ((executable-find "pdfdraw") "pdfdraw")
164 (t "mudraw"))
165 "Name of MuPDF's program to convert PDF files to PNG."
163 :type 'file 166 :type 'file
164 :version "24.4") 167 :version "24.4")
165 168
166(defcustom doc-view-pdf->png-converter-function 169(defcustom doc-view-pdf->png-converter-function
167 'doc-view-pdf->png-converter-ghostscript 170 (if (executable-find doc-view-pdfdraw-program)
171 #'doc-view-pdf->png-converter-mupdf
172 #'doc-view-pdf->png-converter-ghostscript)
168 "Function to call to convert a PDF file into a PNG file." 173 "Function to call to convert a PDF file into a PNG file."
169 :type '(radio 174 :type '(radio
170 (function-item doc-view-pdf->png-converter-ghostscript 175 (function-item doc-view-pdf->png-converter-ghostscript
@@ -174,23 +179,6 @@
174 function) 179 function)
175 :version "24.4") 180 :version "24.4")
176 181
177;; FIXME: Get rid of it: there's no choice.
178(defcustom doc-view-djvu->png-converter-function
179 'doc-view-djvu->png-converter-ddjvu
180 "Function to call to convert a DJVU file into a PNG file"
181 :type '(radio (function-item doc-view-djvu->png-converter-ddjvu
182 :doc "Use ddjvu")
183 function))
184
185;; FIXME: Get rid of it: there's no choice.
186(defcustom doc-view-ps->png-converter-function
187 'doc-view-ps->png-converter-ghostscript
188 "Function to call to convert a PS file into a PNG file."
189 :type '(radio (function-item doc-view-ps->png-converter-ghostscript
190 :doc "Use ghostscript")
191 function)
192 :version "24.4")
193
194(defcustom doc-view-ghostscript-options 182(defcustom doc-view-ghostscript-options
195 '("-dSAFER" ;; Avoid security problems when rendering files from untrusted 183 '("-dSAFER" ;; Avoid security problems when rendering files from untrusted
196 ;; sources. 184 ;; sources.
@@ -358,14 +346,13 @@ Can be `dvi', `pdf', or `ps'.")
358May operate on the source document or on some intermediate (typically PDF) 346May operate on the source document or on some intermediate (typically PDF)
359conversion of it.") 347conversion of it.")
360 348
361(defvar doc-view--image-type nil 349(defvar-local doc-view--image-type nil
362 "The type of image in the current buffer. 350 "The type of image in the current buffer.
363Can be `png' or `tiff'.") 351Can be `png' or `tiff'.")
364 352
365(defvar doc-view--image-file-extension nil 353(defvar-local doc-view--image-file-pattern nil
366 ;; FIXME: Replace it with a `format' string, like "page-%d.png". 354 "The `format' pattern of image file names.
367 "The file extension of the image type in the current buffer. 355Typically \"page-%s.png\".")
368Can be `png' or `tif'.")
369 356
370;;;; DocView Keymaps 357;;;; DocView Keymaps
371 358
@@ -506,7 +493,7 @@ Can be `png' or `tif'.")
506 ;; that's not right if the pages are not generated sequentially 493 ;; that's not right if the pages are not generated sequentially
507 ;; or if the page isn't in doc-view-current-files yet. 494 ;; or if the page isn't in doc-view-current-files yet.
508 (let ((file (expand-file-name 495 (let ((file (expand-file-name
509 (format "page-%d.%s" page doc-view--image-file-extension) 496 (format doc-view--image-file-pattern page)
510 (doc-view-current-cache-dir)))) 497 (doc-view-current-cache-dir))))
511 (doc-view-insert-image file :pointer 'arrow) 498 (doc-view-insert-image file :pointer 'arrow)
512 (set-window-hscroll (selected-window) hscroll) 499 (set-window-hscroll (selected-window) hscroll)
@@ -708,8 +695,7 @@ OpenDocument format)."
708 (executable-find doc-view-dvipdf-program)) 695 (executable-find doc-view-dvipdf-program))
709 (and doc-view-dvipdfm-program 696 (and doc-view-dvipdfm-program
710 (executable-find doc-view-dvipdfm-program))))) 697 (executable-find doc-view-dvipdfm-program)))))
711 ((or (eq type 'postscript) (eq type 'ps) (eq type 'eps) 698 ((memq type '(postscript ps eps pdf))
712 (eq type 'pdf))
713 ;; FIXME: allow mupdf here 699 ;; FIXME: allow mupdf here
714 (and doc-view-ghostscript-program 700 (and doc-view-ghostscript-program
715 (executable-find doc-view-ghostscript-program))) 701 (executable-find doc-view-ghostscript-program)))
@@ -735,13 +721,13 @@ OpenDocument format)."
735 ;; ImageMagick supports on-the-fly-rescaling. 721 ;; ImageMagick supports on-the-fly-rescaling.
736 (let ((new (ceiling (* factor doc-view-image-width)))) 722 (let ((new (ceiling (* factor doc-view-image-width))))
737 (unless (equal new doc-view-image-width) 723 (unless (equal new doc-view-image-width)
738 (set (make-local-variable 'doc-view-image-width) new) 724 (setq-local doc-view-image-width new)
739 (doc-view-insert-image 725 (doc-view-insert-image
740 (plist-get (cdr (doc-view-current-image)) :file) 726 (plist-get (cdr (doc-view-current-image)) :file)
741 :width doc-view-image-width))) 727 :width doc-view-image-width)))
742 (let ((new (ceiling (* factor doc-view-resolution)))) 728 (let ((new (ceiling (* factor doc-view-resolution))))
743 (unless (equal new doc-view-resolution) 729 (unless (equal new doc-view-resolution)
744 (set (make-local-variable 'doc-view-resolution) new) 730 (setq-local doc-view-resolution new)
745 (doc-view-reconvert-doc))))) 731 (doc-view-reconvert-doc)))))
746 732
747(defun doc-view-shrink (factor) 733(defun doc-view-shrink (factor)
@@ -878,35 +864,44 @@ Should be invoked when the cached images aren't up-to-date."
878 (list "-o" pdf dvi) 864 (list "-o" pdf dvi)
879 callback))) 865 callback)))
880 866
881(defun doc-view-pdf->png-converter-ghostscript (resolution pdf png &optional page) 867(defun doc-view-pdf->png-converter-ghostscript (pdf png page callback)
882 `((command . ,doc-view-ghostscript-program) 868 (doc-view-start-process
883 (arguments . (,@doc-view-ghostscript-options 869 "pdf/ps->png" doc-view-ghostscript-program
884 ,(format "-r%d" resolution) 870 `(,@doc-view-ghostscript-options
885 ,@(if page `(,(format "-dFirstPage=%d" page))) 871 ,(format "-r%d" (round doc-view-resolution))
886 ,@(if page `(,(format "-dLastPage=%d" page))) 872 ,@(if page `(,(format "-dFirstPage=%d" page)))
887 ,(concat "-sOutputFile=" png) 873 ,@(if page `(,(format "-dLastPage=%d" page)))
888 ,pdf)))) 874 ,(concat "-sOutputFile=" png)
875 ,pdf)
876 callback))
889 877
890(defalias 'doc-view-ps->png-converter-ghostscript 878(defalias 'doc-view-ps->png-converter-ghostscript
891 'doc-view-pdf->png-converter-ghostscript) 879 'doc-view-pdf->png-converter-ghostscript)
892 880
893(defun doc-view-djvu->png-converter-ddjvu (resolution djvu png &optional page) 881(defun doc-view-djvu->tiff-converter-ddjvu (djvu tiff page callback)
894 `((command . "ddjvu") 882 "Convert PAGE of a DJVU file to bitmap(s) asynchronously.
895 (arguments . ("-format=tiff" 883Call CALLBACK with no arguments when done.
896 ;; ddjvu only accepts the range 1-999. 884If PAGE is nil, convert the whole document."
897 ,(format "-scale=%d" resolution) 885 (doc-view-start-process
898 ;; -eachpage was only added after djvulibre-3.5.25.3! 886 "djvu->tiff" "ddjvu"
899 ,@(unless page '("-eachpage")) 887 `("-format=tiff"
900 ,@(if page `(,(format "-page=%d" page))) 888 ;; ddjvu only accepts the range 1-999.
901 ,djvu 889 ,(format "-scale=%d" (round doc-view-resolution))
902 ,png)))) 890 ;; -eachpage was only added after djvulibre-3.5.25.3!
903 891 ,@(unless page '("-eachpage"))
904(defun doc-view-pdf->png-converter-mupdf (resolution pdf png &optional page) 892 ,@(if page `(,(format "-page=%d" page)))
905 `((command . ,doc-view-pdfdraw-program) 893 ,djvu
906 (arguments . (,(concat "-o" png) 894 ,tiff)
907 ,(format "-r%d" resolution) 895 callback))
908 ,pdf 896
909 ,@(if page `(,(format "%d" page))))))) 897(defun doc-view-pdf->png-converter-mupdf (pdf png page callback)
898 (doc-view-start-process
899 "pdf->png" doc-view-pdfdraw-program
900 `(,(concat "-o" png)
901 ,(format "-r%d" (round doc-view-resolution))
902 ,pdf
903 ,@(if page `(,(format "%d" page))))
904 callback))
910 905
911(defun doc-view-odf->pdf (odf callback) 906(defun doc-view-odf->pdf (odf callback)
912 "Convert ODF to PDF asynchronously and call CALLBACK when finished. 907 "Convert ODF to PDF asynchronously and call CALLBACK when finished.
@@ -919,16 +914,12 @@ is named like ODF with the extension turned to pdf."
919(defun doc-view-pdf/ps->png (pdf-ps png) 914(defun doc-view-pdf/ps->png (pdf-ps png)
920 ;; FIXME: Fix name and docstring to account for djvu&tiff. 915 ;; FIXME: Fix name and docstring to account for djvu&tiff.
921 "Convert PDF-PS to PNG asynchronously." 916 "Convert PDF-PS to PNG asynchronously."
922 (let ((invocation 917 (funcall
923 (funcall (pcase doc-view-doc-type 918 (pcase doc-view-doc-type
924 (`pdf doc-view-pdf->png-converter-function) 919 (`pdf doc-view-pdf->png-converter-function)
925 (`djvu doc-view-djvu->png-converter-function) 920 (`djvu #'doc-view-djvu->tiff-converter-ddjvu)
926 (_ doc-view-ps->png-converter-function)) 921 (_ #'doc-view-ps->png-converter-ghostscript))
927 (round doc-view-resolution) pdf-ps png))) 922 pdf-ps png nil
928
929 (doc-view-start-process
930 "pdf/ps->png" (cdr (assoc 'command invocation))
931 (cdr (assoc 'arguments invocation))
932 (let ((resolution doc-view-resolution)) 923 (let ((resolution doc-view-resolution))
933 (lambda () 924 (lambda ()
934 ;; Only create the resolution file when it's all done, so it also 925 ;; Only create the resolution file when it's all done, so it also
@@ -940,7 +931,8 @@ is named like ODF with the extension turned to pdf."
940 (when doc-view-current-timer 931 (when doc-view-current-timer
941 (cancel-timer doc-view-current-timer) 932 (cancel-timer doc-view-current-timer)
942 (setq doc-view-current-timer nil)) 933 (setq doc-view-current-timer nil))
943 (doc-view-display (current-buffer) 'force))))) 934 (doc-view-display (current-buffer) 'force))))
935
944 ;; Update the displayed pages as soon as they're done generating. 936 ;; Update the displayed pages as soon as they're done generating.
945 (when doc-view-conversion-refresh-interval 937 (when doc-view-conversion-refresh-interval
946 (setq doc-view-current-timer 938 (setq doc-view-current-timer
@@ -948,31 +940,10 @@ is named like ODF with the extension turned to pdf."
948 'doc-view-display 940 'doc-view-display
949 (current-buffer))))) 941 (current-buffer)))))
950 942
951(defun doc-view-pdf->png-1 (pdf png page callback)
952 "Convert a PAGE of a PDF file to PNG asynchronously.
953Call CALLBACK with no arguments when done."
954 (let ((invocation (funcall doc-view-pdf->png-converter-function
955 (round doc-view-resolution) pdf png page)))
956 (doc-view-start-process
957 "pdf/ps->png" (cdr (assoc 'command invocation))
958 (cdr (assoc 'arguments invocation))
959 callback)))
960
961(defun doc-view-djvu->png-1 (djvu png page callback)
962 "Convert a PAGE of a DJVU file to bitmap asynchronously.
963Call CALLBACK with no arguments when done."
964 (let ((invocation (funcall doc-view-djvu->png-converter-function
965 (round doc-view-resolution) djvu png page)))
966 (doc-view-start-process
967 "djvu->png" (cdr (assoc 'command invocation))
968 (cdr (assoc 'arguments invocation))
969 callback)))
970
971(declare-function clear-image-cache "image.c" (&optional filter)) 943(declare-function clear-image-cache "image.c" (&optional filter))
972 944
973(defun doc-view-document->png (pdf png pages single-page-converter) 945(defun doc-view-document->bitmap (pdf png pages single-page-converter)
974 ;; FIXME: Fix docstring. 946 "Convert a document file to bitmap images asynchronously.
975 "Convert a PDF file to PNG asynchronously.
976Start by converting PAGES, and then the rest." 947Start by converting PAGES, and then the rest."
977 (if (null pages) 948 (if (null pages)
978 (doc-view-pdf/ps->png pdf png) 949 (doc-view-pdf/ps->png pdf png)
@@ -985,7 +956,7 @@ Start by converting PAGES, and then the rest."
985 pdf (format png (car pages)) (car pages) 956 pdf (format png (car pages)) (car pages)
986 (lambda () 957 (lambda ()
987 (if rest 958 (if rest
988 (doc-view-document->png pdf png rest) 959 (doc-view-document->bitmap pdf png rest)
989 ;; Yippie, the important pages are done, update the display. 960 ;; Yippie, the important pages are done, update the display.
990 (clear-image-cache) 961 (clear-image-cache)
991 ;; For the windows that have a message (like "Welcome to 962 ;; For the windows that have a message (like "Welcome to
@@ -1065,7 +1036,7 @@ Those files are saved in the directory given by the function
1065 ;; resets during the redisplay). 1036 ;; resets during the redisplay).
1066 (setq doc-view-pending-cache-flush t) 1037 (setq doc-view-pending-cache-flush t)
1067 (let ((png-file (expand-file-name 1038 (let ((png-file (expand-file-name
1068 (concat "page-%d." doc-view--image-file-extension) 1039 (format doc-view--image-file-pattern "%d")
1069 (doc-view-current-cache-dir)))) 1040 (doc-view-current-cache-dir))))
1070 (make-directory (doc-view-current-cache-dir) t) 1041 (make-directory (doc-view-current-cache-dir) t)
1071 (pcase doc-view-doc-type 1042 (pcase doc-view-doc-type
@@ -1092,15 +1063,11 @@ Those files are saved in the directory given by the function
1092 ;; Rename to doc.pdf 1063 ;; Rename to doc.pdf
1093 (rename-file opdf pdf) 1064 (rename-file opdf pdf)
1094 (doc-view-pdf/ps->png pdf png-file))))) 1065 (doc-view-pdf/ps->png pdf png-file)))))
1095 (`pdf 1066 ((or `pdf `djvu)
1096 (let ((pages (doc-view-active-pages)))
1097 ;; Convert PDF to PNG images starting with the active pages.
1098 (doc-view-document->png doc-view-buffer-file-name png-file pages
1099 'doc-view-pdf->png-1)))
1100 (`djvu
1101 (let ((pages (doc-view-active-pages))) 1067 (let ((pages (doc-view-active-pages)))
1102 (doc-view-document->png doc-view-buffer-file-name png-file pages 1068 ;; Convert doc to bitmap images starting with the active pages.
1103 'doc-view-djvu->png-1))) 1069 (doc-view-document->bitmap doc-view-buffer-file-name png-file pages
1070 doc-view-single-page-converter-function)))
1104 (_ 1071 (_
1105 ;; Convert to PNG images. 1072 ;; Convert to PNG images.
1106 (doc-view-pdf/ps->png doc-view-buffer-file-name png-file))))) 1073 (doc-view-pdf/ps->png doc-view-buffer-file-name png-file)))))
@@ -1211,9 +1178,10 @@ much more accurate than could be done manually using
1211 (let* ((is (image-size (doc-view-current-image) t)) 1178 (let* ((is (image-size (doc-view-current-image) t))
1212 (iw (car is)) 1179 (iw (car is))
1213 (ih (cdr is)) 1180 (ih (cdr is))
1214 (ps (or (and (null force-paper-size) (doc-view-guess-paper-size iw ih)) 1181 (ps (or (and (null force-paper-size)
1182 (doc-view-guess-paper-size iw ih))
1215 (intern (completing-read "Paper size: " 1183 (intern (completing-read "Paper size: "
1216 (mapcar #'car doc-view-paper-sizes) 1184 doc-view-paper-sizes
1217 nil t)))) 1185 nil t))))
1218 (bb (doc-view-scale-bounding-box ps iw ih bb)) 1186 (bb (doc-view-scale-bounding-box ps iw ih bb))
1219 (x1 (nth 0 bb)) 1187 (x1 (nth 0 bb))
@@ -1294,16 +1262,15 @@ have the page we want to view."
1294 (let ((prev-pages doc-view-current-files)) 1262 (let ((prev-pages doc-view-current-files))
1295 (setq doc-view-current-files 1263 (setq doc-view-current-files
1296 (sort (directory-files (doc-view-current-cache-dir) t 1264 (sort (directory-files (doc-view-current-cache-dir) t
1297 (concat "page-[0-9]+\\." 1265 (format doc-view--image-file-pattern
1298 doc-view--image-file-extension) 1266 "[0-9]+")
1299 t) 1267 t)
1300 'doc-view-sort)) 1268 'doc-view-sort))
1301 (dolist (win (or (get-buffer-window-list buffer nil t) 1269 (dolist (win (or (get-buffer-window-list buffer nil t)
1302 (list t))) 1270 (list t)))
1303 (let* ((page (doc-view-current-page win)) 1271 (let* ((page (doc-view-current-page win))
1304 (pagefile (expand-file-name 1272 (pagefile (expand-file-name
1305 (format "page-%d.%s" 1273 (format doc-view--image-file-pattern page)
1306 page doc-view--image-file-extension)
1307 (doc-view-current-cache-dir)))) 1274 (doc-view-current-cache-dir))))
1308 (when (or force 1275 (when (or force
1309 (and (not (member pagefile prev-pages)) 1276 (and (not (member pagefile prev-pages))
@@ -1369,7 +1336,7 @@ For now these keys are useful:
1369 (doc-view-kill-proc) 1336 (doc-view-kill-proc)
1370 (setq buffer-read-only nil) 1337 (setq buffer-read-only nil)
1371 (remove-overlays (point-min) (point-max) 'doc-view t) 1338 (remove-overlays (point-min) (point-max) 'doc-view t)
1372 (set (make-local-variable 'image-mode-winprops-alist) t) 1339 (setq-local image-mode-winprops-alist t)
1373 ;; Switch to the previously used major mode or fall back to 1340 ;; Switch to the previously used major mode or fall back to
1374 ;; normal mode. 1341 ;; normal mode.
1375 (doc-view-fallback-mode) 1342 (doc-view-fallback-mode)
@@ -1499,7 +1466,7 @@ If BACKWARD is non-nil, jump to the previous match."
1499 (doc-view-current-cache-dir))) 1466 (doc-view-current-cache-dir)))
1500 (> (length (directory-files 1467 (> (length (directory-files
1501 (doc-view-current-cache-dir) 1468 (doc-view-current-cache-dir)
1502 nil (concat "\\." doc-view--image-file-extension "\\'"))) 1469 nil (format doc-view--image-file-pattern "[0-9]+")))
1503 0))) 1470 0)))
1504 1471
1505(defun doc-view-initiate-display () 1472(defun doc-view-initiate-display ()
@@ -1511,7 +1478,7 @@ If BACKWARD is non-nil, jump to the previous match."
1511 (if (doc-view-already-converted-p) 1478 (if (doc-view-already-converted-p)
1512 (progn 1479 (progn
1513 (message "DocView: using cached files!") 1480 (message "DocView: using cached files!")
1514 ;; Load the saved resolution 1481 ;; Load the saved resolution.
1515 (let* ((res-file (expand-file-name "resolution.el" 1482 (let* ((res-file (expand-file-name "resolution.el"
1516 (doc-view-current-cache-dir))) 1483 (doc-view-current-cache-dir)))
1517 (res 1484 (res
@@ -1520,7 +1487,7 @@ If BACKWARD is non-nil, jump to the previous match."
1520 (insert-file-contents res-file) 1487 (insert-file-contents res-file)
1521 (read (current-buffer)))))) 1488 (read (current-buffer))))))
1522 (when (numberp res) 1489 (when (numberp res)
1523 (set (make-local-variable 'doc-view-resolution) res))) 1490 (setq-local doc-view-resolution res)))
1524 (doc-view-display (current-buffer) 'force)) 1491 (doc-view-display (current-buffer) 'force))
1525 (doc-view-convert-current-doc)) 1492 (doc-view-convert-current-doc))
1526 (message 1493 (message
@@ -1590,23 +1557,23 @@ If BACKWARD is non-nil, jump to the previous match."
1590 ((looking-at "%PDF") '(pdf)) 1557 ((looking-at "%PDF") '(pdf))
1591 ((looking-at "\367\002") '(dvi)) 1558 ((looking-at "\367\002") '(dvi))
1592 ((looking-at "AT&TFORM") '(djvu)))))) 1559 ((looking-at "AT&TFORM") '(djvu))))))
1593 (set (make-local-variable 'doc-view-doc-type) 1560 (setq-local doc-view-doc-type
1594 (car (or (doc-view-intersection name-types content-types) 1561 (car (or (doc-view-intersection name-types content-types)
1595 (when (and name-types content-types) 1562 (when (and name-types content-types)
1596 (error "Conflicting types: name says %s but content says %s" 1563 (error "Conflicting types: name says %s but content says %s"
1597 name-types content-types)) 1564 name-types content-types))
1598 name-types content-types 1565 name-types content-types
1599 (error "Cannot determine the document type")))))) 1566 (error "Cannot determine the document type"))))))
1600 1567
1601(defun doc-view-set-up-single-converter () 1568(defun doc-view-set-up-single-converter ()
1602 "Find the right single-page converter for the current document type" 1569 "Find the right single-page converter for the current document type"
1603 (pcase-let ((`(,conv-function ,type ,extension) 1570 (pcase-let ((`(,conv-function ,type ,extension)
1604 (pcase doc-view-doc-type 1571 (pcase doc-view-doc-type
1605 (`djvu (list #'doc-view-djvu->png-1 'tiff "tif")) 1572 (`djvu (list #'doc-view-djvu->tiff-converter-ddjvu 'tiff "tif"))
1606 (_ (list #'doc-view-pdf->png-1 'png "png"))))) 1573 (_ (list doc-view-pdf->png-converter-function 'png "png")))))
1607 (setq-local doc-view-single-page-converter-function conv-function) 1574 (setq-local doc-view-single-page-converter-function conv-function)
1608 (setq-local doc-view--image-type type) 1575 (setq-local doc-view--image-type type)
1609 (setq-local doc-view--image-file-extension extension))) 1576 (setq-local doc-view--image-file-pattern (concat "page-%s." extension))))
1610 1577
1611;;;###autoload 1578;;;###autoload
1612(defun doc-view-mode () 1579(defun doc-view-mode ()
@@ -1631,8 +1598,7 @@ toggle between displaying the document or editing it as text.
1631 (unless (eq major-mode 'fundamental-mode) 1598 (unless (eq major-mode 'fundamental-mode)
1632 major-mode)))) 1599 major-mode))))
1633 (kill-all-local-variables) 1600 (kill-all-local-variables)
1634 (set (make-local-variable 'doc-view-previous-major-mode) 1601 (setq-local doc-view-previous-major-mode prev-major-mode))
1635 prev-major-mode))
1636 1602
1637 (dolist (var doc-view-saved-settings) 1603 (dolist (var doc-view-saved-settings)
1638 (set (make-local-variable (car var)) (cdr var))) 1604 (set (make-local-variable (car var)) (cdr var)))
@@ -1644,7 +1610,7 @@ toggle between displaying the document or editing it as text.
1644 1610
1645 (doc-view-make-safe-dir doc-view-cache-directory) 1611 (doc-view-make-safe-dir doc-view-cache-directory)
1646 ;; Handle compressed files, remote files, files inside archives 1612 ;; Handle compressed files, remote files, files inside archives
1647 (set (make-local-variable 'doc-view-buffer-file-name) 1613 (setq-local doc-view-buffer-file-name
1648 (cond 1614 (cond
1649 (jka-compr-really-do-compress 1615 (jka-compr-really-do-compress
1650 ;; FIXME: there's a risk of name conflicts here. 1616 ;; FIXME: there's a risk of name conflicts here.
@@ -1683,20 +1649,19 @@ toggle between displaying the document or editing it as text.
1683 'doc-view-new-window-function nil t) 1649 'doc-view-new-window-function nil t)
1684 (image-mode-setup-winprops) 1650 (image-mode-setup-winprops)
1685 1651
1686 (set (make-local-variable 'mode-line-position) 1652 (setq-local mode-line-position
1687 '(" P" (:eval (number-to-string (doc-view-current-page))) 1653 '(" P" (:eval (number-to-string (doc-view-current-page)))
1688 "/" (:eval (number-to-string (doc-view-last-page-number))))) 1654 "/" (:eval (number-to-string (doc-view-last-page-number)))))
1689 ;; Don't scroll unless the user specifically asked for it. 1655 ;; Don't scroll unless the user specifically asked for it.
1690 (set (make-local-variable 'auto-hscroll-mode) nil) 1656 (setq-local auto-hscroll-mode nil)
1691 (set (make-local-variable 'mwheel-scroll-up-function) 1657 (setq-local mwheel-scroll-up-function #'doc-view-scroll-up-or-next-page)
1692 'doc-view-scroll-up-or-next-page) 1658 (setq-local mwheel-scroll-down-function
1693 (set (make-local-variable 'mwheel-scroll-down-function) 1659 #'doc-view-scroll-down-or-previous-page)
1694 'doc-view-scroll-down-or-previous-page) 1660 (setq-local cursor-type nil)
1695 (set (make-local-variable 'cursor-type) nil)
1696 (use-local-map doc-view-mode-map) 1661 (use-local-map doc-view-mode-map)
1697 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc) 1662 (add-hook 'after-revert-hook 'doc-view-reconvert-doc nil t)
1698 (set (make-local-variable 'bookmark-make-record-function) 1663 (setq-local bookmark-make-record-function
1699 'doc-view-bookmark-make-record) 1664 #'doc-view-bookmark-make-record)
1700 (setq mode-name "DocView" 1665 (setq mode-name "DocView"
1701 buffer-read-only t 1666 buffer-read-only t
1702 major-mode 'doc-view-mode) 1667 major-mode 'doc-view-mode)
@@ -1705,7 +1670,7 @@ toggle between displaying the document or editing it as text.
1705 ;; canonical view mode for PDF/PS/DVI files. This could be 1670 ;; canonical view mode for PDF/PS/DVI files. This could be
1706 ;; switched on automatically depending on the value of 1671 ;; switched on automatically depending on the value of
1707 ;; `view-read-only'. 1672 ;; `view-read-only'.
1708 (set (make-local-variable 'view-read-only) nil) 1673 (setq-local view-read-only nil)
1709 (run-mode-hooks 'doc-view-mode-hook))) 1674 (run-mode-hooks 'doc-view-mode-hook)))
1710 1675
1711(defun doc-view-fallback-mode () 1676(defun doc-view-fallback-mode ()