alphapapa / org-bookmark-heading

Emacs bookmark support for Org-mode
GNU General Public License v3.0
93 stars 8 forks source link

Add support for bookmarking Org files, not only headings #11

Closed akirak closed 2 years ago

akirak commented 2 years ago

Hello,

Even though the initial purpose of this package is to bookmark headings in Org files, I sometimes want to bookmark an entire Org file. For example, I write (or am trying to write) documentation in Org, and I want to bookmark the documentation files of projects I am working on. In this case, the default function for making a bookmark record should be used.

Could you add support for adding a fallback for bookmarking an entire file? The implementation should be as easy as follows (tweaking org-bookmark-heading-make-record), but I am not sure if this is true to your intended goal of this package:


(defun org-bookmark-heading-make-record ()
  (if (org-before-first-heading-p)
      (bookmark-make-record-default)
    ;; The existing implementation
    ...)
alphapapa commented 2 years ago

Hi Akira,

AFAIK this is already supported, e.g.

https://github.com/alphapapa/org-bookmark-heading/blob/f7456ddfb869c6c4c1219239ad7ae0686db9fc94/org-bookmark-heading.el#L113 https://github.com/alphapapa/org-bookmark-heading/blob/f7456ddfb869c6c4c1219239ad7ae0686db9fc94/org-bookmark-heading.el#L203

If it doesn't work, it's a bug that needs to be fixed.

akirak commented 2 years ago

Thanks, I didn't notice that.

Actually, it doesn't work. I encounter the following error:

user-error: Before first headline at position 1 in buffer emacs.org

and it is caused because you can't concat nil:

https://github.com/alphapapa/org-bookmark-heading/blob/f7456ddfb869c6c4c1219239ad7ae0686db9fc94/org-bookmark-heading.el#L115-L116

alphapapa commented 2 years ago

Yes, you can:

(concat "foo" nil)
;; => "foo"

(concat nil "foo")
;; => "foo"

That error is not caused by attempting to do that.

When does the error occur? Please provide the backtrace.

akirak commented 2 years ago

Okay, you are right. The culprit was the next line:

(org-get-outline-path 'with-self)

The function correctly returns nil when WITH-SELF is nil:

(org-get-outline-path)

But not when WITH-SELF is non-nil.

A correct solution would be to change the code as follows:

(when heading
  (org-get-outline-path 'with-self))
akirak commented 2 years ago

Aside from the error, the functionality has existed, so I will close this issue.