[TxMt Plugins] Re: tracking the filename of the currently selected tab

Hans-Jörg Bibiko bibiko at eva.mpg.de
Thu Jan 28 22:52:17 UTC 2010


On 28.01.2010, at 23:13, Niko Matsakis wrote:

>> maybe try the obvious, get the env var $TM_FILEPATH
> 
> *blush* Yes, that does make sense, thanks.  However, I do have a few more questions:
> 
> Clearly, I can use this at the time when a bundle command is executed to find out the current file, but can I use TM_FILEPATH to track the current file?

The code I sent is the Objective-C code to be used inside a plugin to read all CURRENT env vars:

id target = [NSApp targetForAction:@selector(allEnvironmentVariables)];
NSString* filepath = [[target allEnvironmentVariables] objectForKey:@"TM_FILEPATH"];

You can test it if you do:
NSLog(@"TM env:\n%@", [[target allEnvironmentVariables] description]);

in a Runloop eg.

In other words this NSDictionary is used to pass these TM_* var to the shell/bundle command.

> I'd like to know when the user navigates to a new file, whether that's through Command-T, selecting a file from the drawer, switching tabs, etc.  I could imagine perhaps observing changes in various state to know when a change has occurred and then re-reading the environment variable, but I'm not sure if the environment variable is kept up to date.
> 
> Also, can environment variables be read by plugins or only from scripts executed as bundle commands? (Not that I have to use a plugin, I'd be just as happy to use a bundle by itself if I thought I could achieve what I wanted that way)

Did you try to do it by using the WebPreview? If you open the WebPreview ^⌥⌘P and open the drawer ("Show options") you can write a script which parses whatever to HTML on-the-fly which will update the HTML view after an adjustable delay under "Refresh after change"

Cheers,
--Hans




More information about the textmate-plugins mailing list