tracking the filename of the currently selected tab

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

tracking the filename of the currently selected tab

Niko Matsakis
Hello,

I would like to write a TextMate plugin which creates a window containing a txt2tags [1] rendered version of the file I am currently editing. (Actually a somewhat modified version of txt2tags)  As I navigate through different files, I'd like this window to update to reflect the current file.

I feel like there is probably a fairly simple way for me to observe the file currently being actively edited, but after spending some time browsing through the methods and fields of OakTextView, OakTabBarView, etc, I haven't found out what it is.

Any advice?  Pointers to similar projects?


Thank you very much,

Niko Matsakis

[1] http://txt2tags.sourceforge.net/
_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins
Reply | Threaded
Open this post in threaded view
|

Re: tracking the filename of the currently selected tab

Hans-Jörg Bibiko

On 28.01.2010, at 22:37, Niko Matsakis wrote:

> Hello,
>
> I would like to write a TextMate plugin which creates a window containing a txt2tags [1] rendered version of the file I am currently editing. (Actually a somewhat modified version of txt2tags)  As I navigate through different files, I'd like this window to update to reflect the current file.
>
> I feel like there is probably a fairly simple way for me to observe the file currently being actively edited, but after spending some time browsing through the methods and fields of OakTextView, OakTabBarView, etc, I haven't found out what it is.
>
> Any advice?  Pointers to similar projects?

Hi Niko,

maybe try the obvious, get the env var $TM_FILEPATH

à la:

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

Cheers,
--Hans

_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins
Reply | Threaded
Open this post in threaded view
|

Re: tracking the filename of the currently selected tab

Niko Matsakis
> 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?  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)


regards,
Niko
_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins
Reply | Threaded
Open this post in threaded view
|

Re: tracking the filename of the currently selected tab

Hans-Jörg Bibiko

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

_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins
Reply | Threaded
Open this post in threaded view
|

Re: tracking the filename of the currently selected tab

Niko Matsakis
> 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]);

Ok, thanks.  I will give it a spin.  Before responding I had tried it out briefly using F-Script and it didn't seem to be working, but that must be because the current window was the F-script console!  It does indeed work from my plugin.


regards,
Niko
_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins
Reply | Threaded
Open this post in threaded view
|

Re: tracking the filename of the currently selected tab

Allan Odgaard-4
In reply to this post by Niko Matsakis
On 28 Jan 2010, at 22:37, Niko Matsakis wrote:

> I would like to write a TextMate plugin which creates a window  
> containing a txt2tags [1] rendered version of the file I am  
> currently editing. (Actually a somewhat modified version of txt2tags)

I assume you are aware of the WebPreview and its ability to have a  
command configured that filters the currnet text!?!

> As I navigate through different files, I'd like this window to  
> update to reflect the current file.
>
> I feel like there is probably a fairly simple way for me to observe  
> the file currently being actively edited, but after spending some  
> time browsing through the methods and fields of OakTextView,  
> OakTabBarView, etc, I haven't found out what it is.
>
> Any advice?  Pointers to similar projects?

If you want this to (potentially) also work for 2.0 then you should  
monitor the NSWindow’s representedFile property. This can be done via  
bindings or method swizzling.


_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins
Reply | Threaded
Open this post in threaded view
|

Re: tracking the filename of the currently selected tab

Niko Matsakis
>> I would like to write a TextMate plugin which creates a window containing a txt2tags [1] rendered version of the file I am currently editing. (Actually a somewhat modified version of txt2tags)
>
> I assume you are aware of the WebPreview and its ability to have a command configured that filters the currnet text!?!

Yes, it doesn't quite do what I want... but thanks to both of you for pointing it out.  In particular, WebPreview doesn't track the current file, as far as I know.  I would also prefer it if the preview window were not separate but rather integrated into the Project editing window, probably with a slider to adjust the real estate used for editing / viewing the transformed version.

>> As I navigate through different files, I'd like this window to update to reflect the current file.
>>
>> I feel like there is probably a fairly simple way for me to observe the file currently being actively edited, but after spending some time browsing through the methods and fields of OakTextView, OakTabBarView, etc, I haven't found out what it is.
>>
>> Any advice?  Pointers to similar projects?
>
> If you want this to (potentially) also work for 2.0 then you should monitor the NSWindow’s representedFile property. This can be done via bindings or method swizzling.

Great, that's exactly what I was looking for!


thanks,
Niko
_______________________________________________
textmate-plugins mailing list
[hidden email]
http://lists.macromates.com/listinfo/textmate-plugins