yeet
This commit is contained in:
109
.config/emacs/modules/tools/pdf/README.org
Normal file
109
.config/emacs/modules/tools/pdf/README.org
Normal file
@@ -0,0 +1,109 @@
|
||||
#+TITLE: tools/pdf
|
||||
#+DATE: February 6, 2018
|
||||
#+SINCE: v2.0
|
||||
#+STARTUP: inlineimages nofold
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#maintainers][Maintainers]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#hacks][Hacks]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#building-epdfinfo-on-windows][Building =epdfinfo= on Windows]]
|
||||
- [[#features][Features]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
|
||||
* Description
|
||||
This module improves support for reading and interacting with PDF files in Emacs.
|
||||
|
||||
It uses =pdf-tools=, which is a replacement for the built-in ~doc-view-mode~ for
|
||||
PDF files. The key difference being pages are not pre-rendered, but instead
|
||||
rendered on-demand and stored in memory; a much faster approach, especially for
|
||||
larger PDFs.
|
||||
|
||||
Displaying PDF files is just one function of =pdf-tools=. See [[https://github.com/politza/pdf-tools][its project
|
||||
website]] for details and videos.
|
||||
|
||||
** Maintainers
|
||||
This module has no dedicated maintainers.
|
||||
|
||||
** Module Flags
|
||||
This module provides no flags.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/politza/pdf-tools][pdf-tools]]
|
||||
|
||||
** Hacks
|
||||
+ Added out-of-the-box support for HiDPI or Retina displays.
|
||||
|
||||
* Prerequisites
|
||||
This module requires =epdfinfo=, a program the the =pdf-tools= plugin will build
|
||||
automatically when you open your first pdf file, unless you're on Windows.
|
||||
Windows users must build it themselves.
|
||||
|
||||
** Building =epdfinfo= on Windows
|
||||
1. [[https://www.msys2.org/][Install MSYS2]] and update the package database and core packages using the
|
||||
instructions provided.
|
||||
|
||||
2. Update and install dependencies, skipping any you already have
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
pacman -Syu
|
||||
pacman -S base-devel
|
||||
pacman -S mingw-w64-x86_64-toolchain
|
||||
pacman -S mingw-w64-x86_64-zlib
|
||||
pacman -S mingw-w64-x86_64-libpng
|
||||
pacman -S mingw-w64-x86_64-poppler
|
||||
pacman -S mingw-w64-x86_64-imagemagick
|
||||
#+END_SRC
|
||||
|
||||
3. Install PDF tools in Emacs, but do not try to compile the server. Instead, get a separate copy of the source somewhere else.
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
git clone https://github.com/politza/pdf-tools
|
||||
#+END_SRC
|
||||
|
||||
4. Open mingw64 shell (Note: You must use mingw64.exe and not msys2.exe)
|
||||
|
||||
5. Compile pdf-tools:
|
||||
#+BEGIN_SRC sh
|
||||
# Cask requires python2 (important: not 3!)
|
||||
pacman -S python2
|
||||
|
||||
# Make the mingw-shell aware of your python installation. Adjust the path if
|
||||
# Emacs is installed elsewhere!
|
||||
export PATH="/c/Program Files (x86)/Emacs/bin/:$PATH"
|
||||
|
||||
# Cask needs to know where git.exe is; change this path if git is installed
|
||||
# elsewhere!
|
||||
export PATH="/c/Program Files/Git/bin:$PATH"
|
||||
|
||||
# Install cask. Certificate errors can be ignored with (unsafe) -k option.
|
||||
curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
|
||||
|
||||
# Make sure the build process can see cask
|
||||
export PATH="$HOME/.cask/bin:$PATH"
|
||||
|
||||
cd /path/to/pdf-tools
|
||||
make -s
|
||||
#+END_SRC
|
||||
|
||||
6. This should produce a file =server/epdfinfo.exe=. Copy this file into the
|
||||
=~/.emacs.d/.local/straight/build/pdf-tools/=.
|
||||
|
||||
7. Start Emacs.
|
||||
|
||||
8. Open a pdf file (or run ~M-x pdf-tools-install~)
|
||||
|
||||
9. Test it out: ~M-x pdf-info-check-epdfinfo~
|
||||
|
||||
* TODO Features
|
||||
# An in-depth list of features, how to use them, and their dependencies.
|
||||
|
||||
* TODO Configuration
|
||||
# How to configure this module, including common problems and how to address them.
|
||||
|
||||
* TODO Troubleshooting
|
||||
# Common issues and their solution, or places to look for help.
|
||||
84
.config/emacs/modules/tools/pdf/config.el
Normal file
84
.config/emacs/modules/tools/pdf/config.el
Normal file
@@ -0,0 +1,84 @@
|
||||
;;; tools/pdf/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(use-package! pdf-tools
|
||||
:mode ("\\.pdf\\'" . pdf-view-mode)
|
||||
:magic ("%PDF" . pdf-view-mode)
|
||||
:init
|
||||
(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)))
|
||||
|
||||
:config
|
||||
(defadvice! +pdf--install-epdfinfo-a (fn &rest args)
|
||||
"Install epdfinfo after the first PDF file, if needed."
|
||||
:around #'pdf-view-mode
|
||||
(if (file-executable-p pdf-info-epdfinfo-program)
|
||||
(apply fn args)
|
||||
;; If we remain in pdf-view-mode, it'll spit out cryptic errors. This
|
||||
;; graceful failure is better UX.
|
||||
(fundamental-mode)
|
||||
(message "Viewing PDFs in Emacs requires epdfinfo. Use `M-x pdf-tools-install' to build it")))
|
||||
|
||||
(pdf-tools-install-noverify)
|
||||
|
||||
;; For consistency with other special modes
|
||||
(map! :map pdf-view-mode-map :gn "q" #'kill-current-buffer)
|
||||
|
||||
(setq-default pdf-view-display-size 'fit-page)
|
||||
;; Enable hiDPI support, but at the cost of memory! See politza/pdf-tools#51
|
||||
(setq pdf-view-use-scaling t
|
||||
pdf-view-use-imagemagick nil)
|
||||
|
||||
;; Handle PDF-tools related popups better
|
||||
(set-popup-rules!
|
||||
'(("^\\*Outline*" :side right :size 40 :select nil)
|
||||
("^\\*Edit Annotation " :quit nil)
|
||||
("\\(?:^\\*Contents\\|'s annots\\*$\\)" :ignore t)))
|
||||
|
||||
;; The mode-line does serve any useful purpose is annotation windows
|
||||
(add-hook 'pdf-annot-list-mode-hook #'hide-mode-line-mode)
|
||||
|
||||
;; HACK Fix #1107: flickering pdfs when evil-mode is enabled
|
||||
(setq-hook! 'pdf-view-mode-hook evil-normal-state-cursor (list nil))
|
||||
|
||||
;; HACK Refresh FG/BG for pdfs when `pdf-view-midnight-colors' is changed by a
|
||||
;; theme or with `setq!'.
|
||||
;; TODO PR this upstream?
|
||||
(defun +pdf-reload-midnight-minor-mode-h ()
|
||||
(when pdf-view-midnight-minor-mode
|
||||
(pdf-info-setoptions
|
||||
:render/foreground (car pdf-view-midnight-colors)
|
||||
:render/background (cdr pdf-view-midnight-colors)
|
||||
:render/usecolors t)
|
||||
(pdf-cache-clear-images)
|
||||
(pdf-view-redisplay t)))
|
||||
(put 'pdf-view-midnight-colors 'custom-set
|
||||
(lambda (sym value)
|
||||
(set-default sym value)
|
||||
(dolist (buffer (doom-buffers-in-mode 'pdf-view-mode))
|
||||
(with-current-buffer buffer
|
||||
(if (get-buffer-window buffer)
|
||||
(+pdf-reload-midnight-minor-mode-h)
|
||||
;; Defer refresh for buffers that aren't visible, to avoid
|
||||
;; blocking Emacs for too long while changing themes.
|
||||
(add-hook 'doom-switch-buffer-hook #'+pdf-reload-midnight-minor-mode-h
|
||||
nil 'local))))))
|
||||
|
||||
;; Silence "File *.pdf is large (X MiB), really open?" prompts for pdfs
|
||||
(defadvice! +pdf-suppress-large-file-prompts-a (fn size op-type filename &optional offer-raw)
|
||||
:around #'abort-if-file-too-large
|
||||
(unless (string-match-p "\\.pdf\\'" filename)
|
||||
(funcall fn size op-type filename offer-raw))))
|
||||
|
||||
|
||||
(use-package! saveplace-pdf-view
|
||||
:after pdf-view)
|
||||
5
.config/emacs/modules/tools/pdf/packages.el
Normal file
5
.config/emacs/modules/tools/pdf/packages.el
Normal file
@@ -0,0 +1,5 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; tools/pdf/packages.el
|
||||
|
||||
(package! pdf-tools :pin "4e6c778194bea39d81871a3caa0b72539fdb6868")
|
||||
(package! saveplace-pdf-view :pin "54ed966b842501c3c092dbf57b372e37b033c578")
|
||||
Reference in New Issue
Block a user