summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Nelson <ultrono@gmail.com>2025-04-05 20:24:57 +0200
committerPaul Nelson <ultrono@gmail.com>2025-04-05 20:25:43 +0200
commit85c60d708b4a8b5bd5a4f0801559b215a4e6f768 (patch)
tree04fa7c7176599f6c390c910b10e260040d274f83
parent592eb01b8ba102fba33f9ddee46152857126170d (diff)
Re-add support for pdf-tools, now via generics
* doc-view-follow-pdf-tools.el: New file providing support for 'doc-view-follow-mode' when using pdf-tools. (doc-view-follow-supported-p, doc-view-follow-setup) (doc-view-follow-teardown, doc-view-follow-set-page) (doc-view-follow-get-page): New generic function implementations.
-rw-r--r--doc-view-follow-pdf-tools.el57
1 files changed, 57 insertions, 0 deletions
diff --git a/doc-view-follow-pdf-tools.el b/doc-view-follow-pdf-tools.el
new file mode 100644
index 0000000..d4c4092
--- /dev/null
+++ b/doc-view-follow-pdf-tools.el
@@ -0,0 +1,57 @@
+;;; doc-view-follow-pdf-tools.el --- Support for doc-view-follow-mode with pdf-tools -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2025 Free Software Foundation, Inc.
+
+;; Author: Paul D. Nelson <ultrono@gmail.com>
+;; Keywords: convenience
+
+;; This program 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 of the License, or
+;; (at your option) any later version.
+
+;; This program 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.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Support for `doc-view-follow-mode' with `pdf-tools'.
+
+;;; Code:
+
+(require 'doc-view-follow)
+(require 'pdf-view)
+
+(declare-function doc-view-follow-sync-pages "doc-view-follow")
+
+(cl-defmethod doc-view-follow-supported-p (&context (major-mode pdf-view-mode))
+ "When MAJOR-MODE is `pdf-view-mode', return t."
+ t)
+
+(cl-defmethod doc-view-follow-setup (&context (major-mode pdf-view-mode))
+ "When MAJOR-MODE is `pdf-view-mode', setup `doc-view-follow-mode'."
+ (add-hook 'pdf-view-after-change-page-hook
+ #'doc-view-follow-sync-pages nil 'local))
+
+(cl-defmethod doc-view-follow-teardown (&context (major-mode pdf-view-mode))
+ "When MAJOR-MODE is `pdf-view-mode', teardown `doc-view-follow-mode'."
+ (remove-hook 'pdf-view-after-change-page-hook
+ #'doc-view-follow-sync-pages 'local))
+
+(cl-defmethod doc-view-follow-set-page (page &context (major-mode pdf-view-mode))
+ "When MAJOR-MODE is `pdf-view-mode', go to PAGE in the document buffer."
+ (let ((pdf-view-inhibit-redisplay nil)
+ (page (max 1 (min page (pdf-cache-number-of-pages)))))
+ (pdf-view-goto-page page)))
+
+(cl-defmethod doc-view-follow-get-page (&context (major-mode pdf-view-mode))
+ "When MAJOR-MODE is `pdf-view-mode', return the current page number."
+ (pdf-view-current-page))
+
+(provide 'doc-view-follow-pdf-tools)
+;;; doc-view-follow-pdf-tools.el ends here