fix(pdf-roll): don't draw a page on Emacs's region overlay - #361
Open
alberti42 wants to merge 1 commit into
Open
fix(pdf-roll): don't draw a page on Emacs's region overlay#361alberti42 wants to merge 1 commit into
alberti42 wants to merge 1 commit into
Conversation
alberti42
force-pushed
the
fix/roll-region-overlay-adoption
branch
3 times, most recently
from
August 24, 2026 09:05
2834ce3 to
63ecf19
Compare
pdf-roll finds the overlay that holds a page by looking for an overlay whose `window' property is the window it is drawing in. But Emacs puts that same property on the overlay it highlights the region with, and in a pdf-roll buffer that overlay can sit right at a page position. So pdf-roll sometimes picked it and drew the page on it. The overlay sits in the PDF buffer, but the window is what holds on to it: Emacs keeps it in the window parameter `internal-region-overlay' and reuses the same one for the next region, by then possibly in another buffer. It simply moves the overlay there, page image and all. You select some text and get a PDF page drawn over it. Pass the category to the lookup, so only overlays pdf-roll made can match. `pdf-roll-new-window-function' had the same problem: when a second window opened on the PDF, it copied whatever overlay it found at the page position. Fixes vedang#345.
alberti42
force-pushed
the
fix/roll-region-overlay-adoption
branch
from
August 24, 2026 09:13
63ecf19 to
154d229
Compare
This was referenced Aug 24, 2026
alberti42
added a commit
to alberti42/emacs-config
that referenced
this pull request
Aug 27, 2026
The `merged` branch carries vedang/pdf-tools#361 (page drawn on Emacs's region overlay) and #362 (overlays replaced by a revert while a page is being rendered). `:post-build` recompiles `epdfinfo`, which a straight rebuild otherwise drops from the build directory -- `pdf-view-mode` then cannot start the server and PDFs open as raw bytes.
This was referenced Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #345.
What happens
Open a PDF with
pdf-view-roll-minor-mode, select some text in it, then show another buffer in that same window. From then on, selecting text in that buffer draws the PDF page over the selection.pdf-view-roll-minor-mode.pdf-view-mouse-set-regioncallspdf-view--push-mark, so the region really is active in the document.)Why
pdf-roll finds the overlay that holds a page like this:
Emacs puts that same
windowproperty on the overlay it highlights the region with (redisplay--highlight-overlay-functioninsimple.el). A pdf-roll buffer has four positions per page, so when the region is active in the document that overlay can sit right at a page position.pdf-roll-display-imagethen draws the page on it.The overlay sits in the PDF buffer, but the window is what holds on to it: Emacs keeps it in the window parameter
internal-region-overlayand reuses the same one for the next region, by then possibly in another buffer. It simply moves the overlay there, page image and all. Deactivating the region does not help, because Emacs only deletes the overlay and later brings it back withmove-overlay.I checked this in a running session. The overlay sitting over my selection in an unrelated buffer was
eqto that window'sinternal-region-overlay. It carriedface regionandpriority (nil . 100)from Emacs,display(a rendered page) andline-prefixfrompdf-roll-display-image, and nocategory.The fix
Pass the category to the lookup, so only overlays pdf-roll made can match.
pdf-roll-new-window-functionhad the same problem: when a second window opened on the PDF, it copied whatever overlay it found at the page position.How this relates to #338
@aikrahguzar diagnosed this bug in #345 and wrote the same category fix in 45b9cc0, before I ran into it. That fix is already part of #338, along with the other pdf-roll fixes on that branch.
The difference between the two pull requests is scope. #338 fixes several pdf-roll bugs, but it also adds features — a child frame preview for links, an isearch preview command, bookmark and slicing work — roughly 1300 added lines across 9 files. A branch that size naturally takes longer to review, and it has been open since January. This pull request changes the overlay lookup and nothing else: two functions, plus tests.
It is your call: if reviewing #338 is going to take a while, merging this one first fixes #345 on master in the meantime, and costs #338 very little afterwards. I deliberately followed @aikrahguzar's approach, so the lookup itself should merge cleanly with their branch. The one spot that will conflict is
pdf-roll-new-window-function, which 9152f1c rewrites anyway. There their version should simply win.Tests
Three tests in
test/pdf-roll-test.el. Two of them check the lookup against a stand-in for Emacs's region overlay, in both creation orders, sinceoverlays-atdoes not promise an order.make testpasses, and the two lookup tests fail with the old code. No new byte-compile warnings.