Ptags. py of VIM

Source: Internet
Author: User

When reading the help document of ctags, You can see ptags. py, which is used to generate tags for python. The specific directory is in Python source code tools/scripts/ptags. py. You can download it from the python official website.

Source code, decompress and extract ptags. py and put it in the PATH variable search directory. Both python2.x and python3.x have corresponding ptags. PY, in fact, the principle is the same here, it does not involve 2. X and 3. there are different syntaxes between X, and the generated tags file is mainly for classes and functions (class and DEF). Therefore, there is no difference. You can completely claim the tags of python3.x, use pytags of python2.x.

 

Location on my machine: Debian squeeze/wheezy/Sid -->/usr/local/bin

Mandriva/opensuse -------------> $ home/bin

 

 

 

[Wolf @ localhost TMP] $ diff ptags. py ptags3.py <br/> 1C1 <br/> <#! /Usr/bin/ENV python <br/> --- <br/> #! /Usr/bin/ENV python3 <br/> # There are only some differences. The interpreter is used differently.

 

Ptags. py (for python2.x ):

#! /Usr/bin/ENV python <br/> # ptags <br/> # create a tags file for python programs, usable with VI. <br/> # tagged are: <br/> #-functions (even inside other defs or classes) <br/> #-classes <br/> #-filenames <br/> # warns about files it cannot open. <br/> # No warnings about duplicate tags. <br/> Import sys, re, OS <br/> tags = [] # modified global variable! <Br/> def main (): <br/> ARGs = sys. argv [1:] <br/> for filename in ARGs: <br/> treat_file (filename) <br/> If tags: <br/> fp = open ('tags', 'w') <br/> tags. sort () <br/> for S in tags: FP. write (s) <br/> expr = '^ [/T] * (DEF | class) [/T] + ([a-zA-Z0-9 _] +) [/T] * [:/(] '<br/> matcher = Re. compile (expr) <br/> def treat_file (filename): <br/> try: <br/> fp = open (filename, 'R') <br/> limit t: <br/> sys. stderr. write ('could not open % S/N' % filename) <br/> return <br/> base = OS. path. basename (filename) <br/> If base [-3:] = '. py': <br/> base = base [: -3] <br/> S = base + '/t' + filename +'/t' + '1/N' <br/> tags. append (s) <br/> while 1: <br/> line = FP. readline () <br/> if not line: <br/> Break <br/> M = matcher. match (line) <br/> If M: <br/> content = m. group (0) <br/> name = m. group (2) <br/> S = Name + '/t' + filename +'/T/^ '+ content +' // n' <br/> tags. append (s) <br/> If _ name _ = '_ main _': <br/> main () <br/>

 

Ptags. py (for python3.x)

 

#! /Usr/bin/ENV python3 <br/> # ptags <br/> # create a tags file for python programs, usable with VI. <br/> # tagged are: <br/> #-functions (even inside other defs or classes) <br/> #-classes <br/> #-filenames <br/> # warns about files it cannot open. <br/> # No warnings about duplicate tags. <br/> Import sys, re, OS <br/> tags = [] # modified global variable! <Br/> def main (): <br/> ARGs = sys. argv [1:] <br/> for filename in ARGs: <br/> treat_file (filename) <br/> If tags: <br/> fp = open ('tags', 'w') <br/> tags. sort () <br/> for S in tags: FP. write (s) <br/> expr = '^ [/T] * (DEF | class) [/T] + ([a-zA-Z0-9 _] +) [/T] * [:/(] '<br/> matcher = Re. compile (expr) <br/> def treat_file (filename): <br/> try: <br/> fp = open (filename, 'R') <br/> limit t: <br/> sys. stderr. write ('could not open % S/N' % filename) <br/> return <br/> base = OS. path. basename (filename) <br/> If base [-3:] = '. py': <br/> base = base [: -3] <br/> S = base + '/t' + filename +'/t' + '1/N' <br/> tags. append (s) <br/> while 1: <br/> line = FP. readline () <br/> if not line: <br/> Break <br/> M = matcher. match (line) <br/> If M: <br/> content = m. group (0) <br/> name = m. group (2) <br/> S = Name + '/t' + filename +'/T/^ '+ content +' // n' <br/> tags. append (s) <br/> If _ name _ = '_ main _': <br/> main () <br/>

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.