Example #1
0
    def find_tag(self, tag):
        if not self.tagsfile_list:
            logging.error('this is not a project context')
            return 0

        wstack = TAG.wstack()
        if wstack and tag == wstack[-1].tagname:
            #相同的tag  平行跳转
            return True

        taglist = None
        for tagsfile in self.tagsfile_list:
            taglist = tagsfile.out_list(tag)
            if taglist:
                break

        if not taglist:
            return 0

        frame = Frame(taglist)

        "加入到stack中tag从定义处开始"
        for pos, taginfos in enumerate(taglist):
            if taginfos.kind == 'function':
                break
            if taginfos.kind  == 'variable':
                break

        frame.index = pos

        #加入到stack中去
        self.wstack_push(frame)
        return True
Example #2
0
    def _open(self): # 回车 TODO
        logging.error("node _open")

        if self.opened:
            self.node_close()
        else:
            self.node_open()
Example #3
0
    def find(self, names):
        " 查找一个节点, 目标如['etc', 'nginx', 'conf.d']"
        # 好喜欢这个函数啊!! 哈哈, good
        if self.level >= len(names):#超出层级了
            return

        if self.name != names[self.level]:# 当前不节点是节查找中的一个节点
            return

        if self.level == len(names) -1 : # 当前节点是是节查找的最后一个
            return self

        if not hasattr(self, 'sub_nodes'): # 如果是leaf 直接返回
            return

        # 这个处理是针对于node 节点的
        self._get_child()

        for n in self.sub_nodes: # node 在子节点中找
            m = n.find(names)
            if m:
                return m
        else:
            logging.error('refind: %s', self.name)
            self.need_fresh = True
            self._get_child()
            for n in self.sub_nodes: # node 在子节点中找
                logging.error(n.name)
                m = n.find(names)
                if m:
                    return m
Example #4
0
 def refresh( self ):
     if self.tag_root_dir:
         os.popen("cd %s;ctags -f .tags -R *"  % self.tag_root_dir )
         vim.command("echo 'the ctags is ok'")
         self.open( )
     else:
         logging.error("this is not a project" )
Example #5
0
def goto_pos(pos):
    vim.current.window.cursor = pos

    try:
        vim.command('normal zz')
    except vim.error as e:
        logging.error(e)
Example #6
0
def handle(key, value):
    if key == "wubi":
        if value == 'true':
            rc.IM_Wubi = True
        else:
            rc.IM_Wubi = False
        log.error("IM Setting: %s: %s", key, value)
Example #7
0
    def add_tag(self, tag):
        if not self.tagsfile_list:
            logging.error( 'this is not a project context')
            return 0

        for tagsfile in self.tagsfile_list:
            taglist = tagsfile.out_list(tag)
            if taglist:
                break

        if not taglist:
            return 0

        num = len(taglist)
        start_file = pyvim.filepath( )
        start_file_pos = vim.current.window.cursor

        "加入到stack中tag从定义处开始"
        for pos, taginfos in enumerate(taglist):
            if taginfos['kind']  == 'function':
                break
            if taginfos['kind']  == 'variable':
                break

        #加入到stack中去
        self.append(taglist,
                tag,
                num,
                pos,
                start_file,
                start_file_pos)
        return True
Example #8
0
    def jumpui(self):
        return
        tags = self.tagsfile_list[0].get_funs( )
        request = gui_options.request( "/gui/tag_jump" )
        request.add( "tags", tags)

        con = gui_options.connect( )
        con.request( request )
        tag = con.response( )
        con.close( )


        if tag.status() == 200:
            tag = tag.get( "tag")[ -1 ]
        else:
            return

        "跳转入口"
        if tag == self.lasttag():
            #相同的tag  平行跳转
            self.open_tag()
        else:
            #新的tag     纵向跳转
            if not self.add_tag(tag):
                return  -1
            self.open_tag()

        try:
            vim.command('normal zz')
            #vim.command('%foldopen!')
        except vim.error, e:
            logging.error(e)
Example #9
0
    def quit_search(self, win, index):
        logging.error("tags search window get: %s", index)

        if index > -1:
            frame = self.wstack()[-1]

            frame.taglist[index].goto()
            frame.index = index
Example #10
0
def cmd_cb(index, args):
    fun  = CMDS[index]
    args =  args.split()

    _min, _max = funnargs(fun)
    if len(args) >= _min and len(args) <= _max:
        fun(*args)
    else:
        logging.error("fun:%s args should [%s, %s]. Now %s", _min, _max,
                ' '.join(args))
Example #11
0
def SendBuf():
    ShowUrl = 'http://localhost/texshow/data'
    data = urllib.urlencode(
            {   "data": '\n'.join(vim.current.buffer),
                "type": "mkiv"})

    req = urllib2.Request(ShowUrl, data)
    try:
        urllib2.urlopen(req).read()
    except Exception, e:
        logging.error(e)
Example #12
0
    def popup_finish_cb(self, ret):
        if ret < 0:
            return

        if self.active_index:
            index = self.active_index[ret]
        else:
            index = ret

        logging.error("tags search window get: %s", index)

        self._goto(index)
Example #13
0
    def load_source(self, path):
        if not path.endswith(".py"):
            return

        sys_name = path.replace('.', '_')

        try:
            module_loaded = imp.load_source(sys_name, path)
        except:
            pyvim.echo("Load [%s] Fail"% path)
            import traceback
            logging.error(traceback.format_exc())
Example #14
0
    def loads(self):
        if not os.path.isdir(self.path):
            logging.error("plugin path:[%s] is not dir"%self.path)
            return

        for module in os.listdir(self.path):
            module_path = os.path.join(self.path, module)
            if os.path.isdir(module_path):
                _module_path = os.path.join(module_path, '__init__.py')
                if not os.path.exists(_module_path):
                    continue
                sys.path.insert(0, module_path)
                self.load_source(_module_path)
            else:
                self.load_source(module_path)
Example #15
0
def TagJump(tag = None):
    global TAG
    if TAG == None:
        TAG = class_tag()

    if not tag:
        tag = pyvim.current_word()

    if TAG.find_tag(tag):
        TAG.jump_tag()

    try:
        vim.command('normal zz')
    except vim.error, e:
        logging.error(e)
Example #16
0
    def jump(self, tag):
        "跳转入口"
        if tag == self.lasttag():
            #相同的tag  平行跳转
            self.open_tag()
        else:
            #新的tag     纵向跳转
            if not self.add_tag(tag):
                return  -1
            self.open_tag()

        try:
            vim.command('normal zz')
            #vim.command('%foldopen!')
        except vim.error, e:
            logging.error(e)
Example #17
0
    def open(self):
        tags = os.path.join(self.tag_root_dir, '.tags')
        if not os.path.isfile(tags):
            tags = os.path.join(self.tag_root_dir, 'tags')
            if not os.path.isfile(tags):
                logging.error("not found the tags/.tags file in %s.",
                        self.tag_root_dir)
                return False

        self.items = None
        self.funs = None

        self.tagsfile = tags;
        self.tagfile = ctags.CTags(self.tagsfile)
        self.entry = ctags.TagEntry()
        return True
Example #18
0
def Debug(level):
    if not level in subcmd:
        return

    level = level.upper()
    if not hasattr(logging, level):
        return

    level = getattr(logging, level)
    log.setLevel(level)


    log.debug('debug')
    log.info('info')
    log.warning('warning')
    log.error('error')
    log.critical('critical')
Example #19
0
def goto(path, prefix, pos):
    if path != vim.current.buffer.name:
        vim.command('update')

        for b in vim.buffers:
            if path == b.name:
                vim.current.buffer = b
                break
        else:
            vim.command('silent edit %s'  % path)

    if prefix:
        line = prefix[0]
        tagname = prefix[1]

        line_nu = None
        if isinstance(line, basestring):
            for i, l in enumerate(vim.current.buffer):
                if l.startswith(line):
                    line_nu = i
        else:
            line_nu = line

        if line_nu != None:
            line = vim.current.buffer[line_nu]
            col_nu = line.find(tagname)
            if col_nu < 0:
                col_nu = 0

            pos = (line_nu + 1, col_nu)
        else:
            logging.error('patten: '+line)
            return

    vim.current.window.cursor = pos

    try:
#        vim.command('%foldopen!')
        vim.command('normal zz')
    except vim.error, e:
        logging.error(e)
Example #20
0
File: IM.py Project: fengidri/wind
def IM(*args):
    """
       处理事件.
       @tp: 表示当前的收到的事件的类型
       @event: 收到的事件

       tp 可以是 digit, upper, lower, punc, mult 也可以是 event
    """
    log.debug('IM >>>> %s <<<<', args)

    emit_event('start')

    cls = args[0]
    handle = RouteMap.get(cls)
    if handle:
        handle(*args[1:])
    else:
        log.error("IM: Not Found Cls: %s", cls)

    emit_event('pre-stop')

    emit_event('stop')
Example #21
0
 def bufnew(self):
     log.error("BufNew")
     if self.buf_node:
         self.buf_node.refresh()
Example #22
0
    def open_tag(self):
        taginfo         = self.taginfo()
        taglist         = taginfo["taglist"]
        tagname         = taginfo["tagname"]
        num_total       = taginfo["num_total"]
        pos_for_taglist = taginfo["pos_for_taglist"]

        if taginfo["num_total"]  == 0:
            vim.command("echo 'not find'")
            return 0

        #echo
        vim.command("echo '%s %s %s/%s'"  % (
            taginfo['tagname'],
            taglist[pos_for_taglist]['kind'],
            pos_for_taglist  + 1,
            num_total))

        taginfo_path = taglist[pos_for_taglist]['filename']
        if taginfo_path != vim.current.buffer.name:
                #保存文件
                vim.command('silent update')
                vim.command("silent edit %s"  %  taginfo_path)
        #cmd  #go to the tag
        try:
            cmd = taglist[pos_for_taglist]['cmd']

            #定位光标到tag上
            show_enco=vim.eval('&encoding')
            file_enco=vim.eval('&fileencoding')
            if file_enco != show_enco:
                if file_enco:
                    cmd = cmd.decode(file_enco)\
                        .encode(show_enco)
            line_nu = 0
            found = [  ]
            if cmd.isdigit():
                line_nu = int(cmd)   - 1
                found.append( line_nu )
            else:
                patten = cmd[2: -2].replace(r'\/','/')
                patten = patten.replace(r'\r','')
                for line in vim.current.buffer:
                    if line.startswith(patten):
                        found.append( line_nu  )
                    line_nu+=1

            if found:
                line_nu = found.pop( )
                line = vim.current.buffer[line_nu]
                col_nu = line.find(tagname)
                if col_nu < 0:
                    col_nu = 0

                vim.current.window.cursor = (line_nu  + 1, 0)
                vim.command("normal %sl"  % col_nu)
            else:
                logging.info('patten'+patten)

        except vim.error, e:
            logging.error(e)
            return  -1
Example #23
0
        col_nu= taginfo["start_file_pos"][1]
        vim.current.window.cursor = (line_nu, 0)
        vim.command("normal %sl"  % col_nu)




        try:
            vim.command('%foldopen!')
        except vim.error, e:
            pass

        try:
            vim.command('normal zz')
        except vim.error, e:
            logging.error(e)


    def open_tag(self):
        taginfo         = self.taginfo()
        taglist         = taginfo["taglist"]
        tagname         = taginfo["tagname"]
        num_total       = taginfo["num_total"]
        pos_for_taglist = taginfo["pos_for_taglist"]

        if taginfo["num_total"]  == 0:
            vim.command("echo 'not find'")
            return 0

        #echo
        vim.command("echo '%s %s %s/%s'"  % (