Coder Social home page Coder Social logo

mgautierfr / python-ctags3 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from universal-ctags/python-ctags3

0.0 2.0 0.0 114 KB

Actively maintained fork of python-ctags with Python 3 support

License: GNU Lesser General Public License v3.0

Makefile 0.12% Python 29.88% C 69.99%

python-ctags3's Introduction

Build Status

NOTE: This a fork from the original python-ctags that adds support for Python 3. It is currently maintained by Jonas Haag.

Exuberant Ctags supports indexing of many modern programming languages. Python is a powerful scriptable dynamic language. Using Python to access Ctags index file is a natural fit in extending an application's capability to examine source code.

This project wrote a wrapper for read tags library. I have been using the package in a couple of projects and it has been shown that it could easily handle hundreds of source files.

Requirements

Installation

From Python Package Index,

pip install python-ctags3

From https://github.com/hddmet/python-ctags/archive/master.zip,

python ./setup.py build
python ./setup.py install

Use Cases

Generating Tags

In command line, run

ctags --fields=afmikKlnsStz readtags.c  readtags.h

Opening Tags File

import ctags
from ctags import CTags, TagEntry
import sys

try:
    tagFile = CTags('tags')
except:
    sys.exit(1)

# Available file information keys:
#  opened -  was the tag file successfully opened?
#  error_number - errno value when 'opened' is false
#  format - format of tag file (1 = original, 2 = extended)
#  sort - how is the tag file sorted? 
#  author - name of author of generating program (may be empy string)
#  name - name of program (may be empy string)
#  url - URL of distribution (may be empy string)
#  version - program version (may be empty string)

print tagFile['name']
print tagFile['author']
print tagFile['format']

# Available sort type:
#  TAG_UNSORTED, TAG_SORTED, TAG_FOLDSORTED

# Note: use this only if you know how the tags file is sorted which is 
# specified when you generate the tag file
status = tagFile.setSortType(ctags.TAG_SORTED)

Obtaining First Tag Entry

entry = TagEntry()
status = tagFile.first(entry)

if status:
    # Available TagEntry keys:
    #  name - name of tag
    #  file - path of source file containing definition of tag
    #  pattern - pattern for locating source line (None if no pattern)
    #  lineNumber - line number in source file of tag definition (may be zero if not known)
    #  kind - kind of tag (none if not known)
    #  fileScope - is tag of file-limited scope?

    # Note: other keys will be assumed as an extension key and will 
    # return None if no such key is found 

    print entry['name']
    print entry['kind']

Finding a Tag Entry

# Available options: 
# TAG_PARTIALMATCH - begin with
# TAG_FULLMATCH - full length matching
# TAG_IGNORECASE - disable binary search
# TAG_OBSERVECASE - case sensitive and allowed binary search to perform

if tagFile.find(entry, 'find', ctags.TAG_PARTIALMATCH | ctags.TAG_IGNORECASE):
    print 'found'
    print entry['lineNumber']
    print entry['pattern']
    print entry['kind']

# Find the next tag matching the name and options supplied to the 
# most recent call to tagFile.find().  (replace the entry if found)
status = tagFile.findNext(entry)

# Step to the next tag in the file (replace entry if found)
status = tagFile.next(entry)

python-ctags3's People

Contributors

sbraz avatar jonashaag avatar hddmet avatar

Watchers

Matthieu Gautier avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.