Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream pdf roll #224

Open
wants to merge 104 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
7b525c0
Remove timer from page prefetching function
Nov 12, 2022
84048f6
Don't assume that bookmark jump will display the buffer
Jan 22, 2023
e6dfe00
Accommodate Emacs 26
Jan 24, 2023
961e41c
Use window-buffer-change-functions only if buffer has not window
Mar 6, 2023
1767957
Save the same bookmark if it wasn't restored
Mar 21, 2023
99e0201
Implement `pdf-view-roll-minor-mode`
dalanicolai May 1, 2022
5feef10
Update names to adhere to Emacs coding conventions
dalanicolai May 3, 2022
bc18448
Fix pdf-view-next-page function
dalanicolai May 4, 2022
28de3d6
Quick fix issue #2 (function does not respect ARG)
dalanicolai May 5, 2022
2c9fdce
Fix isearch functionality
dalanicolai May 9, 2022
254950a
Add mouse support
dalanicolai May 10, 2022
b842782
Add pdf-annots-action-perform function (avy-like edit annots)
dalanicolai May 18, 2022
c17ce1d
Add history tracking function to image-roll-after-change-page-hook
dalanicolai May 20, 2022
b2b6c30
Additionally remove overlays after erase-buffer
dalanicolai Dec 1, 2022
0e7d2b8
Image-roll related tweaks
aikrahguzar May 22, 2023
18050dd
Fix link selection when multiple pages are displayed
aikrahguzar May 24, 2023
3453628
Add margin to the image with link hints
aikrahguzar Jun 14, 2023
2e9dfa5
Fix turning off pdf-roll and minor tweaks
aikrahguzar Jun 14, 2023
61bd009
Bind/unbind mwheel-scroll-up/down-function
aikrahguzar Jun 14, 2023
485cce5
Make pdf-sync work with pdf-roll
aikrahguzar Jun 15, 2023
99b005b
Further tooltip fixes
aikrahguzar Jun 15, 2023
10a5b99
Add some bindings to pdf-view-roll-minor-mode-map
aikrahguzar Jun 16, 2023
ae02ece
Use line-spacing to make margins
aikrahguzar Jun 16, 2023
ff9df5f
Renamings and tweaks
aikrahguzar Jun 16, 2023
a89793b
Remove hooks image-mode and pdf-view hooks from window-conf-chg-h
aikrahguzar Jun 17, 2023
6cc9934
Remove unneeded functions
aikrahguzar Jun 18, 2023
9e557be
Fix pdf-view-page-size to work with image-roll
aikrahguzar Jun 19, 2023
273b6e9
Move to the beginning of link target with image roll
aikrahguzar Jun 19, 2023
383fcbc
Change image roll to rely on pre-display-functions
aikrahguzar Jun 19, 2023
3eb9033
More tooltip tweaks + vscroll on page jump
aikrahguzar Jun 19, 2023
76ff946
Fix pdf-view-image-size-again
aikrahguzar Jun 20, 2023
7460366
Make indirect buffers work
aikrahguzar Jun 23, 2023
e9d0fee
Various changes and refactors for image-roll
aikrahguzar Jun 25, 2023
f9b735d
Try to find a live window that displayed buffer when bookmarking
aikrahguzar Jun 25, 2023
8752674
Better integration of pdf-roll with pdf-view-display-image
aikrahguzar Jun 26, 2023
f2f7918
Fix pdf-links hopefully correctly this time
aikrahguzar Jun 26, 2023
953e3e3
Fix text selection with pdf-roll
aikrahguzar Jun 26, 2023
44d6403
Fix isearch pdf-occur
aikrahguzar Jun 27, 2023
83aa3de
Streamline divergence from upstream
aikrahguzar Jun 28, 2023
f02a48a
Further isearch fixes + autoload pdf roll minor mode
aikrahguzar Jun 28, 2023
5fa27c0
Remap scroll-up/down commands
aikrahguzar Aug 1, 2023
94dd31a
Fix finding next matching page
aikrahguzar Aug 2, 2023
865af2d
Accommodate image-mode commands using an advice
aikrahguzar Aug 3, 2023
4332202
Add image-roll (for rebase)
dalanicolai May 3, 2022
f27cb0c
Fix page jump via 'set-window-start'
dalanicolai May 4, 2022
4047501
Add mouse support to image-roll-mode
dalanicolai May 10, 2022
9ffdcd8
Add missing docstrings
yantar92 May 14, 2022
4c7b89e
Add change page hooks
yantar92 May 14, 2022
2b39f3f
Fix indentation
dalanicolai May 16, 2022
a543f13
Add basic keybindings
dalanicolai Jun 15, 2022
53f11e7
Add modifications to support search functionality
dalanicolai Jun 24, 2022
c91b18f
Shabby fix for pdf-view-auto-slice-minor-mode support
dalanicolai Sep 16, 2022
0c98a27
Fix reapply hscroll on redisplay (see issue #13)
dalanicolai Dec 3, 2022
0ae41b1
fixed hscroll
NightMachinery Dec 3, 2022
49b4ac7
Silence warnings
May 4, 2023
adce639
Fix grey boxes and refactor
aikrahguzar May 22, 2023
d69b3d2
Put back differential displaying, undisplaying
aikrahguzar May 23, 2023
7fa87c4
Tweaks
aikrahguzar May 31, 2023
077bfe5
Hack for a mysterious bug
aikrahguzar Jun 14, 2023
e2a612b
Add command to scroll with mouse wheel
aikrahguzar Jun 16, 2023
6f5f43b
Make the window being used explicit in most places
aikrahguzar Jun 16, 2023
fb8b1c8
Renamings and tweaks
aikrahguzar Jun 16, 2023
bd8f6a1
Only select windows
aikrahguzar Jun 16, 2023
134e8d1
Get back to using with-selected-window for scrolling with wheel
aikrahguzar Jun 17, 2023
87b0ffa
Don't set window start in window-configuration-change-hook
aikrahguzar Jun 17, 2023
c978993
Some cleanup
aikrahguzar Jun 17, 2023
387ca7c
Reorganize the scrolling functions
aikrahguzar Jun 17, 2023
1a176e2
Display and undisplay images dynamically
aikrahguzar Jun 18, 2023
7a61ee1
Move demo to its own file
aikrahguzar Jun 18, 2023
89a4100
Simplify and correct scroll-forward + tweaks
aikrahguzar Jun 19, 2023
bda191b
Rely on pre-display-functions
aikrahguzar Jun 19, 2023
08b21e1
More work on pre-display method
aikrahguzar Jun 19, 2023
626f607
Remove unneeded code from undisplay + more tweaks
aikrahguzar Jun 20, 2023
6a95a74
Get rid of overlays for dead windows
aikrahguzar Jun 20, 2023
c814210
Pass window argument + fix arithmetic condition
aikrahguzar Jun 21, 2023
4eaac76
Use overlays for adding margin
aikrahguzar Jun 25, 2023
f5c725c
Check for overlays first
aikrahguzar Jun 26, 2023
2d4d980
Tweak pre-redisplay function
aikrahguzar Jun 27, 2023
200cc23
Obey next-screen-context-lines
aikrahguzar Jun 28, 2023
07099b1
Actually use image-roll-center and set hscroll too if present
aikrahguzar Jun 29, 2023
305004e
Handle last page and change in window selection better
aikrahguzar Jun 30, 2023
802076f
Combine image-roll.el and pdf-roll.el files
aikrahguzar Aug 3, 2023
81b004c
Cleanup
aikrahguzar Aug 7, 2023
aadd406
Fix annotations and text selection by tracking page number
aikrahguzar Aug 7, 2023
1310f85
Don't hardcode numbers
aikrahguzar Aug 7, 2023
7982e8f
Bring scrolling behavior in line with image-mode/pdf-tools
aikrahguzar Aug 8, 2023
2901056
Get h/vscroll with image-mode-window-get if buffer is not displayed
aikrahguzar Aug 8, 2023
8d8df39
Support pixel-scroll-precision-mode in Emacs 29
aikrahguzar Aug 8, 2023
b42fad6
Deal with nil
aikrahguzar Aug 8, 2023
f3497d8
Pass on win parameter to image-mode-window-get-call
aikrahguzar Aug 9, 2023
7b1fe20
Enable/disable pixel-scroll-precision-mode along with pdf-roll
aikrahguzar Aug 10, 2023
3767024
Define pdf-view-roll-minor-mode in pdf-view
aikrahguzar Aug 10, 2023
7084e72
Don't try to slice twice
aikrahguzar Aug 11, 2023
e43c5c3
Fix interactive spec of pdf-view-scroll-backward
aikrahguzar Aug 12, 2023
01a6c16
Make end of document behavior more predictable
aikrahguzar Aug 12, 2023
e8f0e17
Fix the re-initialization after revert
aikrahguzar Aug 12, 2023
27f4618
Move autoload cookie back to the minor mode definition
aikrahguzar Aug 17, 2023
d88c02a
Don't restore file contents when turning off mode
aikrahguzar Sep 17, 2023
12ba622
Use line-prefix to center images
aikrahguzar Sep 30, 2023
cca8b1c
Fix handling of empty search string
aikrahguzar Nov 16, 2023
902439c
Fix rectangle selection
aikrahguzar Nov 17, 2023
472c80b
Avoid moving the point too much during isearch-repeat
aikrahguzar Nov 19, 2023
009e9c9
Add page information to text annotations
aikrahguzar Feb 29, 2024
d22c98d
Be more defensive during pre-redisplay
aikrahguzar Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions image-roll-mode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
;;; image-roll-mode.el --- Demo for image roll. -*- lexical-binding: t; -*-

;;; Commentary:
;; Demo for image roll. Contains a major mode for displaying images.

;;; Code:

(require 'svg)
(require 'image-roll)

(defun image-roll-demo-display-page (page)
"Return demo image of PAGE.
This function is used for the `image-roll-demo'."
(let* ((o (image-roll-page-overlay page))
(s (cdr (overlay-get o 'display)))
(w (car (plist-get s :width)))
(h (car (plist-get s :height)))
(svg (svg-create w h)))
(unless w (print "NO W" #'external-debugging-output))
(svg-rectangle svg 0 0 w h :fill-color "white")
(svg-text svg
(number-to-string page)
:font-size "40"
:fill "black"
:x 20
:y 50)
(when image-roll-center
(overlay-put o 'before-string
(when (> (window-pixel-width) w)
(propertize " " 'display
`(space :align-to
(,(floor (/ (- (window-pixel-width) w) 2))))))))
(overlay-put o 'display (svg-image svg :margin `(0 . ,image-roll-vertical-margin)))))

(define-derived-mode image-roll-mode special-mode "Image Roll"
;; we don't use `(image-mode-setup-winprops)' because it would additionally
;; add `image-mode-reapply-winprops' to the
;; `window-configuration-change-hook', but `image-roll-redisplay' already
;; reapplies the vscroll, so we simply initialize the
;; `image-mode-winprops-alist' here, and add lines from
;; `image-mode-reapply-winprops' at the start of `image-roll-redisplay'.
(add-hook 'window-size-change-functions 'image-roll-window-size-change-function nil t)
(add-hook 'image-mode-new-window-functions 'image-roll-new-window-function nil t)
(unless (listp image-mode-winprops-alist)
(setq image-mode-winprops-alist nil)))
;; (add-hook 'window-configuration-change-hook
;; #'image-mode-reapply-winprops nil t))
;; (image-mode-setup-winprops))

(setq image-roll-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-n") 'image-roll-scroll-forward)
(define-key map (kbd "<down>") 'image-roll-scroll-forward)
(define-key map (kbd "C-p") 'image-roll-scroll-backward)
(define-key map (kbd "<up>") 'image-roll-scroll-backward)
(define-key map (kbd "<wheel-up>") 'image-roll-scroll-mouse-wheel)
(define-key map (kbd "<wheel-down>") 'image-roll-scroll-mouse-wheel)
(define-key map (kbd "<mouse-5>") 'image-roll-scroll-forward)
(define-key map (kbd "<mouse-4>") 'image-roll-scroll-backward)
(define-key map "n" 'image-roll-next-page)
(define-key map (kbd "<next>") 'image-roll-next-page)
(define-key map "p" 'image-roll-previous-page)
(define-key map (kbd "<prior>") 'image-roll-previous-page)
(define-key map (kbd "S-<next>") 'image-roll-scroll-screen-forward)
(define-key map (kbd "S-<prior>") 'image-roll-scroll-screen-backward)
(define-key map [remap goto-line] 'image-roll-goto-page)
map))

(defun image-roll-demo (&optional page-size pages)
"Display a demo buffer displaying some images.
PAGE-SIZE is the size of each image and PAGES is the number of images."
(interactive)
(let ((buf-name "*image-roll-demo*"))
;; (if (get-buffer buf-name)
;; (switch-to-buffer (current-buffer))
(with-current-buffer (get-buffer-create buf-name)
(erase-buffer)
(image-roll-mode)
(setq cursor-type nil)
(setq image-roll-step-size 50)
(setq-local image-roll-last-page (or pages 3)
image-roll-display-page-function 'image-roll-demo-display-page
image-roll-demo-page-size (or page-size
(lambda ()
(let ((w (window-pixel-width)))
(cons w (* 1.4 w))))))

(setq image-roll-center t)
(switch-to-buffer (current-buffer)))))
(provide 'image-roll-mode)

;;; image-roll-mode.el ends here
83 changes: 75 additions & 8 deletions lisp/pdf-annot.el
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ other annotations."
`("white" "steel blue" 0.35 ,@edges))
:map (pdf-view-apply-hotspot-functions
window page size)
:width (car size))))
:width (car size))
(when pdf-view-roll-minor-mode page)))
(pdf-util-scroll-to-edges
(pdf-util-scale-relative-to-pixel (car edges)))))))

Expand Down Expand Up @@ -1086,8 +1087,8 @@ Return the new annotation."
(pdf-annot-activate-annotation a))
a))

(defun pdf-annot-add-text-annotation (pos &optional icon property-alist)
"Add a new text annotation at POS in the selected window.
(defun pdf-annot-add-text-annotation (pos &optional icon property-alist page)
"Add a new text annotation at POS on PAGE in the selected window.

POS should be a image position object or a cons \(X . Y\), both
being image coordinates.
Expand Down Expand Up @@ -1115,6 +1116,9 @@ Return the new annotation."
(list posn)))
(pdf-util-assert-pdf-window)
(when (posnp pos)
(setq page (or page
(when pdf-view-roll-minor-mode
(1+ (/ (posn-point pos) 4)))))
(setq pos (posn-object-x-y pos)))
(let ((isize (pdf-view-image-size))
(x (car pos))
Expand All @@ -1139,7 +1143,8 @@ Return the new annotation."
property-alist
(cdr (assq 'text pdf-annot-default-annotation-properties))
(cdr (assq t pdf-annot-default-annotation-properties))
`((color . ,(car pdf-annot-color-history))))))))
`((color . ,(car pdf-annot-color-history))))
page))))

(defun pdf-annot-mouse-add-text-annotation (ev)
"Add a text annotation using the mouse.
Expand All @@ -1155,11 +1160,12 @@ EV describes the captured mouse event."
"Click where a new text annotation should be added ..."))
(event-start ev))))

(defun pdf-annot-add-markup-annotation (list-of-edges type &optional color
(defun pdf-annot-add-markup-annotation (region type &optional color
property-alist)
"Add a new markup annotation in the selected window.

LIST-OF-EDGES determines the marked up area and should be a list
REGION determines the marked up area and should be a cons cell
\(PAGE . LIST-OF-EDGES\) where LIST-OF-EDGES should be list
of \(LEFT TOP RIGHT BOT\), each value a relative coordinate.

TYPE should be one of `squiggly', `underline', `strike-out' or
Expand All @@ -1182,7 +1188,7 @@ Return the new annotation."
(pdf-util-assert-pdf-window)
(pdf-annot-add-annotation
type
list-of-edges
(cdr region)
(pdf-annot-merge-alists
(and color `((color . ,color)))
property-alist
Expand All @@ -1191,7 +1197,7 @@ Return the new annotation."
(when pdf-annot-color-history
`((color . ,(car pdf-annot-color-history))))
'((color . "#ffff00")))
(pdf-view-current-page)))
(car region)))

(defun pdf-annot-add-squiggly-markup-annotation (list-of-edges
&optional color property-alist)
Expand Down Expand Up @@ -1540,6 +1546,66 @@ At any given point of time, only one annotation can be in edit mode."
(error "No annotation at this position"))
(pdf-annot-edit-contents a)))

(defun pdf-annot-edit (annot)
"Activate ANNOT, for editing.

Interactively, annot is read via `pdf-annot-read-annot'.
This function displays characters around the annots in the current
page and starts reading characters (ignoring case). After a
sufficient number of characters have been read, the corresponding
annot's annot is invoked. Additionally, SPC may be used to
scroll the current page."
(interactive
(list (or (pdf-annot-read-annot "Activate annot (SPC scrolls): ")
(error "No annot selected"))))
(pdf-annot-activate-annotation annot))

;; TODO 'merge' this function with `pdf-links-read-link-action' into a single
;; universal 'read-action' function (in `pdf-util'?)
(defun pdf-annot-read-annot (prompt)
"Using PROMPT, interactively read an annot-action.

See `pdf-annot-edit' for the interface."
(pdf-util-assert-pdf-window)
(let* ((annots (pdf-annot-getannots (pdf-view-current-page) nil nil))
(keys (pdf-links-read-link-action--create-keys
(length annots)))
(key-strings (mapcar (apply-partially 'apply 'string)
keys))
(alist (cl-mapcar 'cons keys annots))
(size (pdf-view-image-size))
(colors (pdf-util-face-colors
'pdf-links-read-link pdf-view-dark-minor-mode))
(args (list
:foreground (car colors)
:background (cdr colors)
:formats
`((?c . ,(lambda (_edges) (pop key-strings)))
(?P . ,(number-to-string
(max 1 (* (cdr size)
pdf-links-convert-pointsize-scale)))))
:commands pdf-links-read-link-convert-commands
:apply (pdf-util-scale-relative-to-pixel
(mapcar (lambda (l) (cdr (assq 'edges l)))
annots)))))
;; (print (plist-get args :apply))
(unless annots
(error "No annots on this page"))
(unwind-protect
(let ((image-data
(pdf-cache-get-image
(pdf-view-current-page)
(car size) (car size) 'pdf-annot-read-annot)))
(unless image-data
(setq image-data (apply 'pdf-util-convert-page args ))
(pdf-cache-put-image
(pdf-view-current-page)
(car size) image-data 'pdf-annot-read-annot))
(pdf-view-display-image
(create-image image-data (pdf-view-image-type) t)
(when pdf-view-roll-minor-mode (pdf-view-current-page)))
(pdf-links-read-link-action--read-chars prompt alist))
(pdf-view-redisplay))))


;; * ================================================================== *
Expand Down Expand Up @@ -1582,6 +1648,7 @@ Currently supported properties are page, type, label, date and contents."

(defvar pdf-annot-list-mode-map
(let ((km (make-sparse-keymap)))
(define-key km (kbd "e") 'pdf-annot-edit)
(define-key km (kbd "C-c C-f") #'pdf-annot-list-follow-minor-mode)
(define-key km (kbd "SPC") #'pdf-annot-list-display-annotation-from-id)
km))
Expand Down
5 changes: 1 addition & 4 deletions lisp/pdf-cache.el
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,7 @@ WINDOW and IMAGE-WIDTH decide the page and scale of the final image."
(image-size (pdf-view-create-page page))
(pdf-util-debug
(message "Prefetched page %s." page))
;; Avoid max-lisp-eval-depth
(run-with-timer
0.001 nil
#'pdf-cache--prefetch-pages window image-width)))))))
(pdf-cache--prefetch-pages window image-width)))))))
(condition-case err
(pdf-info-renderpage page image-width)
(error
Expand Down
Loading