[TxMt] Re: Codesearch

Allan Odgaard mailinglist at textmate.org
Wed Jan 14 07:16:13 UTC 2009

On 6 Jan 2009, at 09:42, Andrea Crotti wrote:

>> [...]
>> Other than use of the deprecated TM_MODE, no. But in your case the  
>> use
>> seems justified, I’ll have to re-evaluate scrapping that variable.
> I think the mode variable could be useful sometimes, and they are not
> so many, are there good reasons to take away some of them?

The TM_MODE variable is the display name of the currently selected  
grammar, which can technically be anything and does not reflect how  
languages can be embedded into each other (e.g. you can have HTML in  
Ruby, JavaScript in HTML, SQL in PHP, etc.).

The TM_SCOPE variable shows the actual context but a more elegant  
solution is to introduce a variable a la TM_CODE_SEARCH_TERM and set  
this to the proper term for the various scopes.

>> Simply set your command to have HTML output, and it’ll open the
>> “browser” with your commands output as content. What you want is then
>> to have your command output a <meta> tag with a redirect to the  
>> actual
>> page (i.e. the Google search URL).
> Ok I tried with this
> #!/usr/bin/env python
> import webbrowser
> import urllib2
> from os import environ
> lang = environ['TM_MODE'].lower()
> QUERY="http://google.com/codesearch?q=" + environ['TM_CURRENT_WORD'] +
> "++lang:" + lang
> print urllib2.urlopen(QUERY).read()
> And it works, but it stops working at the first click, maybe not  
> supporting
> frames or whatever it is in the details page of the source snippets?

This is because you output the actual page source from the command, if  
you want to do that, you need to insert a <base> tag so that relative  
links resolve properly.

But the better approach is to do something like:

     print "<meta http-equiv='Refresh' content='0;URL=%s'>" % QUERY

> [...] (BTW is it normal we're still at revision 10740 since a long  
> time?)
> in Pristine Copy/Bundles.

If you refer to the version of the repository, no, but it moved to: http://svn.textmate.org/trunk/

> This is the way suggested on the manual which is different from the  
> way
> suggested for developers.. So what should I do, merge everything in  
> the Bundles
> folder? (and how?)

I don’t follow your setup. But if you plan to submit patches you want  
to svn co the bundle you want to contribute to to ~/Library/ 
Application Support/TextMate/Bundles so that TextMate does not create  
delta files.

> I think it would be really nice to use a distributed control system
> like darcs (http://darcs.net/) instead of svn, in such a "distributed"
> project we could have many nice features.

There is a github mirror of the svn repository: http://github.com/kballard/textmate-bundles/tree

> And for last thing I would really love to get a small line of input  
> to launch shell commands directly inside TM, useful whenever you  
> need to launch something but you don't care about the output.
> I know here it's everything is minimal (and that's why it's  
> fantastic), but it could be just activated with some key as the  
> incremental search is, not really
> annoying.
> The default behaviour could be show as tool tip only if you get some  
> errors.

You can easily make such command yourself — if you have the  
interactive input library (included in latest cutting edge) you can  
simply make the command read from stdin for what to execute (rather  
than use DIALOG directly or via lib/ui.rb).

More information about the textmate mailing list