Skip to content

Commit

Permalink
Merge pull request taketwo#19 from pylipp/feature/split_commands
Browse files Browse the repository at this point in the history
Add split-edit commands. Code refactoring.
  • Loading branch information
taketwo authored Jan 24, 2017
2 parents a96bd9a + f8fd2b8 commit c1b3164
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Editor commands

- `:A` to alternate between different kinds of C/C++ files (_.cpp_, _.cc_, _.h_, _.hh_, _.hpp_, _.impl_) in the current package
- `:Roscd` to cd to an arbitrary ROS package (with tab-completion)
- `:Rosed`/`:TabRosed` to open arbitrary files (with tab-completion of both
- `:Rosed`/`:TabRosed`/`:SpRosed`/`:VspRosed` to open arbitrary files (with tab-completion of both
package and filenames)

Filetype support
Expand Down
4 changes: 4 additions & 0 deletions plugin/ros.vim
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ augroup END
command! -nargs=1 -complete=custom,ros#RoscdComplete Roscd :call ros#Roscd(<f-args>)
command! -nargs=* -complete=custom,ros#RosedComplete Rosed :call ros#Rosed(<f-args>)
command! -nargs=* -complete=custom,ros#RosedComplete TabRosed :call ros#TabRosed(<f-args>)
command! -nargs=* -complete=custom,ros#RosedComplete SpRosed :call ros#SpRosed(<f-args>)
command! -nargs=* -complete=custom,ros#RosedComplete VspRosed :call ros#VspRosed(<f-args>)

if g:ros_lowercase_commands
cabbrev roscd <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Roscd' : 'roscd')<CR>
cabbrev rosed <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Rosed' : 'rosed')<CR>
cabbrev tabrosed <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'TabRosed' : 'tabrosed')<CR>
cabbrev sprosed <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'SpRosed' : 'sprosed')<CR>
cabbrev vsprosed <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'VspRosed' : 'vsprosed')<CR>
endif

" }}}
47 changes: 27 additions & 20 deletions plugin/rosvim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ def roscd_complete(arg_lead, cmd_line, cursor_pos):
return '\n'.join(sorted(rosp.Package.list()))


@vimp.function('ros#Rosed')
def rosed(package_name, *file_names):
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:
Expand All @@ -107,32 +114,32 @@ def rosed(package_name, *file_names):
if len(files) == 0:
print('File {0} not found'.format(fn))
elif len(files) == 1:
vimp.edit(files[0])
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:
vimp.edit(f)
vim_func(f)


@vimp.function('ros#Rosed')
def rosed(package_name, *file_names):
_generic_rosed(vimp.edit, package_name, *file_names)


@vimp.function('ros#TabRosed')
def tabrosed(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.tabedit(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.tabedit(f)
_generic_rosed(vimp.tabedit, package_name, *file_names)


@vimp.function('ros#SpRosed')
def sprosed(package_name, *file_names):
_generic_rosed(vimp.split, package_name, *file_names)


@vimp.function('ros#VspRosed')
def vsprosed(package_name, *file_names):
_generic_rosed(vimp.vsplit, package_name, *file_names)


@vimp.function('ros#RosedComplete')
Expand Down
8 changes: 8 additions & 0 deletions plugin/vimp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def tabedit(filename):
vim.command('tabedit {0}'.format(filename))


def split(filename):
vim.command('split {0}'.format(filename))


def vsplit(filename):
vim.command('vsplit {0}'.format(filename))


def lcd(path):
vim.command('lcd {0}'.format(path))

Expand Down

0 comments on commit c1b3164

Please sign in to comment.