[TxMt] Auto-import for java source files
Allan Odgaard
allan at macromates.com
Fri Sep 16 00:16:06 UTC 2005
On 14/09/2005, at 22.37, Alex Garrett wrote:
> I'm trying to figure out a way to do auto-importing for Java in
> TextMate. I'm stuck at a couple of places and I would appreciate it if
> someone who knows more about TM than I do could chime in with some
> suggestions.
As for actually figuring out the import, I won't comment on that.
Let's just assume we have find_import.sh which takes one argument
(class name) and returns the actual import statement.
Then to use it, you could do something like:
1) place caret on class name (no need to select it)
2) Automation / Start Macro Recording
3) Text / Filter Through Command
a) set command to: find_import.sh "$TM_CURRENT_WORD"
b) set input to: none (doesn't really matter)
c) set output to: Place on clipboard
4) Move to begin of document (cmd arrow up)
5) Edit / Find / Find…
a) set Find string to: ^(?=@import) or whatever you use in Java :)
b) enable regular expression check box
c) press next (should find first @import statement and close
dialog)
6) Edit / Paste (i.e. the import line returned from the script)
7) Automation / Stop Macro Recording
Now you can save the macro and use later.
I made it a regexp search only to not have the find actually select
the stuff found (by using look-ahead).
> [...] is there any way to do arbitrary transformations on the
> contents of the buffer as if it were a java AST, instead of a stream
> of characters? I think that would probably be necessary to create
> commands to do source-level refactorings.
And would be pretty tied to Java ;) so no, that's not possible.
More information about the textmate
mailing list