[TxMt] Obj-C: goto method declaration
Allan Odgaard
throw-away-1 at macromates.com
Wed Oct 4 12:38:24 UTC 2006
On 3. Oct 2006, at 20:54, Pierre Bernard wrote:
> I am just getting started with TextMate. I don't know yet what is
> needed to write my own command.
>
> There are however a few features that should be closely related:
> - ctrl-H for documentation lookup must be able to parse the current
> selection so it knows where to head in the documentation
When you run a command you can access both current selection and
current word/line/etc. as environment variables (and you can also get
it from stdin).
So this is pretty easy, e.g. if the header is in the same directory,
and you do not have a space after the return type and name of the
function, you could likely find it using:
grep -n "\)${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}" *.h
If e.g. I have my caret on the ‘stringByDeletingPathExtensions’ word
and run that command, the result is:
CocoaExtensions.h:63:- (NSString*)stringByDeletingPathExtensions;
So this gives file name + line number of match. If you do this from a
scripting language (instead of bash) it should be easy to parse that
line. You can use the mate shell command to then open ‘--line 63
CocoaExtensions.h’.
A twist is that Objective-C method names are actually split in
multiple parts, so to be more robust you would need to merge that --
in the Objective-C bundle there is a (Format) Method Call command.
This has ‘meta.bracketed.objc’ set as scope selector and as input it
takes ‘Current Scope’ -- the ‘meta.bracketed.objc’-scope refers to
stuff inside brackets (see about Scope Selectors in the manual).
The command will then need to parse out the actual method name from
this.
More information about the textmate
mailing list