views:

139

answers:

1

Does anyone know how to get TextMate to search an external file (or even the files contained in a TextMate "project") with which to perform word completion?

I'm coding some stuff on the C64 (using TextMate to write the code) and I have an external file containing labels for all of the hardware registers/kernal routines e.g

VIC2InteruptStatus = $D019

It would be really handy to be able to type, say, 'VIC2I' then press the key for word completion and have TextMate find matches in the external library file. Rather than how I'm having to do it at the moment by opening the library file and copy-paste the register names into my code.

+1  A: 

After some considerable trial and error I got this working....kind of.

You first need an appropriate Bundle for your language/file type. Then within that Bundle you need to use the Bundle Editor to add a new "Preference". Name it however you like and then jump across to the editing pane and add this;

{completionCommand = 'grep -oh "\w*${TM_CURRENT_WORD}\w*" FILESPEC | sort | uniq';}

where FILESPEC is either a single file that contains the keywords you'd like to be offered for word completion.

Close the Bundle Editor.

Now if you start typing a word that is in the FILESPEC file, press ESC (or whatever key you've got Completion mapped to) and TextMate will offer alphabetically sorted word completion. Keep pressing ESC to cycle through all the matches (SHIFT+ESC goes backwards).

Something I couldn't figure out was how to make the search case insensitive. You can use the -i option in GREP but the -o option overrides it. Ideally, if you typed;

com Com COM

it would find all the words in the external file that begin with the letters c, o, m. Instead, if you type "COM" it will only match words that start with "COM" and not "com" or "Com" etc.

If anyone who has more mastery of GREP could figure that out I'd be very grateful.

Neil Baldwin
Interesting; You can always go nuclear and dip into perl. For example, this is case-insensitive do to the "/i" bit: $ echo 'VIC2InteruptStatus = $D019' | perl -lane 'print join "\n", grep /c2i/i, @F' | sort | uniq
Ryan Bright