[TxMt] Python mode: offering some code and some suggestions

Gary Poster gary at modernsongs.com
Wed Nov 30 16:29:31 UTC 2005


Hi.  I liked TextMate but it wasn't quite ready for me.  I'll check  
back in on it in 2006 sometime and see how it's doing then.

In the course of my evaluation, I changed some settings to try and  
get closer to what I expected.  I gave up when I discovered that the  
current approach to code folding (finding code block ends,  
specifically) was apparently fundamentally incompatible with Python.

However, I thought some of my changes might be worth reincorporating  
in your product.  Some of them are arguably preferences, and others  
have odd dependencies, but they are at least worth a look.

First, I added an increaseIndent that increases indent on an open  
parenthesis:

/* preferences */
{	increaseIndentPattern = '^\s*(class|def|elif|else|except|finally| 
for|if|try|while)\b.*:|^.*\(\s*$';
	shellVariables = (
		{	name = 'TM_COMMENT_START';
			value = '# ';
		},
		{	name = 'TM_COMMENT_END';
			value = '';
		},
		{	name = 'TM_COMMENT_MODE';
			value = 'line';
		},
	);
}

That's pretty standard Python style.  I was also curious to see if I  
could make a line break inside a parenthesis autoindent to the open  
parenthesis, but didn't see a way to do that.

Second, the foldingStartMarker probably should include `if` and  
`for`, and maybe even some others...I didn't bother thinking about it  
once I got into a seeming dead end with the foldingStopMarker.  That  
said, here's a little improvement in this part of the parsing.

	foldingStartMarker = '^\s*(if|for|def|class)\s+([.a-zA-Z0-9_ b]+)\s* 
(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$';


Finally, pycheckmate didn't work for me.  The first reason had  
something to do with using a specific Python installation, rather  
than the environment Python.  I fixed that, and then the second  
problem was that the custom popen relied on poll, which wasn't  
included in the framework Python build.  I am using ActiveState's  
Python2.4, so I got rid of the customization of the standard library  
class.  The general approach I took probably would let you use some  
of the 2.3 popens too, and get rid of maintaining that extra bit of  
code.

Pycheckmate also wasn't guessing where to find an installed pychecker  
very well--I guess the intent was that you were supposed to configure  
the environment variable in TextMate.  That seemed unnecessary for  
the common case of installing via distutils.  I fixed that at the  
start of the attached file--a bit of a hack, maybe, but nicer first- 
use experience.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pycheckmate.py
Type: text/x-python-script
Size: 6271 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20051130/3bda3970/attachment.py>
-------------- next part --------------

Hope some of that is helpful.

Gary


More information about the textmate mailing list