" File: objc_cocoa_mappings.vim " Author: Michael Sanders (msanders42 [at] gmail [dot] com) " Description: Sets up mappings for cocoa.vim. " Last Updated: September 08, 2009 if exists('b:cocoa_proj') || &cp || version < 700 finish endif let b:cocoa_proj = fnameescape(globpath(expand(':p:h'), '*.xcodeproj')) 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 if exists('*s:AlternateFile') | finish | endif " Switch from header file to implementation file (and vice versa). fun s:AlternateFile() let path = expand('%:p:r').'.' if expand('%:e') == 'h' if filereadable(path.'m') exe 'e'.fnameescape(path.'m') return elseif filereadable(path.'c') exe 'e'.fnameescape(path.'c') return endif else if filereadable(path.'h') exe 'e'.fnameescape(path.'h') return endif endif echoh ErrorMsg | echo 'Alternate file not readable.' | echoh None endf " Opens Xcode and runs Applescript commands, splitting them onto newlines " if needed. 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