@auto-md: multiple vnodes with gnx

137 views
Skip to first unread message

p.os...@datec.at

unread,
Aug 23, 2023, 8:18:26 AM8/23/23
to leo-editor
It becomes more and more annoying, that when I want to clone a node below a @auto-md file into another @auto-md I get this error:

multiple vnodes with gnx: 'xxx.20230509132609.1'
id(v): 139738387243504 gnx: xxx.20230509132609.1 Variable
id(v): 139738508086256 gnx: xxx.20230509132609.1 Variable
check-outline ERROR! xxxxx.leo 24355 nodes, 2 gnx errors, 0 structure errors

As a resiult the node is only copied and not cloned.

How can I overcome this?

Cheers Paul

Edward K. Ream

unread,
Aug 23, 2023, 10:05:45 AM8/23/23
to leo-e...@googlegroups.com
On Wed, Aug 23, 2023 at 7:18 AM p.os...@datec.at <p.os...@datec.at> wrote:

> when I want to clone a node below a @auto-md file into another @auto-md I get this error:

Thanks for this report. I have just created #3512 for it. I'll investigate immediately.

Edward

Edward K. Ream

unread,
Aug 23, 2023, 11:03:55 AM8/23/23
to leo-editor
On Wednesday, August 23, 2023 at 7:18:26 AM UTC-5 p.os...wrote:
It becomes more and more annoying, that when I want to clone a node below a @auto-md file into another @auto-md I get this error:

What is the value of this setting in your file? (show-settings will list all settings.)

@bool create-at-persistence-nodes-automatically

Everything works for me if this setting is True. (The default in leoSettings.leo is False).

Edward

p.os...@datec.at

unread,
Aug 23, 2023, 11:18:03 AM8/23/23
to leo-editor
[M] @  bool createatpersistencenodesautomatically = True

Forgot to mention I am still running ver. 6.7.1 and on Linux.

Guess I'll keep an eye on this by running Leo in an IDE.

HaveF HaveF

unread,
Aug 24, 2023, 12:29:56 AM8/24/23
to leo-editor

@bool create-at-persistence-nodes-automatically

Everything works for me if this setting is True. (The default in leoSettings.leo is False).
How about set the setting to True as default? 
 

Edward K. Ream

unread,
Aug 24, 2023, 10:44:57 AM8/24/23
to leo-e...@googlegroups.com
Creating `@persistence` nodes by default would be problematic because the setting continually increases the size of the .leo file.

In other words, ` @persistence`is a bit of a hack :-)

Imo, `@clean` is a better option for most people than `@auto`.

Edward


HaveF HaveF

unread,
Aug 24, 2023, 9:09:05 PM8/24/23
to leo-e...@googlegroups.com
Imo, `@clean` is a better option for most people than `@auto`.

I see. But like @auto-md can generate section heading of the appropriate level, this feature is indeed more convenient.
If I use @clean, I have to generate my own structure << ... >> by hand

Edward K. Ream

unread,
Aug 25, 2023, 6:54:59 AM8/25/23
to leo-e...@googlegroups.com
So stick with @auto-md :-)

p.os...@datec.at

unread,
Aug 27, 2023, 9:59:28 AM8/27/23
to leo-editor
The behaviour I experience seems documented: https://leoeditor.com/FAQ.html#why-doesn-t-leo-support-cross-outline-clones - and that makes sense, if MD files are read by Leo. But why are they read? They only need to be written as I want to create MD files using Leo and only Leo.

p.os...@datec.at

unread,
Aug 27, 2023, 10:15:56 AM8/27/23
to leo-editor
Ah, ok, I see: auto-xx nodes are NOT stored w/i Leo files. Hm, how can I overcome this. What I want is that all my MD is stored w/i my Leo file and when I save it, all MD-nodes should be written as they are now. At startup of Leo, Leo would not need to read MD files, because their content is stored w/i my Leo file. Everything would be fine and work as expected ;-)

Thomas Passin

unread,
Aug 27, 2023, 3:05:16 PM8/27/23
to leo-editor
One possibility is to import an MD file as an @auto-md.  This way you will get the sections set up as you expect. Then change it to be an @clean file, then save the outline.  After this, the external file will always track what is in your outline (and if you edit the external file with some other editor, then Leo will pick up those changes).

This is a little extra work but you would only need to do it once for each imported md file.

p.os...@datec.at

unread,
Aug 27, 2023, 4:33:14 PM8/27/23
to leo-editor
I do not import MD files, I create and write them in Leo. The bad about @clean files is, that they do not convert my node tree into a valid MD files containing headings with the right level. Or do they?

Thomas Passin

unread,
Aug 27, 2023, 6:08:03 PM8/27/23
to leo-editor
Oh, you mean that the headline indent level should translate into the right number of "###" characters?  You are right that an @clean file wouldn't do that.  What would be just right is the rst3 command, except adapted for MD instead of RsT.  I've been thinking there ought to be such a command.

Actually, it shouldn't be that hard to write a command that would do that for a single file.  rst3 has some extra functionality that you probably don't need.  You would want it to honor << sections >> and @others, right?  Or maybe there already is such a command; I haven't found it in a quick look, but one could exist somewhere anyway.

p.os...@datec.at

unread,
Aug 28, 2023, 4:56:12 AM8/28/23
to leo-editor
Yes, that's the point. It simply should work as the RST-plugin does.

Edward K. Ream

unread,
Aug 28, 2023, 8:19:06 AM8/28/23
to leo-e...@googlegroups.com
On Mon, Aug 28, 2023 at 3:56 AM p.os...@datec.at <p.os...@datec.at> wrote:

Yes, that's the point. It simply should work as the RST-plugin does.

LeoDocs.leo contains a disabled button: make-md-toc. Please take a look.

Funny, there is a tip about this script.

Edward

Thomas Passin

unread,
Aug 28, 2023, 3:58:26 PM8/28/23
to leo-editor
On Monday, August 28, 2023 at 4:56:12 AM UTC-4 p.os...@datec.at wrote:
Yes, that's the point. It simply should work as the RST-plugin does.

I wrote a small script that does what I think you want, although only for a single @md file at a time.  The top-level node must have a headline that starts with "@md " and a filename or path, like this: @md test.md. This node may optionally be the child of an @path node to write the output file somewhere else besides the outline's location.  To use the command, select any node in the markdown's subtree and invoke the command.

Note that the command as currently written will not recognize an @auto-md node.  The node's headline has to start with @md .  All headlines will be indented according to their nesting level, except that the top node, the one with the file name, will not have a heading (since the @md  headline wouldn't make much sense, at least to me).

There are no extra features such as the rst3 command has, but it's a start.  Try it out, see what you think or want to change.

@language python
"""Write an @md file tree with headings corresponding to node indentation.

Searches node and parents to find the nearest node headline beginning
with *@md*, then writes the entire subtree of that node.

Output file is written to the path in effect at the @md node.
"""

from pathlib import Path
MD_PREFIX = '@md '
def find_md_root(p):
    """Return the top position of an @md tree or None.
   
    The top headline must begin with "@md ".
    """
    for p0 in p.self_and_parents():
        if p0.h.startswith(MD_PREFIX):
            break
    else:
        p0 = None
    return p0

def walk_md(root):
    """Return a string for the markdown file from root position.
   
    Headlines are indented relative to their nesting level under
    the root."""
    markdown = ''
    root_indent = root.level()
    for p in root.self_and_subtree():
        if p.h and p != root:
            indent = p.level() - root_indent + 1
            markdown += '#' * indent
            markdown += p.h + '\n'
        markdown += p.b + '\n'
    return markdown

root = find_md_root(p)

# Get path for node; path does not include the filename
path = Path(c.getNodePath(root)) if root else None
if path and path.exists():
    fname = root.h[len(MD_PREFIX):]
    path = path.joinpath(Path(fname))
    md = walk_md(root)
    try:
        with open(path, 'w', encoding = 'utf-8') as f:
            f.write(md)
        g.es(f'Wrote {path}')
    except Exception as e:
        g.es(f'Could not write file at {path}: {e}')
else:
   g.es(f'Path {path} does not exist')


Thomas Passin

unread,
Aug 29, 2023, 9:03:43 AM8/29/23
to leo-editor
You can also export the Markdown to your external text editor using the viewrendered3 plugin.  The drawback is that you would need to save it to the desired location yourself.

To do this, enable the VR3 plugin and open it in your outline.  Select the "Entire Tree" View Option, select the top node in your markdown tree, and issue the minibuffer command vr3-open-markup-in-editor.

Currently you have to make sure that each node ends with a blank line.  Also, while headlines are turned into section titles, they are all given the same level (that is, "##").  I will look into updating VR3 to give indents relative to the root node instead of all having them the same.  Should be easy to do.

Edward K. Ream

unread,
Aug 29, 2023, 1:53:21 PM8/29/23
to leo-e...@googlegroups.com
On Tue, Aug 29, 2023 at 8:03 AM Thomas Passin <tbp1...@gmail.com> wrote:
You can also export the Markdown to your external text editor using the viewrendered3 plugin.  The drawback is that you would need to save it to the desired location yourself.

Imo, after a certain point of complexity it will be simpler to switch to rST. Where that point is must be a personal choice, but I would encourage some experimentation with rST.

Edward

p.os...@datec.at

unread,
Sep 1, 2023, 4:55:20 AM9/1/23
to leo-editor
Looks good! I'll stick with it.

Replaced
        if p.h and p != root:

by
        if p.h and not p.h.startswith( "!") and p != root:

though.

Thanks a lot!

p.os...@datec.at

unread,
Sep 1, 2023, 4:58:59 AM9/1/23
to leo-editor
Well I am a long-term user of rST and the respective Leo plugin. But this is about creating and maintaining MkDocs websites. I consider Leo being superior here (just as elsewhere also).
Reply all
Reply to author
Forward
0 new messages