summaryrefslogtreecommitdiff
path: root/pdf.el
blob: f595e7bd74d179a3b3951ad5916dec3f4496c351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(use-package "pdf-tools/lisp" 'pdf-view)

;;;###autoload
(defun pdf-view-down-half-page-or-previous-page ()
  "Scroll down half page or go to the previous page."
  (interactive)
  (pdf-view-scroll-down-or-previous-page
   (floor (window-body-height) 2)))

;;;###autoload
(defun pdf-view-up-half-page-or-next-page ()
  "Scroll down half page or go to the previous page."
  (interactive)
  (pdf-view-scroll-up-or-next-page
   (floor (window-body-height) 2)))

;; If this information is shown in the mode line, then it will take a
;; century to display a PDF page, probably because it uses such
;; functions as `image-next-line', thus I bind a key to show this
;; information when I want to acquire this information.

;;;###autoload
(defun pdf-view-page-position ()
  (interactive)
  "Show the current position in the page."
  (let* ((edges (pdf-util-image-displayed-edges nil t))
         (percent-floats (pdf-util-scale-pixel-to-relative
                          (cons (car edges) (cadr edges)) nil t))
         (bottom-p
          (cond ((= (window-vscroll nil pdf-view-have-image-mode-pixel-vscroll)
                    (image-next-line 1)))
                ;; The return value of `image-previous-line' is not
                ;; specified in its documentation string, but if
                ;; `image-previous-line' returns a non-nil value, then
                ;; this will return nil; if it returns nil, then this
                ;; still returns nil.
                ((image-previous-line 1) nil)))
         (str
          (cond
           ((and bottom-p (= (cdr percent-floats) 0)) "All")
           ((= (cdr percent-floats) 0) "Top")
           (bottom-p "Bot")
           ((format "%d%%%%" (* 100 (cdr percent-floats)))))))
    (message str)))

(define-key pdf-view-mode-map (vector ?j) #'pdf-view-next-line-or-next-page)
(define-key pdf-view-mode-map (vector ?k) #'pdf-view-previous-line-or-previous-page)
(define-key pdf-view-mode-map (vector ?y) #'pdf-view-previous-line-or-previous-page)
(define-key pdf-view-mode-map (vector ?d) #'pdf-view-up-half-page-or-next-page)
(define-key pdf-view-mode-map (vector ?u) #'pdf-view-down-half-page-or-previous-page)
(define-key pdf-view-mode-map (vector 'tab) #'pdf-view-page-position)
(define-key pdf-view-mode-map (vector ?\C-<) #'image-scroll-left)
(define-key pdf-view-mode-map (vector ?\C->) #'image-scroll-right)

(use-package "pdf-tools/lisp" 'pdf-history)
(use-package "pdf-tools/lisp" 'pdf-links)
(use-package "pdf-tools/lisp" 'pdf-outline)
(use-package "pdf-tools/lisp" 'pdf-sync)
(use-package "pdf-tools/lisp" 'pdf-occur)
(use-package "pdf-tools/lisp" 'pdf-annot)
(use-package "pdf-tools/lisp" 'pdf-tools)
(pdf-tools-install)