Python Line Continuations

Using TextMate, it is very easy to get snippets and commands to do things that you often do. However, the python bundle is a bit lacking, and this is a great opportunity to improve that.

I’ve created a Command that will enter a newline, and if not inside a list, function call, dictionary or multi-line string, automatically add a trailing .

I’ve hooked it in to the Enter key, and the other settings can be seen in the screenshot below:

The actual code follows:

 1 #!/usr/bin/env ruby
 2 
 3 scope = ENV['TM_SCOPE'].split
 4 
 5 no_trail = ['punctuation.definition.arguments.end.python',
 6             'meta.structure.list.python',
 7             'meta.structure.dictionary.python',
 8             'string.quoted.single.block.python',
 9             'string.quoted.double.block.python']
10 
11 print (scope & no_trail) == [] ? "\\\n" : "\n"
blog comments powered by Disqus