I'm creating a custom bundle for screenwriting and I've got most of it down, but I want to leverage textmate's completion abilities. For example, I've got this is the language:
{ name = 'splay.character'; match = '\t\t\t\t+(.*)'; },
...to define anything that starts with 4 tabs as "splay.character"
Now, I want to collect all the words in the current document (but only within the "splay.character" scope, and use them as a list for auto-completion. So that when I tab 4 times and type "Ki" then escape, "King John" will pop up.
I know this is done with a shell command (right?) but I have no idea how to do this.
On 17/12/2005, at 2:03, Oliver Taylor wrote:
[...] Now, I want to collect all the words in the current document (but only within the "splay.character" scope, and use them as a list for auto-completion. So that when I tab 4 times and type "Ki" then escape, "King John" will pop up.
I know this is done with a shell command (right?) but I have no idea how to do this.
http://macromates.com/textmate/manual/working_with_text.html#completion
In your case, something like this should work (I assumed the four tabs needs to be at the begin of the line):
{ completionCommand = 'perl -pe "s/^\t{4}($TM_CURRENT_WORD.*)$|.* \n?/$1/" <"$TM_FILEPATH"'; disableDefaultCompletion = 1; }
Add that as a preferences item and set the scope for it to “splay.character”. One caveat: it extracts completions from the saved file (the completion command ought to get the entire document as stdin, but it currently doesn't).
On 17/12/2005, at 13:40, Allan Odgaard wrote:
On 17/12/2005, at 11:14, Allan Odgaard wrote:
[...] completionCommand = 'perl -pe "s/^\t{4}($TM_CURRENT_WORD.*)\ $|.*\n?/$1/" <"$TM_FILEPATH"';
Btw: you probably want to add: “|sort|uniq” after the command.
Oh, and change .* to .+ to exclude the current word, i.e.:
completionCommand = 'perl -pe "s/^\t{4}($TM_CURRENT_WORD.+)$|.* \n?/$1/" <"$TM_FILEPATH"|sort|uniq';