Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jan 7, 2024
2 parents 4776c2f + 8957730 commit ae48221
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
7 changes: 7 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 7 additions & 22 deletions ctags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions ctagsplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
Expand 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())

Expand Down

0 comments on commit ae48221

Please sign in to comment.