nobiot / org-remark

Highlight & annotate text, EWW, Info, and EPUB
https://nobiot.github.io/org-remark/
GNU General Public License v3.0
436 stars 22 forks source link

Visit source buffer at location from notes #53

Closed sati-bodhi closed 1 year ago

sati-bodhi commented 1 year ago

Just wondering if it is possible to "sync" current note with the source buffer in the sense that when I call a function at point under a note heading, I would be brought to the highlight position in my source.

This would probably not be as straightforward with epub support because org-remark needs to know the source file but the nov buffer is not really visiting a file when rendering the ebook.

nobiot commented 1 year ago

The image below illustrates the current way to achieve the intent of your feature request. You can navigate from the notes to the highlight's location via Org link stored in org-remark-source-link property; e.g. pressing C-c C-o while your cursor is on the link.

image

nov.el adds a new Org link type nov: to link to a specific position of an epub document.

We have a facility to add a link to the notes headline. I have used the nov: link type and implemented a hook to add a link to the notes. You can see the source in the the new file named org-remark-nov.el in the new branch ded/nov.el.

sati-bodhi commented 1 year ago

You can navigate from the notes to the highlight's location via Org link stored in org-remark-source-link property; e.g. pressing C-c C-o while your cursor is on the link.

nov link tries to open a new instance of the epub file when I click on it, instead of following the link through the buffer that's already open . I suppose this is due to the fact that the nov buffer is not exactly visiting a file.

(defun nov-org-link-follow (path)
  "Follow nov: link designated by PATH."
  (if (string-match "^\\(.*\\)::\\([0-9]+\\):\\([0-9]+\\)$" path)
      (let ((file (match-string 1 path))
            (index (string-to-number (match-string 2 path)))
            (point (string-to-number (match-string 3 path))))
        (nov--find-file file index point))
    (error "Invalid nov.el link")))

nov-org-link-follow uses nov--find-file to locate the annotation, which explains this behavior.

sati-bodhi commented 1 year ago

We need to check the presence of a nov buffer, switch to the nov buffer, use nov-file-name and nov-document-index to match with file and index respectively before calling nov-goto-document to follow the link. Only if no matches to nov-file-name has been found do we call (nov--find-file file index point) to find the annotation marker.

sati-bodhi commented 1 year ago

check the presence of a nov buffer, switch to the nov buffer

There may be more than 1 epub ebook open at the same time. Having something (an alist?) to keep track of nov buffer instances could come in handy if we wish to perform multiple matches.

nobiot commented 1 year ago

In the current dev/nov.el branch, I have included a test command test/find-nov-file-buffer. It's a WIP.

Place a cursor anywhere within the headline for the notes you would like to jump to and call the command. At the moment, the nov-mode buffer would need to already exist but if so you should be able to jump to it without creating another buffer.

I will work on this logic; I am looking to generalize it beyond nov-mode.

nobiot commented 1 year ago

@sati-bodhi Not sure if you are still around to talk to, but just so that you would be informed.

The latest version 1.2.1 (ELPA is being updated) adds a link to EPUB file with using novlel's Org link extension :nov Org link type. This should resolve correctly to the right chapter/section of the EPUB file.

image

nov link tries to open a new instance of the epub file when I click on it, instead of following the link through the buffer that's already open . I suppose this is due to the fact that the nov buffer is not exactly visiting a file.

I do not seem to have this issue. Perhaps it might be fixed in a newer version nov.el? I'm now using nov.el Version: 20230715.1434

I will close this issue now. Let me know if there is an issue by re-opening it.