-
Notifications
You must be signed in to change notification settings - Fork 90
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
Don't assume that bookmark jump will display the buffer #188
base: master
Are you sure you want to change the base?
Conversation
As a result don't assume that there is a window displaying the buffer. Instead of `bookmark-after-jump-hook` use `window-buffer-change-functions` so that the buffer is actually displayed when the code assuming a window is run.
Yes, I'm willing to accept this change as long as it handles Emacs 26 correctly. Thank you for your work! Once you move the PR out of draft, I will test it and get back with feedback if any. |
If `window-buffer-change-functions` isn't bound fallback to `bookmark-after-jump-hook`. The window argument for the inserted hook is optional to accommodate both cases.
a9ee1fb
to
02de69a
Compare
Thanks a lot! I have adapted the code to fallback to |
I worked with this code a little, and my feedback is that this change needs to be hidden behind a flag which can maintain the current behaviour, to avoid surprising current users. I will do this over the weekend if it is easy to do. If I face a problem, I will let you know the exact issue and ask that you please debug / fix it so that I can merge this in. |
Thanks! I did surprise myself soon after submitting this pr but I fixed the problems and I think by now the code should just work. Since I have been messing with pdf-tools in other ways I made those changes on an another branch and forgot to add them on this one. But basically they way code works now is that If buffer is not displayed and Emacs is recent enough I sometimes have a quite a few pdf buffers open and sometimes don't switch to a buffer for the duration of a whole session. Since the buffer has never been displayed and all pdf buffers are automatically bookmarked when I close Emacs this resulted in the bookmark pointing to the beginning of the buffer. So I added a variable Since making these changes a few months ago everything has been working smoothly for me. If you can think of other potential surprises I think it would be better to deal with them even if you decide to add the flag and it is changed to be non-nil.
|
The context for this change is that I use a workspace manager that saves the workspaces to a bookmark. When it is restoring the buffers, it calls
bookmark-jump
with adisplay-func
argument which is just,i.e. the buffer is not actually displayed. I think this is the right behavior, but in case of bookmarks for pdf buffers, this results in errors.
This change moves the hook that needs to be run from
bookmark-after-jump-hook
to a local hook inwindow-buffer-change-functions
. This ensures that a window is always available when the code is run.I think this is also better when restoring a large number of bookmarks since most of the work is deferred to when the user actually displays the buffer. Restoring a previous session is the case when this scenario occurs.
From what I can tell
window-buffer-change-functions
were introduced in Emacs 27 whilepdf-tools
supports Emacs 26. So I will convert this pr into a draft for now. Let me know if are willing to accept this change and I can try change this pr into which chooses the hook based on Emacs version.