2 """Create a TAGS file for Python programs, usable with GNU Emacs.
4 usage: eptags pyfiles...
6 The output TAGS file is usable with Emacs version 18, 19, 20.
8 - functions (even inside other defs or classes)
11 eptags warns about files it cannot open.
12 eptags will not give warnings about duplicate tags.
15 Because of tag duplication (methods with the same name in different
16 classes), TAGS files are not very useful for most object-oriented
21 expr
= r
'^[ \t]*(def|class)[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*[:\(]'
22 matcher
= re
.compile(expr
)
24 def treat_file(filename
, outfp
):
25 """Append tags found in file named 'filename' to the open file 'outfp'"""
27 fp
= open(filename
, 'r')
29 sys
.stderr
.write('Cannot open %s\n'%filename
)
40 m
= matcher
.search(line
)
42 tag
= m
.group(0) + '\177%d,%d\n' % (lineno
, charno
)
44 size
= size
+ len(tag
)
45 charno
= charno
+ len(line
)
46 outfp
.write('\f\n%s,%d\n' % (filename
,size
))
51 outfp
= open('TAGS', 'w')
52 for filename
in sys
.argv
[1:]:
53 treat_file(filename
, outfp
)
55 if __name__
=="__main__":