[TxMt] Auto-import for java source files
ljagged at gmail.com
Fri Sep 16 13:36:24 UTC 2005
On 9/15/05, Allan Odgaard <allan at macromates.com> wrote:
> 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
> 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.
Thanks, Allan, that's very helpful. I hadn't considered using a macro
-- I was fixated on commands. Is there a way to put the caret back
where you started?
> 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.
I suppose I was thinking more along the lines of pulling in the
contents of the buffer, antlr-izing it, doing whatever
transformations, and writing it back. I agree, it doesn't make sense
to have a backing AST in the way that a Java IDE like eclipse would.
BTW, I ask because I've started using TextMate for all my non-Java
programming and I really love it. But, unfortunately, I'm a
professional Java programmer and need a productive Java programming
environment. Eclipse and Netbeans both run slowly on my powerbook, so
I wind up doing Java in Windows and everything else in OS X. As I
become more familiar with TextMate I plan on enhancing the Java bundle
(which I'll happily contribute back to the TM community, if anyone's
Let me ask you this: emacs supports a full-featured major mode for
Java and XRefactory has an emacs refactoring library for emacs that
does many of the things that Java IDEs do, but emacs is language
agnostic in the same (or similar) way to TM. Is there any a priori
reason why TM couldn't provide the same sort of functionality as a
collection of macros, commands, snippets, etc?
Thanks again for your help,
More information about the textmate