alphapapa / burly.el

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

Saving non-narrowed org buffers #38

Closed tpeacock19 closed 3 years ago

tpeacock19 commented 3 years ago

Since this commit cd1715d318fe831612bbc880b498c483ee958665 I have been unable to save org buffers that do not have a heading in the first line. I get thrown an error Before first headline at position 1 in buffer wiki.org.

I believe this is an error in burly--org-mode-buffer-url, specifically the top-olp section:

(when (org-heading-components)
                (org-with-wide-buffer
                 (nreverse (cl-loop collect (substring-no-properties (nth 4 (org-heading-components)))
                                    while (org-up-heading-safe)))))

If the buffer is not narrowed org-heading-components will result in a user-error. This can be mitigated with the following:

diff --git a/burly.el b/burly.el
index a18555b..4ee17a5 100644
--- a/burly.el
+++ b/burly.el
@@ -439,7 +439,7 @@ URLOBJ should be a URL object as returned by
               (goto-char (point-min))
               ;; `org-get-outline-path' replaces links in headings with their
               ;; descriptions, which prevents using them in regexp searches.
-              (when (org-heading-components)
+              (when (and (buffer-narrowed-p) (org-heading-components))
                 (org-with-wide-buffer
                  (nreverse (cl-loop collect (substring-no-properties (nth 4 (org-heading-components)))
                                     while (org-up-heading-safe)))))))
alphapapa commented 3 years ago

Thanks; I was afraid that I might have caused a bug like this, but I was hoping not. This "before first heading" issue happens so often in Org-related packages...

I'm not sure that the change you propose will fix it correctly. In non-narrowed Org buffers, the current heading should still be selected when point is in an entry rather than before the first one. I think that, rather than testing whether the buffer is narrowed, we should probably test org-before-first-heading-p.

tpeacock19 commented 3 years ago

I'm not sure that the change you propose will fix it correctly. In non-narrowed Org buffers, the current heading should still be selected when point is in an entry rather than before the first one.

Doesn't this case get handled by the point-olp? I'm pretty sure this captures the current heading at point.

hrehfeld commented 3 years ago

I can confirm the bug as well as that the proposed fix seems to work for now.

In non-narrowed Org buffers, the current heading should still be selected when point is in an entry rather than before the first one.

Also, evaling (org-heading-components) in my non-narrowed org-mode buffers gives the same error.

Here are two test cases where point at 0 give the same error:

test.org

# a comment

* a headline

empty.org

alphapapa commented 3 years ago

Thanks. Would one or both of you mind testing this branch? It tests narrowing earlier in the form. https://github.com/alphapapa/burly.el/commit/9b5b480f1f378e7d8873bfaa2c4fa175ed687ef0

tpeacock19 commented 3 years ago

I can confirm that this works saving non-narrowed and narrowed buffers.

alphapapa commented 3 years ago

Thanks!