Skip to content

Instantly share code, notes, and snippets.

@persquare
Last active August 29, 2015 14:01
Show Gist options
  • Save persquare/8ba4dfee1a64b8a98aa2 to your computer and use it in GitHub Desktop.
Save persquare/8ba4dfee1a64b8a98aa2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python -S
#encoding: utf-8
# For TM2:TextTasks
# Settings:
# Input::Line::Text
# output::Insert after input::Snippet
import os
import sys
import re
tm_support_path = os.environ['TM_BUNDLE_SUPPORT']
if tm_support_path not in sys.path:
sys.path.insert(0, tm_support_path)
import exit_codes as exit
if os.environ.get('TM_SELECTED_TEXT', None):
# If there is a selection I can't get access to the line?! Bail.
exit.discard()
line = os.environ.get('TM_CURRENT_LINE')
line = line.rstrip('\r\n ')
col = int(os.environ.get('TM_LINE_INDEX'))
match = re.match(r'^(\s*).*$', line)
if not match:
# Not a task => just insert newline
sys.stdout.write('\n- ${0}')
else:
indent = match.group(1)
sys.stdout.write('%s\n- ${0}' % indent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment