nobiot / org-transclusion

Emacs package to enable transclusion with Org Mode
https://nobiot.github.io/org-transclusion/
GNU General Public License v3.0
917 stars 44 forks source link

Support `denote:` links #160

Closed sthesing closed 1 year ago

sthesing commented 1 year ago

Hey @nobiot,

thanks for this wonderful package!

Any chance of supporting the denote:-links of Prot's denote - package?

That would be much appreciated.

nobiot commented 1 year ago

Hi @sthesing Thank you for your kind words. My first gut feel is that I will see what I can add to the documentation. I will unlikely add the code to the code base (but this also depends on the demand). I don't think it will be too challenging.

It will be something very similar to what @alejandrogallo has done here.

sthesing commented 1 year ago

Thanks for pointing out #159 so me. Sorry that I overlooked that. Any helpful additions to the documentation would be welcome. I fear my current skills in reading elisp code and knowledge of what's under the hood in custom links is not enough to adapt the work of @alejandrogallo. So anything helpful on where to start reading would be much appreciated.

alejandrogallo commented 1 year ago

if there is a function in denote that from a denote link gives you the filepath for the notes file, then you could write, let us suppose that this function is denote-file-path-from-id, then

    (defun denote-org-transclusion-add (link plist)
      (when (string= "denote" (org-element-property :type link))
        (let* ((denote-id (org-element-property :path link))     ;; get denote id from denote:<denote-id> link
               (file-path (denote-file-path-from-id denote-id))  ;; path resolved by the id
               (new-link (with-temp-buffer                       ;; create a [[file:/path/to/denote/note]] org link
                           (insert "file:")                      ;; and store it in 'new-link' variable
                           (insert file-path)
                           (beginning-of-buffer)
                           (org-element-link-parser))))
          (org-transclusion-add-org-file new-link plist))))      ;; re-use the org transclusion infrastructure for file: links
    (cl-pushnew 'denote-org-transclusion-add                     ;; register the org transclusion 'plugin'
                org-transclusion-add-functions)

I hope this helps you, you just have to find the denote-file-path-from-id functionality in denote

sthesing commented 1 year ago

I hope this helps you, you just have to find the denote-file-path-from-id functionality in denote

Wow, thanks @alejandrogallo ! With that explanation, it was very easy to set this up. The function in question is called denote-get-path-by-id. So for anyone who came here looking for a solution, this is the complete code:

  (defun denote-org-transclusion-add (link plist)
    (when (string= "denote" (org-element-property :type link))
      (let* ((denote-id (org-element-property :path link))     ;; get denote id from denote:<denote-id> link
             (file-path (denote-get-path-by-id denote-id))     ;; path resolved by the id
             (new-link (with-temp-buffer                       ;; create a [[file:/path/to/denote/note]] org link
                         (insert "file:")                      ;; and store it in 'new-link' variable
                         (insert file-path)
                         (beginning-of-buffer)
                         (org-element-link-parser))))
        (org-transclusion-add-org-file new-link plist))))      ;; re-use the org transclusion infrastructure for file: links
  (cl-pushnew 'denote-org-transclusion-add                     ;; register the org transclusion 'plugin'
              org-transclusion-add-functions)

Thanks, @nobiot and @alejandrogallo, this was so very helpful!

(Edit: fixed a quoting issue)

nobiot commented 1 year ago

@sthesing does the function you have in your last comment work?

I don’t have capacity to follow the discussion now but I can come back to help you if you have not found a function that works. You can keep the issue open if this is the case.

sthesing commented 1 year ago

Yes, it works. Thanks a lot!

nobiot commented 1 year ago

Great to hear that. @alejandrogallo Thank you :)

alejandrogallo commented 1 year ago

@sthesing glad this worked out! Enjoy!

ctanas commented 10 months ago

I hope this helps you, you just have to find the denote-file-path-from-id functionality in denote

Wow, thanks @alejandrogallo ! With that explanation, it was very easy to set this up. The function in question is called denote-get-path-by-id. So for anyone who came here looking for a solution, this is the complete code:

  (defun denote-org-transclusion-add (link plist)
    (when (string= "denote" (org-element-property :type link))
      (let* ((denote-id (org-element-property :path link))     ;; get denote id from denote:<denote-id> link
             (file-path (denote-get-path-by-id denote-id))     ;; path resolved by the id
             (new-link (with-temp-buffer                       ;; create a [[file:/path/to/denote/note]] org link
                         (insert "file:")                      ;; and store it in 'new-link' variable
                         (insert file-path)
                         (beginning-of-buffer)
                         (org-element-link-parser))))
        (org-transclusion-add-org-file new-link plist))))      ;; re-use the org transclusion infrastructure for file: links
  (cl-pushnew 'denote-org-transclusion-add                     ;; register the org transclusion 'plugin'
              org-transclusion-add-functions)

Thanks, @nobiot and @alejandrogallo, this was so very helpful!

(Edit: fixed a quoting issue)

I'm not sure I know how to use this function. I've pasted it into init.el, but it's not available after buffer evaluation or start-up (when trying to invoke it with M-x). Maybe I'm doing it wrong?

nobiot commented 10 months ago

You don't use this function with M-x. This piece of code does two things: define the function and set the function to a hook. Once this is done, you can use the normal command org-transclusion-add (and its friends) while your cursor is on a denote link.

ctanas commented 10 months ago

Well, this makes sense. And it works. Thank you!

nobiot commented 10 months ago

Good :) I would appreciate it if you could update Reddit and StackOverflow if it is also by you.