Exemple #1
0
 def fastAddLastChild(self, parent_v, gnxString):
     '''
     Create new VNode as last child of the receiver.
     If the gnx exists already, create a clone instead of new VNode.
     '''
     trace = False and not g.unitTesting
     c = self.c
     gnxString = g.toUnicode(gnxString)
     gnxDict = c.fileCommands.gnxDict
     if gnxString is None: v = None
     else: v = gnxDict.get(gnxString)
     is_clone = v is not None
     if trace: g.trace(
         'clone', '%-5s' % (is_clone),
         'parent_v', parent_v, 'gnx', gnxString, 'v', repr(v))
     if is_clone:
         pass
     else:
         if gnxString:
             assert g.isUnicode(gnxString)
             v = leoNodes.VNode(context=c, gnx=gnxString)
             if g.trace_gnxDict: g.trace(c.shortFileName(), gnxString, v)
         else:
             v = leoNodes.VNode(context=c)
             # This is not an error: it can happen with @auto nodes.
             # g.trace('**** no gnx for',v,parent_v)
     child_v = v
     child_v._linkAsNthChild(parent_v, parent_v.numberOfChildren())
     child_v.setVisited() # Supress warning/deletion of unvisited nodes.
     return is_clone, child_v
Exemple #2
0
 def init_env(self):
     '''
     Init c.abbrev_subst_env by executing the contents of the
     @data abbreviations-subst-env node.
     '''
     c = self.c
     at = c.atFileCommands
     if c.abbrev_place_start and self.enabled:
         aList = self.subst_env
         script = []
         for z in aList:
             # Compatibility with original design.
             if z.startswith('\\:'):
                 script.append(z[2:])
             else:
                 script.append(z)
         script = ''.join(script)
         # Allow Leo directives in @data abbreviations-subst-env trees.
         import leo.core.leoNodes as leoNodes
         v = leoNodes.VNode(context=c)
         root = leoNodes.Position(v)
         # Similar to g.getScript.
         script = at.writeFromString(
             root=root,
             s=script,
             forcePythonSentinels=True,
             useSentinels=False)
         script = script.replace("\r\n", "\n")
         try:
             exec(script, c.abbrev_subst_env, c.abbrev_subst_env)
         except Exception:
             g.es('Error exec\'ing @data abbreviations-subst-env')
             g.es_exception()
     else:
         c.abbrev_subst_start = False
Exemple #3
0
    def fastAddLastChild(self,parent_v,gnxString):
        '''Create new VNode as last child of the receiver.

        If the gnx exists already, create a clone instead of new VNode.
        '''

        trace = False and not g.unitTesting
        c = self.c
        indices = g.app.nodeIndices
        gnxDict = c.fileCommands.gnxDict
        if gnxString is None: v = None
        else:                 v = gnxDict.get(gnxString)
        is_clone = v is not None
        if trace: g.trace(
            'clone','%-5s' % (is_clone),
            'parent_v',parent_v,'gnx',gnxString,'v',repr(v))
        if is_clone:
            pass
        else:
            v = leoNodes.VNode(context=c)
            if gnxString:
                gnx = indices.scanGnx(gnxString,0)
                v.fileIndex = gnx
                gnxDict[gnxString] = v
            else:
                g.trace('**** no gnx for',v)
        child_v = v
        child_v._linkAsNthChild(parent_v,parent_v.numberOfChildren())
        child_v.setVisited() # Supress warning/deletion of unvisited nodes.
        return is_clone,child_v
Exemple #4
0
 def createVnode(self, c, node, v=None):
     if not v:
         v = leoNodes.VNode(context=c)
         v.b, v.h = node.bodyString, node.headString
     if node.gnx:
         ni = g.app.nodeIndices
         v.fileIndex = ni.tupleToString(ni.scanGnx(node.gnx))
         self.generated_gnxs[node.gnx] = v
     self.handleVnodeAttributes(node, v)
     return v
Exemple #5
0
 def fastAddLastChild(self, fileName, gnxString, parent_v):
     '''
     Create new VNode as last child of the receiver.
     If the gnx exists already, create a clone instead of new VNode.
     '''
     trace = 'gnx' in g.app.debug
     c = self.c
     gnxString = g.toUnicode(gnxString)
     gnxDict = c.fileCommands.gnxDict
     if gnxString is None:
         v = None
     else:
         v = gnxDict.get(gnxString)
     is_clone = v is not None
     if trace:
         g.trace('clone', '%-5s' % (is_clone), 'parent_v', parent_v, 'gnx',
                 gnxString, 'v', repr(v))
     if is_clone:
         # new-read: update tempRoots.
         if not hasattr(v, 'tempRoots'):
             v.tempRoots = set()
         v.tempRoots.add(fileName)
     else:
         if gnxString:
             assert g.isUnicode(gnxString)
             v = leoNodes.VNode(context=c, gnx=gnxString)
             if 'gnx' in g.app.debug:
                 g.trace(c.shortFileName(), gnxString, v)
         else:
             v = leoNodes.VNode(context=c)
             # This is not an error: it can happen with @auto nodes.
             # g.trace('**** no gnx for',v,parent_v)
         # Indicate that this node came from an external file.
         v.tempRoots = set()
         v.tempRoots.add(fileName)
     child_v = v
     child_v._linkAsNthChild(parent_v, parent_v.numberOfChildren())
     child_v.setVisited()  # Supress warning/deletion of unvisited nodes.
     return is_clone, child_v
Exemple #6
0
 def recreateV(_vlist):
     h, b, gnx, c_vlist = _vlist
     v = gnxDict.get(gnx)
     if not v:
         v = leoNodes.VNode(context=c, gnx=gnx)
     else:
         del v.children[:]
     v.h = h
     v.b = b
     for x in c_vlist:
         cv = recreateV(x)
         v.children.append(cv)
         if v not in cv.parents:
             cv.parents.append(v)
     return v
Exemple #7
0
 def init_env(self):
     """
     Init c.abbrev_subst_env by executing the contents of the
     @data abbreviations-subst-env node.
     """
     c = self.c
     at = c.atFileCommands
     if c.abbrev_place_start and self.enabled:
         aList = self.subst_env
         script = []
         for z in aList:
             # Compatibility with original design.
             if z.startswith('\\:'):
                 script.append(z[2:])
             else:
                 script.append(z)
         script = ''.join(script)
         # Allow Leo directives in @data abbreviations-subst-env trees.
         import leo.core.leoNodes as leoNodes
         # #1674: Avoid unnecessary entries in c.fileCommands.gnxDict.
         root = c.rootPosition()
         if root:
             v = root.v
         else:
             # Defensive programming. Probably will never happen.
             v = leoNodes.VNode(context=c)
             root = leoNodes.Position(v)
         # Similar to g.getScript.
         script = at.stringToString(root=root,
                                    s=script,
                                    forcePythonSentinels=True,
                                    sentinels=False)
         script = script.replace("\r\n", "\n")
         try:
             exec(script, c.abbrev_subst_env, c.abbrev_subst_env)
         except Exception:
             g.es('Error exec\'ing @data abbreviations-subst-env')
             g.es_exception()
     else:
         c.abbrev_subst_start = False