Changeset 1472

Show
Ignore:
Timestamp:
07/08/08 12:21:02 (7 weeks ago)
Author:
rob
Message:

Added action to lookup ctags value by name and display matches
* changed project.ini to project.cfg

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/plugins/project.py

    r1454 r1472  
    2020from peppy.yapsy.plugins import * 
    2121from peppy.actions import * 
     22from peppy.actions.minibuffer import * 
    2223from peppy.lib.userparams import * 
    2324from peppy.lib.processmanager import * 
     
    2526 
    2627class CTAGS(InstancePrefs): 
     28    # lookup table for kinds of ctags 
     29    kind_of_tag = { 
     30        'c': 'class name', 
     31        'd': 'define', 
     32        'e': 'enumerator', 
     33        'f': 'function', 
     34        'F': 'file name', 
     35        'g': 'enumeration name', 
     36        'm': 'member', 
     37        'p': 'function prototype', 
     38        's': 'structure name', 
     39        't': 'typedef', 
     40        'u': 'union name', 
     41        'v': 'variable', 
     42        } 
     43     
     44    special_tags = { 
     45        'file:': '(static scope)', 
     46        } 
     47     
    2748    default_prefs = ( 
    2849        StrParam('ctags_extra_args', '', 'extra arguments for the ctags command', fullwidth=True), 
     
    97118    def getTag(self, tag): 
    98119        return self.tags.get(tag, None) 
     120     
     121    def getTagInfo(self, tag): 
     122        """Get a text description of all the tags associated with the given 
     123        keyword. 
     124         
     125        Returns a string of text suitable to be used in a grep-style output 
     126        reporter; that is, a bunch of lines starting with the string 
     127        'filename:line number:' followed by descriptive text about each tag. 
     128        """ 
     129        tags = self.getTag(tag) 
     130        refs = [] 
     131        for t in tags: 
     132            info = "%s:%s: %s  " % (t[0], t[1], tag) 
     133            fields = t[2].split('\t') 
     134            for field in fields: 
     135                if ':' in field: 
     136                    if field in self.special_tags: 
     137                        info += self.special_tags[field] 
     138                    else: 
     139                        info += field + " " 
     140                elif field in self.kind_of_tag: 
     141                    info += "kind:" + self.kind_of_tag[field] + " " 
     142            refs.append(info) 
     143        if refs: 
     144            text = os.linesep.join(refs) + os.linesep 
     145        else: 
     146            text = '' 
     147        return text 
     148 
     149    def getSortedTagList(self): 
     150        tags = self.tags.keys() 
     151        tags.sort() 
     152        return tags 
    99153 
    100154 
     
    202256 
    203257 
     258class LookupCtag(SelectAction): 
     259    """Display all references given a tag name""" 
     260    name = "Lookup Tag" 
     261    default_menu = ("Project", -400) 
     262    key_bindings = {'emacs': "C-c C-t"} 
     263 
     264    def action(self, index=-1, multiplier=1): 
     265        tags = self.mode.project_info.getSortedTagList() 
     266        minibuffer = StaticListCompletionMinibuffer(self.mode, self, _("Lookup Tag:"), list=tags) 
     267        self.mode.setMinibuffer(minibuffer) 
     268 
     269    def processMinibuffer(self, minibuffer, mode, name): 
     270        text = self.mode.project_info.getTagInfo(name) 
     271        if not text: 
     272            text = "No information about %s" % name 
     273        Publisher().sendMessage('peppy.log.info', text) 
     274 
     275 
    204276class RebuildCtags(SelectAction): 
    205277    """Rebuild tag file""" 
    206278    name = "Rebuild Tag File" 
    207     default_menu = ("Project", -500) 
     279    default_menu = ("Project", 499) 
    208280 
    209281    def action(self, index=-1, multiplier=1): 
     
    371443    default_classprefs = ( 
    372444        StrParam('project_directory', '.peppy-project', 'Directory used within projects to store peppy specific information'), 
    373         StrParam('project_file', 'project.ini', 'File within project directory used to store per-project information'), 
     445        StrParam('project_file', 'project.cfg', 'File within project directory used to store per-project information'), 
    374446        StrParam('template_directory', 'templates', 'Directory used to store template files for given major modes'), 
    375447        PathParam('ctags_command', 'exuberant-ctags', 'Path to ctags command', fullwidth=True), 
     
    539611            actions.append(SaveGlobalTemplate) 
    540612        if mode.buffer.url in self.known_project_dirs: 
    541             actions.extend([SaveProjectTemplate, BuildProject, RunProject, RebuildCtags]) 
     613            actions.extend([SaveProjectTemplate, BuildProject, RunProject, 
     614                             
     615                            RebuildCtags, LookupCtag]) 
    542616        actions.extend([CreateProject, CreateProjectFromExisting, ShowProjectSettings]) 
    543617        return actions