about summary refs log tree commit diff stats
path: root/lisp/+pdf-tools.el
blob: 9b15b2743f62638bc55c1196b9fb792999c7b8a6 (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
;;; +pdf-tools.el --- Extras for the excellent pdf-tools' -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:

;; XXX: The way I'm dispatching browsers here is /very/ down-and-dirty.  It
;; needs to be much improved.

(defun +pdf-view-open-all-pagelinks (&optional browse-url-func)
  "Open all the links on this page of a PDF.
BROWSE-URL-FUNC overrides the default `browse-url'."
  (interactive)
  (let ((links (pdf-info-pagelinks (pdf-view-current-page)))
        (browse-url-func (or browse-url-func #'browse-url))
        (seen))
    (dolist (link links)
      (when-let* ((uri (alist-get 'uri link))
                  (_ (not (member uri seen))))
        (push uri seen)
        (funcall browse-url-func uri)))))

(defun +pdf-view-open-links-in-chrome ()
  "Open all links on this PDF page in Chrome.
See also `+pdf-view-open-all-pagelinks'."
  (interactive)
  (+pdf-view-open-all-pagelinks #'browse-url-chrome))

(defun +pdf-view-position (&optional spacer)
  "Return the page we're on for the modeline."
  (when (derived-mode-p 'pdf-view-mode)
    (format "%sp.%s/%s"
            (or spacer (bound-and-true-p +modeline-default-spacer) " ")
            (pdf-view-current-page)
            (pdf-info-number-of-pages))))

(provide '+pdf-tools)
;;; +pdf-tools.el ends here