aboutsummaryrefslogtreecommitdiffstats
path: root/misc/easytags/normalize-tags.py
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2011-06-14 06:43:24 +0200
committerPeter Odding <peter@peterodding.com>2011-06-14 06:43:24 +0200
commit9abe34873b1ea7c5fcc0bad20b311d85b04fc648 (patch)
treef92bb8e6e59a7e59162a31c9ff37207ba4cf077b /misc/easytags/normalize-tags.py
parent980843ec662fa06990f3522999b2ad53e3cf625a (diff)
downloadvim-easytags-9abe34873b1ea7c5fcc0bad20b311d85b04fc648.tar.gz
2x faster syntax highlighting using Python Interface to Vim :-)
Diffstat (limited to 'misc/easytags/normalize-tags.py')
-rwxr-xr-xmisc/easytags/normalize-tags.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/misc/easytags/normalize-tags.py b/misc/easytags/normalize-tags.py
new file mode 100755
index 0000000..6701c53
--- /dev/null
+++ b/misc/easytags/normalize-tags.py
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+
+'''
+Resolve symbolic links in tags files and remove duplicate entries from the
+resulting list of tags. If your tags files contain symbolic links as well as
+canonical filenames this can significantly reduce the size of your tags file.
+This script makes a backup of the tags file in case something goes wrong.
+
+Author: Peter Odding <peter@peterodding.com>
+Last Change: May 11, 2011
+URL: https://github.com/xolox/vim-easytags/blob/master/normalize-tags.py
+'''
+
+import os, sys, time
+
+tagsfile = os.path.expanduser(len(sys.argv) > 1 and sys.argv[1] or '~/.vimtags')
+tempname = '%s-new-%d' % (tagsfile, time.time())
+results, cache = {}, {}
+infile = open(tagsfile)
+outfile = open(tempname, 'w')
+nprocessed = 0
+fold_case = False
+
+for line in infile:
+ nprocessed += 1
+ line = line.rstrip()
+ fields = line.split('\t')
+ if line.startswith('!_TAG_'):
+ results[line] = True
+ if line.startswith('!_TAG_FILE_SORTED\t2'):
+ fold_case = True
+ else:
+ pathname = fields[1]
+ if pathname not in cache:
+ if not os.path.exists(pathname): continue
+ cache[pathname] = os.path.realpath(pathname)
+ fields[1] = cache[pathname]
+ results['\t'.join(fields)] = True
+
+infile.close()
+
+lines = results.keys()
+if fold_case:
+ lines.sort(key=str.lower)
+else:
+ lines.sort()
+
+outfile.write('\n'.join(lines))
+outfile.write('\n')
+outfile.close()
+
+backup = '%s-backup-%d' % (tagsfile, time.time())
+print "Making a backup of %s as %s" % (tagsfile, backup)
+os.rename(tagsfile, backup)
+
+print "Replacing old", tagsfile, "with new one"
+os.rename(tempname, tagsfile)
+
+nfiltered = nprocessed - len(lines)
+print "Filtered %d out of %d entries" % (nfiltered, nprocessed)
+
+# vim: ts=2 sw=2 et