diff --git a/Default.sublime-commands b/Default.sublime-commands index 9da3ad8..b2ce5a7 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -7,6 +7,13 @@ "caption": "CTags: Show Symbols (file)", "command": "show_symbols", }, + { + "caption": "CTags: Show Symbols (current language)", + "command": "show_symbols", + "args": { + "type": "lang" + }, + }, { "caption": "CTags: Show Symbols (all)", "command": "show_symbols", diff --git a/ctags.py b/ctags.py index 027f60e..824c1b5 100644 --- a/ctags.py +++ b/ctags.py @@ -353,39 +353,24 @@ def resort_ctags(tag_file): :returns: None """ - meta = [] - symbols = [] - tmp_file = tag_file + '.tmp' + groups = {} with codecs.open(tag_file, encoding='utf-8', errors='replace') as file_: for line in file_: + # meta data not needed in sorted files if line.startswith('!_TAG'): - meta.append(line) continue # read all valid symbol tags, which contain at least # symbol name and containing file and build a list of tuples - split = line.split('\t') + split = line.split('\t', FILENAME + 1) if len(split) > FILENAME: - symbols.append((split[FILENAME], split)) + groups.setdefault(split[FILENAME], []).append(line) - # sort inplace to save some RAM with large .tags files - meta.sort() - symbols.sort() - - with codecs.open(tmp_file, 'w', encoding='utf-8', + with codecs.open(tag_file + '_sorted_by_file', 'w', encoding='utf-8', errors='replace') as file_: - - # write sourted metadata - file_.writelines(meta) - - # followed by sorted list of symbols - for _, split in symbols: - split[FILENAME] = split[FILENAME].lstrip('.\\') - file_.write('\t'.join(split)) - - os.remove(tag_file) - os.rename(tmp_file, tag_file) + for group in sorted(groups): + file_.writelines(groups[group]) # # Models diff --git a/ctagsplugin.py b/ctagsplugin.py index 18c73c3..7ea8a75 100644 --- a/ctagsplugin.py +++ b/ctagsplugin.py @@ -758,6 +758,7 @@ def run(self, view, args, tags_file): # filter and cache by file suffix suffix = get_current_file_suffix(view.file_name()) key = suffix + files = [] elif multi: # request all symbols of given tags file key = "__all__" @@ -769,20 +770,9 @@ def run(self, view, args, tags_file): return key = get_rel_path_to_source(key, tags_file) key = key.replace('\\', '/') - files = [key] - # Note: Help migrating existing tags files to new file name. - # Needed, because this plugin now sorts .tags file in-place, - # while former versions used to create a dedicated file. - sorted_tags_file = tags_file + '_sorted_by_file' - if os.path.isfile(sorted_tags_file): - try: - os.remove(tags_file) - os.rename(sorted_tags_file, tags_file) - except OSError: - pass - + tags_file = tags_file + '_sorted_by_file' base_path = get_common_ancestor_folder( view.file_name(), view.window().folders())