def __command(vimcmd, fun, complete): vimcmd = vimcmd[0].upper() + vimcmd[1:] _min, _max = funnargs(fun) if _min == _max: if _min == 0: nargs = '-nargs=0' elif _min == 1: nargs = '-nargs=1' else: nargs = '-nargs=+' elif _max == 0: nargs = '-nargs=0' elif _min == 0: if _max == 1: nargs = '-nargs=?' else: nargs = '-nargs=*' else: nargs = '-nargs=+' command = "command {args} {complete} {vimcmd} " \ "py IM('command', {index}, '<args>')" c = command.format(args = nargs, complete= complete, vimcmd = vimcmd, index=len(CMDS)) CMDS.append(fun) logging.debug(c) vim.command(c)
def leaf_handle(leaf): log.debug('leaf_handle: %s', leaf.ctx) vim.command( "update") path = libpath.pull(leaf.ctx) if not path: return vim.command( "e %s" % path )
def handle(tp, key): tp = "im_%s" % tp log.debug("stream handle ft: %s syn: %s", env.ft, env.syntax) if env.ft.startswith('frainui'): frainui.inputstream(tp, key) return if env.pumvisible and env.pumvisible_handler: env.pumvisible_handler(tp, key) return __map.get(env.ft, handler.HD_WubiStream).handler(tp, key)
def wubi(patten): log.debug("wubi patten: %s", patten) words, associate = search(''.join(patten)) #abuild(" ", "%s " % patten) i = 0 for w in words: i += 1 prompt.abuild(w, "%s.%s" % (i, w)) for w, k, c in associate: i += 1 prompt.abuild( w, "%s.%s %s"%(i, w, k))
def handle(ev, name = None): #处理由 IM 触发的事件 # 在不指定 name 的情况下, 会把事件传递给当前的 buffer # 所以多大情况下, 在 Buffer 对象会是 widget 的事件代理. if not name: name = vim.current.buffer log.debug(utils.Objects) obj = utils.Objects.get(name) if not obj: return # 由 IM 触发 object 的事件 obj.FREventEmit(ev)
def getnode(self, linenu = None): if linenu == None: # 没有输入行号, 使用当前行 line = self.BFb[self.BFw.cursor[0] - 1] else: if linenu >= len(self.BFb): return line = self.BFb[linenu] #line = line.decode('utf8') try: node_index = int(line.split('<|>')[1]) logging.debug("getnode ID: %s" % node_index) return self.nodes.get(node_index) except: logging.debug('getnode by line [%s]: fail' % line)
def call(hd, tp, key): """ 调用 handle, 依赖于 tp 调用不同的接口 """ handle = __Handles.get(hd) if not handle: return attr_nm = "im_%s" % tp if not hasattr(handle, attr_nm): return log.debug('redirct to handle: %s', hd) return getattr(handle, attr_nm)(key)
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')
def getnode(cls, linenu = None): if not cls.lswin: return if linenu == None: # 没有输入行号, 使用当前行 line = vim.current.line else: if linenu >= cls.lswin.linenu(): return line = cls.lswin.getline(linenu) line = line.decode('utf8') try: node_index = int(line.split('<|>')[1]) return cls.nodes.get(node_index) except: logging.debug('getnode by linenu: fail')
def handle(tp, key): """ 重定向处理 """ if pyvim.pumvisible(): if call("prompt", tp, key): return log.debug("key: %s", key) handle_list = Redirect().getcur('stream') for hd in handle_list: if call(hd, tp, key): break call("activeprompt", tp, key)
def node_open(self): if self.opened: return logging.debug("node_open:%s" % self.name) self.opened = True linenu = self.getlinenu() self._get_child() buf = self.lswin.BFb buf[linenu - 1] = buf[linenu - 1].replace('+', '-', 1) for n in self.sub_nodes: if hasattr(n, 'opened'): n.opened = False self.lswin.BFb.append(n.show(), linenu) linenu += 1
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')
def IM(*args): """ 处理事件. @tp: 表示当前的收到的事件的类型 @event: 收到的事件 tp 可以是 digit, upper, lower, punc, mult 也可以是 event """ cls = args[0] log.debug('---------------------%s--------------------------', cls) emit_event('start') if cls == "prompt": prompt.handle(*args[1:]) elif cls == "key": stream.handle(*args[1:]) elif cls == "setting": setting.handle(*args[1:]) elif cls == "command": pyvim.cmd_cb(*args[1:]) elif cls == "event": pyvim.event_callback(*args[1:]) elif cls == "cmd_complete": pyvim.command_complete(*args[1:]) elif cls == "frainui": frainui.handle(*args[1:]) emit_event('pre-stop') emit_event('stop')
def findstart(): tt = None col = -3 handle_list = Redirect().getcur('prompt') log.debug('findstart hande list: %s', handle_list ) for hd in handle_list: tt = __Handles.get(hd) if not tt: continue try: col = tt[0]() if not isinstance(col, int): col = -3 except NotPrompt: col = -3 if col > -1: log.debug('@findstart redirect: %s' % hd) Status.name = hd _col = env.col - col return _col return col