Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRemember PDF positions across sessions #18
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
politza
Dec 6, 2014
Owner
Just use bookmark.el for that, maybe with a dedicated file for PDF
documents. What we could do, is store display attributes like
image-size, slice and image-origin in a bookmark. Which I just did.
|
Just use bookmark.el for that, maybe with a dedicated file for PDF |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
oscarfv
Dec 6, 2014
Thank you.
It would be useful to automatically set a bookmark when the PDF buffer is killed. I can solve this locally with kill-buffer-hook, which is more convenient for my use case, because I don't want to set those bookmarks for certain PDFs (ephemeral ones.)
Thanks again.
oscarfv
commented
Dec 6, 2014
|
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
closed this
Dec 6, 2014
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
manuel-uberti
May 13, 2015
@oscarfv could you share your solution? I would really like to save the position in the PDF I am reading.
manuel-uberti
commented
May 13, 2015
|
@oscarfv could you share your solution? I would really like to save the position in the PDF I am reading. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
alezost
May 13, 2015
Just a related note: there is org-pdfview package. It also may be used to save a page.
alezost
commented
May 13, 2015
|
Just a related note: there is org-pdfview package. It also may be used to save a page. |
politza
reopened this
Jun 19, 2015
politza
referenced this issue
Jul 3, 2015
Closed
How to store/restore PDF file watching position? #109
politza
changed the title from
Bookmarking/remembering files
to
Remember PDF positions across sessions
Oct 20, 2015
politza
added
the
enhancement
label
Oct 20, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Andre0991
Jan 9, 2016
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.
Andre0991
commented
Jan 9, 2016
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Andre0991
Jan 9, 2016
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.
Edit: No, it doesn't have to do with this.
Andre0991
commented
Jan 9, 2016
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Andre0991
Jan 10, 2016
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.
Andre0991
commented
Jan 10, 2016
|
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. |
michaelmrose
referenced this issue
Apr 14, 2016
Closed
Relative numbering + pdf-tools results in interminable freeze. #202
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boyanpenkov
Aug 4, 2016
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.
boyanpenkov
commented
Aug 4, 2016
•
|
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. |
braham-snyder
referenced this issue
Dec 26, 2016
Closed
Redisplaying first page after opening helm window #111
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
politza
Dec 28, 2016
Owner
Andre's first solution seems to work/should work, that is after correcting the function names added to the hooks.
|
Andre's first solution seems to work/should work, that is after correcting the function names added to the hooks. |
braham-snyder
referenced this issue
Jan 8, 2017
Open
[pdf-tools & layout] Restore last location in a PDF buffer #8128
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boyanpenkov
commented
Feb 7, 2017
|
What function names need to be changed? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
braham-snyder
Feb 7, 2017
The functions being added to the hooks just weren't consistent with those defined earlier in the snippet.
;; workaround for pdf-tools not reopening to last-viewed page of the pdf:
;; https://github.com/politza/pdf-tools/issues/18
;; TODO: save bookmarks in separate file
(defun brds/pdf-set-last-viewed-bookmark ()
(when (eq major-mode 'pdf-view-mode)
(bookmark-set (brds/pdf-generate-bookmark-name))))
(defun brds/pdf-jump-last-viewed-bookmark ()
(when
(brds/pdf-has-last-viewed-bookmark)
(bookmark-jump (brds/pdf-generate-bookmark-name))))
(defun brds/pdf-has-last-viewed-bookmark ()
(assoc
(brds/pdf-generate-bookmark-name) bookmark-alist))
(defun brds/pdf-generate-bookmark-name ()
(concat "PDF-LAST-VIEWED: " (buffer-file-name)))
(add-hook 'kill-buffer-hook 'brds/pdf-set-last-viewed-bookmark)
(add-hook 'pdf-view-mode-hook 'brds/pdf-jump-last-viewed-bookmark)
braham-snyder
commented
Feb 7, 2017
•
|
The functions being added to the hooks just weren't consistent with those defined earlier in the snippet.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boyanpenkov
Feb 7, 2017
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.
boyanpenkov
commented
Feb 7, 2017
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
braham-snyder
Feb 8, 2017
My bad--I hadn't tested the kill-emacs-hook bit well enough (I thought I had a weird persp-mode-related bug causing bookmark issues).
No one has mentioned save-place-mode? I've only looked at it briefly, but, e.g., it correctly handles the kill-emacs-hook case (see save-places-to-alist)--perhaps it just needs to be slightly modified to work with pdf-view buffers? At the least, it seems like the perfect reference for this issue. Unfortunately, I can't work on this in the near future.
braham-snyder
commented
Feb 8, 2017
|
My bad--I hadn't tested the No one has mentioned |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boyanpenkov
Feb 8, 2017
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.
boyanpenkov
commented
Feb 8, 2017
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
politza
Feb 8, 2017
Owner
|
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.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boyanpenkov
Feb 8, 2017
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.
boyanpenkov
commented
Feb 8, 2017
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
braham-snyder
Mar 22, 2017
The kill-emacs-hook bit finally bothered me enough to attempt to fix it--surprisingly, this has worked perfectly for me the last few days (only changes are the last defun and add-hook calls):
;; workaround for pdf-tools not reopening to last-viewed page of the pdf:
;; https://github.com/politza/pdf-tools/issues/18#issuecomment-269515117
(defun brds/pdf-set-last-viewed-bookmark ()
(interactive)
(when (eq major-mode 'pdf-view-mode)
(bookmark-set (brds/pdf-generate-bookmark-name))))
(defun brds/pdf-jump-last-viewed-bookmark ()
(when
(brds/pdf-has-last-viewed-bookmark)
(bookmark-jump (brds/pdf-generate-bookmark-name))))
(defun brds/pdf-has-last-viewed-bookmark ()
(assoc
(brds/pdf-generate-bookmark-name) bookmark-alist))
(defun brds/pdf-generate-bookmark-name ()
(concat "PDF-LAST-VIEWED: " (buffer-file-name)))
(defun brds/pdf-set-all-last-viewed-bookmarks ()
(dolist (buf (buffer-list))
(with-current-buffer buf
(brds/pdf-set-last-viewed-bookmark))))
(add-hook 'kill-buffer-hook 'brds/pdf-set-last-viewed-bookmark)
(add-hook 'pdf-view-mode-hook 'brds/pdf-jump-last-viewed-bookmark)
(unless noninteractive ; as `save-place-mode' does
(add-hook 'kill-emacs-hook #'brds/pdf-set-all-last-viewed-bookmarks))
@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 pdf-history-backward).
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.
braham-snyder
commented
Mar 22, 2017
•
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
boyanpenkov
Mar 23, 2017
After incorporating the change and restarting emacs a few times, no dice, I'm afraid....
boyanpenkov
commented
Mar 23, 2017
|
After incorporating the change and restarting emacs a few times, no dice, I'm afraid.... |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
aijony
May 27, 2017
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 would only have to be done at the start up of emacs, but I was lazy. Edit: I have no clue how anything works
This is what I had to do to get it to work for me:
Thanks Braham!
;; workaround for pdf-tools not reopening to last-viewed page of the pdf:
;; https://github.com/politza/pdf-tools/issues/18#issuecomment-269515117
(defun brds/pdf-set-last-viewed-bookmark ()
(interactive)
(when (eq major-mode 'pdf-view-mode)
(bookmark-set (brds/pdf-generate-bookmark-name))))
(defun brds/pdf-jump-last-viewed-bookmark ()
(bookmark-set "fake") ; this is new
(when
(brds/pdf-has-last-viewed-bookmark)
(bookmark-jump (brds/pdf-generate-bookmark-name))))
(defun brds/pdf-has-last-viewed-bookmark ()
(assoc
(brds/pdf-generate-bookmark-name) bookmark-alist))
(defun brds/pdf-generate-bookmark-name ()
(concat "PDF-LAST-VIEWED: " (buffer-file-name)))
(defun brds/pdf-set-all-last-viewed-bookmarks ()
(dolist (buf (buffer-list))
(with-current-buffer buf
(brds/pdf-set-last-viewed-bookmark))))
(add-hook 'kill-buffer-hook 'brds/pdf-set-last-viewed-bookmark)
(add-hook 'pdf-view-mode-hook 'brds/pdf-jump-last-viewed-bookmark)
(unless noninteractive ; as `save-place-mode' does
(add-hook 'kill-emacs-hook #'brds/pdf-set-all-last-viewed-bookmarks))`
aijony
commented
May 27, 2017
•
|
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!
|
added a commit
to manuel-uberti/.emacs.d
that referenced
this issue
Jun 25, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
andrewSteer
Sep 8, 2017
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).
andrewSteer
commented
Sep 8, 2017
|
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). |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
braham-snyder
Sep 8, 2017
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.)
braham-snyder
commented
Sep 8, 2017
|
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.) |
AegisAK
referenced this issue
Sep 18, 2017
Open
[OS X] LuaTeX, synctex, and pdf-tools don't play nicely #286
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
caadar
Sep 20, 2017
(Unusable) variant with records stored in separate file:
(require 'bookmark+)
(setq bookmarks-pdf "~/.emacs.d/bookmarks-pdf")
(defun brds/pdf-set-last-viewed-bookmark ()
(interactive)
(when (eq major-mode 'pdf-view-mode)
(bmkp-switch-bookmark-file-create bookmarks-pdf t)
(bookmark-set (brds/pdf-generate-bookmark-name))
(bmkp-switch-bookmark-file-create bookmark-default-file t)))
(defun brds/pdf-jump-last-viewed-bookmark ()
(bmkp-switch-bookmark-file-create bookmarks-pdf t)
(bookmark-set "PDF-LAST-VIEWED: fake") ; this is new
(when
(brds/pdf-has-last-viewed-bookmark)
(bookmark-jump (brds/pdf-generate-bookmark-name)))
(bmkp-switch-bookmark-file-create bookmark-default-file t))
(defun brds/pdf-has-last-viewed-bookmark ()
(assoc
(brds/pdf-generate-bookmark-name) bmkp-latest-bookmark-alist))
(defun brds/pdf-generate-bookmark-name ()
(concat "PDF-LAST-VIEWED: " (buffer-file-name)))
(defun brds/pdf-set-all-last-viewed-bookmarks ()
(dolist (buf (buffer-list))
(with-current-buffer buf
(brds/pdf-set-last-viewed-bookmark))))
(add-hook 'kill-buffer-hook 'brds/pdf-set-last-viewed-bookmark)
(add-hook 'pdf-view-mode-hook 'brds/pdf-jump-last-viewed-bookmark)
(unless noninteractive ; as `save-place-mode' does
(add-hook 'kill-emacs-hook #'brds/pdf-set-all-last-viewed-bookmarks))
It's slow cuz bookmark files savings.
caadar
commented
Sep 20, 2017
|
(Unusable) variant with records stored in separate file:
It's slow cuz bookmark files savings. |
oscarfv commentedDec 5, 2014
For using pdf-tools as a book reader it would be useful to remember the visited files and the position, zoom level...