nobiot / org-transclusion

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

live sync can not start here #140

Open WaytrueDeng opened 2 years ago

WaytrueDeng commented 2 years ago
image

GNU Emacs 29.0.50 (build 1, aarch64-apple-darwin21.4.0, NS appkit-2113.40 Version 12.3 (Build 21E230)) of 2022-03-21 Org mode version 9.5.2 (release_9.5.2-24-g668205 @ /Users/waytrue/.emacs.d/straight/build/org/)

with org-indent-mode on

WaytrueDeng commented 2 years ago

when I turn indent mode off still not working

nobiot commented 2 years ago

Could you please provide more detail? The message and behavior look to be expected. What do you see as an issue?

WaytrueDeng commented 2 years ago

Could you please provide more detail? The message and behavior look to be expected. What do you see as an issue? Sorry for my poor English, I mean that the transclusion live sync is supported right? but I can not do that, it always says can not start here, and I do not know how to start it. I see the Doc say maybe the indentation problem, I turn it off but still not working

nobiot commented 2 years ago

Your English is fine. For live-sync for an Org file, there is a limitation; refer to this part of the user manual, or in the doc string of org-transclusion-live-sync-start

org-transclusion-live-sync-start does not support all Org elements For transclusions of Org elements or buffers, live-sync works only on the following elements: ‘center-block’, ‘drawer’, ‘dynamic-block’, ‘latex-environment’, ‘paragraph’, ‘plain-list’, ‘quote-block’, ‘special-block’, ‘table’, and ‘verse-block’.

It is known that live-sync does not work for the other elements; namely: ‘comment-block’, ‘export-block’, ‘example-block’, ‘fixed-width’, ‘keyword’, ‘src-block’, and ‘property-drawer’.

More technical reason for this limitation is documented in the docstring of function org-transclusion-live-sync-enclosing-element.

Work is in progress to lift this limitation but I’m still experimenting different ideas

ParetoOptimalDev commented 1 year ago

Is there any issue to track the status of allowing org-transclusion-live-sync-start to work on src-block? It'd be great to get closer to feature parity with clones from leo and https://github.com/boltex/leointeg.

Even if that issue is just to say "no longer actively working on this", of course any pointers for very interested parties is always appreciated :smile:

nobiot commented 1 year ago

@ParetoOptimalDev I suggest this discussion as a pointer: https://github.com/nobiot/org-transclusion/discussions/114#discussioncomment-5201326

Any help would be appreciated

nobiot commented 1 year ago

The literate code tool referenced looks like you could already achieve it with pure Org mode. What would transclusion add?

ParetoOptimalDev commented 1 year ago

The literate code tool referenced looks like you could already achieve it with pure Org mode. What would transclusion add?

"Clones" or different views of the same data. If you take literate programming as "code written for people", then you might consider there are different kinds of people. So in the extreme case you might have the same codebase presented two totally different org heading hiearchies and with a different order, but with the blocks of each being the same and allowing editing either to be reflected to all transcluded versions or "clones".

An example:

* all use cases
** install git
* personal use cases
** install git
* work use cases
** install git

In the above I'd like the install git in both personal and work use case headings to be transcluded from all use cases. You might similarly think of a codebase that is organized like:

* business use cases
** we provide feature 1 using parts of module 1 and module 3
*** module 1 part 2
*** module 3 part 1
* standard codebase hierarchy
** module 1
*** part 1
*** part 2
** module 2
** module 3
*** part 1
*** part 2

The above would then enable someone less familiar with code to audit the surrounding prose to ensure it looks correct for the business case. While a programmer less familiar with literate programming being onboarded will likely jump straight to standard codebase hierarchy.

The key to this being doable is seamless editing of the transcluded blocks, for which I think the current live-sync mechanism is good enough. Platonic ideal would be org source blocks and transcluded org source blocks working the same, but I'm not sure that's possible or feasible.

nobiot commented 1 year ago

If the source file is a text file — e.g. .el, .py., etc, and not an .org file you can transclude a specific part of it into a sourc block, and (if I remember correctly) you should be able to use live sync — have you tried this approach?

ParetoOptimalDev commented 1 year ago

I haven't, but I'll try that now. As long as it lets me use the org file as the source of truth that should work.

ParetoOptimalDev commented 1 year ago

Alright... this is workable and perhaps a better option given that you can't easily universally use lsp integration directly in org source blocks. Or maybe the experimental LSP support for org from lsp-mode has progressed further.

The feel of it isn't as nice as leo where you just never leave the interactive document, but as I said definitely workable.

Here is my example:

Main.hs

f = 1

g = 2

try.org

* standard codebase hierarchy

** main

*** f

#+transclude: [[file:Main.hs::f]]

*** g

#+transclude: [[file:Main.hs::g]]

* business cases

** business case 1 uses only function g below

#+transclude: [[file:Main.hs::g]]

Then FYI to any observers not familar with org-transclusion the workflow is:

Hm, it looks like I may have a bug though because the transclusion to f includes the definition of g for some reason. Maybe [[file:Main.hs::f]] isn't specific enough?? The one for g seems to work though.

image

vleonbonnet commented 1 year ago

@ParetoOptimalDev I believe the behavior you're seeing is normal: when you specify a search term (in your case ::f or ::g) Org jumps to the specified location in the file and includes all remaining lines. As such, when you search for f you also get g. If you wish to limit the results, you can use :lines 1-1.

While live sync in a standard file transclusion works, it is a shame that it is not available if the :src tag is added, which means we cannot get code formatting&coloring on top of live sync, and must choose one or the other.

I get a user-error: No live sync for src-code block. While I understand it is not currently implemented, calling it a 'user-error' is a little odd.

nobiot commented 1 year ago

it is a shame that it is not available if the :src tag is added

Does this commit address this limitation? It would be great if you could let us know if it works.

vleonbonnet commented 1 year ago

Thanks for sharing, I just gave it go and and it seems to work, this is great news. Will report back if I experience issues as I work some more with it.