1

I have a bookmark in one of my org files (set using the usual emacs bookmarks), but I'm finding that when I try to jump to the bookmark (with the usual C-x r b, which invokes bookmark-jump), it doesn't jump to the right place if the heading containing the location for my bookmark is collapsed.

Is there a way to get org and bookmark-jump to cooperate? I think what I want is something analogous to S-tab and C-c C-r (org-reveal): after S-tab, point is not moved, but the headlines collapse; if I then do C-c C-r, org shows exactly those heading necessary to display the exact line point is on. I want bookmark-jump to do the same thing -- put point on the right line -- so that even if org has the heading collapsed, things like org-reveal do what I expect.

Is there a way to do this? Or an org-specific feature for this kind of bookmark?

I have emacs 26.1 and org-mode 9.3.1.

Dan Drake
  • 503
  • 2
  • 15
  • I can't reproduce the problem with Emacs 28.0.50 and Org mode 9.3-74 (both built from their respective git repos). What version of Emacs and Org mode are you running? – NickD Jan 22 '20 at 20:56
  • Please put the version info in the question. Comments can be deleted at any time. Thx. – Drew Jan 22 '20 at 23:02

1 Answers1

1

If your Org mode contains the function org-bookmark-jump-unhide, then all you have to do is add it to bookmark-after-jump-hook:

   (add-hook 'bookmark-after-jump-hook '#org-bookmark-jump-unhide)

If your emacs version's bookmark.el does not define/use bookmark-after-jump-hook, then you can advise bookmark-jump:

 (defadvice bookmark-jump (after org-make-visible activate)
       "Make the position visible."
       (org-bookmark-jump-unhide))))

All of this comes courtesy of the current org-compat.el file.

NickD
  • 27,023
  • 3
  • 23
  • 42
  • I do have the `org-bookmark-jump-unhide` function, and my `bookmark-after-jump-hook` already has `org-bookmark-jump-unhide`. But it's still not working: `C-x r b` with my bookmark jumps me to the correct buffer, but not the right position, and it's not unhiding. If I jump the bookmark a *second* time, it does seem to work, though. When I jump to the bookmark and am in the wrong place, `point` really is in the wrong place: `C-f` or similar shows that I am not in the right place at all. It seems like the bookmark jump function is not finding the location. – Dan Drake Jan 24 '20 at 15:48
  • You can look at the location that has been recorded in your bookmark file (`~/.emacs.d/bookmarks` by default) and see whether it is correct. I wonder if the recording of the bookmark was wrong, maybe because you had folded sections and it did not take that into account - but these are wild guesses. – NickD Jan 24 '20 at 15:51
  • I did some tests, and when you record a bookmark, the position that emacs uses is independent of the folded/collapsed state of the various org-mode headings. I deleted and re-added my bookmark and it's *still* not working. It always works when I'm already in the buffer. It's only when jumping from elsewhere that it doesn't work. So I wonder if there's something to that. – Dan Drake Jan 24 '20 at 21:59
  • Can you try reproducing this without your init file? Start wtin `emacs -q` and go from there. FWIW, I cannot reproduce your problem, hence the suggestion. If it works with `-q`, then there is a problem in your init file: [bisect it](https://emacs.stackexchange.com/questions/13868/how-to-get-emacs-to-locate-the-error-in-my-init-file-without-relaunching) to find the culprit. – NickD Jan 24 '20 at 22:15