Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: AndrewRadev/coffee_tools.vim
base: 16ac11325c
...
head fork: AndrewRadev/coffee_tools.vim
compare: b9c2ede48b
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
5 README.markdown
@@ -4,5 +4,8 @@ This plugin will hold various tools I can think of for dealing with coffeescript
- A "delete and dedent" mapping that deletes the current line and fixes anything that's indented below it.
- An "open line above and indent" mapping that indents the visually selected area and opens up a new line above.
- A pair of "paste" mappings to paste some code, maintaining the level of indentation of the current line.
+ - A function text object, providing mappings like "cif" and "vaf" to
+ easily manipulate functions
+ - Some minor syntax extensions
-Since it's a work in progress, it's not published on vim.org and has no documentation for now. The latter will probably be adressed soonish. If you feel like using it, and you encounter any problems, please open an issue on github's bugtracker.
+Since it's a work in progress, it's not published on vim.org and has no documentation for now. If you feel like using it, and you encounter any problems, please open an issue on github's bugtracker.
View
65 autoload/coffee_tools.vim
@@ -101,6 +101,33 @@ function! coffee_tools#Paste(paste_key, register)
exe 'normal! "'.a:register.a:paste_key
endfunction
+function! coffee_tools#FunctionTextObject(type)
+ let function_start = search('\((.\{-})\)\=\s*[-=]>$', 'Wbc')
+ if function_start < 0
+ return
+ endif
+
+ let body_start = function_start + 1
+ if body_start > line('$') || indent(nextnonblank(body_start)) <= indent(function_start)
+ if a:type == 'a'
+ normal! vg_
+ endif
+
+ return
+ endif
+
+ let indent_limit = s:LowerIndentLimit(body_start)
+
+ if a:type == 'i'
+ let start = body_start
+ else
+ let start = function_start
+ endif
+
+ call s:MarkVisual('v', start, indent_limit)
+endfunction
+
+" TODO (2012-04-03) Refactor to use *IndentLimit helper
function! s:DedentBelow(lineno, depth)
if line(a:lineno) == line('$')
" then it's the last line, don't mind it
@@ -125,3 +152,41 @@ function! s:DedentBelow(lineno, depth)
silent exe (line(a:lineno) + 1).','.current_line.repeat('<', a:depth)
call setpos('.', saved_cursor)
endfunction
+
+function! s:LowerIndentLimit(lineno)
+ let base_indent = indent(a:lineno)
+ let current_line = a:lineno
+ let next_line = nextnonblank(current_line + 1)
+
+ while current_line < line('$') && indent(next_line) >= base_indent
+ let current_line = next_line
+ let next_line = nextnonblank(current_line + 1)
+ endwhile
+
+ return current_line
+endfunction
+
+function! s:UpperIndentLimit(lineno)
+ let base_indent = indent(a:lineno)
+ let current_line = a:lineno
+ let prev_line = prevnonblank(current_line - 1)
+
+ while current_line > 0 && indent(prev_line) >= base_indent
+ let current_line = prev_line
+ let prev_line = prevnonblank(current_line - 1)
+ endwhile
+
+ return current_line
+endfunction
+
+function! s:MarkVisual(command, start_line, end_line)
+ if a:start_line != line('.')
+ exe a:start_line
+ endif
+
+ if a:end_line > a:start_line
+ exe 'normal! '.a:command.(a:end_line - a:start_line).'jg_'
+ else
+ exe 'normal! '.a:command.'g_'
+ endif
+endfunction
View
25 plugin/coffee_tools.vim
@@ -22,6 +22,14 @@ if !exists('g:coffee_tools_invasive_mappings')
let g:coffee_tools_invasive_mappings = 0
endif
+if !exists('g:coffee_tools_function_text_object')
+ let g:coffee_tools_function_text_object = 1
+endif
+
+if !exists('g:coffee_tools_syntax_extensions')
+ let g:coffee_tools_syntax_extensions = 1
+endif
+
command! CoffeePreviewOpen call coffee_tools#OpenPreview()
command! CoffeePreviewClose call coffee_tools#ClosePreview()
command! CoffeePreviewToggle call coffee_tools#TogglePreview()
@@ -47,8 +55,17 @@ if g:coffee_tools_default_mappings
autocmd FileType coffee nmap <buffer> <localleader>P <Plug>CoffeeToolsPasteAbove
endif
-autocmd Syntax coffee syntax match coffeeConstructor +\<\zsconstructor\ze:\s*\%((.*)\)\=\s*[-=]>+
-autocmd Syntax coffee syntax match nodejsKeywords +module\.exports\|module\|exports\|global+
+if g:coffee_tools_function_text_object
+ onoremap if :<c-u>call coffee_tools#FunctionTextObject('i')<cr>
+ onoremap af :<c-u>call coffee_tools#FunctionTextObject('a')<cr>
+ xnoremap if :<c-u>call coffee_tools#FunctionTextObject('i')<cr>
+ xnoremap af :<c-u>call coffee_tools#FunctionTextObject('a')<cr>
+endif
+
+if g:coffee_tools_syntax_extensions
+ autocmd Syntax coffee syntax match coffeeConstructor +\<\zsconstructor\ze:\s*\%((.*)\)\=\s*[-=]>+
+ autocmd Syntax coffee syntax match nodejsKeywords +module\.exports\|module\|exports\|global+
-autocmd Syntax coffee hi link coffeeConstructor Operator
-autocmd Syntax coffee hi link nodejsKeywords Operator
+ autocmd Syntax coffee hi link coffeeConstructor Operator
+ autocmd Syntax coffee hi link nodejsKeywords Operator
+endif

No commit comments for this range

Something went wrong with that request. Please try again.