Exemple #1
0
def open_module(name):
    syspath = env.get().eval('import sys\nreturn sys.path')
    syspath = env.get_sources() + syspath

    mname = name.split('.')
    pkgname = mname[:] + ['__init__.py']
    mname[-1] += '.py'

    foundpath = None
    for p in syspath:
        n = os.path.join(p, *mname)
        if os.path.exists(n):
            foundpath = n
            break

        n = os.path.join(p, *pkgname)
        if os.path.exists(n):
            foundpath = n
            break

    if foundpath:
        mark()
        vim.command('edit {}'.format(foundpath))
    else:
        print >>sys.stderr, "Can't find {}".format(name)
Exemple #2
0
def open_module(name):
    syspath = env.get().eval('import sys\nreturn sys.path')
    syspath = env.get_sources() + syspath

    mname = name.split('.')
    pkgname = mname[:] + ['__init__.py']
    mname[-1] += '.py'

    foundpath = None
    for p in syspath:
        n = os.path.join(p, *mname)
        if os.path.exists(n):
            foundpath = n
            break

        n = os.path.join(p, *pkgname)
        if os.path.exists(n):
            foundpath = n
            break

    if foundpath:
        mark()
        vim.command('edit {}'.format(foundpath))
    else:
        print >> sys.stderr, "Can't find {}".format(name)
Exemple #3
0
    def on_select(self, item, cursor):
        focus_window(self.last_window)
        mark()

        item = item[0]
        if 'offset' in item:
            line = vfunc.byte2line(item['offset'] + 1)
        else:
            line = item['line']

        vim.command('normal! {}Gzz'.format(line))
Exemple #4
0
    def on_select(self, item, cursor):
        focus_window(self.last_window)
        mark()

        item = item[0]
        if 'offset' in item:
            line = vfunc.byte2line(item['offset'] + 1)
        else:
            line = item['line']

        vim.command('normal! {}Gzz'.format(line))
Exemple #5
0
def goto_definition():
    source = get_content()
    pos = vim.current.window.cursor
    dpos, fname = env.get().location(source, pos, vim.current.buffer.name)

    if dpos:
        mark()
        if fname and fname != vim.current.buffer.name:
            vim.command(':edit {}'.format(vfunc.fnameescape(fname)))
            vim.current.window.cursor = dpos
        else:
            vim.current.window.cursor = dpos
    else:
        print 'Location not found'
Exemple #6
0
def goto_definition():
    source = get_content()
    pos = vim.current.window.cursor
    locs = env.get().location(source, pos, vim.current.buffer.name)

    if locs:
        mark()
        last = locs[-1]
        if isinstance(last, dict):
            head = locs[:-1]
            tail = [last]
        else:
            tail = last
            last = tail[0]
            head = locs[:-1]

        locs = head + tail
        if len(locs) > 1:
            llist = [{
                'bufnr': '',
                'filename': loc['file'],
                'pattern': '',
                'valid': 1,
                'nr': -1,
                'lnum': loc['loc'][0],
                'vcol': 0,
                'col': loc['loc'][1] + 1,
            } for loc in locs]
            vfunc.setloclist(0, llist, ' ')
            vim.command(':ll {}'.format(len(head) + 1))
            redraw()
            if len(tail) > 1:
                print 'Multiple locations'
            else:
                print 'Chained locations'
        else:
            fname = last['file']
            dpos = last['loc']
            if fname and fname != vim.current.buffer.name:
                vim.command(':edit {}'.format(vfunc.fnameescape(fname)))
                vim.current.window.cursor = dpos
            else:
                vim.current.window.cursor = dpos
    else:
        redraw()
        print 'Location not found'
Exemple #7
0
def goto_definition():
    source = get_content()
    pos = vim.current.window.cursor
    locs = env.get().location(source, pos, vim.current.buffer.name)

    if locs:
        mark()
        last = locs[-1]
        if isinstance(last, dict):
            head = locs[:-1]
            tail = [last]
        else:
            tail = last
            last = tail[0]
            head = locs[:-1]

        locs = head + tail
        if len(locs) > 1:
            llist = [{
                'bufnr': '',
                'filename': loc['file'],
                'pattern': '',
                'valid': 1,
                'nr': -1,
                'lnum': loc['loc'][0],
                'vcol': 0,
                'col': loc['loc'][1] + 1,
            } for loc in locs]
            vfunc.setloclist(0, llist, ' ')
            vim.command(':ll {}'.format(len(head) + 1))
            redraw()
            if len(tail) > 1:
                print 'Multiple locations'
            else:
                print 'Chained locations'
        else:
            fname = last['file']
            dpos = last['loc']
            if fname and fname != vim.current.buffer.name:
                vim.command(':edit {}'.format(vfunc.fnameescape(fname)))
                vim.current.window.cursor = dpos
            else:
                vim.current.window.cursor = dpos
    else:
        redraw()
        print 'Location not found'
Exemple #8
0
def create_module(name):
    parts = name.split('.')
    pkg = parts[:-1]
    module = parts[-1]

    root = env.get_sources()[0]
    for r in pkg:
        path = os.path.join(root, r)
        if not os.path.exists(path):
            os.mkdir(path)

        init = os.path.join(path, '__init__.py')
        if not os.path.exists(init):
            with open(init, 'w') as f:
                f.write('')
        root = path

    mark()
    vim.command('edit {}'.format(os.path.join(root, module + '.py')))
Exemple #9
0
def create_module(name):
    parts = name.split('.')
    pkg = parts[:-1]
    module = parts[-1]

    root = env.get_sources()[0]
    for r in pkg:
        path = os.path.join(root, r)
        if not os.path.exists(path):
            os.mkdir(path)

        init = os.path.join(path, '__init__.py')
        if not os.path.exists(init):
            with open(init, 'w') as f:
                f.write('')
        root = path

    mark()
    vim.command('edit {}'.format(os.path.join(root, module + '.py')))
Exemple #10
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('e {}'.format(item[2]))
Exemple #11
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('e {}'.format(item[2]))
Exemple #12
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('normal! {}Gzz^'.format(item[1]))
Exemple #13
0
 def on_select(self, item, cursor):
     focus_window(self.last_window)
     mark()
     vim.command('normal! {}Gzz^'.format(item[1]))