Exemplo n.º 1
0
 def getRectanglePoints(self, w):
     c = self.c
     c.widgetWantsFocusNow(w)
     s = w.getAllText()
     i, j = w.getSelectionRange()
     r1, r2 = g.convertPythonIndexToRowCol(s, i)
     r3, r4 = g.convertPythonIndexToRowCol(s, j)
     return r1 + 1, r2, r3 + 1, r4
Exemplo n.º 2
0
 def getRectanglePoints(self, w):
     c = self.c
     c.widgetWantsFocusNow(w)
     s = w.getAllText()
     i, j = w.getSelectionRange()
     r1, r2 = g.convertPythonIndexToRowCol(s, i)
     r3, r4 = g.convertPythonIndexToRowCol(s, j)
     return r1 + 1, r2, r3 + 1, r4
Exemplo n.º 3
0
 def getRectanglePoints(self, w):
     """Return the rectangle corresponding to the selection range."""
     c = self.c
     c.widgetWantsFocusNow(w)
     s = w.getAllText()
     i, j = w.getSelectionRange()
     r1, r2 = g.convertPythonIndexToRowCol(s, i)
     r3, r4 = g.convertPythonIndexToRowCol(s, j)
     return r1 + 1, r2, r3 + 1, r4
Exemplo n.º 4
0
 def toAtEdit(self, p):
     '''Convert p from @auto to @edit.'''
     c = self.c
     w = c.frame.body.wrapper
     p.h = '@edit' + p.h[5:]
     # Compute the position of the present line within the *selected* node c.p
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(c.p.b, ins)
     # Ignore directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Count preceding lines from p to c.p, again ignoring directives.
     for p2 in p.self_and_subtree():
         if p2 == c.p:
             break
         lines = [z for z in g.splitLines(p2.b) if not g.isDirective(z)]
         row += len(lines)
     # Reload the file into a single node.
     c.selectPosition(p, enableRedrawFlag=False)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     ins = g.convertRowColToPythonIndex(p.b, row+1, 0)
     w.setInsertPoint(ins)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Exemplo n.º 5
0
def xdb_breakpoint(event):
    '''Set the breakpoint at the presently select line in Leo.'''
    c = event.get('c')
    if not c:
        return
    p = c.p
    xdb = getattr(g.app, 'xdb', None)
    if not xdb:
        print('xdb not active')
        return
    w = c.frame.body.wrapper
    if not w:
        return
    x = c.gotoCommands
    root, fileName = x.find_root(p)
    if not root:
        g.trace('no root', p.h)
        return
    path = g.fullPath(c, root)
    n0 = x.find_node_start(p=p)
    if n0 is None:
        g.trace('no n0')
        return
    c.bodyWantsFocusNow()
    i = w.getInsertPoint()
    s = w.getAllText()
    row, col = g.convertPythonIndexToRowCol(s, i)
    n = x.node_offset_to_file_line(row, p, root)
    if n is not None:
        xdb.qc.put('b %s:%s' % (path, n+1))
Exemplo n.º 6
0
 def get_cursor_arg(self):
     '''Compute the cursor argument for vim.'''
     wrapper = self.c.frame.body.wrapper
     s = wrapper.getAllText()
     ins = wrapper.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(s, ins)
     return "+" + str(row + 1)
Exemplo n.º 7
0
def xdb_breakpoint(event):
    '''Set the breakpoint at the presently select line in Leo.'''
    c = event.get('c')
    if not c:
        return
    p = c.p
    xdb = getattr(g.app, 'xdb', None)
    if not xdb:
        print('xdb not active')
        return
    w = c.frame.body.wrapper
    if not w:
        return
    x = c.gotoCommands
    root, fileName = x.find_root(p)
    if not root:
        g.trace('no root', p.h)
        return
    path = g.fullPath(c, root)
    n0 = x.find_node_start(p=p)
    if n0 is None:
        g.trace('no n0')
        return
    c.bodyWantsFocusNow()
    i = w.getInsertPoint()
    s = w.getAllText()
    row, col = g.convertPythonIndexToRowCol(s, i)
    n = x.node_offset_to_file_line(row, p, root)
    if n is not None:
        xdb.qc.put('b %s:%s' % (path, n+1))
Exemplo n.º 8
0
 def toAtEdit(self, p):
     """Convert p from @auto to @edit."""
     c = self.c
     w = c.frame.body.wrapper
     p.h = '@edit' + p.h[5:]
     # Compute the position of the present line within the *selected* node c.p
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(c.p.b, ins)
     # Ignore directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Count preceding lines from p to c.p, again ignoring directives.
     for p2 in p.self_and_subtree(copy=False):
         if p2 == c.p:
             break
         lines = [z for z in g.splitLines(p2.b) if not g.isDirective(z)]
         row += len(lines)
     # Reload the file into a single node.
     c.selectPosition(p)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     ins = g.convertRowColToPythonIndex(p.b, row + 1, 0)
     w.setInsertPoint(ins)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Exemplo n.º 9
0
    def update(self, *args, **keys):

        c = self.c

        # This is called at idle-time, and there can be problems when closing the window.
        if g.app.killed or not c or not hasattr(c, 'frame'):
            return

        w = c.frame.body.bodyCtrl
        tab_width = c.frame.tab_width

        s = w.getAllText()
        index = w.getInsertPoint()
        row, col = g.convertPythonIndexToRowCol(s, index)

        if col > 0:
            s2 = s[index - col:index]
            s2 = g.toUnicode(s2)
            col = g.computeWidth(s2, c.tab_width)

        if row != self.lastRow or col != self.lastCol:
            s = "line %d, col %d " % (row, col)
            self.label.configure(text=s)
            self.lastRow, self.lastCol = row, col

        if 0:  # Done in idle handler.
            self.label.after(500, self.update)
Exemplo n.º 10
0
    def parameterize(self, event=None):

        c = self.c
        tree = c.frame.tree
        body = c.frame.body
        w = body.bodyCtrl
        current = c.currentVnode()

        if not self.params:
            self.params = self.findParameters(current)
            if not self.params: return

        sr = s = body.getAllText()
        sr = sr.split('\n')

        i = w.getInsertPoint()
        row, col = g.convertPythonIndexToRowCol(s, i)
        sr = sr[row]
        sr = sr[:col]
        sr = sr.rstrip()

        match = self.regex.search(sr)
        if not match:
            g.trace(self.regex)
            g.trace('no match', repr(sr))
            return

        sr = sr[match.start():match.end()]
        for z in range(current.numberOfChildren()):
            child = current.nthChild(z)
            if child.headString == sr:
                return

        pieces = sr.split('(', 1)
        searchline = pieces[0] + ">>"
        pieces[1] = pieces[1].rstrip('>')
        pieces[1] = pieces[1].rstrip(')')
        sections = pieces[1].split(',')

        node = None
        for z in range(self.params.numberOfChildren()):
            child = self.params.nthChild(z)
            if child.matchHeadline(searchline):
                node = child
                break
            return

        bodys = node.b
        v = current.insertAsNthChild(0)  #,tn)
        v.setBodyString(bodys)
        v.setHeadString(sr)
        for z in range(0, len(sections)):
            head = g.angleBrackets(str(z + 1) + "$")
            bod = sections[z]
            v.insertAsNthChild(0)  #,t)
            v.setBodyString(bod)
            v.setHeadString(head)
        c.redraw()
Exemplo n.º 11
0
    def parameterize (self,event=None):

        c = self.c
        tree = c.frame.tree
        body = c.frame.body
        w = body.wrapper
        current = c.currentVnode()

        if not self.params:
            self.params = self.findParameters(current)
            if not self.params: return

        sr = s = body.getAllText()
        sr = sr.split('\n')

        i = w.getInsertPoint()
        row,col = g.convertPythonIndexToRowCol(s,i)
        sr = sr[row]
        sr = sr[:col]
        sr = sr.rstrip()
        
        match = self.regex.search(sr)
        if not match:
            g.trace(self.regex)
            g.trace('no match',repr(sr))
            return

        sr = sr [match.start(): match.end()]
        for z in range(current.numberOfChildren()):
            child = current.nthChild(z)
            if child.headString == sr:
                return

        pieces = sr.split('(',1)
        searchline = pieces [0] + ">>"
        pieces [1] = pieces [1].rstrip('>')
        pieces [1] = pieces [1].rstrip(')')
        sections = pieces [1].split(',')

        node = None
        for z in range(self.params.numberOfChildren()):
            child = self.params.nthChild(z)
            if child.matchHeadline(searchline):
                node = child
                break
            return

        bodys = node.b
        v = current.insertAsNthChild(0) #,tn)
        v.setBodyString(bodys)
        v.setHeadString(sr)
        for z in range(0,len(sections)):
            head = g.angleBrackets(str(z+1)+"$")
            bod = sections [z]
            v.insertAsNthChild(0) #,t)
            v.setBodyString(bod)
            v.setHeadString(head)
        c.redraw()
Exemplo n.º 12
0
 def get_cursor_arg(self):
     """Compute the cursor argument for vim."""
     wrapper = self.c.frame.body.wrapper
     s = wrapper.getAllText()
     ins = wrapper.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(s, ins)
     # This is an Ex command, not a normal Vim command.  See:
     # http://vimdoc.sourceforge.net/htmldoc/remote.html
     # and
     # http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ex.html#tag_20_40_13_02
     return "+" + str(row + 1)
Exemplo n.º 13
0
 def parameterize (self,event=None):
     trace = True and not g.unitTesting
     c = self.c
     w = c.frame.body.wrapper
     # EKR: always search for parms.
     params = self.findParameters(c.p)
     if not params:
         return
     sr = s = w.getAllText()
     if trace: g.trace("body: %s" % sr)
     sr = sr.split('\n')
     i = w.getInsertPoint()
     row,col = g.convertPythonIndexToRowCol(s,i)
     sr = sr[row]
     sr = sr[:col]
     sr = sr.rstrip()
     if trace: g.trace("regex search on: %s" % sr)
     match = self.regex.search(sr)
     if not match:
         g.es("no match")
         return
     sr = sr [match.start(): match.end()]
     if trace: g.trace("found sr",sr)
     for child in c.p.children():
         if child.h == sr:
             return
     pieces = sr.split('(',1)
     searchline = pieces [0] + ">>"
     # EKR: added rstrip().
     pieces [1] = pieces [1].rstrip().rstrip('>')
     pieces [1] = pieces [1].rstrip().rstrip(')')
     sections = pieces [1].split(',')
     if trace: g.trace(
         "pieces: %s\n" % (pprint.pformat(pieces)),
         "searchline: %s\n" % (searchline),
         "sections: %s\n" % (pprint.pformat(sections)))
     node = None
     for child in params.children():
         if child.matchHeadline(searchline):
             node = child
             break
     else:
         if trace: g.trace('not found',searchline)
         return
     c.setCurrentPosition(node)
     if trace: g.trace("found: %s'\n%s" % (node.h,node.b))
     for i in range(0,len(sections)):
         p = c.p.insertAsNthChild(i)
         p.b = sections [i]
         p.h = g.angleBrackets(str(i+1)+"$")
     c.redraw()
Exemplo n.º 14
0
 def parameterize(self, event=None):
     trace = False and not g.unitTesting
     c = self.c
     w = c.frame.body.wrapper
     # EKR: always search for parms.
     params = self.findParameters(c.p)
     if not params:
         return
     sr = s = w.getAllText()
     if trace: g.trace("body: %s" % sr)
     sr = sr.split('\n')
     i = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(s, i)
     sr = sr[row]
     sr = sr[:col]
     sr = sr.rstrip()
     if trace: g.trace("regex search on: %s" % sr)
     match = self.regex.search(sr)
     if not match:
         g.es("no match")
         return
     sr = sr[match.start():match.end()]
     if trace: g.trace("found sr", sr)
     for child in c.p.children():
         if child.h == sr:
             return
     pieces = sr.split('(', 1)
     searchline = pieces[0] + ">>"
     # EKR: added rstrip().
     pieces[1] = pieces[1].rstrip().rstrip('>')
     pieces[1] = pieces[1].rstrip().rstrip(')')
     sections = pieces[1].split(',')
     if trace:
         g.trace("pieces: %s\n" % (pprint.pformat(pieces)),
                 "searchline: %s\n" % (searchline),
                 "sections: %s\n" % (pprint.pformat(sections)))
     node = None
     for child in params.children():
         if child.matchHeadline(searchline):
             node = child
             break
     else:
         if trace: g.trace('not found', searchline)
         return
     c.setCurrentPosition(node)
     if trace: g.trace("found: %s'\n%s" % (node.h, node.b))
     for i, section in enumerate(sections):
         p = c.p.insertAsNthChild(i)
         p.b = section
         p.h = g.angleBrackets(str(i + 1) + "$")
     c.redraw()
Exemplo n.º 15
0
def show_file_line(event):
    c = event.get('c')
    if not c:
        return
    w = c.frame.body.wrapper
    if not w:
        return
    n0 = GoToCommands(c).find_node_start(p=c.p)
    if n0 is None:
        return
    i = w.getInsertPoint()
    s = w.getAllText()
    row, col = g.convertPythonIndexToRowCol(s, i)
    g.es_print(1 + n0 + row)
Exemplo n.º 16
0
 def get_table(self, ch, w):
     '''Return i, lines, if w's insert point is inside a table.'''
     s = w.getAllText()
     lines = g.splitLines(s)
     ins = w.getInsertPoint()
     i_row1, i_col1 = g.convertPythonIndexToRowCol(s, ins)
     s1 = lines[i_row1] if i_row1 < len(lines) else ''
     starts_row1 = ch in ('|', 'return') and not s1[:i_col1].strip()
     if self.enabled and g.isTextWrapper(w):
         i1, i2 = None, None
         for i, s in enumerate(lines):
             is_row = s.strip().startswith('|')
             if i == i_row1:
                 if is_row or starts_row1:
                     if i1 is None:
                         i1 = i2 = i  # Selected line starts the table.
                     else:
                         pass  # Table head already found.
                 elif i1 is None:
                     return -1, s1, []
                 else:
                     # Selected line ends the table.
                     return i_row1, s1, lines[i1:i]
             elif is_row:
                 if i1 is None:
                     i1 = i2 = i  # Row i starts the head.
                 elif i > i_row1:
                     i2 = i  # Row i extends the tail
                 else:
                     pass  # Table head already found.
             else:
                 if i1 is None:
                     pass  # Table head not yet found.
                 elif i < i_row1:
                     i1 = None  # Forget previous tables.
                     i2 = None
                 else:
                     # Selected line ends the table.
                     return i_row1, s1, lines[i1:i]
         # The end of the enumeration.
         if i_row1 == len(lines) and starts_row1 and not i1:
             g.trace('FOUND-end', i1)
             return i_row1, s1, [s1]
         elif i1 is None or i2 is None:
             return -1, s1, []
         else:
             # Last line ends the table.
             return i_row1, s1, lines[i1:len(lines)]
     else:
         return -1, s1, []
Exemplo n.º 17
0
def show_file_line(event):
    c = event.get('c')
    if not c:
        return
    w = c.frame.body.wrapper
    if not w:
        return
    n0 = GoToCommands(c).find_node_start(p=c.p)
    if n0 is None:
        return
    i = w.getInsertPoint()
    s = w.getAllText()
    row, col = g.convertPythonIndexToRowCol(s, i)
    g.es_print(1+n0+row)
Exemplo n.º 18
0
 def get_table(self, ch, w):
     '''Return i, lines, if w's insert point is inside a table.'''
     s = w.getAllText()
     lines = g.splitLines(s)
     ins = w.getInsertPoint()
     i_row1, i_col1 = g.convertPythonIndexToRowCol(s, ins)
     s1 = lines[i_row1] if i_row1 < len(lines) else ''
     starts_row1 = ch in ('|', 'return') and not s1[:i_col1].strip()
     if self.enabled and g.isTextWrapper(w):
         i1, i2 = None, None
         for i, s in enumerate(lines):
             is_row = s.strip().startswith('|')
             if i == i_row1:
                 if is_row or starts_row1:
                     if i1 is None:
                         i1 = i2 = i # Selected line starts the table.
                     else:
                         pass # Table head already found.
                 elif i1 is None:
                     return -1, s1, []
                 else:
                     # Selected line ends the table.
                     return i_row1, s1, lines[i1:i]
             elif is_row:
                 if i1 is None:
                     i1 = i2 = i # Row i starts the head.
                 elif i > i_row1:
                     i2 = i # Row i extends the tail
                 else:
                     pass # Table head already found.
             else:
                 if i1 is None:
                     pass # Table head not yet found.
                 elif i < i_row1:
                     i1 = None # Forget previous tables.
                     i2 = None
                 else:
                     # Selected line ends the table.
                     return i_row1, s1, lines[i1:i]
         # The end of the enumeration.
         if i_row1 == len(lines) and starts_row1 and not i1:
             g.trace('FOUND-end', i1)
             return i_row1, s1, [s1]
         elif i1 is None or i2 is None:
             return -1, s1, []
         else:
             # Last line ends the table.
             return i_row1, s1, lines[i1:len(lines)]
     else:
         return -1, s1, []
Exemplo n.º 19
0
    def parameterize (self,event=None):

        c = self.c
        w = c.frame.body.wrapper
        # EKR: always search for parms.
        params = self.findParameters(c.p)
        if not params:
            return
        sr = s = w.getAllText()
        sr = sr.split('\n')
        i = w.getInsertPoint()
        row,col = g.convertPythonIndexToRowCol(s,i)
        sr = sr[row]
        sr = sr[:col]
        sr = sr.rstrip()
        match = self.regex.search(sr)
        if not match:
            g.es("no match")
            return
        sr = sr [match.start(): match.end()]
        for child in c.p.children():
            if child.h == sr:
                return
        pieces = sr.split('(',1)
        searchline = pieces [0] + ">>"
        # EKR: added rstrip().
        pieces [1] = pieces [1].rstrip().rstrip('>')
        pieces [1] = pieces [1].rstrip().rstrip(')')
        sections = pieces [1].split(',')
        node = None
        for child in params.children():
            if child.matchHeadline(searchline):
                node = child
                break
        else:
            return
        c.setCurrentPosition(node)
        for i, section in enumerate(sections):
            p = c.p.insertAsNthChild(i)
            p.b = section
            p.h = g.angleBrackets(str(i+1)+"$")
        c.redraw()
Exemplo n.º 20
0
    def parameterize (self,event=None):

        c = self.c
        w = c.frame.body.wrapper
        # EKR: always search for parms.
        params = self.findParameters(c.p)
        if not params:
            return
        sr = s = w.getAllText()
        sr = sr.split('\n')
        i = w.getInsertPoint()
        row,col = g.convertPythonIndexToRowCol(s,i)
        sr = sr[row]
        sr = sr[:col]
        sr = sr.rstrip()
        match = self.regex.search(sr)
        if not match:
            g.es("no match")
            return
        sr = sr [match.start(): match.end()]
        for child in c.p.children():
            if child.h == sr:
                return
        pieces = sr.split('(',1)
        searchline = pieces [0] + ">>"
        # EKR: added rstrip().
        pieces [1] = pieces [1].rstrip().rstrip('>')
        pieces [1] = pieces [1].rstrip().rstrip(')')
        sections = pieces [1].split(',')
        node = None
        for child in params.children():
            if child.matchHeadline(searchline):
                node = child
                break
        else:
            return
        c.setCurrentPosition(node)
        for i, section in enumerate(sections):
            p = c.p.insertAsNthChild(i)
            p.b = section
            p.h = g.angleBrackets(str(i+1)+"$")
        c.redraw()
Exemplo n.º 21
0
 def toAtAuto(self, p):
     """Convert p from @edit to @auto."""
     c = self.c
     # Change the headline.
     p.h = '@auto' + p.h[5:]
     # Compute the position of the present line within the file.
     w = c.frame.body.wrapper
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(p.b, ins)
     # Ignore *preceding* directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Reload the file, creating new nodes.
     c.selectPosition(p)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     c.gotoCommands.find_file_line(row + 1)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Exemplo n.º 22
0
 def toAtAuto(self, p):
     '''Convert p from @edit to @auto.'''
     c = self.c
     # Change the headline.
     p.h = '@auto' + p.h[5:]
     # Compute the position of the present line within the file.
     w = c.frame.body.wrapper
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(p.b, ins)
     # Ignore *preceding* directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Reload the file, creating new nodes.
     c.selectPosition(p, enableRedrawFlag=False)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     c.gotoCommands.find_file_line(row+1)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
Exemplo n.º 23
0
Arquivo: vim.py Projeto: AG4GitHub/leo
def open_in_vim_helper (c):
    
    p = c.p
    v = p.v

    # Load contextmenu plugin if required.
    contextMenu = g.loadOnePlugin('contextmenu.py',verbose=True)
    if not contextMenu:
        if not contextmenu_message_given:
            contextmenu_message_given = True
            g.trace('can not load contextmenu.py')
        return

    if p.h.find('file-ref') == 1: # Must be at 2nd position
        return

    #URL nodes
    openURLNodes = c.config.getBool('vim_plugin_opens_url_nodes')
    if not openURLNodes and p.h.startswith('@url'):
        return # Avoid conflicts with @url nodes.

    vim_cmd = c.config.getString('vim_cmd') or _vim_cmd
    vim_exe = c.config.getString('vim_exe') or _vim_exe

    global locationMessageGiven

    if not locationMessageGiven:
        locationMessageGiven = True
        print('vim_cmd: %s' % vim_cmd)
        print('vim_exe: %s' % vim_exe)

    #Cursor positioning
    Lnum = ""
    if c.config.getBool('vim_plugin_positions_cursor'):    
        #Line number - start at same line as Leo cursor
        #  get node's body text
        bodyCtrl = c.frame.body.bodyCtrl
        s = bodyCtrl.getAllText()    
        #  Get cursors row & column number
        index = bodyCtrl.getInsertPoint()
        row,col = g.convertPythonIndexToRowCol(s,index)
        #  Build gVim command line parameter for setting cursor row
        Lnum = "+" + str(row + 1)

    #Vim's tab card stack
    useTabs = ""

    if c.config.getBool('vim_plugin_uses_tab_feature'):    
        useTabs = "-tab"

    # Search g.app.openWithFiles for a file corresponding to v.
    for d in g.app.openWithFiles:
        if d.get('v') == id(v):
            path = d.get('path','') ; break
    else: path = ''

    # if the body has changed we need to open a new 
    # temp file containing the new body in vim
    if (
        not g.os_path_exists(path) or 
        not hasattr(v,'OpenWithOldBody') or
        v.b != v.OpenWithOldBody
    ):
        # Open a new temp file.
        if path:
            # Remove the old file and the entry in g.app.openWithFiles.
            os.remove(path)
            g.app.openWithFiles = [d for d in g.app.openWithFiles if d.get('path') != path]
            os.system(vim_cmd+"--remote-send '<C-\\><C-N>:bd "+path+"<CR>'")

        v.OpenWithOldBody=v.b # Remember the previous contents.
    
        # New code by Jim Sizemore. TL: added support for gVim tabs.
        args = [vim_exe,"--servername","LEO","--remote"+useTabs+"-silent",Lnum]
        d = {'kind':'subprocess.Popen','args':args,'ext':None}
        c.openWith(d=d)
    else:
        # Reopen the old temp file.
        os.system(vim_cmd+"--remote-send '<C-\\><C-N>:e "+path+"<CR>'")
Exemplo n.º 24
0
 def get_table(self, ch, w):
     '''Return i, lines, if w's insert point is inside a table.'''
     trace = True and not g.unitTesting
     trace_entry = True
     trace_fail = True
     trace_lines = True
     s = w.getAllText()
     lines = g.splitLines(s)
     ins = w.getInsertPoint()
     i_row1, i_col1 = g.convertPythonIndexToRowCol(s, ins)
     s1 = lines[i_row1] if i_row1 < len(lines) else ''
     starts_row1 = ch in ('|', 'return') and not s1[:i_col1].strip()
     if trace and trace_entry:
         g.trace('=====', repr(ch), i_row1, starts_row1, repr(s1))
         g.printList(lines)
     if self.enabled and g.isTextWrapper(w):
         i1, i2 = None, None
         for i, s in enumerate(lines):
             is_row = s.strip().startswith('|')
             if trace and trace_lines:
                 g.trace(i, is_row, repr(i1), repr(i2), repr(s))
             if i == i_row1:
                 if is_row or starts_row1:
                     if i1 is None:
                         i1 = i2 = i  # Selected line starts the table.
                     else:
                         pass  # Table head already found.
                 elif i1 is None:
                     if trace and trace_fail: g.trace('not in table')
                     return -1, s1, []
                 else:
                     # Selected line ends the table.
                     if trace:
                         g.trace('FOUND1', i1, i)
                         g.printList(lines[i1:i])
                     return i_row1, s1, lines[i1:i]
             elif is_row:
                 if i1 is None:
                     i1 = i2 = i  # Row i starts the head.
                 elif i > i_row1:
                     i2 = i  # Row i extends the tail
                 else:
                     pass  # Table head already found.
             else:
                 if i1 is None:
                     pass  # Table head not yet found.
                 elif i < i_row1:
                     i1 = None  # Forget previous tables.
                     i2 = None
                 else:
                     # Selected line ends the table.
                     if trace:
                         g.trace('FOUND2', i1, i)
                         g.printList(lines[i1:i])
                     return i_row1, s1, lines[i1:i]
         # The end of the enumeration.
         if i_row1 == len(lines) and starts_row1 and not i1:
             g.trace('FOUND-end', i1)
             return i_row1, s1, [s1]
         elif i1 is None or i2 is None:
             if trace and trace_fail: g.trace('end', repr(i1), repr(i2))
             return -1, s1, []
         else:
             # Last line ends the table.
             if trace:
                 g.trace('FOUND3', i1)
                 g.printList(lines[i1:])
             return i_row1, s1, lines[i1:len(lines)]
     else:
         if trace and trace_fail: g.trace('not enabled')
         return -1, s1, []
Exemplo n.º 25
0
 def get_table(self, ch, w):
     '''Return i, lines, if w's insert point is inside a table.'''
     trace = True and not g.unitTesting
     trace_entry = True
     trace_fail = True
     trace_lines = True
     s = w.getAllText()
     lines = g.splitLines(s)
     ins = w.getInsertPoint()
     i_row1, i_col1 = g.convertPythonIndexToRowCol(s, ins)
     s1 = lines[i_row1] if i_row1 < len(lines) else ''
     starts_row1 = ch in ('|', 'return') and not s1[:i_col1].strip()
     if trace and trace_entry:
         g.trace('=====', repr(ch), i_row1, starts_row1, repr(s1))
         g.printList(lines)
     if self.enabled and g.isTextWrapper(w):
         i1, i2 = None, None
         for i, s in enumerate(lines):
             is_row = s.strip().startswith('|')
             if trace and trace_lines: g.trace(i, is_row, repr(i1), repr(i2), repr(s))
             if i == i_row1:
                 if is_row or starts_row1:
                     if i1 is None:
                         i1 = i2 = i # Selected line starts the table.
                     else:
                         pass # Table head already found.
                 elif i1 is None:
                     if trace and trace_fail: g.trace('not in table')
                     return -1, s1, []
                 else:
                     # Selected line ends the table.
                     if trace:
                         g.trace('FOUND1', i1, i)
                         g.printList(lines[i1:i])
                     return i_row1, s1, lines[i1:i]
             elif is_row:
                 if i1 is None:
                     i1 = i2 = i # Row i starts the head.
                 elif i > i_row1:
                     i2 = i # Row i extends the tail
                 else:
                     pass # Table head already found.
             else:
                 if i1 is None:
                     pass # Table head not yet found.
                 elif i < i_row1:
                     i1 = None # Forget previous tables.
                     i2 = None
                 else:
                     # Selected line ends the table.
                     if trace:
                         g.trace('FOUND2', i1, i)
                         g.printList(lines[i1:i])
                     return i_row1, s1, lines[i1:i]
         # The end of the enumeration.
         if i_row1 == len(lines) and starts_row1 and not i1:
             g.trace('FOUND-end', i1)
             return i_row1, s1, [s1]
         elif i1 is None or i2 is None:
             if trace and trace_fail: g.trace('end', repr(i1), repr(i2))
             return -1, s1, []
         else:
             # Last line ends the table.
             if trace:
                 g.trace('FOUND3', i1)
                 g.printList(lines[i1:])
             return i_row1, s1, lines[i1:len(lines)]
     else:
         if trace and trace_fail: g.trace('not enabled')
         return -1, s1, []