On Saturday, February 17, 2018 at 5:57:19 PM UTC-6, John Clark wrote:

Firstly, I can't seem to find a way to programmatically reference the vnode 
> containing the script that is being executed (or the root vnode thereof in 
> the case where the script is composed using numerous child nodes).
>

That would be p.v.  p is predefined in scripts.  Outside of scripts, say in 
Leo's commands, the answer is c.p.v, c.p being the presently selected nodes.

It is usually clear how to get c.  Within  Leo's own classes, there is 
almost always a self.c ivar.  Otherwise, say in commands, you get c this 
way:

@g.command('my-command-name')
def my_command(event):
    c = event and event.get('c') 

But are you sure you want p.v instead of v?  Most code does just fine using 
positions.  You want to use p.v only when saving references to vnodes when 
the outline itself may change.

Secondly, ...I would really like...to reference the vnode containing the 
> @path directory. Specifically, I would like to be able to programmatically 
> reference the headline of the node containing the path directive to form a 
> pathspec based on the headline. E.g.
>

Given c.p, the presently selected node, you could look up the tree, looking 
for the nearest @path node:

for p in c.p.self_and_parents():
    if p.h.startswith('@path '):
        # p is the nearest @path node. 

But the following probably does exactly what you want:

path = g.fullPath(c, c.p)

g.fullPath is defined as follows:

def fullPath(c, p, simulate=False):
    '''
    Return the full path (including fileName) in effect at p. Neither the
    path nor the fileName will be created if it does not exist.
    '''
    trace = False and not g.unitTesting
    # 2016/03/30: search p and p's parents.
    for p in p.self_and_parents():
        aList = g.get_directives_dict_list(p)
        path = c.scanAtPathDirectives(aList)
        fn = p.h if simulate else p.anyAtFileNodeName()
            # Use p.h for unit tests.
        if fn:
            # Fix #102: call commander method, not the global function.
            if trace and c and c.p == p: g.trace('found', p.h)
            return c.os_path_finalize_join(path, fn)
    return ''

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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to