This Engineering notebook post discusses how to support code/text snippets 
in Leo. The Aha: gnx's are an underused resource! 

I have been thinking about literate programming (LP), documentation, and 
related Leo issues. Some links:

- Dynamic Notebooks and Literate Programming 
<https://www.youtube.com/watch?v=UCEzBNh9ufs>
- #189 <https://github.com/leo-editor/leo-editor/issues/189>: Better 
Support for UNL Navigation.
- #946 <https://github.com/leo-editor/leo-editor/issues/946>: Create a way 
to isolate documentation in a subnode.
- #1035 <https://github.com/leo-editor/leo-editor/issues/1035>: References 
to nodes via gnx's or tags.
- Discussion of retiring @root 
<https://groups.google.com/g/leo-editor/c/kv2AF69pC38>.

These topics are all related to the wish to make Leo a better mimic of the 
original goals of LP, which morphs into the desire to allow references to 
snippets of code, especially in Leo's rst3 command.

Yesterday I realized that gnx's, the unique, unchanging part of each node, 
provides a way to identify *snippets*, much like org mode's code block:

@snippet <description>
<Lines of text or code>
@end-snippet

The snippet would be like a section definition. A *snippet reference* would 
be a text-based way of referring to a particular snippet.

Snippet references will contain the gnx of the node containing the snippet 
and the *snippet description*. Snippet descriptions need to be unique only 
within each Leo node.

*Leo will search all open outlines for snippets, *much like Leo searches 
for @button nodes when we right-click the @button node and choose "Find 
Script."

*Using snippets in @rst trees*

Inside @rst trees, Leo's rst3 command could support a new kind of @rst node:

  @rst-insert-snippet (description)

These nodes would insert the snippet into the rST output. The body text of 
@insert-snippet nodes would contain the gnx.

*Using snippets in @file trees*

Similarly, Leo *might *be able to incorporate snippets into external files 
using a new Leo directive:

     @insert-snippet (description) 

Outlines must define all snippets referenced in @file trees. This 
constraint will likely ensure that the @file read logic will never fail to 
find snippets.

*Summary*

Using snippets, users, documents, and scripts can safely use text from all 
open outlines. Snippets are, in effect, permalinks, uniquely defined by the 
combination of gnx and description. 

Snippets can become invalid only if the user permanently deletes the node 
containing the snippets.  Leo will provide tools for finding snippets, just 
as Leo can find the script corresponding to @button nodes.

Within @rst trees, snippets will provide all LP's features in a more 
Leonine way.

Snippets *might* also work in @file trees.  If so, snippets would provide 
most (all?) of the benefits of cross-file clones.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/97b44c5e-468b-4403-b90a-21d89e6ea62dn%40googlegroups.com.

Reply via email to