コード例 #1
0
ファイル: __init__.py プロジェクト: jobleier/vim-ros
def buf_enter():
    p = vimp.var['b:ros_package_name']
    if p not in packages:
        packages[p] = rosp.Package(p)
    if vimp.var['g:ros_build_system'] == 'catkin':
        _path = packages[p].path
        idx_src = _path.find('/src')
        if idx_src > -1:
            # Remove from the first '/src' to the end
            catkin_ws = _path[:idx_src]
        else:
            catkin_ws = _path
        make_cmd = 'catkin_make -C {0} {1} '.format(
            catkin_ws, vimp.var['g:ros_catkin_make_options'])
    elif vimp.var['g:ros_build_system'] == 'catkin-tools':
        make_cmd = 'catkin build '
    else:
        make_cmd = 'rosmake '
    if 'b:ros_test_target' in vimp.var:
        vimp.opt['makeprg'] = make_cmd + vimp.var['b:ros_test_target']
    else:
        if vimp.var['g:ros_make'] == 'all':
            vimp.opt['makeprg'] = make_cmd + ' --pkg ' + ' '.join(
                packages.keys())
        else:
            vimp.opt['makeprg'] = make_cmd + ' --pkg ' + p
コード例 #2
0
 def get_completions(self):
     attr = pxp.get_inner_attr(vim.current.buffer, vimp.buf.cursor)
     if attr:
         if attr[0] == 'pkg':
             return sorted(rosp.Package.list())
         elif attr[0] == 'type':
             tag = pxp.get_inner_tag(vim.current.buffer, vimp.buf.cursor)
             try:
                 pkg = rosp.Package(tag.attr['pkg'])
                 return sorted(pkg.list_executables())
             except KeyError:
                 pass  # there is no "pkg" attribute
             except rospkg.ResourceNotFound:
                 pass  # package does not exist
         elif attr[0] == 'output':
             return ['log', 'screen']
         elif attr[0] == 'launch-prefix':
             # The prefixes are taken from ROS Wiki
             return ['gdb -ex run --args',
                     'nice',
                     'screen -d -m gdb --args',
                     'valgrind',
                     'xterm -e',
                     'xterm -e gdb --args',
                     'xterm -e python -m pdb']
     return []
コード例 #3
0
ファイル: __init__.py プロジェクト: jobleier/vim-ros
def roscd(package_name):
    try:
        pkg = rosp.Package(package_name)
    except rospkg.ResourceNotFound:
        print('Package {0} not found'.format(package_name))
        return
    vimp.lcd(pkg.path)
コード例 #4
0
ファイル: __init__.py プロジェクト: jobleier/vim-ros
def rosed_complete(arg_lead, cmd_line, cursor_pos):
    """
    Returns a list of complete suggestions for :Rosed command.

    Arguments
    ---------
    arg_lead:
        The leading portion of the argument currently being completed on.
    cmd_line:
        The entire command line.
    cursor_pos:
        The cursor position in the line (byte index).
    """
    args = cmd_line[0:int(cursor_pos)].split(' ')
    if len(args) == 2:
        # still entering package name
        return '\n'.join(sorted(rosp.Package.list()))
    elif len(args) >= 3:
        # package name already entered
        try:
            pkg = rosp.Package(args[1])
        except rospkg.ResourceNotFound:
            return ''
        pattern = arg_lead + '*'
        return '\n'.join(set(pkg.locate_files(pattern, mode='filename')))
コード例 #5
0
def buf_enter():
    p = vimp.var['b:ros_package_name']
    if p not in packages:
        packages[p] = rosp.Package(p)
    if vimp.var['g:ros_build_system'] == 'catkin':
        _path = packages[p].path
        idx_src = _path.find('/src')
        if idx_src > -1:
            # Remove from the first '/src' to the end
            catkin_ws = _path[:idx_src]
        else:
            catkin_ws = _path
        make_cmd = 'catkin_make -C {0} {1} --pkg '.format(
            catkin_ws, vimp.var['g:ros_catkin_make_options'])
    elif vimp.var['g:ros_build_system'] == 'catkin-tools':
        make_cmd = 'catkin build '
    elif vimp.var['g:ros_build_system'] == 'ros_make':
        make_cmd = 'rosmake '
    else:
        _path = packages[p].path
        idx_src = _path.find('/src')
        if idx_src > -1:
            # Remove from the first '/src' to the end
            catkin_ws = _path[:idx_src]
        else:
            catkin_ws = _path
        make_cmd = 'cd ' + catkin_ws + ' && ' + vimp.var['g:ros_build_system']
    if vimp.var['g:ros_make'] == 'all':
        vimp.opt['makeprg'] = make_cmd
    else:
        vimp.opt['makeprg'] = make_cmd + p
コード例 #6
0
ファイル: __init__.py プロジェクト: jobleier/vim-ros
def _generic_rosed(vim_func, package_name, *file_names):
    """
    Helper method to edit a file using a specific `vim_func`.

    Arguments
    ---------
    vim_func:
        Reference to a function defined in the `vimp` module.
    """
    try:
        pkg = rosp.Package(package_name)
    except rospkg.ResourceNotFound:
        print('Package {0} not found'.format(package_name))
        return
    for fn in file_names:
        files = list(pkg.locate_files(fn))
        if len(files) == 0:
            print('File {0} not found'.format(fn))
        elif len(files) == 1:
            vim_func(files[0])
        else:
            f = vimp.inputlist(
                'You have chosen a non-unique filename, please '
                'pick one of the following:', files)
            if f is not None:
                vim_func(f)
コード例 #7
0
ファイル: __init__.py プロジェクト: nus/vim-ros
def buf_init(package_name):
    p = rosp.Package(package_name)
    vimp.var['b:ros_package_path'] = p.path
    vimp.var['b:ros_package_name'] = p.name
    if not p.name in packages:
        packages[p.name] = p
    ft.init()
コード例 #8
0
ファイル: __init__.py プロジェクト: nus/vim-ros
def buf_enter():
    p = vimp.var['b:ros_package_name']
    if not p in packages:
        packages[p] = rosp.Package(p)
    if vimp.var['g:ros_make'] == 'all':
        vimp.opt['makeprg'] = 'rosmake ' + ' '.join(packages.keys())
    else:
        vimp.opt['makeprg'] = 'rosmake ' + p
コード例 #9
0
 def get_completions(self):
     line = vim.current.line[:vim.current.window.cursor[1]]
     matches = list(re.finditer(self.PATTERN, line))
     groups = matches[-1].groupdict()
     try:
         pkg = rosp.Package(groups['package'])
         return os.listdir(os.path.join(pkg.path, groups['path']))
     except rospkg.ResourceNotFound:
         return []
コード例 #10
0
def buf_init(package_name):
    try:
        p = rosp.Package(package_name)
    except rospkg.common.ResourceNotFound:
        return
    vimp.var['b:ros_package_path'] = p.path
    vimp.var['b:ros_package_name'] = p.name
    if p.name not in packages:
        packages[p.name] = p
    ft.init()
コード例 #11
0
def buf_init(package_name):
    try:
        p = rosp.Package(str(package_name))
    except rospkg.common.ResourceNotFound:
        return
    vimp.var['b:ros_package_path'] = p.path
    vimp.var['b:ros_package_name'] = p.name
    if p.build_tool is not None:
        vimp.var['b:ros_package_workspace'] = p.build_tool.ws_path
    if p.name not in packages:
        packages[p.name] = p
    ft.init()
コード例 #12
0
ファイル: msg.py プロジェクト: nus/vim-ros
def goto_definition():
    text, group, start, end = vimp.syntax.get_entire_syntax_region()
    # We can go to the definition of only "complex" user-defined message types,
    # because build-in types have no definition. The only exception is the
    # "Header" type, which despite being a built-in is actually a "complex"
    # message type with a definition.
    if group == 'rosmsgBuiltInType' and text == 'Header':
        group, text = 'rosmsgType', 'std_msgs/Header'
    if group == 'rosmsgType':
        package_name, msg_type = text.split('/')
        for f in rosp.Package(package_name).locate_files(msg_type + '.msg'):
            vimp.edit(f)
    elif group == 'rosmsgBuiltInType':
        print '"{0}" is a built-in type and has no definition'.format(text)
    else:
        print 'Not a message type'
コード例 #13
0
ファイル: __init__.py プロジェクト: jobleier/vim-ros
def buf_init(package_name):
    try:
        p = rosp.Package(package_name)
    except rospkg.common.ResourceNotFound:
        return
    vimp.var['b:ros_package_path'] = p.path
    vimp.var['b:ros_package_name'] = p.name
    if 'g:ros_catkin_run_tests' in vimp.var and p.name + '/test' in vimp.buf.path:
        template = Template(vimp.var['g:ros_catkin_run_tests'])
        target = template.substitute(
            package='run_tests_' + p.name,
            package_gtest='run_tests_' + p.name + '_gtest',
            filename='run_tests_' + p.name + '_gtest' + '_' + vimp.buf.stem)
        vimp.var['b:ros_test_target'] = target
    if p.name not in packages:
        packages[p.name] = p
    ft.init()
コード例 #14
0
def rosed(package_name, *file_names):
    try:
        pkg = rosp.Package(package_name)
    except rospkg.ResourceNotFound:
        print('Package {0} not found'.format(package_name))
        return
    for fn in file_names:
        files = list(pkg.locate_files(fn))
        if len(files) == 0:
            print('File {0} not found'.format(fn))
        elif len(files) == 1:
            vimp.edit(files[0])
        else:
            f = vimp.inputlist('You have chosen a non-unique filename, please '
                               'pick one of the following:', files)
            if f is not None:
                vimp.edit(f)