alphapapa / burly.el

Save and restore frames and windows with their buffers in Emacs
GNU General Public License v3.0
303 stars 14 forks source link

org-find-olp: Heading not found #10

Closed diamond-lizard closed 3 years ago

diamond-lizard commented 3 years ago

When I have a frame with two windows, both viewing an org-mode file /tmp/foo.org which contains only a heading with a URL in a org-mode link format, like so:

* [[http://example.com][Example]]

then with point on that heading in the window on the right I create a Burly bookmark using burly-bookmark-windows, when I go to open that bookmark using bookmark-bmenu-this-window then instead of restoring the windows with their respective buffers, I get an error:

org-find-olp: Heading not found on level 1: Example

Here is a copy of my bookmarks file containing a Burly bookmark of two windows, which does not work.

I've also been able to reproduce this issue with the left window containing just an empty *scratch* buffer, and the right containing the same org buffer as above.

Curiously, this issue does not manifest when there is only one window that is bookmarked by Burly.

Here is a copy of my bookmarks file containing a Burly bookmark made from just one window with the same org-mode buffer, which works.

If I make an ordinary bookmark to the same heading in the same org-mode file using bookmark-set it also opens just fine.

Here is my bookmarks file for this scenario.

Finally, a Burly bookmark made of two windows viewing /tmp/foo.org which this time contains only an ordinary heading:

* Example

also works.

Here is my bookmarks file with a working link made by Burly of two windows containing an org-mode buffer with a plain heading.

So I think this issue likely has something to do with the heading containing an org-mode link, but there have to be two windows involved.

I am using:

alphapapa commented 3 years ago

Burly uses org-get-outline-path and org-find-olp to locate headings in Org buffers. Unfortunately, these functions don't work together when a heading contains a link, because org-get-outline-path replaces links with their descriptions.

This should probably be fixed in Org, probably by giving org-get-outline-path an additional argument to disable the replacing of links with their descriptions. If you feel like it, you could check the Org mailing list for any prior discussion about this, because I'm guessing it's been mentioned before.

In the meantime, we have two options in Burly:

  1. Fall back to using the buffer position. I don't think this is a good solution, because it will fail to return to the right location when the Org buffer has been edited since it was bookmarked.
  2. Write our own get-outline-path function which returns the heading literally. I'd prefer not to do this, but it's probably the best option. This should probably also be implemented in org-bookmark-heading, because it has the same problem IIRC.

What do you think?

Thanks.

diamond-lizard commented 3 years ago

I agree that merely saving and restoring the buffer position in an org-mode file is not a good solution, for the reason you mention.

As to Burly having its own get-outline-path and org-bookmark-heading functions, that does seem a better approach, though I wonder if some work could be saved by reusing most of the code that does this from the respective org functions.

alphapapa commented 3 years ago

I wonder if some work could be saved by reusing most of the code that does this from the respective org functions.

Sure, we could probably copy some of that code into Burly as long as we need it.

alphapapa commented 3 years ago

2. Write our own get-outline-path function which returns the heading literally. I'd prefer not to do this, but it's probably the best option. This should probably also be implemented in org-bookmark-heading, because it has the same problem IIRC.

For my own reference (all these Org-related packages that have minor overlap...), this is what I already do in org-recent-headings. So I'm going to use the same approach in Burly.

alphapapa commented 3 years ago

@diamond-lizard That should do it. Please let me know if it works for you. Thanks for reporting.