2018-02-06 01:07:36 +01:00
|
|
|
;;; tools/pdf/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! pdf-tools
|
2018-05-25 00:46:11 +02:00
|
|
|
:mode ("\\.pdf\\'" . pdf-view-mode)
|
2018-02-06 01:07:36 +01:00
|
|
|
:config
|
2019-05-30 18:54:58 -07:00
|
|
|
(map! :map pdf-view-mode-map :gn "q" #'kill-current-buffer)
|
2018-06-15 03:32:46 +02:00
|
|
|
|
2019-09-26 13:15:44 -04:00
|
|
|
(after! pdf-annot
|
|
|
|
(defun +pdf-cleanup-windows-h ()
|
|
|
|
"Kill left-over annotation buffers when the document is killed."
|
|
|
|
(when (buffer-live-p pdf-annot-list-document-buffer)
|
|
|
|
(pdf-info-close pdf-annot-list-document-buffer))
|
|
|
|
(when (buffer-live-p pdf-annot-list-buffer)
|
|
|
|
(kill-buffer pdf-annot-list-buffer))
|
|
|
|
(let ((contents-buffer (get-buffer "*Contents*")))
|
|
|
|
(when (and contents-buffer (buffer-live-p contents-buffer))
|
|
|
|
(kill-buffer contents-buffer))))
|
|
|
|
(add-hook! 'pdf-view-mode-hook
|
|
|
|
(add-hook 'kill-buffer-hook #'+pdf-cleanup-windows-h nil t)))
|
2018-06-15 03:32:46 +02:00
|
|
|
|
2019-08-27 12:36:20 +08:00
|
|
|
(setq-default pdf-view-display-size 'fit-page
|
|
|
|
pdf-view-use-scaling t
|
|
|
|
pdf-view-use-imagemagick nil)
|
|
|
|
|
2019-09-19 18:39:09 -04:00
|
|
|
;; Add retina support for MacOS users
|
|
|
|
(when IS-MAC
|
|
|
|
(advice-add #'pdf-util-frame-scale-factor :around #'+pdf--util-frame-scale-factor-a)
|
|
|
|
(advice-add #'pdf-view-use-scaling-p :before-until #'+pdf--view-use-scaling-p-a)
|
|
|
|
(defadvice! +pdf--supply-width-to-create-image-calls-a (orig-fn &rest args)
|
|
|
|
:around '(pdf-annot-show-annotation
|
|
|
|
pdf-isearch-hl-matches
|
|
|
|
pdf-view-display-region)
|
|
|
|
(cl-letf* ((old-create-image (symbol-function #'create-image))
|
|
|
|
((symbol-function #'create-image)
|
|
|
|
(lambda (file-or-data &optional type data-p &rest props)
|
|
|
|
(apply old-create-image file-or-data type data-p
|
|
|
|
:width (car (pdf-view-image-size))
|
|
|
|
props))))
|
|
|
|
(apply orig-fn args))))
|
|
|
|
|
2018-04-12 16:03:48 +02:00
|
|
|
;; Turn off cua so copy works
|
|
|
|
(add-hook! 'pdf-view-mode-hook (cua-mode 0))
|
|
|
|
;; Handle PDF-tools related popups better
|
2018-06-18 02:26:05 +02:00
|
|
|
(set-popup-rule! "^\\*Outline*" :side 'right :size 40 :select nil)
|
2019-09-19 18:42:46 -04:00
|
|
|
(set-popup-rule! "\\(?:^\\*Contents\\|'s annots\\*$\\)" :ignore t)
|
|
|
|
(add-hook 'pdf-annot-list-mode-hook #'hide-mode-line-mode)
|
2019-01-22 19:28:10 -05:00
|
|
|
;; Fix #1107: flickering pdfs when evil-mode is enabled
|
2019-09-20 01:19:40 -04:00
|
|
|
(setq-hook! 'pdf-view-mode-hook evil-normal-state-cursor (list nil))
|
|
|
|
|
|
|
|
;; Install epdfinfo binary if needed, blocking until it is finished
|
|
|
|
(unless (file-executable-p pdf-info-epdfinfo-program)
|
|
|
|
(let ((wconf (current-window-configuration)))
|
|
|
|
(pdf-tools-install)
|
|
|
|
(message "Building epdfinfo, this will take a moment...")
|
2019-09-22 20:15:20 -04:00
|
|
|
;; HACK We reset all `pdf-view-mode' buffers to fundamental mode so that
|
|
|
|
;; `pdf-tools-install' has a change to reinitialize them as
|
|
|
|
;; `pdf-view-mode' buffers. This is necessary because `pdf-tools-install'
|
|
|
|
;; won't do this to buffers that are already in pdf-view-mode for some
|
|
|
|
;; reason -- even though those are the buffers we need to reload!
|
2019-09-20 01:19:40 -04:00
|
|
|
(dolist (buffer (doom-buffers-in-mode 'pdf-view-mode))
|
|
|
|
(with-current-buffer buffer (fundamental-mode)))
|
|
|
|
(while compilation-in-progress
|
2019-09-22 20:15:20 -04:00
|
|
|
;; Block until `pdf-tools-install' is done
|
2019-09-20 01:19:40 -04:00
|
|
|
(sleep-for 1))
|
2019-09-22 20:15:20 -04:00
|
|
|
;; HACK If pdf-tools was loaded by you opening a pdf file, once
|
|
|
|
;; `pdf-tools-install' completes, `pdf-view-mode' will throw an error
|
|
|
|
;; because the compilation buffer is focused, not the pdf buffer.
|
|
|
|
;; Therefore, it is imperative that the window config is restored.
|
2019-09-20 01:19:40 -04:00
|
|
|
(when (file-executable-p pdf-info-epdfinfo-program)
|
|
|
|
(set-window-configuration wconf)))))
|