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

org-transclusion-exclude-elements don't work with :src #172

Closed Cletip closed 1 year ago

Cletip commented 1 year ago

Hi!

I was testing this part of the manual : https://nobiot.github.io/org-transclusion/#Transclude-source-file-into-src_002dblock, and I tested with a file. Unfortunately, the whole file is transcluded (which is complicated to use with org-roam), even if I have the variable org-transclusion-exclude-elements with the value '(property-drawer keyword).

You can try with this : 

:PROPERTIES:
:ID:       39897abb-0065-4e56-8dcf-6d9f4a6687cb
:END:
#+title: Exemple

print("Hello word")

In another file :

#+transclude: [[id:39897abb-0065-4e56-8dcf-6d9f4a6687cb][Exemple]] :src python :rest ":session :results value"

As you can see, the things that are transcluded do not respect the variable org-transclusion-exclude-elements (because all the text is transcluded). Is this a bug? Is there another solution to exclude some element ?

Thank you in advance for your answer

nobiot commented 1 year ago

This is not a bug. when you put :src property, Org-transclusion treats the file as a text file. This is because :src property is meant to be used with a source file -- text file; not with an Org file.

Filters via variable org-transclusion-exclude-elements works only for Org files.

Because of the :src property, Org-transclusion does not (cannot) apply the filters that are designed to work only for Org files.

For your example to work, you would need to put the code in a python file and transclude it, rather than in an org file.

If you would like Org-transclusion to treat your file as an Org file, remove :src and :rest properties. (In this case, I believe you would like the code to be inside a src block).

nobiot commented 1 year ago

Additionally, for your example, the use of :lines: property should work together with :src (manual entry here). You can skip the first few lines and include the rest of the file if you wish with something like :lines 5-

Cletip commented 1 year ago

This is not a bug. when you put :src property, Org-transclusion treats the file as a text file. This is because :src property is meant to be used with a source file -- text file; not with an Org file.

Filters via variable org-transclusion-exclude-elements works only for Org files.

Oh right, that makes sense, I had misunderstood.

If you would like Org-transclusion to treat your file as an Org file, remove :src and :rest properties. (In this case, I believe you would like the code to be inside a src block).

Yes, I think this will be the best solution: put my code in a source code block directly at the origin (before the transclusion)

Additionally, for your example, the use of :lines: property should work together with :src (manual entry here). You can skip the first few lines and include the rest of the file if you wish with something like :lines 5-

This solution could work, the problem is that I would have to have the same number of lines: if I add something before the lines, it will not work anymore. Anyway, I'm thinking of going with the previous solution.

Thank you for your answer!