Permalink
Browse files

Add my own patched version of cocoa-vim.

It provides some annoying keybindings and there's no easy way to disable them
without editing the source.
  • Loading branch information...
1 parent a34a10f commit da9971c6945d121ecae3593a670370c9d0ea12cf @philc committed Aug 21, 2012
Showing with 7,467 additions and 0 deletions.
  1. +6 −0 bundle/cocoa-vim/README.markdown
  2. +28 −0 bundle/cocoa-vim/after/syntax/cocoa_keywords.vim
  3. +59 −0 bundle/cocoa-vim/after/syntax/objc_enhanced.vim
  4. +215 −0 bundle/cocoa-vim/autoload/objc/cocoacomplete.vim
  5. +185 −0 bundle/cocoa-vim/autoload/objc/man.vim
  6. +124 −0 bundle/cocoa-vim/autoload/objc/method_builder.vim
  7. +115 −0 bundle/cocoa-vim/autoload/objc/method_list.vim
  8. +87 −0 bundle/cocoa-vim/autoload/objc/pum_snippet.vim
  9. +154 −0 bundle/cocoa-vim/doc/cocoa.txt
  10. +88 −0 bundle/cocoa-vim/ftplugin/objc_cocoa_mappings.vim
  11. +637 −0 bundle/cocoa-vim/lib/cocoa_indexes/classes.txt
  12. +1,714 −0 bundle/cocoa-vim/lib/cocoa_indexes/constants.txt
  13. +330 −0 bundle/cocoa-vim/lib/cocoa_indexes/functions.txt
  14. BIN bundle/cocoa-vim/lib/cocoa_indexes/methods.txt.gz
  15. +105 −0 bundle/cocoa-vim/lib/cocoa_indexes/notifications.txt
  16. +222 −0 bundle/cocoa-vim/lib/cocoa_indexes/types.txt
  17. +2 −0 bundle/cocoa-vim/lib/extras/README-if-you-like
  18. +94 −0 bundle/cocoa-vim/lib/extras/build_syntaxfile.py
  19. +64 −0 bundle/cocoa-vim/lib/extras/cocoa_classes.py
  20. +100 −0 bundle/cocoa-vim/lib/extras/cocoa_definitions.py
  21. BIN bundle/cocoa-vim/lib/extras/cocoa_definitions.pyc
  22. +637 −0 bundle/cocoa-vim/lib/extras/cocoa_indexes/classes.txt
  23. +1,714 −0 bundle/cocoa-vim/lib/extras/cocoa_indexes/constants.txt
  24. +330 −0 bundle/cocoa-vim/lib/extras/cocoa_indexes/functions.txt
  25. BIN bundle/cocoa-vim/lib/extras/cocoa_indexes/methods.txt.gz
  26. +105 −0 bundle/cocoa-vim/lib/extras/cocoa_indexes/notifications.txt
  27. +222 −0 bundle/cocoa-vim/lib/extras/cocoa_indexes/types.txt
  28. +63 −0 bundle/cocoa-vim/lib/extras/cocoa_methods.py
  29. BIN bundle/cocoa-vim/lib/extras/superclasses
  30. +47 −0 bundle/cocoa-vim/lib/extras/superclasses.m
  31. +4 −0 bundle/cocoa-vim/lib/get_methods.sh
  32. +16 −0 bundle/cocoa-vim/plugin/cocoa.vim
@@ -0,0 +1,6 @@
+Quickly install with:
+
+ mkdir cocoa.vim
+ cd !$
+ git clone git://github.com/msanders/cocoa.vim.git
+ cp -r . ~/.vim

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,59 @@
+" Author: Michael Sanders (msanders42 [at] gmail [dot] com)
+" Description: Better syntax highlighting for Objective-C files (part of the
+" cocoa.vim plugin).
+" Last Updated: June 23, 2009
+
+" NOTE: This next file (cocoa_keywords.vim) is rather large and may slow
+" things down. Loading it seems to take less than 0.5 microseconds
+" on my machine, but I'm not sure of the consequences; if it is slow
+" for you, just comment out the next line.
+ru after/syntax/cocoa_keywords.vim
+
+syn match objcDirective '@synthesize\|@property\|@optional\|@required' display
+syn keyword objcType IBOutlet IBAction Method
+syn keyword objcConstant YES NO TRUE FALSE
+
+syn region objcImp start='@implementation' end='@end' transparent
+syn region objcHeader start='@interface' end='@end' transparent
+
+" I make this typo sometimes so it's nice to have it highlighted.
+syn match objcError '\v(NSLogv=\(\s*)@<=[^@]=["'].*'me=e-1
+
+syn match objcSubclass '\(@implementation\|@interface\)\@<=\s*\k\+' display contained containedin=objcImp,objcHeader
+syn match objcSuperclass '\(@\(implementation\|interface\)\s*\k\+\s*:\)\@<=\s*\k*' display contained containedin=objcImp,objcHeader
+
+" Matches "- (void) foo: (int) bar and: (float) foobar"
+syn match objcMethod '^\s*[-+]\s*\_.\{-}[\{;]'me=e-1 transparent contains=cParen,objcInstMethod,objcFactMethod
+" Matches "bar & foobar" in above
+syn match objcMethodArg ')\@<=\s*\k\+' contained containedin=objcMethod
+" Matches "foo:" & "and:" in above
+syn match objcMethodName '\(^\s*[-+]\s*(\_[^)]*)\)\@<=\_\s*\_\k\+' contained containedin=objcMethod
+syn match objcMethodColon '\k\+\s*:' contained containedin=objcMethod
+" Don't match these groups in cParen "(...)"
+syn cluster cParenGroup add=objcMethodName,objcMethodArg,objcMethodColon
+" This fixes a bug with completion inside parens (e.g. if ([NSString ]))
+syn cluster cParenGroup remove=objcMessage
+
+" Matches "bar" in "[NSObject bar]" or "bar" in "[[NSObject foo: baz] bar]",
+" but NOT "bar" in "[NSObject foo: bar]".
+syn match objcMessageName '\(\[\s*\k\+\s\+\|\]\s*\)\@<=\k*\s*\]'me=e-1 display contained containedin=objcMessage
+" Matches "foo:" in "[NSObject foo: bar]" or "[[NSObject new] foo: bar]"
+syn match objcMessageColon '\(\_\S\+\_\s\+\)\@<=\k\+\s*:' display contained containedin=objcMessage
+
+" Don't match these in this strange group for edge cases...
+syn cluster cMultiGroup add=objcMessageColon,objcMessageName,objcMethodName,objcMethodArg,objcMethodColon
+
+" You may want to customize this one. I couldn't find a default group to suit
+" it, but you can modify your colorscheme to make this a different color.
+hi link objcMethodName Special
+hi link objcMethodColon objcMethodName
+
+hi link objcMethodArg Identifier
+
+hi link objcMessageName objcMethodArg
+hi link objcMessageColon objcMessageName
+
+hi link objcSubclass objcMethodName
+hi link objcSuperclass String
+
+hi link objcError Error
@@ -0,0 +1,215 @@
+" File: cocoacomplete.vim (part of the cocoa.vim plugin)
+" Author: Michael Sanders (msanders42 [at] gmail [dot] com)
+" Last Updated: June 30, 2009
+" Description: An omni-completion plugin for Cocoa/Objective-C.
+
+let s:lib_dir = fnameescape(expand('<sfile>:p:h:h:h').'/lib/')
+let s:cocoa_indexes = s:lib_dir.'cocoa_indexes/'
+
+if !isdirectory(s:cocoa_indexes)
+ echom 'Error in cocoacomplete.vim: could not find ~/.vim/lib/cocoa_indexes directory'
+endif
+
+fun! objc#cocoacomplete#Complete(findstart, base)
+ if a:findstart
+ " Column where completion starts:
+ return match(getline('.'), '\k\+\%'.col('.').'c')
+ else
+ let matches = []
+ let complete_type = s:GetCompleteType(line('.'), col('.') - 1)
+
+ if complete_type == 'methods'
+ call s:Complete(a:base, ['alloc', 'init', 'retain', 'release',
+ \ 'autorelease', 'retainCount',
+ \ 'description', 'class', 'superclass',
+ \ 'self', 'zone', 'isProxy', 'hash'])
+ let obj_pos = s:GetObjPos(line('.'), col('.'))
+ call extend(matches, s:CompleteMethod(line('.'), obj_pos, a:base))
+ elseif complete_type == 'types' || complete_type == 'returntypes'
+ let opt_types = complete_type == 'returntypes' ? ['IBAction'] : []
+ call s:Complete(a:base, opt_types + ['void', 'id', 'BOOL', 'int',
+ \ 'double', 'float', 'char'])
+ call extend(matches, s:CompleteCocoa(a:base, 'classes', 'types',
+ \ 'notifications'))
+ elseif complete_type != ''
+ if complete_type =~ 'function_params$'
+ let complete_type = substitute(complete_type, 'function_params$', '', '')
+ let functions = s:CompleteFunction(a:base)
+ endif
+
+ " Mimic vim's dot syntax for other complete types (see :h ft).
+ let word = a:base == '' ? 'NS' : a:base
+ let args = [word] + split(complete_type, '\.')
+ call extend(matches, call('s:CompleteCocoa', args))
+
+ " List functions after the other items in the menu.
+ if exists('functions') | call extend(matches, functions) | endif
+ endif
+ return matches
+ endif
+endf
+
+fun s:GetCompleteType(lnum, col)
+ let scopelist = map(synstack(a:lnum, a:col), 'synIDattr(v:val, "name")')
+ if empty(scopelist) | return 'types' | endif
+
+ let current_scope = scopelist[-1]
+ let beforeCursor = strpart(getline(a:lnum), 0, a:col)
+
+ " Completing a function name:
+ if getline(a:lnum) =~ '\%'.(a:col + 1).'c\s*('
+ return 'functions'
+ elseif current_scope == 'objcSuperclass'
+ return 'classes'
+ " Inside brackets "[ ... ]":
+ elseif index(scopelist, 'objcMessage') != -1
+ return beforeCursor =~ '\[\k*$' ? 'classes' : 'methods'
+ " Inside parentheses "( ... )":
+ elseif current_scope == 'cParen'
+ " Inside parentheses for method definition:
+ if beforeCursor =~ '^\s*[-+]\s*([^{;]*'
+ return beforeCursor =~ '^\s*[-+]\s*([^)]*$' ? 'returntypes' : 'types'
+ " Inside function, loop, or conditional:
+ else
+ return 'classes.types.constants.function_params'
+ endif
+ " Inside braces "{ ... }" or after equals "=":
+ elseif current_scope == 'cBlock' || current_scope == 'objcAssign' || current_scope == ''
+ let type = current_scope == 'cBlock' ? 'types.constants.' : ''
+ let type = 'classes.'.type.'function_params'
+
+ if beforeCursor =~ 'IBOutlet' | return 'classes' | endif
+ return beforeCursor =~ '\v(^|[{};=\])]|return)\s*\k*$'? type : 'methods'
+ " Directly inside "@implementation ... @end" or "@interface ... @end"
+ elseif current_scope == 'objcImp' || current_scope == 'objcHeader'
+ " TODO: Complete delegate/subclass methods
+ endif
+ return ''
+endf
+
+" Adds item to the completion menu if they match the base.
+fun s:Complete(base, items)
+ for item in a:items
+ if item =~ '^'.a:base | call complete_add(item) | endif
+ endfor
+endf
+
+" Returns position of "foo" in "[foo bar]" or "[baz bar: [foo bar]]".
+fun s:GetObjPos(lnum, col)
+ let beforeCursor = strpart(getline(a:lnum), 0, a:col)
+ return match(beforeCursor, '\v.*(^|[\[=;])\s*\[*\zs[A-Za-z0-9_@]+') + 1
+endf
+
+" Completes a method given the position of the object and the method
+" being completed.
+fun s:CompleteMethod(lnum, col, method)
+ let class = s:GetCocoaClass(a:lnum, a:col)
+ if class == ''
+ let object = matchstr(getline(a:lnum), '\%'.a:col.'c\k\+')
+ let class = s:GetDeclWord(object)
+ if class == '' | return [] | endif
+ endif
+ let method = s:GetMethodName(a:lnum, a:col, a:method)
+ let matches = split(system(s:lib_dir.'get_methods.sh '.class.
+ \ '|grep "^'.method.'"'), "\n")
+ if exists('g:loaded_snips') " Use snipMate if it's installed
+ call objc#pum_snippet#Map()
+ else " Otherwise, only complete the method name.
+ call map(matches, 'substitute(v:val, ''\v:\zs.{-}\ze(\w+:|$)'', " ", "g")')
+ endif
+
+ " If dealing with a partial method name, only complete past it. E.g., in
+ " "[NSString stringWithCharacters:baz l|]" (where | is the cursor),
+ " only return "length", not "stringWithCharacters:length:".
+ if stridx(method, ':') != -1
+ let method = substitute(method, a:method.'$', '\\\\zs&', '')
+ call map(matches, 'matchstr(v:val, "'.method.'.*")')
+ endif
+ return matches
+endf
+
+" Returns the Cocoa class at a given position if it exists, or
+" an empty string "" if it doesn't.
+fun s:GetCocoaClass(lnum, col)
+ let class = matchstr(getline(a:lnum), '\%'.a:col.'c[A-Za-z0-9_"@]\+')
+ if class =~ '^@"' | return 'NSString' | endif " Treat @"..." as an NSString
+ let v:errmsg = ''
+ sil! hi cocoaClass
+ if v:errmsg == '' && synIDattr(synID(a:lnum, a:col, 0), 'name') == 'cocoaClass'
+ return class " If cocoaClass is defined, try using that.
+ endif
+ return system('grep ^'.class.' '.s:cocoa_indexes.'classes.txt') != ''
+ \ ? class : '' " Use grep as a fallback.
+endf
+
+" Returns the word before a variable declaration.
+fun s:GetDeclWord(var)
+ let startpos = [line('.'), col('.')]
+ let line_found = searchdecl(a:var) != 0 ? 0 : line('.')
+ call cursor(startpos)
+ let matchstr = '\v(IBOutlet\s+)=\zs\k+\s*\ze\**\s*'
+
+ " If the declaration was not found in the implementation file, check
+ " the header.
+ if !line_found && expand('%:e') == 'm'
+ let header_path = expand('%:p:r').'.h'
+ if filereadable(header_path)
+ for line in readfile(header_path)
+ if line =~ '^\s*\(IBOutlet\)\=\s*\k*\s*\ze\**\s*'.a:var.'\s*'
+ return matchstr(line, matchstr)
+ endif
+ endfor
+ return ''
+ endif
+ endif
+
+ return matchstr(getline(line_found), matchstr.a:var)
+endf
+
+fun s:SearchList(list, regex)
+ for line in a:list
+ if line =~ a:regex
+ return line
+ endif
+ endfor
+ return ''
+endf
+
+" Returns the method name, ready to be searched by grep.
+" The "base" word needs to be passed in separately, because
+" Vim apparently removes it from the line during completions.
+fun s:GetMethodName(lnum, col, base)
+ let line = getline(a:lnum)
+ let col = matchend(line, '\%'.a:col.'c\S\+\s\+') + 1 " Skip past class name.
+ if line =~ '\%'.col.'c\k\+:'
+ let base = a:base == '' ? '' : ' '.a:base
+ let method = matchstr(line, '\%'.col.'c.\{-}\ze]').base
+ return substitute(method, '\v\k+:\zs.{-}\ze(\s*\k+:|'.base.'$)', '[^:]*', 'g')
+ else
+ return a:base
+ endif
+endf
+
+" Completes Cocoa functions, using snippets for the parameters if possible.
+fun s:CompleteFunction(word)
+ let files = s:cocoa_indexes.'functions.txt' " TODO: Add C functions.
+ let matches = split(system('zgrep -h "^'.a:word.'" '.files), "\n")
+ if exists('g:loaded_snips') " Use snipMate if it's installed
+ call objc#pum_snippet#Map()
+ else " Otherwise, just complete the function name
+ call map(matches, "{'word':matchstr(v:val, '^\\k\\+'), 'abbr':v:val}")
+ endif
+ return matches
+endf
+
+" Completes word for Cocoa "classes", "types", "notifications", or "constants".
+" (supplied as the optional parameters).
+fun s:CompleteCocoa(word, file, ...)
+ let files = ''
+ for file in [a:file] + a:000
+ let files .= ' '.s:cocoa_indexes.file.'.txt'
+ endfor
+
+ return split(system('grep -ho "^'.a:word.'[A-Za-z0-9_]*" '.files), "\n")
+endf
+" vim:noet:sw=4:ts=4:ft=vim
Oops, something went wrong.

0 comments on commit da9971c

Please sign in to comment.