summaryrefslogtreecommitdiff
path: root/evil-pdf.el
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2017-11-06 17:53:22 +0100
committerPierre Neidhardt <ambrevar@gmail.com>2017-11-06 17:53:22 +0100
commit25eaaa49bf9dcf393b30e1cc7cb28b715f21d8d3 (patch)
treec42aa93150749c98e5906cd5ef953f1b7c49eb0a /evil-pdf.el
parentb1433f101a3ae99c2c37512a03be3a6b01517ccf (diff)
Add evil-pdf
Diffstat (limited to 'evil-pdf.el')
-rw-r--r--evil-pdf.el220
1 files changed, 220 insertions, 0 deletions
diff --git a/evil-pdf.el b/evil-pdf.el
new file mode 100644
index 0000000..51ba499
--- /dev/null
+++ b/evil-pdf.el
@@ -0,0 +1,220 @@
+;;; evil-pdf.el --- Evil bindings for pdf-tools -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Pierre Neidhardt
+
+;; Author: Pierre Neidhardt <ambrevar@gmail.com>
+;; Maintainer: James Nguyen <james@jojojames.com>, Pierre Neidhardt <ambrevar@gmail.com>
+;; URL: https://github.com/jojojames/evil-collection
+;; Version: 0.0.1
+;; Package-Requires: ((emacs "25.1"))
+;; Keywords: emacs, compile, evil
+;; HomePage: https://github.com/jojojames/evil-collection
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published
+;; by the Free Software Foundation; either version 3, or (at your
+;; option) any later version.
+;;
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; For a full copy of the GNU General Public License
+;; see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+;; TODO: `image-mode-map' is the parent of `pdf-view-mode-map'. A bug(?) in
+;; image-mode-map and pdf-mode-map seem to conflict with Evil.
+;; See https://github.com/emacs-evil/evil/issues/938
+;; and https://github.com/politza/pdf-tools/issues/324.
+;; Changing load order only changes which mode overrides the other.
+
+(require 'evil)
+(require 'pdf-view)
+
+(defun evil-pdf-view-goto-page (&optional page)
+ (interactive "P")
+ (if page
+ (pdf-view-goto-page page)
+ (pdf-view-last-page)))
+
+(defun evil-pdf-view-goto-first-page (&optional page)
+ (interactive "P")
+ (if page
+ (pdf-view-goto-page page)
+ (pdf-view-first-page)))
+
+(defun evil-pdf-set-keys ()
+ (evil-set-initial-state 'pdf-view-mode 'motion)
+ (evil-define-key 'motion pdf-view-mode-map
+ ;; motion
+ (kbd "<return>") 'image-next-line
+ "j" 'pdf-view-next-line-or-next-page
+ "k" 'pdf-view-previous-line-or-previous-page
+ (kbd "SPC") 'pdf-view-scroll-up-or-next-page
+ (kbd "S-SPC") 'pdf-view-scroll-down-or-previous-page
+ (kbd "<delete>") 'pdf-view-scroll-down-or-previous-page
+ (kbd "C-f") 'pdf-view-scroll-up-or-next-page
+ (kbd "C-b") 'pdf-view-scroll-down-or-previous-page
+ "]" 'pdf-view-next-page-command
+ "[" 'pdf-view-previous-page-command
+ (kbd "C-j") 'pdf-view-next-page-command
+ (kbd "C-k") 'pdf-view-previous-page-command
+ (kbd "<next>") 'forward-page
+ (kbd "<prior>") 'backward-page
+ (kbd "<down>") 'pdf-view-next-line-or-next-page
+ (kbd "<up>") 'pdf-view-previous-line-or-previous-page
+ "gg" 'evil-pdf-view-goto-first-page
+ "G" 'evil-pdf-view-goto-page
+
+ ;; mark
+ "'" 'pdf-view-jump-to-register
+ "m" 'pdf-view-position-to-register
+
+ "+" 'pdf-view-enlarge
+ "-" 'pdf-view-shrink
+ "0" 'pdf-view-scale-reset
+ "=" 'pdf-view-enlarge
+
+ ;; TODO: Why are those image-* bindings in pdf-tools?
+ "a+" 'image-increase-speed
+ "a-" 'image-decrease-speed
+ "a0" 'image-reset-speed
+ "ar" 'image-reverse-speed
+ "F" 'image-goto-frame
+ "b" 'image-previous-frame
+ "f" 'image-next-frame
+ "h" 'image-backward-hscroll
+ "^" 'image-bol
+ "$" 'image-eol
+ "l" 'image-forward-hscroll
+
+ "H" 'pdf-view-fit-height-to-window ; evil-image has "H"
+ "P" 'pdf-view-fit-page-to-window
+ "W" 'pdf-view-fit-width-to-window ; evil-image has "W"
+
+ ;; update
+ "gr" 'revert-buffer
+
+ (kbd "<C-down-mouse-1>") 'pdf-view-mouse-extend-region
+ (kbd "<M-down-mouse-1>") 'pdf-view-mouse-set-region-rectangle
+ (kbd "<down-mouse-1>") 'pdf-view-mouse-set-region
+
+ (kbd "C-c C-c") 'docview-mode
+ (kbd "C-c <tab>") 'pdf-view-extract-region-image
+
+ "sb" 'pdf-view-set-slice-from-bounding-box
+ "sm" 'pdf-view-set-slice-using-mouse
+ "sr" 'pdf-view-reset-slice
+
+ ;; goto
+ "gl" 'pdf-view-goto-label
+
+ "y" 'pdf-view-kill-ring-save
+
+ ;; search
+ (kbd "M-s o") 'pdf-occur ; TODO: More Evil bindings?
+
+ "zd" 'pdf-view-dark-minor-mode
+ "zm" 'pdf-view-midnight-minor-mode
+ "zp" 'pdf-view-printer-minor-mode
+
+ ;; quit
+ "q" 'quit-window
+ "Q" 'kill-this-buffer
+ "ZQ" 'kill-this-buffer
+ "ZZ" 'quit-window)
+
+ (evil-set-initial-state 'pdf-outline-buffer-mode 'motion)
+ (evil-define-key 'motion pdf-outline-buffer-mode-map
+ (kbd "<return>") 'pdf-outline-follow-link
+ (kbd "M-<return>") 'pdf-outline-follow-link-and-quit
+ (kbd "SPC") 'pdf-outline-display-link
+ "." 'pdf-outline-move-to-current-page
+ "o" 'pdf-outline-select-pdf-window
+
+ "G" 'pdf-outline-end-of-buffer
+ "^" 'pdf-outline-up-heading
+ "<" 'pdf-outline-up-heading ; TODO: Don't set this by default?
+
+ "zf" 'pdf-outline-follow-mode ; Helm has "C-c C-f" in Emacs state.
+
+ ;; quit
+ (kbd "C-w q") 'pdf-outline-quit-and-kill ; TODO: Do we need to set this? I think not.
+ "q" 'quit-window
+ "ZQ" 'quit-window
+ "ZZ" 'pdf-outline-quit-and-kill)
+
+ (evil-define-key 'motion pdf-occur-buffer-mode-map
+ (kbd "<return>") 'pdf-occur-goto-occurrence
+ (kbd "o") 'pdf-occur-view-occurrence
+ (kbd "C-o") 'pdf-occur-view-occurrence ; TODO: "o" is probably a better binding.
+ (kbd "SPC") 'pdf-occur-view-occurrence
+
+ "A" 'pdf-occur-tablist-gather-documents
+ "D" 'pdf-occur-tablist-do-delete
+
+ ;; sort
+ "S" 'tabulated-list-sort
+
+ ;; update
+ "G" 'tablist-revert
+
+ "K" 'pdf-occur-abort-search
+
+ ;; mark
+ "*m" 'tablist-mark-forward
+ "m" 'tablist-mark-forward
+ "~" 'tablist-toggle-marks
+ "u" 'tablist-unmark-forward
+ "M" 'tablist-unmark-all-marks
+ "*!" 'tablist-unmark-all-marks
+ "*c" 'tablist-change-marks
+ "*n" 'tablist-mark-items-numeric
+ "*r" 'tablist-mark-items-regexp
+ "%" 'tablist-mark-items-regexp
+
+ "a" 'tablist-flag-forward
+
+ ;; "f" 'tablist-find-entry ; TODO: Equivalent to 'pdf-occur-goto-occurrence?
+ "r" 'pdf-occur-revert-buffer-with-args
+ "d" 'tablist-do-kill-lines
+ "s" 'tablist-sort
+ "x" 'pdf-occur-tablist-do-flagged-delete
+ (kbd "<delete>") 'tablist-unmark-backward
+ (kbd "S-SPC") 'scroll-down-command
+ (kbd "<backtab>") 'tablist-backward-column
+ (kbd "C-c C-e") 'tablist-export-csv
+
+ [remap evil-first-non-blank] 'tablist-move-to-major-columnj
+ [remap evil-next-line] 'tablist-next-line
+ [remap evil-previous-line] 'tablist-previous-line
+
+ ;; filter
+ ;; TODO: See if overriding "/" is a good idea.
+ "/!" 'tablist-negate-filter
+ "//" 'tablist-display-filter
+ "/=" 'tablist-push-equal-filter
+ "/C" 'tablist-clear-filter
+ "/D" 'tablist-delete-named-filter
+ "/a" 'tablist-push-named-filter
+ "/d" 'tablist-deconstruct-named-filter
+ "/e" 'tablist-edit-filter
+ "/n" 'tablist-push-numeric-filter
+ "/p" 'tablist-pop-filter
+ "/r" 'tablist-push-regexp-filter
+ "/s" 'tablist-name-current-filter
+ "/t" 'tablist-toggle-first-filter-logic
+ "/z" 'tablist-suspend-filter
+
+ ;; quit
+ "q" 'tablist-quit
+ "ZQ" 'tablist-quit
+ "ZZ" 'tablist-quit))
+
+(provide 'evil-pdf)
+;;; evil-pdf.el ends here