diff options
author | Guido van Rossum <guido@python.org> | 1991-06-04 20:36:54 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-06-04 20:36:54 (GMT) |
commit | ec758ead391daa2ce0e5697aa0e67ec3ba0f37af (patch) | |
tree | 7f2d186afd41d797882d5b5be3330e921804ebe9 /Tools/scripts/ptags.py | |
parent | 0481447f4135c11d42ae25f55696af8e8d52fe74 (diff) | |
download | cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.zip cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.tar.gz cpython-ec758ead391daa2ce0e5697aa0e67ec3ba0f37af.tar.bz2 |
Initial revision
Diffstat (limited to 'Tools/scripts/ptags.py')
-rwxr-xr-x | Tools/scripts/ptags.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Tools/scripts/ptags.py b/Tools/scripts/ptags.py new file mode 100755 index 0000000..b3a693e --- /dev/null +++ b/Tools/scripts/ptags.py @@ -0,0 +1,49 @@ +#! /usr/local/python + +# ptags +# +# Create a tags file for Python programs, usable with vi. +# Tagged are: +# - functions (even inside other defs or classes) +# - classes +# - filenames +# Warns about files it cannot open. +# No warnings about duplicate tags. + +import sys +import regexp +import path + +tags = [] # Modified global variable! + +def main(): + args = sys.argv[1:] + for file in args: treat_file(file) + if tags: + fp = open('tags', 'w') + tags.sort() + for s in tags: fp.write(s) + +matcher = regexp.compile('^[ \t]*(def|class)[ \t]+([a-zA-Z0-9_]+)[ \t]*\(') + +def treat_file(file): + try: + fp = open(file, 'r') + except: + print 'Cannot open', file + return + base = path.basename(file) + if base[-3:] = '.py': base = base[:-3] + s = base + '\t' + file + '\t' + '1\n' + tags.append(s) + while 1: + line = fp.readline() + if not line: break + res = matcher.exec(line) + if res: + (a, b), (a1, b1), (a2, b2) = res + name = line[a2:b2] + s = name + '\t' + file + '\t/^' + line[a:b] + '/\n' + tags.append(s) + +main() |