Skip to content

Instantly share code, notes, and snippets.

@politza
Created April 6, 2015 19:53
Show Gist options
  • Save politza/a3339a4f3b3901fcce4c to your computer and use it in GitHub Desktop.
Save politza/a3339a4f3b3901fcce4c to your computer and use it in GitHub Desktop.
diff --git a/lisp/pdf-misc.el b/lisp/pdf-misc.el
index 4aedf47..26a194a 100644
--- a/lisp/pdf-misc.el
+++ b/lisp/pdf-misc.el
@@ -201,6 +201,93 @@
(display-buffer (current-buffer)))
md))
+
+;; * ================================================================== *
+;; * Multipage windows
+;; * ================================================================== *
+
+(defcustom pdf-misc-multipage-horizontally nil
+ "If non-nil, windows are sorted left to right first."
+ :group 'pdf-misc)
+
+;;;###autoload
+(defvar pdf-misc-multipage-minor-mode-map
+ (let ((kmap (make-sparse-keymap)))
+ (set-keymap-parent kmap pdf-view-mode-map)
+ (define-key kmap [remap pdf-view-next-page-command]
+ 'pdf-misc-multipage-next-page)
+ (define-key kmap [remap pdf-view-previous-page-command]
+ 'pdf-misc-multipage-previous-page)
+ kmap))
+
+(define-minor-mode pdf-misc-multipage-minor-mode
+ "View and navigate multiple pages in all windows."
+ nil nil nil
+ (pdf-util-assert-pdf-buffer)
+ (cond
+ (pdf-misc-multipage-minor-mode
+ (pdf-misc-multipage-next-page 0))))
+
+(defun pdf-misc-multipage-get-windows (&optional horizontally-p)
+ (sort (get-buffer-window-list (current-buffer))
+ (lambda (w1 w2)
+ (let* ((e1 (window-edges w1))
+ (e2 (window-edges w2))
+ (l1 (car e1)) (t1 (cadr e1))
+ (l2 (car e2)) (t2 (cadr e2)))
+ (if horizontally-p
+ (or (< t1 t2)
+ (and (= t1 t2)
+ (< l1 l2)))
+ (or (< l1 l2)
+ (and (= l1 l2)
+ (< t1 t2))))))))
+
+(defun pdf-misc-multipage-next-page (&optional arg)
+ (interactive "p")
+ (let* ((windows (pdf-misc-multipage-get-windows
+ pdf-misc-multipage-horizontally))
+ (selwin (selected-window))
+ (pos (cl-position selwin windows))
+ (page (pdf-view-current-page))
+ (npages (pdf-info-number-of-pages)))
+ (cond
+ ((> arg 0)
+ (setq arg (min arg (- npages
+ (+ page (- (length windows) pos 1)))))
+ (when (<= arg 0)
+ (error "End of document"))
+ ;; Set page of first window.
+ (setq page (- (+ page arg) pos)))
+ ((< arg 0)
+ (setq arg (max arg (- (- page pos 1))))
+ (when (>= arg 0)
+ (error "Beginning of document"))
+ (setq page (- (+ page arg) pos)))
+ (t
+ ;; Adjust pages in this case, starting at the first window.
+ (setq page (max 1
+ (min (with-selected-window (car windows)
+ (pdf-view-current-page))
+ (- npages (1- (length windows))))))))
+ (dolist (w windows)
+ (with-selected-window w
+ (pdf-view-goto-page page)
+ (setq page (min (1+ page) npages))))))
+
+(defun pdf-misc-multipage-adjust-pages ()
+ (interactive)
+ (pdf-misc-multipage-next-page 0))
+
+(defun pdf-misc-multipage-previous-page (&optional arg)
+ (interactive "p")
+ (pdf-misc-multipage-next-page (- (or arg 1))))
+
+
+;; * ================================================================== *
+;; * Printing
+;; * ================================================================== *
+
(defcustom pdf-misc-print-programm nil
"The program used for printing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment