-
Notifications
You must be signed in to change notification settings - Fork 160
Remember PDF positions across sessions #18
Comments
Just use bookmark.el for that, maybe with a dedicated file for PDF |
Thank you. It would be useful to automatically set a bookmark when the PDF buffer is killed. I can solve this locally with Thanks again. |
@oscarfv could you share your solution? I would really like to save the position in the PDF I am reading. |
Just a related note: there is org-pdfview package. It also may be used to save a page. |
I second this suggestion, remembering the last page would be tremendously useful. I mean, transparently, without bookmarking or doing something manually, although I'll try something like bookmarking with a hook for now. |
Well, I tried this: ;; TODO: save bookmarks in separate file
(defun andre//pdf-tools--set-bookmark-pdf ()
(when (eq major-mode 'pdf-view-mode)
(bookmark-set (andre//pdf-tools--generate-bookmark-name-for-this-buffer))))
(defun andre//pdf-tools--jump-to-last-page-viewed-in-last-session ()
(when (andre//pdf-tools--buffer-has-bookmark-from-previous-session)
(bookmark-jump (andre//pdf-tools--generate-bookmark-name-for-this-buffer))))
(defun andre//pdf-tools--buffer-has-bookmark-from-previous-session ()
(assoc (andre//pdf-tools--generate-bookmark-name-for-this-buffer) bookmark-alist))
(defun andre//pdf-tools--generate-bookmark-name-for-this-buffer ()
(concat "PDF: "(buffer-file-name)))
;; using this spacemacs' function, but it's the same thing except that it takes a list of funtions
(spacemacs/add-to-hook 'kill-buffer-hook '(spacemacs//pdf-tools--set-bookmark-pdf))
(spacemacs/add-to-hook 'pdf-view-mode-hook '(spacemacs//pdf-tools--jump-to-last-page-viewed-in-last-session)) But it's always saving a bookmark on the first page. I wonder if it has to do with the hook. Maybe when it runs the position on the buffer is lost, I don't know (I don't know much elisp, still learning). Anyone? Edit: Actually, I suspect that it always sets the bookmark to the first page when it is not called interactively. |
OK, this is rather ugly, but it works: ;; --- Save last page viewed in pdf-view-mode ---
;; Ideally we would set this as hook instead of an advice.
;; However, for some reason, if this is done, it sets the bookmark to the first page of the PDF.
;; TODO: Save those bookmarks in another file; don't show them on the list of bookmarks.
(defun andre//pdf-tools--generate-bookmark-name-for-this-buffer ()
(concat "PDF: " (buffer-file-name)))
(defun andre//pdf-tools--set-bookmark-pdf (&optional arg1)
(when (eq major-mode 'pdf-view-mode)
(bookmark-set (andre//pdf-tools--generate-bookmark-name-for-this-buffer))))
(defun andre//pdf-tools--jump-to-last-page-viewed-in-last-session ()
(bookmark-maybe-load-default-file)
(condition-case err
(bookmark-jump (andre//pdf-tools--generate-bookmark-name-for-this-buffer))
(error
(princ (format "Unable to get to last bookmark. Error: %s" err)))))
(defun andre//pdf-tools--set-bookmarks-before-quitting-emacs (&optional arg1)
(cl-loop for buffer in (buffer-list) do
(with-current-buffer buffer
(when (eq major-mode 'pdf-view-mode)
(andre//pdf-tools--set-bookmark-pdf)))))
(add-hook 'pdf-view-mode-hook 'spacemacs//pdf-tools--jump-to-last-page-viewed-in-last-session)
(advice-add 'kill-buffer :before 'andre//pdf-tools--set-bookmark-pdf)
(advice-add 'kill-emacs :before 'andre//pdf-tools--set-bookmarks-before-quitting-emacs)
;; --- End save last page viewed in pdf-view-mode --- Edit: Oh, actually this doesn't work properly across Emacs sessions (sometimes it does). I give up for now, haha. Edit 2: OK, I got it. It doesn't work across emacs sessions because of #111. |
Can confirm Andre0991's works for me, on vanilla emacs (debian). Edit 1: nope, never mind -- I do see similar erroneous behavior to what Andre was seeing. |
Andre's first solution seems to work/should work, that is after correcting the function names added to the hooks. |
What function names need to be changed? |
The functions being added to the hooks just weren't consistent with those defined earlier in the snippet.
|
Am I missing something here? This does not touch my ~/.emacs.d/bookmarks after a few restarts -- while the same files under doc-view-mode work well. |
My bad--I hadn't tested the No one has mentioned |
Same-pace does sound good -- I had played with this before, but suspect that the failure mode here is that the pdf-view regnerates the file every time emacs opens. FWIW, my short-term solution is to take PDFs I want to save and open then in doc-view (which converts each to a series of png's), on which save-place and the like work well. However, this is clearly a bad hack. |
I also think this belongs into save-place. It has already special code
for hexl and dired mode, but I wasn't aware that it works for doc-view
buffers as well.
|
On a technical note, I'm not claiming that save-place has special code -- I do observe that my combination of save-place and bookmarks works for doc-view (but not pdf-view). And I'm certainly under-educated here, so someone who knows should speak up. |
The
@boyanpenkov was something similar to this broken for you? Tangentially, as noted in #199, my place is still occasionally lost intra-session (though that can be worked-around with a call to edit: Oh, this is barely different from the version in andre's second post--were you guys encountering something other than #199? I think that's the only related issue I'm still seeing. |
After incorporating the change and restarting emacs a few times, no dice, I'm afraid.... |
After restarting emacs, brds/pdf-has-last-viewed-bookmark returned nil unless I initialized the bookmark system so I put in (bokmark-set "fake"). This is what I had to do to get it to work for me: Thanks Braham!
|
I would just like to subscribe to this request. Saving PDF positions (maybe also zoom?) between sessions would be amazing. It is a bit annoying to have to find exactly where I was last time I checked the pdf, or having to manually set a bookmark just for that purpose (besides re-zooming every single time I open a PDF). |
You can subscribe to any GitHub issue by clicking the "Subscribe" button at the top of the issue's page on the right hand side. If you'd just like to express your support of an issue, I (and I suspect other subscribers) would greatly appreciate it if you gave the OP a thumbs up (by clicking the smiley face in its top right corner) instead of making a "+1" post. (In case you haven't seen it, GitHub's issue tracker can sort issues by the numbers of reactions they've garnered -- ideally, IMO, we'd have explicit issue voting with votes displayed next to the number of comments as in isaacs/github#9 or, e.g., GitLab, but that doesn't look like it will happen in the near future.) |
(Unusable) variant with records stored in separate file:
It's slow cuz bookmark files savings. |
What's the update on this issue? Did people give up? I mean it's been hanging around 2014. This and absence of continuous scrolling unfortunately makes pdf-tools quite inconvenient (almost unusable). |
I'm so sorry. I'll immediately get one of my dev-teams working shifts on this important issue.
|
My apologies if my comment makes it look demanding - wasn't my intention. I am genuinely interested, because I have recently re-discovered pdf-tools and even with all the downsides and issues it seems to be the best solution these days for handling pdf in Emacs, especially if you want to use Interleave or Org-noter. |
Never mind. As for "continuous-view": I don't see that happening, since many, if not all, parts of the software assume a 1:1 relation between pages and windows.
|
Here's an update to aijony's version without the fake bookmark kludge. Which works for me...
|
I would just like to point out that if you decide to restore last position in mode hook like this Best way to use both |
#18 (comment) sadly this didn't work for me. Does it still work for you? |
I'm trying out |
Hi, here's a package I wrote (saveplace-pdf-view) that implements this functionality with the help of |
For using pdf-tools as a book reader it would be useful to remember the visited files and the position, zoom level...
The text was updated successfully, but these errors were encountered: