[TxMt] Re: Adding python commands

Andrea Crotti kerny404 at gmail.com
Mon Dec 29 20:41:26 UTC 2008




Rob McBroom wrote:
> 
> 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?
> 
> 
> 
> 
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
> 
> 


Thanks a lot Rob, I have another problem, the thing
#!/usr/bin/env python

import dis
from os import environ
mod = environ['TM_FILENAME'].split('.')[0]
dis.dis(mod)

Doesn't work because I also need to import mod, but if I put also
import mod, of course it doesn't work as it's not substituted the variable
value in the import statement.

I also tried with
python -c << EOF
etc etc
EOF
but without success..
-- 
View this message in context: http://www.nabble.com/Adding-python-commands-tp21201499p21208834.html
Sent from the textmate users mailing list archive at Nabble.com.




More information about the textmate mailing list