diff options
| author | Stefan Monnier | 2019-01-23 17:27:21 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2019-01-23 17:27:21 -0500 |
| commit | 95b2f1a0c05fa72248afd87ebf79d0667dba0278 (patch) | |
| tree | 8499e9496879ba63e97351df959cf1ae4562620c | |
| parent | dbc48d758ac90748df4befc677b2d21c5cd06d3b (diff) | |
| download | emacs-95b2f1a0c05fa72248afd87ebf79d0667dba0278.tar.gz emacs-95b2f1a0c05fa72248afd87ebf79d0667dba0278.zip | |
doc-view-presentation, doc-view-fit-window-to-page, and use mutool
* lisp/doc-view.el (doc-view-pdfdraw-program): Use "mutool" if available.
(doc-view-mode-map): Keep default 'g' binding of 'revert-buffer'.
Change 'r' binding to 'revert-buffer'.
(doc-view-revert-buffer): Make it an obsolete alias.
(doc-view--revert-buffer): Rename from doc-view-revert-buffer, change
calling convention for use in add-function.
(doc-view-fit-window-to-page): New command.
(doc-view-pdf->png-converter-mupdf): Make it work with "mutool".
(doc-view-mode): Use add-function for revert-buffer-function.
(doc-view-presentation-mode-map, doc-view-presentation--src-data):
New vars.
(doc-view-presentation-exit, doc-view-presentation-mode)
(doc-view-presentation--propagate-pn, doc-view-presentation):
New functions.
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/doc-view.el | 198 |
2 files changed, 154 insertions, 47 deletions
| @@ -334,6 +334,9 @@ the node "(emacs) Directory Variables" of the user manual. | |||
| 334 | 334 | ||
| 335 | * Changes in Specialized Modes and Packages in Emacs 27.1 | 335 | * Changes in Specialized Modes and Packages in Emacs 27.1 |
| 336 | 336 | ||
| 337 | ** doc-view-mode | ||
| 338 | *** New commands doc-view-presentation and doc-view-fit-window-to-page | ||
| 339 | |||
| 337 | ** map.el | 340 | ** map.el |
| 338 | *** Now also understands plists. | 341 | *** Now also understands plists. |
| 339 | *** Now defined via generic functions that can be extended via 'cl-defmethod'. | 342 | *** Now defined via generic functions that can be extended via 'cl-defmethod'. |
diff --git a/lisp/doc-view.el b/lisp/doc-view.el index af025ec9974..df8a9fc70fe 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el | |||
| @@ -155,12 +155,13 @@ | |||
| 155 | 155 | ||
| 156 | (defcustom doc-view-ghostscript-program "gs" | 156 | (defcustom doc-view-ghostscript-program "gs" |
| 157 | "Program to convert PS and PDF files to PNG." | 157 | "Program to convert PS and PDF files to PNG." |
| 158 | :type 'file | 158 | :type 'file) |
| 159 | :group 'doc-view) | ||
| 160 | 159 | ||
| 161 | (defcustom doc-view-pdfdraw-program | 160 | (defcustom doc-view-pdfdraw-program |
| 162 | (cond | 161 | (cond |
| 163 | ((executable-find "pdfdraw") "pdfdraw") | 162 | ((executable-find "pdfdraw") "pdfdraw") |
| 163 | ((executable-find "mudraw") "mudraw") | ||
| 164 | ((executable-find "mutool") "mutool") | ||
| 164 | (t "mudraw")) | 165 | (t "mudraw")) |
| 165 | "Name of MuPDF's program to convert PDF files to PNG." | 166 | "Name of MuPDF's program to convert PDF files to PNG." |
| 166 | :type 'file | 167 | :type 'file |
| @@ -185,14 +186,12 @@ | |||
| 185 | "-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4" | 186 | "-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4" |
| 186 | "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET") | 187 | "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET") |
| 187 | "A list of options to give to ghostscript." | 188 | "A list of options to give to ghostscript." |
| 188 | :type '(repeat string) | 189 | :type '(repeat string)) |
| 189 | :group 'doc-view) | ||
| 190 | 190 | ||
| 191 | (defcustom doc-view-resolution 100 | 191 | (defcustom doc-view-resolution 100 |
| 192 | "Dots per inch resolution used to render the documents. | 192 | "Dots per inch resolution used to render the documents. |
| 193 | Higher values result in larger images." | 193 | Higher values result in larger images." |
| 194 | :type 'number | 194 | :type 'number) |
| 195 | :group 'doc-view) | ||
| 196 | 195 | ||
| 197 | (defcustom doc-view-scale-internally t | 196 | (defcustom doc-view-scale-internally t |
| 198 | "Whether we should try to rescale images ourselves. | 197 | "Whether we should try to rescale images ourselves. |
| @@ -207,8 +206,7 @@ scaling." | |||
| 207 | Has only an effect if `doc-view-scale-internally' is non-nil and support for | 206 | Has only an effect if `doc-view-scale-internally' is non-nil and support for |
| 208 | scaling is compiled into emacs." | 207 | scaling is compiled into emacs." |
| 209 | :version "24.1" | 208 | :version "24.1" |
| 210 | :type 'number | 209 | :type 'number) |
| 211 | :group 'doc-view) | ||
| 212 | 210 | ||
| 213 | (defcustom doc-view-dvipdfm-program "dvipdfm" | 211 | (defcustom doc-view-dvipdfm-program "dvipdfm" |
| 214 | "Program to convert DVI files to PDF. | 212 | "Program to convert DVI files to PDF. |
| @@ -218,8 +216,7 @@ converted to PNG. | |||
| 218 | 216 | ||
| 219 | If this and `doc-view-dvipdf-program' are set, | 217 | If this and `doc-view-dvipdf-program' are set, |
| 220 | `doc-view-dvipdf-program' will be preferred." | 218 | `doc-view-dvipdf-program' will be preferred." |
| 221 | :type 'file | 219 | :type 'file) |
| 222 | :group 'doc-view) | ||
| 223 | 220 | ||
| 224 | (defcustom doc-view-dvipdf-program "dvipdf" | 221 | (defcustom doc-view-dvipdf-program "dvipdf" |
| 225 | "Program to convert DVI files to PDF. | 222 | "Program to convert DVI files to PDF. |
| @@ -229,8 +226,7 @@ converted to PNG. | |||
| 229 | 226 | ||
| 230 | If this and `doc-view-dvipdfm-program' are set, | 227 | If this and `doc-view-dvipdfm-program' are set, |
| 231 | `doc-view-dvipdf-program' will be preferred." | 228 | `doc-view-dvipdf-program' will be preferred." |
| 232 | :type 'file | 229 | :type 'file) |
| 233 | :group 'doc-view) | ||
| 234 | 230 | ||
| 235 | (define-obsolete-variable-alias 'doc-view-unoconv-program | 231 | (define-obsolete-variable-alias 'doc-view-unoconv-program |
| 236 | 'doc-view-odf->pdf-converter-program | 232 | 'doc-view-odf->pdf-converter-program |
| @@ -245,8 +241,7 @@ If this and `doc-view-dvipdfm-program' are set, | |||
| 245 | 241 | ||
| 246 | Needed for viewing OpenOffice.org (and MS Office) files." | 242 | Needed for viewing OpenOffice.org (and MS Office) files." |
| 247 | :version "24.4" | 243 | :version "24.4" |
| 248 | :type 'file | 244 | :type 'file) |
| 249 | :group 'doc-view) | ||
| 250 | 245 | ||
| 251 | (defcustom doc-view-odf->pdf-converter-function | 246 | (defcustom doc-view-odf->pdf-converter-function |
| 252 | (cond | 247 | (cond |
| @@ -267,22 +262,19 @@ Needed for viewing OpenOffice.org (and MS Office) files." | |||
| 267 | "Program to convert PS files to PDF. | 262 | "Program to convert PS files to PDF. |
| 268 | 263 | ||
| 269 | PS files will be converted to PDF before searching is possible." | 264 | PS files will be converted to PDF before searching is possible." |
| 270 | :type 'file | 265 | :type 'file) |
| 271 | :group 'doc-view) | ||
| 272 | 266 | ||
| 273 | (defcustom doc-view-pdftotext-program "pdftotext" | 267 | (defcustom doc-view-pdftotext-program "pdftotext" |
| 274 | "Program to convert PDF files to plain text. | 268 | "Program to convert PDF files to plain text. |
| 275 | 269 | ||
| 276 | Needed for searching." | 270 | Needed for searching." |
| 277 | :type 'file | 271 | :type 'file) |
| 278 | :group 'doc-view) | ||
| 279 | 272 | ||
| 280 | (defcustom doc-view-cache-directory | 273 | (defcustom doc-view-cache-directory |
| 281 | (expand-file-name (format "docview%d" (user-uid)) | 274 | (expand-file-name (format "docview%d" (user-uid)) |
| 282 | temporary-file-directory) | 275 | temporary-file-directory) |
| 283 | "The base directory, where the PNG images will be saved." | 276 | "The base directory, where the PNG images will be saved." |
| 284 | :type 'directory | 277 | :type 'directory) |
| 285 | :group 'doc-view) | ||
| 286 | 278 | ||
| 287 | (defvar doc-view-conversion-buffer " *doc-view conversion output*" | 279 | (defvar doc-view-conversion-buffer " *doc-view conversion output*" |
| 288 | "The buffer where messages from the converter programs go to.") | 280 | "The buffer where messages from the converter programs go to.") |
| @@ -293,8 +285,7 @@ After such a refresh newly converted pages will be available for | |||
| 293 | viewing. If set to nil there won't be any refreshes and the | 285 | viewing. If set to nil there won't be any refreshes and the |
| 294 | pages won't be displayed before conversion of the whole document | 286 | pages won't be displayed before conversion of the whole document |
| 295 | has finished." | 287 | has finished." |
| 296 | :type 'integer | 288 | :type 'integer) |
| 297 | :group 'doc-view) | ||
| 298 | 289 | ||
| 299 | (defcustom doc-view-continuous nil | 290 | (defcustom doc-view-continuous nil |
| 300 | "In Continuous mode reaching the page edge advances to next/previous page. | 291 | "In Continuous mode reaching the page edge advances to next/previous page. |
| @@ -302,7 +293,6 @@ When non-nil, scrolling a line upward at the bottom edge of the page | |||
| 302 | moves to the next page, and scrolling a line downward at the top edge | 293 | moves to the next page, and scrolling a line downward at the top edge |
| 303 | of the page moves to the previous page." | 294 | of the page moves to the previous page." |
| 304 | :type 'boolean | 295 | :type 'boolean |
| 305 | :group 'doc-view | ||
| 306 | :version "23.2") | 296 | :version "23.2") |
| 307 | 297 | ||
| 308 | ;;;; Internal Variables | 298 | ;;;; Internal Variables |
| @@ -412,6 +402,7 @@ Typically \"page-%s.png\".") | |||
| 412 | (define-key map "W" 'doc-view-fit-width-to-window) | 402 | (define-key map "W" 'doc-view-fit-width-to-window) |
| 413 | (define-key map "H" 'doc-view-fit-height-to-window) | 403 | (define-key map "H" 'doc-view-fit-height-to-window) |
| 414 | (define-key map "P" 'doc-view-fit-page-to-window) | 404 | (define-key map "P" 'doc-view-fit-page-to-window) |
| 405 | (define-key map "F" 'doc-view-fit-window-to-page) ;F = frame | ||
| 415 | ;; Killing the buffer (and the process) | 406 | ;; Killing the buffer (and the process) |
| 416 | (define-key map (kbd "K") 'doc-view-kill-proc) | 407 | (define-key map (kbd "K") 'doc-view-kill-proc) |
| 417 | ;; Slicing the image | 408 | ;; Slicing the image |
| @@ -429,22 +420,20 @@ Typically \"page-%s.png\".") | |||
| 429 | (define-key map (kbd "C-c C-c") 'doc-view-toggle-display) | 420 | (define-key map (kbd "C-c C-c") 'doc-view-toggle-display) |
| 430 | ;; Open a new buffer with doc's text contents | 421 | ;; Open a new buffer with doc's text contents |
| 431 | (define-key map (kbd "C-c C-t") 'doc-view-open-text) | 422 | (define-key map (kbd "C-c C-t") 'doc-view-open-text) |
| 432 | ;; Reconvert the current document. Don't just use revert-buffer | 423 | (define-key map (kbd "r") 'revert-buffer) |
| 433 | ;; because that resets the scale factor, the page number, ... | ||
| 434 | (define-key map (kbd "g") 'doc-view-revert-buffer) | ||
| 435 | (define-key map (kbd "r") 'doc-view-revert-buffer) | ||
| 436 | map) | 424 | map) |
| 437 | "Keymap used by `doc-view-mode' when displaying a doc as a set of images.") | 425 | "Keymap used by `doc-view-mode' when displaying a doc as a set of images.") |
| 438 | 426 | ||
| 439 | (defun doc-view-revert-buffer (&optional ignore-auto noconfirm) | 427 | (define-obsolete-function-alias 'doc-view-revert-buffer #'revert-buffer "27.1") |
| 440 | "Like `revert-buffer', but preserves the buffer's current modes." | 428 | (defvar revert-buffer-preserve-modes) |
| 441 | (interactive (list (not current-prefix-arg))) | 429 | (defun doc-view--revert-buffer (orig-fun &rest args) |
| 430 | "Preserve the buffer's current mode and check PDF sanity." | ||
| 442 | (if (< undo-outer-limit (* 2 (buffer-size))) | 431 | (if (< undo-outer-limit (* 2 (buffer-size))) |
| 443 | ;; It's normal for this operation to result in a very large undo entry. | 432 | ;; It's normal for this operation to result in a very large undo entry. |
| 444 | (setq-local undo-outer-limit (* 2 (buffer-size)))) | 433 | (setq-local undo-outer-limit (* 2 (buffer-size)))) |
| 445 | (cl-labels ((revert () | 434 | (cl-labels ((revert () |
| 446 | (let (revert-buffer-function) | 435 | (let ((revert-buffer-preserve-modes t)) |
| 447 | (revert-buffer ignore-auto noconfirm 'preserve-modes)))) | 436 | (apply orig-fun args)))) |
| 448 | (if (and (eq 'pdf doc-view-doc-type) | 437 | (if (and (eq 'pdf doc-view-doc-type) |
| 449 | (executable-find "pdfinfo")) | 438 | (executable-find "pdfinfo")) |
| 450 | ;; We don't want to revert if the PDF file is corrupted which | 439 | ;; We don't want to revert if the PDF file is corrupted which |
| @@ -492,6 +481,8 @@ Typically \"page-%s.png\".") | |||
| 492 | 481 | ||
| 493 | ;;;; Navigation Commands | 482 | ;;;; Navigation Commands |
| 494 | 483 | ||
| 484 | ;; FIXME: The doc-view-current-* definitions below are macros because they | ||
| 485 | ;; map to accessors which we want to use via `setf' as well! | ||
| 495 | (defmacro doc-view-current-page (&optional win) | 486 | (defmacro doc-view-current-page (&optional win) |
| 496 | `(image-mode-window-get 'page ,win)) | 487 | `(image-mode-window-get 'page ,win)) |
| 497 | (defmacro doc-view-current-info () '(image-mode-window-get 'info)) | 488 | (defmacro doc-view-current-info () '(image-mode-window-get 'info)) |
| @@ -683,7 +674,7 @@ at the top edge of the page moves to the previous page." | |||
| 683 | (file-error | 674 | (file-error |
| 684 | (error | 675 | (error |
| 685 | (format "Unable to use temporary directory %s: %s" | 676 | (format "Unable to use temporary directory %s: %s" |
| 686 | dir (mapconcat 'identity (cdr error) " ")))))))) | 677 | dir (mapconcat #'identity (cdr error) " ")))))))) |
| 687 | 678 | ||
| 688 | (defun doc-view--current-cache-dir () | 679 | (defun doc-view--current-cache-dir () |
| 689 | "Return the directory where the png files of the current doc should be saved. | 680 | "Return the directory where the png files of the current doc should be saved. |
| @@ -872,6 +863,38 @@ min {(window-width / image-width), (window-height / image-height)} times." | |||
| 872 | (setf (doc-view-current-slice) new-slice) | 863 | (setf (doc-view-current-slice) new-slice) |
| 873 | (doc-view-goto-page (doc-view-current-page)))))) | 864 | (doc-view-goto-page (doc-view-current-page)))))) |
| 874 | 865 | ||
| 866 | (defun doc-view-fit-window-to-page () | ||
| 867 | "Resize selected window so it just fits the current page. | ||
| 868 | Resize the containing frame if needed." | ||
| 869 | (interactive) | ||
| 870 | (let* ((slice (doc-view-current-slice)) | ||
| 871 | (img-width (if slice (nth 2 slice) | ||
| 872 | (car (image-display-size | ||
| 873 | (image-get-display-property) t)))) | ||
| 874 | (img-height (if slice (nth 3 slice) | ||
| 875 | (cdr (image-display-size | ||
| 876 | (image-get-display-property) t)))) | ||
| 877 | (win-width (- (nth 2 (window-inside-pixel-edges)) | ||
| 878 | (nth 0 (window-inside-pixel-edges)))) | ||
| 879 | (win-height (- (nth 3 (window-inside-pixel-edges)) | ||
| 880 | (nth 1 (window-inside-pixel-edges)))) | ||
| 881 | (width-diff (- img-width win-width)) | ||
| 882 | (height-diff (- img-height win-height)) | ||
| 883 | (new-frame-params | ||
| 884 | (append | ||
| 885 | (if (= (window-width) (frame-width)) | ||
| 886 | `((width . (text-pixels | ||
| 887 | . ,(+ (frame-text-width) width-diff)))) | ||
| 888 | (enlarge-window (/ width-diff (frame-char-width)) 'horiz) | ||
| 889 | nil) | ||
| 890 | (if (= (window-height) (frame-height)) | ||
| 891 | `((height . (text-pixels | ||
| 892 | . ,(+ (frame-text-height) height-diff)))) | ||
| 893 | (enlarge-window (/ height-diff (frame-char-height)) nil) | ||
| 894 | nil)))) | ||
| 895 | (when new-frame-params | ||
| 896 | (modify-frame-parameters (selected-frame) new-frame-params)))) | ||
| 897 | |||
| 875 | (defun doc-view-reconvert-doc () | 898 | (defun doc-view-reconvert-doc () |
| 876 | "Reconvert the current document. | 899 | "Reconvert the current document. |
| 877 | Should be invoked when the cached images aren't up-to-date." | 900 | Should be invoked when the cached images aren't up-to-date." |
| @@ -906,7 +929,7 @@ Should be invoked when the cached images aren't up-to-date." | |||
| 906 | (let* ((default-directory (or (unhandled-file-name-directory | 929 | (let* ((default-directory (or (unhandled-file-name-directory |
| 907 | default-directory) | 930 | default-directory) |
| 908 | (expand-file-name "~/"))) | 931 | (expand-file-name "~/"))) |
| 909 | (proc (apply 'start-process name doc-view-conversion-buffer | 932 | (proc (apply #'start-process name doc-view-conversion-buffer |
| 910 | program args))) | 933 | program args))) |
| 911 | (push proc doc-view--current-converter-processes) | 934 | (push proc doc-view--current-converter-processes) |
| 912 | (setq mode-line-process (list (format ":%s" proc))) | 935 | (setq mode-line-process (list (format ":%s" proc))) |
| @@ -960,7 +983,10 @@ If PAGE is nil, convert the whole document." | |||
| 960 | (defun doc-view-pdf->png-converter-mupdf (pdf png page callback) | 983 | (defun doc-view-pdf->png-converter-mupdf (pdf png page callback) |
| 961 | (doc-view-start-process | 984 | (doc-view-start-process |
| 962 | "pdf->png" doc-view-pdfdraw-program | 985 | "pdf->png" doc-view-pdfdraw-program |
| 963 | `(,(concat "-o" png) | 986 | ;; FIXME: Ugly hack: recent mupdf distribution replaced "mudraw" with |
| 987 | ;; "mutool draw". | ||
| 988 | `(,@(if (string-match "mutool[^/\\]*$" doc-view-pdfdraw-program) '("draw")) | ||
| 989 | ,(concat "-o" png) | ||
| 964 | ,(format "-r%d" (round doc-view-resolution)) | 990 | ,(format "-r%d" (round doc-view-resolution)) |
| 965 | 991 | ||
| 966 | ,@(if page `(,(format "%d" page)))) | 992 | ,@(if page `(,(format "%d" page)))) |
| @@ -1217,7 +1243,8 @@ dragging it to its bottom-right corner. See also | |||
| 1217 | (save-match-data | 1243 | (save-match-data |
| 1218 | (when (string-match (concat "%%BoundingBox: " | 1244 | (when (string-match (concat "%%BoundingBox: " |
| 1219 | "\\([[:digit:]]+\\) \\([[:digit:]]+\\) " | 1245 | "\\([[:digit:]]+\\) \\([[:digit:]]+\\) " |
| 1220 | "\\([[:digit:]]+\\) \\([[:digit:]]+\\)") o) | 1246 | "\\([[:digit:]]+\\) \\([[:digit:]]+\\)") |
| 1247 | o) | ||
| 1221 | (mapcar #'string-to-number | 1248 | (mapcar #'string-to-number |
| 1222 | (list (match-string 1 o) | 1249 | (list (match-string 1 o) |
| 1223 | (match-string 2 o) | 1250 | (match-string 2 o) |
| @@ -1301,10 +1328,10 @@ ARGS is a list of image descriptors." | |||
| 1301 | (let* ((image (if (and file (file-readable-p file)) | 1328 | (let* ((image (if (and file (file-readable-p file)) |
| 1302 | (if (not (and doc-view-scale-internally | 1329 | (if (not (and doc-view-scale-internally |
| 1303 | (fboundp 'imagemagick-types))) | 1330 | (fboundp 'imagemagick-types))) |
| 1304 | (apply 'create-image file doc-view--image-type nil args) | 1331 | (apply #'create-image file doc-view--image-type nil args) |
| 1305 | (unless (member :width args) | 1332 | (unless (member :width args) |
| 1306 | (setq args `(,@args :width ,doc-view-image-width))) | 1333 | (setq args `(,@args :width ,doc-view-image-width))) |
| 1307 | (apply 'create-image file 'imagemagick nil args)))) | 1334 | (apply #'create-image file 'imagemagick nil args)))) |
| 1308 | (slice (doc-view-current-slice)) | 1335 | (slice (doc-view-current-slice)) |
| 1309 | (img-width (and image (car (image-size image)))) | 1336 | (img-width (and image (car (image-size image)))) |
| 1310 | (displayed-img-width (if (and image slice) | 1337 | (displayed-img-width (if (and image slice) |
| @@ -1725,7 +1752,7 @@ If BACKWARD is non-nil, jump to the previous match." | |||
| 1725 | ;; window-parameters in the window-state(s) and then restoring this | 1752 | ;; window-parameters in the window-state(s) and then restoring this |
| 1726 | ;; window-state should call us back (to interpret/use those parameters). | 1753 | ;; window-state should call us back (to interpret/use those parameters). |
| 1727 | (doc-view-goto-page page) | 1754 | (doc-view-goto-page page) |
| 1728 | (when slice (apply 'doc-view-set-slice slice)) | 1755 | (when slice (apply #'doc-view-set-slice slice)) |
| 1729 | (current-buffer)))) | 1756 | (current-buffer)))) |
| 1730 | 1757 | ||
| 1731 | (add-to-list 'desktop-buffer-mode-handlers | 1758 | (add-to-list 'desktop-buffer-mode-handlers |
| @@ -1789,22 +1816,22 @@ toggle between displaying the document or editing it as text. | |||
| 1789 | (when (not (string= doc-view--buffer-file-name buffer-file-name)) | 1816 | (when (not (string= doc-view--buffer-file-name buffer-file-name)) |
| 1790 | (write-region nil nil doc-view--buffer-file-name)) | 1817 | (write-region nil nil doc-view--buffer-file-name)) |
| 1791 | 1818 | ||
| 1792 | (setq-local revert-buffer-function #'doc-view-revert-buffer) | 1819 | (add-function :around (local 'revert-buffer-function) #'doc-view--revert-buffer) |
| 1793 | 1820 | ||
| 1794 | (add-hook 'change-major-mode-hook | 1821 | (add-hook 'change-major-mode-hook |
| 1795 | (lambda () | 1822 | (lambda () |
| 1796 | (doc-view-kill-proc) | 1823 | (doc-view-kill-proc) |
| 1797 | (remove-overlays (point-min) (point-max) 'doc-view t)) | 1824 | (remove-overlays (point-min) (point-max) 'doc-view t)) |
| 1798 | nil t) | 1825 | nil t) |
| 1799 | (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t) | 1826 | (add-hook 'clone-indirect-buffer-hook #'doc-view-clone-buffer-hook nil t) |
| 1800 | (add-hook 'kill-buffer-hook 'doc-view-kill-proc nil t) | 1827 | (add-hook 'kill-buffer-hook #'doc-view-kill-proc nil t) |
| 1801 | (setq-local desktop-save-buffer 'doc-view-desktop-save-buffer) | 1828 | (setq-local desktop-save-buffer #'doc-view-desktop-save-buffer) |
| 1802 | 1829 | ||
| 1803 | (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case. | 1830 | (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case. |
| 1804 | ;; Keep track of display info ([vh]scroll, page number, overlay, | 1831 | ;; Keep track of display info ([vh]scroll, page number, overlay, |
| 1805 | ;; ...) for each window in which this document is shown. | 1832 | ;; ...) for each window in which this document is shown. |
| 1806 | (add-hook 'image-mode-new-window-functions | 1833 | (add-hook 'image-mode-new-window-functions |
| 1807 | 'doc-view-new-window-function nil t) | 1834 | #'doc-view-new-window-function nil t) |
| 1808 | (image-mode-setup-winprops) | 1835 | (image-mode-setup-winprops) |
| 1809 | 1836 | ||
| 1810 | (setq-local mode-line-position | 1837 | (setq-local mode-line-position |
| @@ -1820,7 +1847,7 @@ toggle between displaying the document or editing it as text. | |||
| 1820 | #'doc-view-scroll-down-or-previous-page)) | 1847 | #'doc-view-scroll-down-or-previous-page)) |
| 1821 | (setq-local cursor-type nil) | 1848 | (setq-local cursor-type nil) |
| 1822 | (use-local-map doc-view-mode-map) | 1849 | (use-local-map doc-view-mode-map) |
| 1823 | (add-hook 'after-revert-hook 'doc-view-reconvert-doc nil t) | 1850 | (add-hook 'after-revert-hook #'doc-view-reconvert-doc nil t) |
| 1824 | (setq-local bookmark-make-record-function | 1851 | (setq-local bookmark-make-record-function |
| 1825 | #'doc-view-bookmark-make-record) | 1852 | #'doc-view-bookmark-make-record) |
| 1826 | (setq mode-name "DocView" | 1853 | (setq mode-name "DocView" |
| @@ -1862,8 +1889,7 @@ to the next best mode." | |||
| 1862 | "Toggle displaying buffer via Doc View (Doc View minor mode). | 1889 | "Toggle displaying buffer via Doc View (Doc View minor mode). |
| 1863 | 1890 | ||
| 1864 | See the command `doc-view-mode' for more information on this mode." | 1891 | See the command `doc-view-mode' for more information on this mode." |
| 1865 | nil " DocView" doc-view-minor-mode-map | 1892 | :lighter " DocView" |
| 1866 | :group 'doc-view | ||
| 1867 | (when doc-view-minor-mode | 1893 | (when doc-view-minor-mode |
| 1868 | (add-hook 'change-major-mode-hook (lambda () (doc-view-minor-mode -1)) nil t) | 1894 | (add-hook 'change-major-mode-hook (lambda () (doc-view-minor-mode -1)) nil t) |
| 1869 | (message | 1895 | (message |
| @@ -1881,6 +1907,84 @@ See the command `doc-view-mode' for more information on this mode." | |||
| 1881 | (interactive) | 1907 | (interactive) |
| 1882 | (dired doc-view-cache-directory)) | 1908 | (dired doc-view-cache-directory)) |
| 1883 | 1909 | ||
| 1910 | ;;;; Presentation mode | ||
| 1911 | |||
| 1912 | (defvar doc-view-presentation-mode-map | ||
| 1913 | (let ((map (make-sparse-keymap))) | ||
| 1914 | (define-key map "\e" 'doc-view-presentation-exit) | ||
| 1915 | (define-key map "q" 'doc-view-presentation-exit) | ||
| 1916 | ;; (define-key map "C" 'doc-view-convert-all-pages) | ||
| 1917 | map)) | ||
| 1918 | |||
| 1919 | (defvar-local doc-view-presentation--src-data nil) | ||
| 1920 | |||
| 1921 | (defun doc-view-presentation-exit () | ||
| 1922 | "Leave Doc-View's presentation mode." | ||
| 1923 | (interactive) | ||
| 1924 | (doc-view-presentation-mode -1)) | ||
| 1925 | |||
| 1926 | (define-minor-mode doc-view-presentation-mode | ||
| 1927 | "Minor mode used while in presentation mode." | ||
| 1928 | :init-value nil :keymap doc-view-presentation-mode-map | ||
| 1929 | (if doc-view-presentation-mode | ||
| 1930 | (progn | ||
| 1931 | (set (make-local-variable 'mode-line-format) nil) | ||
| 1932 | (doc-view-fit-page-to-window) | ||
| 1933 | ;; (doc-view-convert-all-pages) | ||
| 1934 | ) | ||
| 1935 | (kill-local-variable 'mode-line-format) | ||
| 1936 | (let ((pn (doc-view-current-page)) | ||
| 1937 | (win (selected-window))) | ||
| 1938 | (doc-view-presentation--propagate-pn doc-view-presentation--src-data pn) | ||
| 1939 | (setq doc-view-presentation--src-data nil) | ||
| 1940 | (with-selected-window win | ||
| 1941 | (if (and (one-window-p) (window-dedicated-p)) | ||
| 1942 | (delete-frame)))))) | ||
| 1943 | |||
| 1944 | (defun doc-view-presentation--propagate-pn (src-data pn) | ||
| 1945 | (when src-data | ||
| 1946 | (let ((win (car src-data))) | ||
| 1947 | (when (and (window-live-p win) | ||
| 1948 | (eq (current-buffer) (window-buffer win))) | ||
| 1949 | (select-window win)) | ||
| 1950 | (when (eq (doc-view-current-page) (cdr src-data)) | ||
| 1951 | (doc-view-goto-page pn))))) | ||
| 1952 | |||
| 1953 | (defun doc-view-presentation () | ||
| 1954 | "Put Doc-View in presentation mode." | ||
| 1955 | (interactive) | ||
| 1956 | (let* ((src-data (cons (selected-window) (doc-view-current-page))) | ||
| 1957 | (mal (display-monitor-attributes-list)) | ||
| 1958 | (monitor-top 0) | ||
| 1959 | (monitor-left 0) | ||
| 1960 | (monitor-height (display-pixel-height)) | ||
| 1961 | (monitor-width (display-pixel-width))) | ||
| 1962 | (dolist (attrs mal) | ||
| 1963 | (when (memq (selected-frame) (alist-get 'frames attrs)) | ||
| 1964 | (let ((geom (alist-get 'geometry attrs))) | ||
| 1965 | (when geom | ||
| 1966 | (setq monitor-top (nth 0 geom)) | ||
| 1967 | (setq monitor-left (nth 1 geom)) | ||
| 1968 | (setq monitor-width (nth 2 geom)) | ||
| 1969 | (setq monitor-height (nth 3 geom)))))) | ||
| 1970 | (let ((frame (make-frame | ||
| 1971 | `((minibuffer . nil) | ||
| 1972 | (fullscreen . fullboth) | ||
| 1973 | (height . ,(ceiling monitor-height (frame-char-height))) | ||
| 1974 | ;; Don't use `ceiling' here since doc-view will center the | ||
| 1975 | ;; image instead. | ||
| 1976 | (width . ,(ceiling monitor-width (frame-char-width))) | ||
| 1977 | (name . "Doc-View-Presentation") | ||
| 1978 | (top . ,monitor-top) (left . ,monitor-left) (user-position . t) | ||
| 1979 | (vertical-scroll-bars . nil) | ||
| 1980 | (left-fringe . 0) (right-fringe . 0) | ||
| 1981 | (menu-bar-lines . 0) | ||
| 1982 | (tool-bar-lines . 0))))) | ||
| 1983 | (select-window (frame-root-window frame)) | ||
| 1984 | (setq doc-view-presentation--src-data src-data) | ||
| 1985 | (set-window-dedicated-p (selected-window) t) | ||
| 1986 | (doc-view-presentation-mode 1)))) | ||
| 1987 | |||
| 1884 | 1988 | ||
| 1885 | ;;;; Bookmark integration | 1989 | ;;;; Bookmark integration |
| 1886 | 1990 | ||