Python Line Continuations
-
Comments:
- here.
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:
#!/usr/bin/env ruby
scope = ENV['TM_SCOPE'].split
no_trail = ['punctuation.definition.arguments.end.python',
'meta.structure.list.python',
'meta.structure.dictionary.python',
'string.quoted.single.block.python',
'string.quoted.double.block.python']
print (scope & no_trail) == [] ? "\\\n" : "\n"