[TxMt] Re: Adding python commands

Rob McBroom textmate at skurfer.com
Mon Dec 29 17:53:48 UTC 2008


On 2008-Dec-29, at 5:45 AM, Andrea Crotti wrote:

> I would like to add a couple of things (at least), but I'm afraid I  
> need some
> clarifications...
> I need a disassembler command, it's just
> import dis
> dis.dis(module)
>
> or dis.dis(function) or dis.dis(object)
>
> Maybe I need a menu to let it know what I want to disassemble..

What about something based on current word, so you could select (or  
type) something then invoke the command? Note that commands don't have  
to be shell scripts. You can use Python directly, if that's the  
language that'll do the work. Assuming you had a command that took  
either Selection or Word as input, it could do something like this:

    #!/usr/bin/env python
    import sys
    import dis
    module = [line.rstrip() for line in sys.stdin.readlines()][0]
    dis.dis(module)

You could also get environment variables using Python  
(os.environ['TM_BLAH']) if you prefer that to using STDIN.

> But it doesn't change dir at all, what am I missing?

I don't see a TM_CURRENT_DIR, but I do see TM_DIRECTORY. Could that be  
it? In any case, aren't you just switching to the current directory  
which, by definition, won't change anything?

> Another nice command would be
> execute line/selection as python, should I use eval?

What about a command that uses Selection or Line as input and just runs

    ${TM_PYTHON:-python}

This is equivalent to echoing the current line and piping it to python  
on the command line, which seems to work. Maybe you're wanting  
something fancier.

-- 
Rob McBroom
<http://www.skurfer.com/>

Because it screws up the order in which people normally read text.

Original message:

> Why is it bad to top-post your reply?

-- 
Rob McBroom
<http://www.skurfer.com/>

Because it screws up the order in which people normally read text.

Original message:

> Why is it bad to top-post your reply?






More information about the textmate mailing list