def identifier_before_dot(): if 'TM_CURRENT_WORD' not in os.environ: os.environ['TM_CURRENT_WORD'] = os.environ.get('TM_CURRENT_LINE') word = current_word(r"^[\.A-Za-z_0-9]*", direction='left') if word: return word[:-1] return ""
def complete(choices, options={}): if '2' not in pytm.DIALOG: raise 'Dialog2 not found.' if 'initial_filter' not in options: characters = 'a-zA-Z0-9' if 'extra_chars' in options: characters += re.escape(options['extra_chars']) options['initial_filter'] = current_word(characters, "left") command = [pytm.DIALOG, "popup", "--returnChoice"] if "initial_filter" in options and options['initial_filter']: command.append("--alreadyTyped %s" % sh_escape(options["initial_filter"])) if "static_prefix" in options and options['static_prefix']: command.append("--staticPrefix %s" % sh_escape(options["static_prefix"])) if "extra_chars" in options and options['extra_chars']: command.append("--additionalWordCharacters %s" % sh_escape(options['extra_chars'])) if "case_insensitive" in options and options['case_insensitive']: command.append("--caseInsensitive") def formalize(choice): try: choice['display'] return choice except (KeyError, IndexError, TypeError): return {'display': choice} choices = [formalize(choice) for choice in choices] plist = {'suggestions': choices} try: f = tempfile.NamedTemporaryFile() plistlib.writePlist(plist, f) f.seek(0) command = ' '.join(command).strip() process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) process.stdin.write(f.read()) process.stdin.close() f.close() except Exception as e: pytm.textmate.exit_show_tool_tip('ERROR: %s' % e) finally: f.close()
def current_identifier(): return current_word(r"[A-Za-z_0-9]*")