Ejemplo n.º 1
0
 def adjustDefStart(self, s, i):
     '''A hook to allow the Python importer to adjust the 
     start of a class or function to include decorators.
     '''
     # Invariant: i does not change.
     # Invariant: start is the present return value.
     try:
         assert s[i] != '\n'
         start = j = g.find_line_start(s, i) if i > 0 else 0
         # g.trace('entry',j,i,repr(s[j:i+10]))
         assert j == 0 or s[j - 1] == '\n'
         while j > 0:
             progress = j
             j1 = j = g.find_line_start(s, j - 2)
             # g.trace('line',repr(s[j:progress]))
             j = g.skip_ws(s, j)
             if not g.match(s, j, '@'):
                 break
             k = g.skip_id(s, j + 1)
             word = s[j: k]
             # Leo directives halt the scan.
             if word and word in g.globalDirectiveList:
                 break
             # A decorator.
             start = j = j1
             assert j < progress
         # g.trace('**returns %s, %s' % (repr(s[start:i]),repr(s[i:i+20])))
         return start
     except AssertionError:
         g.es_exception()
         return i
Ejemplo n.º 2
0
 def adjustDefStart(self, s, i):
     '''A hook to allow the Python importer to adjust the
     start of a class or function to include decorators.
     '''
     # Invariant: i does not change.
     # Invariant: start is the present return value.
     try:
         assert s[i] != '\n'
         start = j = g.find_line_start(s, i) if i > 0 else 0
         # g.trace('entry',j,i,repr(s[j:i+10]))
         assert j == 0 or s[j - 1] == '\n'
         while j > 0:
             progress = j
             j1 = j = g.find_line_start(s, j - 2)
             # g.trace('line',repr(s[j:progress]))
             j = g.skip_ws(s, j)
             if not g.match(s, j, '@'):
                 break
             k = g.skip_id(s, j + 1)
             word = s[j:k]
             # Leo directives halt the scan.
             if word and word in g.globalDirectiveList:
                 break
             # A decorator.
             start = j = j1
             assert j < progress
         # g.trace('**returns %s, %s' % (repr(s[start:i]),repr(s[i:i+20])))
         return start
     except AssertionError:
         g.es_exception()
         return i
Ejemplo n.º 3
0
def line_to_headline(self, event=None):
    '''
    Create child node from the selected line.
    
    Cut the selected line and make it the new node's headline
    '''
    c, w = self, self.frame.body.wrapper
    p = c.p
    ins, s = w.getInsertPoint(), p.b
    u, undoType = c.undoer, 'Extract Line'
    i = g.find_line_start(s, ins)
    j = g.skip_line(s, i)
    line = s[i:j].strip()
    if not line:
        return
    u.beforeChangeGroup(p, undoType)
    undoData = u.beforeInsertNode(p)
    p2 = p.insertAsLastChild()
    p2.h = line
    u.afterInsertNode(p2, undoType, undoData)
    oldText = p.b
    p.b = s[:i] + s[j:]
    w.setInsertPoint(i)
    u.setUndoTypingParams(p, undoType, oldText=oldText, newText=p.b)
    p2.setDirty()
    c.setChanged(True)
    u.afterChangeGroup(p, undoType=undoType)
    c.redraw_after_icons_changed()
    p.expand()
    c.redraw(p)
    c.bodyWantsFocus()
Ejemplo n.º 4
0
 def startsHelper(self, s, i, kind, tags, tag=None):
     '''return True if s[i:] starts an rST section.
     Sets sigStart, sigEnd, sigId and codeEnd ivars.'''
     trace = False and not g.unitTesting
     verbose = True
     kind, name, next, ch = self.startsSection(s, i)
     if kind == 'plain': return False
     self.underlineCh = ch
     self.lastSectionLevel = self.sectionLevel
     self.sectionLevel = self.computeSectionLevel(ch, kind)
     self.sigStart = g.find_line_start(s, i)
     self.sigEnd = next
     self.sigId = name
     i = next + 1
     if trace: g.trace('sigId', self.sigId, 'next', next)
     while i < len(s):
         progress = i
         i, j = g.getLine(s, i)
         kind, name, next, ch = self.startsSection(s, i)
         if trace and verbose: g.trace(kind, repr(s[i: j]))
         if kind in ('over', 'under'):
             break
         else:
             i = j
         assert i > progress
     self.codeEnd = i
     if trace:
         if verbose:
             g.trace('found...\n%s' % s[self.sigStart: self.codeEnd])
         else:
             g.trace('level %s %s' % (self.sectionLevel, self.sigId))
     return True
Ejemplo n.º 5
0
 def startsHelper(self,s,i,kind,tags,tag=None):
     '''
     return True if s[i:] starts an markdown section.
     Sets sigStart, sigEnd, sigId and codeEnd ivars.
     '''
     trace = False and not g.unitTesting
     level,name,i = self.startsSection(s,i)
     if level == 0:
         return False
     self.lastSectionLevel = self.sectionLevel
     self.sectionLevel = level
     self.sigStart = g.find_line_start(s,i)
     self.sigEnd = i
     self.sigId = name
     i += 1
     while i < len(s):
         progress = i
         i,j = g.getLine(s,i)
         level,name,j = self.startsSection(s,i)
         if level > 0: break
         else: i = j
         assert i > progress
     self.codeEnd = i
     if trace: g.trace('found %s...\n%s' % (
         self.sigId,s[self.sigStart:self.codeEnd]))
     return True
Ejemplo n.º 6
0
 def startsHelper(self, s, i, kind, tags, tag=None):
     '''return True if s[i:] starts section.
     Sets sigStart, sigEnd, sigId and codeEnd ivars.'''
     trace = False
     self.codeEnd = self.sigEnd = self.sigId = None
     self.sigStart = i
     sigStart = i
     ok, sigId, i = self.isSectionLine(s, i)
     if not sigId or not ok:
         # if trace: g.trace('fail',repr(g.getLine(s,i)))
         return False
     i = sigEnd = g.skip_line(s, i)
     # Skip everything until the next section.
     while i < len(s):
         progress = i
         ok, junk, junk = self.isSectionLine(s, i)
         if ok: break # don't change i.
         i = g.skip_line(s, i)
         assert progress < i
     # Success: set the ivars.
     self.sigStart = sigStart
     self.codeEnd = i
     self.sigEnd = sigEnd
     self.sigId = sigId
     self.classId = None
     # Note: backing up here is safe because
     # we won't back up past scan's 'start' point.
     # Thus, characters will never be output twice.
     k = self.sigStart
     if not g.match(s, k, '\n'):
         self.sigStart = g.find_line_start(s, k)
     if trace: g.trace(sigId, 'returns\n' + s[self.sigStart: i] + '\nEND')
     return True
Ejemplo n.º 7
0
 def startsHelper(self, s, i, kind, tags, tag=None):
     '''return True if s[i:] starts an rST section.
     Sets sigStart, sigEnd, sigId and codeEnd ivars.'''
     trace = False and not g.unitTesting
     verbose = True
     kind, name, next, ch = self.startsSection(s, i)
     if kind == 'plain': return False
     self.underlineCh = ch
     self.lastSectionLevel = self.sectionLevel
     self.sectionLevel = self.computeSectionLevel(ch, kind)
     self.sigStart = g.find_line_start(s, i)
     self.sigEnd = next
     self.sigId = name
     i = next + 1
     if trace: g.trace('sigId', self.sigId, 'next', next)
     while i < len(s):
         progress = i
         i, j = g.getLine(s, i)
         kind, name, next, ch = self.startsSection(s, i)
         if trace and verbose: g.trace(kind, repr(s[i:j]))
         if kind in ('over', 'under'):
             break
         else:
             i = j
         assert i > progress
     self.codeEnd = i
     if trace:
         if verbose:
             g.trace('found...\n%s' % s[self.sigStart:self.codeEnd])
         else:
             g.trace('level %s %s' % (self.sectionLevel, self.sigId))
     return True
Ejemplo n.º 8
0
def line_to_headline(self, event=None):
    '''
    Create child node from the selected line.
    
    Cut the selected line and make it the new node's headline
    '''
    c, w = self, self.frame.body.wrapper
    p = c.p
    ins, s = w.getInsertPoint(), p.b
    u, undoType = c.undoer, 'Extract Line'
    i = g.find_line_start(s, ins)
    j = g.skip_line(s, i)
    line = s[i:j].strip()
    if not line:
        return
    u.beforeChangeGroup(p, undoType)
    undoData = u.beforeInsertNode(p)
    p2 = p.insertAsLastChild()
    p2.h = line
    u.afterInsertNode(p2, undoType, undoData)
    oldText = p.b
    p.b = s[:i] + s[j:]
    w.setInsertPoint(i)
    u.setUndoTypingParams(p, undoType, oldText=oldText, newText=p.b)
    p2.setDirty()
    c.setChanged(True)
    u.afterChangeGroup(p, undoType=undoType)
    c.redraw_after_icons_changed()
    p.expand()
    c.redraw(p)
    c.bodyWantsFocus()
Ejemplo n.º 9
0
 def startsHelper(self, s, i, kind, tags, tag=None):
     '''
     return True if s[i:] starts an markdown section.
     Sets sigStart, sigEnd, sigId and codeEnd ivars.
     '''
     trace = False and not g.unitTesting
     level, name, i = self.startsSection(s, i)
     if level == 0:
         if trace:
             i2, j2 = g.getLine(s, i-1)
             g.trace('==== False:', s[i2:j2].rstrip())
         return False
     self.lastSectionLevel = self.sectionLevel
     self.sectionLevel = level
     self.sigStart = g.find_line_start(s, i-1)
     self.sigEnd = i
     self.sigId = name
     if trace:
         i2, j2 = g.getLine(s, i-1)
         g.trace('====  True:', s[i2:j2].rstrip())
     i += 1
     while i < len(s):
         progress = i
         i2, j2 = g.getLine(s, i)
         level, name, j = self.startsSection(s, i2)
         if trace: g.trace('---- body:', level, name, s[i2:j2].rstrip())
         if level > 0:
             break
         else:
             i = j
         assert i > progress
     self.codeEnd = i
     if trace: g.trace('found %s...\n%s' % (
         self.sigId, s[self.sigStart: self.codeEnd]))
     return True
Ejemplo n.º 10
0
 def vim_O(self):
     '''Open a new line above the current line N times.'''
     vc = self
     w = vc.event.w
     s = w.getAllText()
     i = w.getInsertPoint()
     i = g.find_line_start(s,i)
     # if i > 0: w.setInsertPoint(i-1)
     # i = w.getInsertPoint()
     w.insert(max(0,i-1),'\n')
     return vc.begin_insert_mode()
Ejemplo n.º 11
0
 def vim_O(self):
     '''Open a new line above the current line N times.'''
     vc = self
     w = vc.event.w
     s = w.getAllText()
     i = w.getInsertPoint()
     i = g.find_line_start(s, i)
     # if i > 0: w.setInsertPoint(i-1)
     # i = w.getInsertPoint()
     w.insert(max(0, i - 1), '\n')
     return vc.begin_insert_mode()
Ejemplo n.º 12
0
def line_to_headline(self, event=None):
    """
    Create child node from the selected line.

    Cut the selected line and make it the new node's headline
    """
    c, p, u, w = self, self.p, self.undoer, self.frame.body.wrapper
    undoType = 'line-to-headline'
    ins, s = w.getInsertPoint(), p.b
    i = g.find_line_start(s, ins)
    j = g.skip_line(s, i)
    line = s[i:j].strip()
    if not line:
        return
    u.beforeChangeGroup(p, undoType)
    #
    # Start outer undo.
    undoData = u.beforeInsertNode(p)
    p2 = p.insertAsLastChild()
    p2.h = line
    u.afterInsertNode(p2, undoType, undoData)
    #
    # "before" snapshot.
    bunch = u.beforeChangeBody(p)
    p.b = s[:i] + s[j:]
    w.setInsertPoint(i)
    p2.setDirty()
    c.setChanged()
    #
    # "after" snapshot.
    u.afterChangeBody(p, undoType, bunch)
    #
    # Finish outer undo.
    u.afterChangeGroup(p, undoType=undoType)
    c.redraw_after_icons_changed()
    p.expand()
    c.redraw(p)
    c.bodyWantsFocus()