Add pdf-tools layer
This commit is contained in:
parent
534cb7a7cd
commit
919865a3b7
|
@ -0,0 +1,202 @@
|
|||
#+TITLE: pdf-tools layer
|
||||
#+HTML_HEAD_EXTRA: <link rel="stylesheet" type="text/css" href="../css/readtheorg.css" />
|
||||
|
||||
|
||||
* Table of Contents :TOC_4_org:noexport:
|
||||
- [[Description][Description]]
|
||||
- [[Install][Install]]
|
||||
- [[Prerequisites][Prerequisites]]
|
||||
- [[Dotfile][Dotfile]]
|
||||
- [[Usage][Usage]]
|
||||
- [[Known Issues ][Known Issues ]]
|
||||
- [[Key bindings][Key bindings]]
|
||||
- [[PDF View][PDF View]]
|
||||
- [[Leader keys][Leader keys]]
|
||||
- [[Outline buffer mode][Outline buffer mode]]
|
||||
- [[Annotation list mode][Annotation list mode]]
|
||||
- [[Occur mode][Occur mode]]
|
||||
|
||||
* Description
|
||||
This layer enables support for the [[https://github.com/politza/pdf-tools][=pdf-tools=]] package.
|
||||
|
||||
According to the official repository, "PDF Tools is, among other things, a
|
||||
replacement of DocView for PDF files. The key difference is, that pages are not
|
||||
pre-rendered by e.g. ghostscript and stored in the file-system, but rather
|
||||
created on-demand and stored in memory."
|
||||
|
||||
Examples of features that =pdf-tools= provides:
|
||||
- Use =occur= in the pdf file;
|
||||
- Show all headings in a outline buffer;
|
||||
- Manipulate annotations.
|
||||
|
||||
* Install
|
||||
** Prerequisites
|
||||
Linux is the only operating system officially supported, but it's possible to
|
||||
use =pdf-tools= on OS X as well, and possibly on other Unix flavors.
|
||||
|
||||
You'll need to install a few libraries. Check the [[https://github.com/politza/pdf-tools#server-prerequisites][instructions]] on
|
||||
=pdf-tools= page. Note that compiling from source might not be necessary, as
|
||||
the documentation states.
|
||||
|
||||
If you use a Debian based system such as Ubuntu, you can skip this step, as
|
||||
=pdf-tools= installation asks whether you want it to try to download
|
||||
automatically all dependencies using ~apt-get~.
|
||||
|
||||
|
||||
** Dotfile
|
||||
After installing the dependencies, add this to your =~/.spacemacs=.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(setq-default dotspacemacs-configuration-layers '(pdf-tools))
|
||||
#+end_src
|
||||
|
||||
After that, syncronize your configuration with ~SPC f e R~. This will pop up a
|
||||
window showing the compilation process.
|
||||
|
||||
If everything goes right, the compilation won't display any error and you will
|
||||
be able to see /PDFView/ (instead of /DocView/) on the spaceline after opening a
|
||||
pdf file.
|
||||
|
||||
If the compilation run successfully but you get
|
||||
~Error (use-package): pdf-tools :config: No executable `epdfinfo' found~,
|
||||
try restarting Spacemacs ([[https://github.com/politza/pdf-tools/issues/31][issue]]).
|
||||
|
||||
If the compilation does not run successfully, you should confirm whether all
|
||||
dependencies are properly installed and run the command ~pdf-tools-install~.
|
||||
|
||||
* Usage
|
||||
Use ~M-SPC~ or ~s-M-SPC~ to activate the pdf-tools transient state.
|
||||
The keybindings that the transient displays can be also accessed using ~SPC m~. The
|
||||
navigation keybindings can be used directly.
|
||||
|
||||
|
||||
Try out opening the outline (~O~). The outline window shows the structure of the
|
||||
pdf, displaying all headings.
|
||||
|
||||
You can set annotations by selecting regions and right clicking on the buffer.
|
||||
Additionally, all annotation related functions are can be accessed with ~SPC m a~.
|
||||
|
||||
Searching with =occur= can be done by using =pdf-occur= (~SPC m s s~).
|
||||
|
||||
Tips:
|
||||
- You'll probably want to use =pdf-view-set-slice-from-bounding-box= (bound to
|
||||
~SPC m s b~) This command trims the blank parts of the
|
||||
lateral margins, making the useful portion larger.
|
||||
- The last visited page is not saved across Emacs sessions. If you want save it,
|
||||
use the bookmarks commands =bookmark-set= (~C-x r m~) and =bookmark-jump=
|
||||
(~SPC j b~) to save and go to a bookmark, respectively.
|
||||
|
||||
|
||||
* Known Issues
|
||||
Due to =image-mode='s behaviour, the =pdf-tools= buffer might go back to the
|
||||
first page after switching windows. If this happens, you can quickly go back to
|
||||
the previous page in history with =pdf-history-backward= (~``~ in Evil state and
|
||||
~B~ in Emacs state.)
|
||||
|
||||
* Key bindings
|
||||
If you use Emacs editing style, check the key bindings at the [[https://github.com/politza/pdf-tools#some-keybindings][pdf-tools page]].
|
||||
|
||||
** PDF View
|
||||
|
||||
| *Key Binding* | *Description* |
|
||||
|----------------------+-------------------------------------------|
|
||||
| *Navigation* | |
|
||||
|----------------------+-------------------------------------------|
|
||||
| ~M-SPC~ or ~s-M-SPC~ | pdf-tools transient state |
|
||||
| ~J~ | Move to next page |
|
||||
| ~K~ | Move to previous page |
|
||||
| ~u~ | Scroll page up |
|
||||
| ~d~ | Scroll page down |
|
||||
| ~gg~ | Go to the first page |
|
||||
| ~G~ | Go to the last page |
|
||||
| ~gt~ | Go to page |
|
||||
| ~gl~ | Go to label (usually the line as printed) |
|
||||
| ~C-u~ | Scroll up |
|
||||
| ~C-d~ | Scroll down |
|
||||
| ~``~ | Go to last page in the history |
|
||||
| ~m~ | Set mark |
|
||||
| ~'~ | Go to mark |
|
||||
| ~y~ | Yank selected region |
|
||||
|----------------------+-------------------------------------------|
|
||||
| *Search* | |
|
||||
|----------------------+-------------------------------------------|
|
||||
| ~/~ | Search forward |
|
||||
| ~?~ | Search backward |
|
||||
|----------------------+-------------------------------------------|
|
||||
| *Actions* | |
|
||||
|----------------------+-------------------------------------------|
|
||||
| ~o~ | Follow link |
|
||||
| ~O~ | Show outline |
|
||||
| ~r~ | Refresh file |
|
||||
|----------------------+-------------------------------------------|
|
||||
|
||||
/For evil users/: Note that the search keys activate =isearch=, which works
|
||||
differently from the default Evil search. To go to the next match, use ~C-s~.
|
||||
|
||||
** Leader keys
|
||||
|
||||
| *Key Binding* | *Description* |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| *Slicing* | |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| ~sm~ | Set slice using mouse |
|
||||
| ~sb~ | Set slice from bounding box |
|
||||
| ~sr~ | Reset slice |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| *Annotations* | |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| ~aD~ | Delete annotation (select it with mouse) |
|
||||
| ~aa~ | List all attachments in a dired buffer |
|
||||
| ~ah~ | Highlight visual selection |
|
||||
| ~al~ | List all annotations |
|
||||
| ~am~ | Add markup annotation to visual selection |
|
||||
| ~ao~ | Strikeout visual selection |
|
||||
| ~as~ | Add squiggly to visual selection |
|
||||
| ~at~ | Add annotation text |
|
||||
| ~au~ | Underline to visual selection |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| *Fit image to window* | |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| ~fw~ | Fit width to window |
|
||||
| ~fh~ | Fit height to window |
|
||||
| ~fp~ | Fit page to window |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| *Other* | |
|
||||
|-----------------------+-------------------------------------------|
|
||||
| ~n~ | Toggle night view mode |
|
||||
| ~s~ | Run =pdf-occur= |
|
||||
| ~p~ | Display print version |
|
||||
|
||||
** Outline buffer mode
|
||||
|
||||
| *Key Binding* | *Description* |
|
||||
|---------------+-------------------------------------------------------|
|
||||
| ~S-tab~ | Expand all trees |
|
||||
| ~RET~ | Follow link |
|
||||
| ~M-RET~ | Follow link and close outline window |
|
||||
| ~o~ | Go to pdf view window |
|
||||
| ~``~ | Move to the heading correspondent to the current page |
|
||||
| ~''~ | Move to the heading correspondent to the current page |
|
||||
| ~f~ | Go to selected heading without leaving outline buffer |
|
||||
| ~F~ | Enable follow mode |
|
||||
| ~q~ | Quit |
|
||||
| ~Q~ | Quit and kill outline buffer |
|
||||
|
||||
Note that you can use also typical Vim keys such as ~j~ and ~G~.
|
||||
|
||||
** Annotation list mode
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+-------------------------------|
|
||||
| ~d~ | Mark for deletion |
|
||||
| ~x~ | Apply action for marked items |
|
||||
| ~u~ | Unmark item |
|
||||
| ~q~ | Quit |
|
||||
|
||||
** Occur mode
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+----------------|
|
||||
| ~q~ | Quit |
|
||||
| ~g~ | Refresh buffer |
|
||||
| ~r~ | Refresh buffer |
|
|
@ -0,0 +1,181 @@
|
|||
;;; packages.el --- pdf-tools Layer packages File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2014 Sylvain Benner
|
||||
;; Copyright (c) 2014-2016 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: André Peric Tavares <andre.peric.tavares@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(setq pdf-tools-packages
|
||||
'(
|
||||
pdf-tools
|
||||
))
|
||||
|
||||
(defun pdf-tools/init-pdf-tools ()
|
||||
(use-package pdf-tools
|
||||
:defer t
|
||||
:mode (("\\.pdf$" . pdf-view-mode))
|
||||
:config
|
||||
(progn
|
||||
(pdf-tools-install)
|
||||
;; TODO: Make `/', `?' and `n' work like in Evil
|
||||
(evilified-state-evilify pdf-view-mode pdf-view-mode-map
|
||||
;; Navigation
|
||||
"j" 'pdf-view-next-line-or-next-page
|
||||
"k" 'pdf-view-previous-line-or-previous-page
|
||||
"l" 'image-forward-hscroll
|
||||
"h" 'image-backward-hscroll
|
||||
"J" 'pdf-view-next-page
|
||||
"K" 'pdf-view-previous-page
|
||||
"gg" 'pdf-view-first-page
|
||||
"G" 'pdf-view-last-page
|
||||
"gt" 'pdf-view-goto-page
|
||||
"gl" 'pdf-view-goto-label
|
||||
"u" 'pdf-view-scroll-down-or-previous-page
|
||||
"d" 'pdf-view-scroll-up-or-next-page
|
||||
(kbd "C-u") 'pdf-view-scroll-down-or-previous-page
|
||||
(kbd "C-d") 'pdf-view-scroll-up-or-next-page
|
||||
(kbd "``") 'pdf-history-backward
|
||||
;; Search
|
||||
"/" 'isearch-forward
|
||||
"?" 'isearch-backward
|
||||
;; Actions
|
||||
"r" 'pdf-view-revert-buffer
|
||||
"o" 'pdf-links-action-perform
|
||||
"O" 'pdf-outline
|
||||
)
|
||||
|
||||
(evil-define-key 'visual pdf-view-mode-map
|
||||
"y" 'pdf-view-kill-ring-save
|
||||
)
|
||||
|
||||
(spacemacs/declare-prefix-for-mode 'pdf-view-mode "ma" "annotations")
|
||||
(spacemacs/declare-prefix-for-mode 'pdf-view-mode "mf" "fit")
|
||||
(spacemacs/declare-prefix-for-mode 'pdf-view-mode "ms" "slice/search")
|
||||
|
||||
(spacemacs/set-leader-keys-for-major-mode 'pdf-view-mode
|
||||
;; Slicing image
|
||||
"sm" 'pdf-view-set-slice-using-mouse
|
||||
"sb" 'pdf-view-set-slice-from-bounding-box
|
||||
"sr" 'pdf-view-reset-slice
|
||||
;; Annotations
|
||||
"aD" 'pdf-annot-delete
|
||||
"at" 'pdf-annot-attachment-dired
|
||||
"ah" 'pdf-annot-add-highlight-markup-annotation
|
||||
"al" 'pdf-annot-list-annotations
|
||||
"am" 'pdf-annot-add-markup-annotation
|
||||
"ao" 'pdf-annot-add-strikeout-markup-annotation
|
||||
"as" 'pdf-annot-add-squiggly-markup-annotation
|
||||
"at" 'pdf-annot-add-text-annotation
|
||||
"au" 'pdf-annot-add-underline-markup-annotation
|
||||
;; Fit image to window
|
||||
"fw" 'pdf-view-fit-width-to-window
|
||||
"fh" 'pdf-view-fit-height-to-window
|
||||
"fp" 'pdf-view-fit-page-to-window
|
||||
;; Other
|
||||
"ss" 'pdf-occur
|
||||
"p" 'pdf-misc-print-document
|
||||
"O" 'pdf-outline
|
||||
"n" 'pdf-view-midnight-minor-mode
|
||||
)
|
||||
|
||||
|
||||
(evilified-state-evilify pdf-outline-buffer-mode pdf-outline-buffer-mode-map
|
||||
"-" 'negative-argument
|
||||
"j" 'next-line
|
||||
"k" 'previous-line
|
||||
"gk" 'outline-backward-same-level
|
||||
"gj" 'outline-forward-same-level
|
||||
(kbd "<backtab>") 'show-all
|
||||
"gh" 'pdf-outline-up-heading
|
||||
"gg" 'beginning-of-buffer
|
||||
"G" 'pdf-outline-end-of-buffer
|
||||
"TAB" 'outline-toggle-children
|
||||
"RET" 'pdf-outline-follow-link
|
||||
(kbd "M-RET") 'pdf-outline-follow-link-and-quit
|
||||
"f" 'pdf-outline-display-link
|
||||
[mouse-1] 'pdf-outline-mouse-display-link
|
||||
"o" 'pdf-outline-select-pdf-window
|
||||
"``" 'pdf-outline-move-to-current-page
|
||||
"''" 'pdf-outline-move-to-current-page
|
||||
"Q" 'pdf-outline-quit-and-kill
|
||||
"q" 'quit-window
|
||||
"F" 'pdf-outline-follow-mode
|
||||
)
|
||||
|
||||
(evilified-state-evilify pdf-annot-list-mode pdf-annot-list-mode-map
|
||||
"f" 'pdf-annot-list-display-annotation-from-id
|
||||
"d" 'tablist-flag-forward
|
||||
"x" 'tablist-do-flagged-delete
|
||||
"u" 'tablist-unmark-forward
|
||||
"q" 'tablist-quit
|
||||
)
|
||||
|
||||
(evilified-state-evilify pdf-occur-buffer-mode pdf-occur-buffer-mode-map
|
||||
"q" 'tablist-quit
|
||||
"g" 'pdf-occur-revert-buffer-with-args
|
||||
"r" 'pdf-occur-revert-buffer-with-args
|
||||
"*" 'spacemacs/enter-ahs-forward
|
||||
"?" 'evil-search-backward
|
||||
)))
|
||||
|
||||
(spacemacs|define-transient-state pdf-tools
|
||||
:title "PDF-tools transient state"
|
||||
:on-enter (setq which-key-inhibit t)
|
||||
:on-exit (setq which-key-inhibit nil)
|
||||
:doc
|
||||
"
|
||||
Navigation^^^^ Scale/Fit^^ Annotations^^ Actions^^ Other^^
|
||||
----------^^^^--------------- ---------^^------------------ -----------^^------ -------^^---------- -----^^---
|
||||
[_j_/_k_] scroll down/up [_W_] fit to width [_al_] list [_s_] search [_q_] quit
|
||||
[_h_/_l_] scroll left/right [_H_] fit to height [_at_] text [_O_] outline
|
||||
[_d_/_u_] pg down/up [_P_] fit to page [_aD_] delete [_p_] print
|
||||
[_J_/_K_] next/prev pg [_m_] slice using mouse [_am_] markup [_o_] open link
|
||||
^^^^ [_b_] slice from bounding box ^^ [_r_] revert
|
||||
^^^^ [_R_] reset slice ^^ [_t_] attachments
|
||||
^^^^ ^^ ^^ [_n_] night mode
|
||||
"
|
||||
:bindings
|
||||
;; Navigation
|
||||
("j" pdf-view-next-line-or-next-page)
|
||||
("k" pdf-view-previous-line-or-previous-page)
|
||||
("l" image-forward-hscroll)
|
||||
("h" image-backward-hscroll)
|
||||
("J" pdf-view-next-page)
|
||||
("K" pdf-view-previous-page)
|
||||
("u" pdf-view-scroll-down-or-previous-page)
|
||||
("d" pdf-view-scroll-up-or-next-page)
|
||||
;; Scale/Fit
|
||||
("W" pdf-view-fit-width-to-window)
|
||||
("H" pdf-view-fit-height-to-window)
|
||||
("P" pdf-view-fit-page-to-window)
|
||||
("m" pdf-view-set-slice-using-mouse)
|
||||
("b" pdf-view-set-slice-from-bounding-box)
|
||||
("R" pdf-view-reset-slice)
|
||||
;; Annotations
|
||||
("aD" pdf-annot-delete)
|
||||
("at" pdf-annot-attachment-dired :exit t)
|
||||
("al" pdf-annot-list-annotations :exit t)
|
||||
("am" pdf-annot-add-markup-annotation)
|
||||
;; Actions
|
||||
("s" pdf-occur :exit t)
|
||||
("O" pdf-outline :exit t)
|
||||
("p" pdf-misc-print-document :exit t)
|
||||
("o" pdf-links-action-perform :exit t)
|
||||
("r" pdf-view-revert-buffer)
|
||||
("t" pdf-annot-attachment-dired :exit t)
|
||||
("n" pdf-view-midnight-minor-mode)
|
||||
;; Other
|
||||
("q" nil :exit t))
|
||||
|
||||
;; pdf-view-mode-map is not recognized unless wrapped in with-eval-after-load
|
||||
(with-eval-after-load "pdf-view"
|
||||
(define-key pdf-view-mode-map (kbd "M-SPC")
|
||||
|
||||
'spacemacs/pdf-tools-transient-state/body)
|
||||
(define-key pdf-view-mode-map (kbd "s-M-SPC")
|
||||
'spacemacs/pdf-tools-transient-state/body)))
|
Loading…
Reference in New Issue