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

[pdf-tools & layout] Restore last location in a PDF buffer #8128

Closed
korayal opened this issue Jan 7, 2017 · 7 comments
Closed

[pdf-tools & layout] Restore last location in a PDF buffer #8128

korayal opened this issue Jan 7, 2017 · 7 comments
Labels
- Bug tracker - PDF stale marked as a stale issue/pr (usually by a bot)

Comments

@korayal
Copy link
Contributor

korayal commented Jan 7, 2017

I have a layout for a programming book which allow me to recreate my workspace pretty fast. So In that layout, I have the book's PDF opened in one of the windows.

But the problem is, while in a text buffer the cursor is at the correct position whenever I saved the layout, the PDF buffer always loses it's saved location. Which as you can imagine requires some extra steps that it became boring after a bunch of repeats.

@braham-snyder
Copy link
Contributor

braham-snyder commented Jan 8, 2017

politza/pdf-tools#18 (please go "thumbs up" that issue if you're using this workaround):

    ;; workaround for pdf-tools not reopening to last-viewed page of the pdf:
    ;; https://github.com/politza/pdf-tools/issues/18
    (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))

@deb0ch
Copy link
Contributor

deb0ch commented Jan 9, 2017

@braham-snyder It would be neat to have it in Spacemacs (even neater to have it upstream in pdf-tools, but maybe we can add it here in the meantime).

Maybe you could open a PR with this code integrated so that we can review and test it ? 😸

@korayal
Copy link
Contributor Author

korayal commented Jan 16, 2017

@braham-snyder this snippet works nicely, but only if we kill the buffer before exiting emacs. after SPC q R I'm not seeing the page as I left before. Maybe there is some other hook to do this.

@deb0ch
Copy link
Contributor

deb0ch commented Jan 16, 2017

Maybe kill-emacs-hook ?

@korayal
Copy link
Contributor Author

korayal commented Jan 16, 2017

I was hoping for a more general approach, so there is also a restart-emacs-hook, I wonder how many cases are there. Also adding this hook to kill-emacs or restart-emacs or even kill-buffer seems like an overkill since this is only about pdf-mode buffers.

@braham-snyder
Copy link
Contributor

braham-snyder commented Jan 16, 2017

perhaps we should do whatever it is save-place-mode does, since it's nearly the same idea

@deb0ch I really don't want to stifle the development of pdf-tools--I feel like adding this snippet would (or at least should?) be outside the scope of Spacemacs

I've edited my original post to request that anyone using this workaround go thumbs up that issue

EDIT: see the linked pdf-tools issue above for further discussion

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Bug tracker - PDF stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

4 participants