Skip to content
Browse files

Add mapping to toggle a function's arrow type

  • Loading branch information...
1 parent b9c2ede commit 35fe52329a1a43a0742efd9b3dc8c8fbff3e7783 @AndrewRadev committed Apr 4, 2012
Showing with 20 additions and 0 deletions.
  1. +16 −0 autoload/coffee_tools.vim
  2. +4 −0 plugin/coffee_tools.vim
View
16 autoload/coffee_tools.vim
@@ -127,6 +127,22 @@ function! coffee_tools#FunctionTextObject(type)
call s:MarkVisual('v', start, indent_limit)
endfunction
+function! coffee_tools#ToggleFunctionArrow()
+ let line = getline('.')
+ let double_arrow_pattern = '\s\zs=>\ze\%(\s\|$\)'
+ let single_arrow_pattern = '\s\zs->\ze\%(\s\|$\)'
+
+ let saved_cursor = getpos('.')
+
+ if line =~ double_arrow_pattern
+ exe 's/'.double_arrow_pattern.'/->/'
+ elseif line =~ single_arrow_pattern
+ exe 's/'.single_arrow_pattern.'/=>/'
+ endif
+
+ call setpos('.', saved_cursor)
+endfunction
+
" TODO (2012-04-03) Refactor to use *IndentLimit helper
function! s:DedentBelow(lineno, depth)
if line(a:lineno) == line('$')
View
4 plugin/coffee_tools.vim
@@ -41,18 +41,22 @@ xnoremap <Plug>CoffeeToolsOpenLineAndIndent :<c-u>call coffee_tools#OpenLineAndI
nnoremap <Plug>CoffeeToolsPasteBelow :call coffee_tools#Paste('p', v:register)<cr>
nnoremap <Plug>CoffeeToolsPasteAbove :call coffee_tools#Paste('P', v:register)<cr>
+nnoremap <Plug>CoffeeToolsToggleFunctionArrow :call coffee_tools#ToggleFunctionArrow()<cr>
+
if g:coffee_tools_invasive_mappings
autocmd FileType coffee nmap <buffer> dd <Plug>CoffeeToolsDeleteAndDedent
autocmd FileType coffee xmap <buffer> d <Plug>CoffeeToolsDeleteAndDedent
autocmd FileType coffee nmap <buffer> p <Plug>CoffeeToolsPasteBelow
autocmd FileType coffee nmap <buffer> P <Plug>CoffeeToolsPasteAbove
+ autocmd FileType coffee nmap <buffer> - <Plug>CoffeeToolsToggleFunctionArrow
endif
if g:coffee_tools_default_mappings
autocmd FileType coffee nmap <buffer> <localleader>dd <Plug>CoffeeToolsDeleteAndDedent
autocmd FileType coffee xmap <buffer> <localleader>d <Plug>CoffeeToolsDeleteAndDedent
autocmd FileType coffee nmap <buffer> <localleader>p <Plug>CoffeeToolsPasteBelow
autocmd FileType coffee nmap <buffer> <localleader>P <Plug>CoffeeToolsPasteAbove
+ autocmd FileType coffee nmap <buffer> <localleader>- <Plug>CoffeeToolsToggleFunctionArrow
endif
if g:coffee_tools_function_text_object

0 comments on commit 35fe523

Please sign in to comment.
Something went wrong with that request. Please try again.