def build_interfaces(cls, nvim): cmd = [] cmd_name = getattr(cls, 'name') if not cmd_name: return nargs = getattr(cls, 'nargs', 0) cmd.append( 'command! -buffer -nargs={} Acid{} AcidCommand {} {}'.format( nargs, cmd_name, cmd_name, (nargs != '0' and '<args>' or '') ) ) mapping_var = "acid_{}_command_mapping".format(convert_case(cmd_name)) mapping = getattr(cls, 'mapping', None) opfunc = getattr(cls, 'opfunc', False) default_mapping = mapping is not None and not opfunc motion_mapping = mapping is not None and opfunc if default_mapping: mapping = nvim.vars.get(mapping_var, mapping) if nargs in [0, '?', '*']: cmd.append(silent_map(mapping, ':Acid{}<CR>'.format(cmd_name))) elif hasattr(cls, 'prompt'): cmd.append(silent_map(mapping, ':Acid{}Prompt<CR>'.format(cmd_name))) elif motion_mapping: mapping = nvim.vars.get(mapping_var, mapping) cmd.append(opfuncfw(cmd_name)) cmd.append(silent_map( mapping, ':set opfunc=Acid{}OpfuncFw<CR>g@'.format(cmd_name) )) if hasattr(cls, 'shorthand'): shorthand_mapping = "acid_{}_shorthand_mapping".format( convert_case(cmd_name) ) mapping = getattr( cls, 'shorthand_mapping',"{}{}".format( mapping, mapping[-1] ) if mapping is not None else None ) mapping = nvim.vars.get(shorthand_mapping, mapping) shorthand = cls.shorthand cmd.append(silent_map( mapping, ":call AcidShorthand(\"{}\", \"{}\")<CR>".format( cmd_name, shorthand) )) if hasattr(cls, 'prompt'): has_default = int(hasattr(cls, 'prompt_default')) cmd.append(prompt_fw.format(cmd_name, cmd_name, has_default)) return cmd
def init_extensions(self, ext_type, klass): for path in find_extensions(self.nvim, ext_type): extension = import_extensions(path, ext_type, klass) if extension: name = extension.name priority = extension.priority enabled = bool( self.nvim.vars.get( "{}_{}_enabled".format(convert_case(name), ext_type.lower()), getattr(extension, 'enabled', 1))) if enabled and (name not in self.extensions[ext_type] or self.extensions[ext_type][name].priority < priority): self.extensions[ext_type][name] = extension
def call(cls, acid, context, *args): inst = cls.__instances__[cls.name] payload = inst.prepare_payload(*args) if payload is None: return if not 'op' in payload: payload.update({'op': cls.op}) handlers_var = "{}_command_handler".format(convert_case(inst.cmd_name)) custom = get_customization_variable(acid.nvim, handlers_var, inst.handlers) handlers = (inst.start_handler(context, context['handlers'].get(h), *args) for h, *args in items(custom)) acid.command(payload, handlers)