" File: objc_cocoa_mappings.vim " Author: Michael Sanders (msanders42 [at] gmail [dot] com) " Description: Sets up mappings for cocoa.vim. " Last Updated: December 26, 2009 if exists('b:cocoa_proj') || &cp || version < 700 finish endif let b:cocoa_proj = fnameescape(globpath(expand(':p:h'), '*.xcodeproj')) " Search a few levels up to see if we can find the project file if empty(b:cocoa_proj) let b:cocoa_proj = fnameescape(globpath(expand(':p:h:h'), '*.xcodeproj')) if empty(b:cocoa_proj) let b:cocoa_proj = fnameescape(globpath(expand(':p:h:h:h'), '*.xcodeproj')) if empty(b:cocoa_proj) let b:cocoa_proj = fnameescape(globpath(expand(':p:h:h:h:h'), '*.xcodeproj')) endif endif endif let g:x = b:cocoa_proj com! -buffer ListMethods call objc#method_list#Activate(1) com! -buffer -nargs=? -complete=customlist,objc#method_builder#Completion BuildMethods call objc#method_builder#Build('') com! -buffer -nargs=? -complete=custom,objc#man#Completion CocoaDoc call objc#man#ShowDoc('') com! -buffer -nargs=? Alternate call AlternateFile() let objc_man_key = exists('objc_man_key') ? objc_man_key : 'K' exe 'nn '.objc_man_key.' :call objc#man#ShowDoc()' nn A :calAlternateFile() " Mimic some of Xcode's mappings. nn :wcalBuildAnd('launch') nn :wcalXcodeRun('build') nn :wcalXcodeRun('clean') " TODO: Add this " nn :wcalBuildAnd('debug') nn :calAlternateFile() nn :call system('open -a Xcode '.b:cocoa_proj) nn :ListMethods nm ino nn I// nn << nn >> if exists('*s:AlternateFile') | finish | endif " Switch from header file to implementation file (and vice versa). fun s:AlternateFile() let path = expand('%:p:r').'.' let extensions = expand('%:e') == 'h' ? ['m', 'c', 'cpp'] : ['h'] if !s:ReadableExtensionIn(path, extensions) echoh ErrorMsg | echo 'Alternate file not readable.' | echoh None endif endf " Returns true and switches to file if file with extension in any of " |extensions| is readable, or returns false if not. fun s:ReadableExtensionIn(path, extensions) for ext in a:extensions if filereadable(a:path.ext) exe 'e'.fnameescape(a:path.ext) return 1 endif endfor return 0 endf " Opens Xcode and runs Applescript command. fun s:XcodeRun(command) call system("open -a Xcode ".b:cocoa_proj." && osascript -e 'tell app " \ .'"Xcode" to '.a:command."' &") endf fun s:BuildAnd(command) call system("open -a Xcode ".b:cocoa_proj." && osascript -e 'tell app " \ ."\"Xcode\"' -e '" \ .'set target_ to project of active project document ' \ ."' -e '" \ .'if (build target_) starts with "Build succeeded" then ' \ .a:command.' target_' \ ."' -e 'end tell'") endf