nobiot / org-remark

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

Using org-remark with buffers not associated with a file #24

Closed Vidianos-Giannitsis closed 2 years ago

Vidianos-Giannitsis commented 2 years ago

Hello, I was trying to setup integration between org-remark and zetteldesk.el and was facing some issues. Zetteldesk.el is a library that creates the so-called "desktop" described in How to Take Smart Notes, a buffer where you can gather all your org-roam nodes (and more generally your information sources) for use in revision, outlining and creating manuscripts. From the inception of this, I was thinking it would definitely be useful to have the ability to annotate the buffer and write notes on each node. Naturally, this buffer isn't associated with any file, so I have been having some difficulties with org-remark due to it needing a file.

I wrote an advice function trying to solve this starting with org-remark-mark, which should highlight the section and save it in a specified file. It takes the heading's title, finds a node associated with it (which in my system will yield a result) and with that file-name and does the part org-remark-mark missed. Here is the code for it

(defun zetteldesk-remark-highlight-advice
    (beg end &optional id mode label face properties)
  "Advice function to be used with `org-remark-highlight-mark'.

If the current buffer isn't associated to a file, find the
heading's title, associate it with an org-roam-node and find the
file associated with that node. Then run the part of
`org-remark-highlight-save' that wasn't ran if the buffer isn't
associated with a file. This part is a call to
`org-remark-highlight-save'.

This is meant to be used when taking margin notes from the
*zetteldesk-scratch* buffer. However, this will only work if the
current heading's title is associated with a node. In this case
org-remark will be able to associate the margin note with the
node its related to."
  (unless buffer-file-name
    (let* ((title (org-entry-get nil "ITEM"))
       (node (org-roam-node-from-title-or-alias title))
       (file (org-roam-node-file node))
       (org-remark-notes-file-name
        (concat org-roam-directory "zetteldesk-margin-notes.org"))
       (ov (make-overlay beg end nil :front-advance)))
      (org-remark-highlight-save file
                 beg end
                 (overlay-properties ov)
                 title))))

(advice-add 'org-remark-highlight-mark :after #'zetteldesk-remark-highlight-advice)

However, this does not appear to be ample. This will make org-remark-mark have the behavior I want, however, the rest of the package won't interface properly with this, meaning that I will need to write advice (or in some cases maybe rewrite functions) for all the functionality I need.

Since this is a feature I am interested in, I am considering trying it, even if it will have difficulties. However, I thought I should ask if there is any plan for something like this or if you have any ideas for helping me in this endeavor. I think it would benefit both packages to have the ability to use org-remark in buffers not associated with a file.

Thanks in advance for your help, Best regards, Vidianos

nobiot commented 2 years ago

How do you ensure the *zetteldesk-scratch* buffer is exactly the same when you create it again after quitting and re-launching Emacs (between two consecutive Emacs sessions)?

Persisting a buffer in a file (mostly) ensures the buffer visiting the file will be identical between two Emacs sessions. The location of the highlights is saved in the marginal-notes file as "from-" and "to-" points, so even a small difference (e.g. adding a single space) will make the location of highlights all wrong.

Vidianos-Giannitsis commented 2 years ago

Yeah, I hadn't thought of that issue. I can understand the problem this has. I guess its fair to say that annotating will work only if you are done organizing the desktop and have written it to a file. I am going to experiment a bit with this, as I would like for margin notes to somehow connect with the node they refer to, even if taken from the *zetteldesk-scratch* after its written to a file.

I will report back when I try this or ask for your help should I need it. Thanks!

Vidianos-Giannitsis commented 2 years ago

Well, its been a bit, as I was preoccupied with various other things, but I think I got what I wanted. To be honest, I kinda abused the fact that headings in that buffer are the titles of org-roam nodes and associated those with the capture, but after looking a bit more into it I think I made it in a better looking way. So my conclusion is that this feature is possible if you can associate your notes with a file, even if that file isn't the current buffer.

I am definitely grateful for your work on this package as its a great idea imo. I had to modify some stuff so that the capturing isn't dependent on the buffer used being associated with a file (which after thinking a bit about it I understood its a very sensible decision for the general workings of the package) so that it can work in my use case, but after doing that (which in the end wasn't too hard actually) this is now a breeze. In case you want to check how I worked around this issue, the code can be found here.

Feel free to close this issue as I basically solved it (at least for my case). Just leaving it open in case you want to reply or something. Peace and thanks again for this package mate!

nobiot commented 2 years ago

@Vidianos-Giannitsis Happy that you’ve got what you wished for :)