def ctags(): """Open tags file and return ctags instance.""" proj_dir = os.environ['TM_PROJECT_DIRECTORY'] tag_file = os.path.normpath(os.path.join(proj_dir, '../../tags')) if not os.path.isfile(tag_file): print "Tag File not found (%s)." % tag_file print html_footer() sys.exit() return CTags(tag_file)
def find_tag(prompt=False): tags = ctags() if prompt: current_word = get_string() else: current_word = os.environ['TM_CURRENT_WORD'] entry = TagEntry() res = tags.find(entry, current_word, TAG_FULLMATCH | TAG_OBSERVECASE) print html_header('CTags', 'Find Tag') if res==0: print "Not found." sys.exit() matches = [(entry['name'], entry['kind'], entry['file'], entry['pattern'])] while tags.findNext(entry): matches.append((entry['name'], entry['kind'], entry['file'], entry['pattern'])) matches.sort(key=priority) for entry in matches: line, col = position(entry[2], entry[3]) # Try to figure out package name from file path m = re.search(r'/([^/]+)\-[^-]+\-py\d\.\d\.egg/', entry[2]) if m: package_name = m.group(1) else: m = re.search(r'/src/([^/]+)', entry[2]) if m: package_name = m.group(1) else: package_name = '-' # #short_file = re.sub(r'(.*)\-[^-]+\-py\d\.\d\.egg/', r'\1', entry[2]) #short_file = re.sub(r'.*/src/', '', short_file) print ("""<a href="txmt://open?url=file://%(file)s&line=""" """%(line)s">%(name)s</a>""" """ (%(kind)s, %(package_name)s)<pre>%(file)s:%(line)s</pre>""" % (dict( line=line+1, col=col+1, name=entry[0], kind=entry[1], file=entry[2], pattern=entry[3], package_name=package_name,))) print html_footer()