update packages
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'image-mode)
|
||||
(require 'pdf-macs)
|
||||
(require 'pdf-util)
|
||||
(require 'pdf-info)
|
||||
(require 'pdf-cache)
|
||||
@@ -33,7 +34,7 @@
|
||||
(require 'password-cache)
|
||||
|
||||
(declare-function cua-copy-region "cua-base")
|
||||
|
||||
(declare-function pdf-tools-pdf-buffer-p "pdf-tools")
|
||||
|
||||
;; * ================================================================== *
|
||||
;; * Customizations
|
||||
@@ -91,10 +92,7 @@ FIXME: Explain dis-/advantages of imagemagick and png."
|
||||
This variable affects both the reuse of higher-resolution images
|
||||
as lower-resolution ones by down-scaling the image. As well as
|
||||
the rendering of higher-resolution for high-resolution displays,
|
||||
if available.
|
||||
|
||||
It has no effect, unless either the imagemagick or image-io
|
||||
image-format is available."
|
||||
if available."
|
||||
:group 'pdf-view
|
||||
:type 'boolean)
|
||||
|
||||
@@ -113,7 +111,7 @@ image-format is available."
|
||||
:group 'pdf-tools-faces)
|
||||
|
||||
(defcustom pdf-view-midnight-colors '("#839496" . "#002b36" )
|
||||
"Colors used when `pdf-view-midnight-minor-mode' is activated.
|
||||
"Colors used when command `pdf-view-midnight-minor-mode' is activated.
|
||||
|
||||
This should be a cons \(FOREGROUND . BACKGROUND\) of colors."
|
||||
:group 'pdf-view
|
||||
@@ -169,7 +167,7 @@ See :relief property in Info node `(elisp) Image Descriptors'."
|
||||
:type '(integer :tag "Pixel"))
|
||||
|
||||
(defcustom pdf-view-use-unicode-ligther t
|
||||
"Whether to use unicode symbols in the mode-line
|
||||
"Decide whether to use unicode symbols in the mode-line.
|
||||
|
||||
On some systems finding a font which supports those symbols can
|
||||
take some time. If you don't want to spend that time waiting and
|
||||
@@ -222,29 +220,6 @@ regarding display of the region in the later function.")
|
||||
(defvar-local pdf-view-register-alist nil
|
||||
"Local, dedicated register for PDF positions.")
|
||||
|
||||
(defmacro pdf-view-current-page (&optional window)
|
||||
;;TODO: write documentation!
|
||||
`(image-mode-window-get 'page ,window))
|
||||
|
||||
(defmacro pdf-view-current-overlay (&optional window)
|
||||
;;TODO: write documentation!
|
||||
`(image-mode-window-get 'overlay ,window))
|
||||
|
||||
(defmacro pdf-view-current-image (&optional window)
|
||||
;;TODO: write documentation!
|
||||
`(image-mode-window-get 'image ,window))
|
||||
|
||||
(defmacro pdf-view-current-slice (&optional window)
|
||||
;;TODO: write documentation!
|
||||
`(image-mode-window-get 'slice ,window))
|
||||
|
||||
(defmacro pdf-view-current-window-size (&optional window)
|
||||
;;TODO: write documentation!
|
||||
`(image-mode-window-get 'window-size ,window))
|
||||
|
||||
(defmacro pdf-view-window-needs-redisplay (&optional window)
|
||||
`(image-mode-window-get 'needs-redisplay ,window))
|
||||
|
||||
(defun pdf-view-current-pagelabel (&optional window)
|
||||
(nth (1- (pdf-view-current-page window)) (pdf-info-pagelabels)))
|
||||
|
||||
@@ -259,7 +234,7 @@ regarding display of the region in the later function.")
|
||||
|
||||
(defconst pdf-view-have-image-mode-pixel-vscroll
|
||||
(>= emacs-major-version 27)
|
||||
"Whether image-mode scrolls vertically by pixels.")
|
||||
"Whether `image-mode' scrolls vertically by pixels.")
|
||||
|
||||
|
||||
;; * ================================================================== *
|
||||
@@ -282,10 +257,14 @@ regarding display of the region in the later function.")
|
||||
(define-key map (kbd "DEL") 'pdf-view-scroll-down-or-previous-page)
|
||||
(define-key map (kbd "C-n") 'pdf-view-next-line-or-next-page)
|
||||
(define-key map (kbd "<down>") 'pdf-view-next-line-or-next-page)
|
||||
(define-key map (kbd "C-p") 'pdf-view-previous-line-or-previous-page)
|
||||
(define-key map (kbd "<up>") 'pdf-view-previous-line-or-previous-page)
|
||||
(define-key map (kbd "M-<") 'pdf-view-first-page)
|
||||
(define-key map (kbd "M->") 'pdf-view-last-page)
|
||||
(define-key map [remap next-line] 'pdf-view-next-line-or-next-page)
|
||||
(define-key map (kbd "C-p") 'pdf-view-previous-line-or-previous-page)
|
||||
(define-key map (kbd "<up>") 'pdf-view-previous-line-or-previous-page)
|
||||
(define-key map [remap previous-line] 'pdf-view-previous-line-or-previous-page)
|
||||
(define-key map (kbd "M-<") 'pdf-view-first-page)
|
||||
(define-key map [remap beginning-of-buffer] 'pdf-view-first-page)
|
||||
(define-key map (kbd "M->") 'pdf-view-last-page)
|
||||
(define-key map [remap end-of-buffer] 'pdf-view-last-page)
|
||||
(define-key map [remap goto-line] 'pdf-view-goto-page)
|
||||
(define-key map (kbd "M-g l") 'pdf-view-goto-label)
|
||||
(define-key map (kbd "RET") 'image-next-line)
|
||||
@@ -305,7 +284,6 @@ regarding display of the region in the later function.")
|
||||
;; Reconvert
|
||||
(define-key map (kbd "C-c C-c") 'doc-view-mode)
|
||||
(define-key map (kbd "g") 'revert-buffer)
|
||||
(define-key map (kbd "r") 'revert-buffer)
|
||||
;; Region
|
||||
(define-key map [down-mouse-1] 'pdf-view-mouse-set-region)
|
||||
(define-key map [M-down-mouse-1] 'pdf-view-mouse-set-region-rectangle)
|
||||
@@ -321,6 +299,7 @@ regarding display of the region in the later function.")
|
||||
(define-key map (kbd "C-c C-i") 'pdf-view-extract-region-image)
|
||||
;; Rendering
|
||||
(define-key map (kbd "C-c C-r m") 'pdf-view-midnight-minor-mode)
|
||||
(define-key map (kbd "C-c C-r t") 'pdf-view-themed-minor-mode)
|
||||
(define-key map (kbd "C-c C-r p") 'pdf-view-printer-minor-mode)
|
||||
map)
|
||||
"Keymap used by `pdf-view-mode' when displaying a doc as a set of images.")
|
||||
@@ -339,12 +318,7 @@ PNG images in Emacs buffers."
|
||||
(not (and buffer-file-name
|
||||
(file-readable-p buffer-file-name)))))
|
||||
(pdf-tools-pdf-buffer-p))
|
||||
(let ((tempfile (pdf-util-make-temp-file
|
||||
(concat (if buffer-file-name
|
||||
(file-name-nondirectory
|
||||
buffer-file-name)
|
||||
(buffer-name))
|
||||
"-"))))
|
||||
(let ((tempfile (pdf-util-make-temp-file)))
|
||||
(write-region nil nil tempfile nil 'no-message)
|
||||
(setq-local pdf-view--buffer-file-name tempfile)))
|
||||
;; Decryption needs to be done before any other function calls into
|
||||
@@ -426,16 +400,15 @@ PNG images in Emacs buffers."
|
||||
(current-buffer)))
|
||||
|
||||
(unless (version< emacs-version "24.4")
|
||||
(advice-add 'cua-copy-region
|
||||
:before-until
|
||||
#'cua-copy-region--pdf-view-advice)
|
||||
(defun cua-copy-region--pdf-view-advice (&rest _)
|
||||
"If the current buffer is in `pdf-view' mode, call
|
||||
`pdf-view-kill-ring-save'."
|
||||
(when (eq major-mode 'pdf-view-mode)
|
||||
(pdf-view-kill-ring-save)
|
||||
t))
|
||||
|
||||
(advice-add 'cua-copy-region
|
||||
:before-until
|
||||
#'cua-copy-region--pdf-view-advice))
|
||||
t)))
|
||||
|
||||
(defun pdf-view-check-incompatible-modes (&optional buffer)
|
||||
"Check BUFFER for incompatible modes, maybe issue a warning."
|
||||
@@ -606,6 +579,9 @@ For example, (pdf-view-shrink 1.25) decreases size by 20%."
|
||||
;; * Moving by pages and scrolling
|
||||
;; * ================================================================== *
|
||||
|
||||
(defvar pdf-view-inhibit-redisplay nil)
|
||||
(defvar pdf-view-inhibit-hotspots nil)
|
||||
|
||||
(defun pdf-view-goto-page (page &optional window)
|
||||
"Go to PAGE in PDF.
|
||||
|
||||
@@ -626,7 +602,7 @@ windows."
|
||||
(save-selected-window
|
||||
;; Select the window for the hooks below.
|
||||
(when (window-live-p window)
|
||||
(select-window window))
|
||||
(select-window window 'norecord))
|
||||
(let ((changing-p
|
||||
(not (eq page (pdf-view-current-page window)))))
|
||||
(when changing-p
|
||||
@@ -809,9 +785,9 @@ displayed page number."
|
||||
;; * ================================================================== *
|
||||
|
||||
(defun pdf-view-set-slice (x y width height &optional window)
|
||||
;; TODO: add WINDOW to docstring.
|
||||
"Set the slice of the pages that should be displayed.
|
||||
"Set the slice of the pages that should be displayed in WINDOW.
|
||||
|
||||
WINDOW defaults to `selected-window' if not provided.
|
||||
X, Y, WIDTH and HEIGHT should be relative coordinates, i.e. in
|
||||
\[0;1\]. To reset the slice use `pdf-view-reset-slice'."
|
||||
(unless (equal (pdf-view-current-slice window)
|
||||
@@ -848,9 +824,10 @@ dragging it to its bottom-right corner. See also
|
||||
(/ 1.0 (float (cdr size))))))))
|
||||
|
||||
(defun pdf-view-set-slice-from-bounding-box (&optional window)
|
||||
;; TODO: add WINDOW to docstring.
|
||||
"Set the slice from the page's bounding-box.
|
||||
|
||||
WINDOW defaults to `selected-window' if not provided.
|
||||
|
||||
The result is that the margins are almost completely cropped,
|
||||
much more accurate than could be done manually using
|
||||
`pdf-view-set-slice-using-mouse'.
|
||||
@@ -871,8 +848,9 @@ See also `pdf-view-bounding-box-margin'."
|
||||
(append slice (and window (list window))))))
|
||||
|
||||
(defun pdf-view-reset-slice (&optional window)
|
||||
;; TODO: add WINDOW to doctring.
|
||||
"Reset the current slice.
|
||||
"Reset the current slice and redisplay WINDOW.
|
||||
|
||||
WINDOW defaults to `selected-window' if not provided.
|
||||
|
||||
After calling this function the whole page will be visible
|
||||
again."
|
||||
@@ -886,7 +864,7 @@ again."
|
||||
"Automatically slice pages according to their bounding boxes.
|
||||
|
||||
See also `pdf-view-set-slice-from-bounding-box'."
|
||||
nil nil nil
|
||||
:group 'pdf-view
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
(cond
|
||||
(pdf-view-auto-slice-minor-mode
|
||||
@@ -896,17 +874,15 @@ See also `pdf-view-set-slice-from-bounding-box'."
|
||||
(add-hook 'pdf-view-change-page-hook
|
||||
'pdf-view-set-slice-from-bounding-box nil t))
|
||||
(t
|
||||
(remove-hook 'pdf-view-change-page-hook
|
||||
'pdf-view-set-slice-from-bounding-box t))))
|
||||
(progn (remove-hook 'pdf-view-change-page-hook
|
||||
'pdf-view-set-slice-from-bounding-box t)
|
||||
(pdf-view-reset-slice)))))
|
||||
|
||||
|
||||
;; * ================================================================== *
|
||||
;; * Display
|
||||
;; * ================================================================== *
|
||||
|
||||
(defvar pdf-view-inhibit-redisplay nil)
|
||||
(defvar pdf-view-inhibit-hotspots nil)
|
||||
|
||||
(defun pdf-view-image-type ()
|
||||
"Return the image type that should be used.
|
||||
|
||||
@@ -928,12 +904,6 @@ See also `pdf-view-use-imagemagick'."
|
||||
(t
|
||||
(error "PNG image supported not compiled into Emacs"))))
|
||||
|
||||
(defun pdf-view-use-scaling-p ()
|
||||
"Return t if scaling should be used."
|
||||
(and (memq (pdf-view-image-type)
|
||||
'(imagemagick image-io))
|
||||
pdf-view-use-scaling))
|
||||
|
||||
(defmacro pdf-view-create-image (data &rest props)
|
||||
;; TODO: add DATA and PROPS to docstring.
|
||||
"Like `create-image', but with set DATA-P and TYPE arguments."
|
||||
@@ -952,7 +922,7 @@ See also `pdf-view-use-imagemagick'."
|
||||
(let* ((size (pdf-view-desired-image-size page window))
|
||||
(data (pdf-cache-renderpage
|
||||
page (car size)
|
||||
(if (not (pdf-view-use-scaling-p))
|
||||
(if (not pdf-view-use-scaling)
|
||||
(car size)
|
||||
(* 2 (car size)))))
|
||||
(hotspots (pdf-view-apply-hotspot-functions
|
||||
@@ -1167,7 +1137,7 @@ This will display a text cursor, when hovering over them."
|
||||
"Mode for PDF documents with dark background.
|
||||
|
||||
This tells the various modes to use their face's dark colors."
|
||||
nil nil nil
|
||||
:group 'pdf-view
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
;; FIXME: This should really be run in a hook.
|
||||
(when (bound-and-true-p pdf-isearch-active-mode)
|
||||
@@ -1178,7 +1148,8 @@ This tells the various modes to use their face's dark colors."
|
||||
|
||||
(define-minor-mode pdf-view-printer-minor-mode
|
||||
"Display the PDF as it would be printed."
|
||||
nil " Prn" nil
|
||||
:group 'pdf-view
|
||||
:lighter " Prn"
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
(let ((enable (lambda ()
|
||||
(pdf-info-setoptions :render/printed t))))
|
||||
@@ -1198,8 +1169,8 @@ This tells the various modes to use their face's dark colors."
|
||||
|
||||
The colors are determined by the variable
|
||||
`pdf-view-midnight-colors', which see. "
|
||||
|
||||
nil " Mid" nil
|
||||
:group 'pdf-view
|
||||
:lighter " Mid"
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
;; FIXME: Maybe these options should be passed stateless to pdf-info-renderpage ?
|
||||
(let ((enable (lambda ()
|
||||
@@ -1219,6 +1190,43 @@ The colors are determined by the variable
|
||||
(pdf-cache-clear-images)
|
||||
(pdf-view-redisplay t))
|
||||
|
||||
(defun pdf-view-refresh-themed-buffer (&optional get-theme)
|
||||
"Refresh the current buffer to activate applied colors.
|
||||
|
||||
When GET-THEME is non-nil, also reset the applied colors to the
|
||||
current theme's colors."
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
(pdf-cache-clear-images)
|
||||
(when get-theme
|
||||
(pdf-view-set-theme-background))
|
||||
(pdf-view-redisplay t))
|
||||
|
||||
(defun pdf-view-set-theme-background ()
|
||||
"Set the buffer's color filter to correspond to the current Emacs theme."
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
(pdf-info-setoptions
|
||||
:render/foreground (face-foreground 'default nil)
|
||||
:render/background (face-background 'default nil)
|
||||
:render/usecolors t))
|
||||
|
||||
(define-minor-mode pdf-view-themed-minor-mode
|
||||
"Synchronize color filter with the present Emacs theme.
|
||||
|
||||
The colors are determined by the `face-foreground' and
|
||||
`face-background' of the currently active theme."
|
||||
:group 'pdf-view
|
||||
:lighter " Thm"
|
||||
(pdf-util-assert-pdf-buffer)
|
||||
(cond
|
||||
(pdf-view-themed-minor-mode
|
||||
(add-hook 'after-save-hook #'pdf-view-set-theme-background nil t)
|
||||
(add-hook 'after-revert-hook #'pdf-view-set-theme-background nil t))
|
||||
(t
|
||||
(remove-hook 'after-save-hook #'pdf-view-set-theme-background t)
|
||||
(remove-hook 'after-revert-hook #'pdf-view-set-theme-background t)
|
||||
(pdf-info-setoptions :render/usecolors nil)))
|
||||
(pdf-view-refresh-themed-buffer pdf-view-themed-minor-mode))
|
||||
|
||||
(when pdf-view-use-unicode-ligther
|
||||
;; This check uses an implementation detail, which hopefully gets the
|
||||
;; right answer.
|
||||
@@ -1261,7 +1269,7 @@ supersede hotspots in lower ones."
|
||||
;; TODO: write documentation!
|
||||
(unless pdf-view-inhibit-hotspots
|
||||
(save-selected-window
|
||||
(when window (select-window window))
|
||||
(when window (select-window window 'norecord))
|
||||
(apply 'nconc
|
||||
(mapcar (lambda (fn)
|
||||
(funcall fn page image-size))
|
||||
@@ -1418,7 +1426,8 @@ This is more useful for commands like
|
||||
`(,(car colors) ,(cdr colors) 0.35 ,@region))
|
||||
(pdf-info-renderpage-text-regions
|
||||
page width nil nil
|
||||
`(,(car colors) ,(cdr colors) ,@region)))))))
|
||||
`(,(car colors) ,(cdr colors) ,@region)))
|
||||
:width width))))
|
||||
|
||||
(defun pdf-view-kill-ring-save ()
|
||||
"Copy the region to the `kill-ring'."
|
||||
|
||||
Reference in New Issue
Block a user