def load_sources(self, context):
        # Load sources from runtimepath
        rtps = globruntime(
            context['runtimepath'],
            'rplugin/python3/denite/source/base.py')
        rtps.extend(globruntime(context['runtimepath'],
                                'rplugin/python3/denite/source/*.py'))
        for path in rtps:
            name = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.matchers = get_custom_source(
                self.__custom, source.name,
                'matchers', source.matchers)
            source.sorters = get_custom_source(
                self.__custom, source.name,
                'sorters', source.sorters)
            source.converters = get_custom_source(
                self.__custom, source.name,
                'converters', source.converters)
            source.vars.update(
                get_custom_source(self.__custom, source.name,
                                  'vars', source.vars))

            self.__sources[source.name] = source
Example #2
0
    def filter(self, context):
        if not context['candidates'] or not context['input'] or self.__disabled:
            return context['candidates']

        if not self.__initialized:
            # cpsm installation check
            if globruntime(context['runtimepath'], 'bin/cpsm_py.so'):
                # Add path
                sys.path.append(
                    os.path.dirname(
                        globruntime(context['runtimepath'],
                                    'bin/cpsm_py.so')[0]))
                self.__initialized = True
            else:
                error(
                    self.vim, 'matcher_cpsm: bin/cpsm_py.so' +
                    ' is not found in your runtimepath.')
                error(
                    self.vim, 'matcher_cpsm: You must install/build' +
                    ' Python3 support enabled cpsm.')
                self.__disabled = True
                return []

        import cpsm_py
        cpsm_result = cpsm_py.ctrlp_match(
            (d['word'] for d in context['candidates']),
            context['input'],
            limit=1000,
            highlight_mode='detailed',
            ispath=('action__path' in context['candidates'][0]))[0]
        return [x for x in context['candidates'] if x['word'] in cpsm_result]
Example #3
0
    def filter(self, context):
        if not context['candidates'] or not context[
                'input'] or self._disabled:
            return context['candidates']

        if not self._initialized:
            # cpsm installation check
            ext = '.pyd' if context['is_windows'] else '.so'
            if globruntime(context['runtimepath'], 'bin/cpsm_py' + ext):
                # Add path
                sys.path.append(os.path.dirname(
                    globruntime(context['runtimepath'],
                                'bin/cpsm_py' + ext)[0]))
                self._initialized = True
            else:
                self.error_message(context,
                                   'matcher/cpsm: bin/cpsm_py' + ext +
                                   ' is not found in your runtimepath.')
                self.error_message(context,
                                   'matcher/cpsm: You must install/build' +
                                   ' Python3 support enabled cpsm.')
                self._disabled = True
                return []

        ispath = (os.path.exists(context['candidates'][0]['word']))
        cpsm_result = self._get_cpsm_result(
            ispath, context['candidates'], context['input'],
            context['bufname'])
        d = {x['word']: x for x in context['candidates']}
        return [d[x] for x in cpsm_result]
Example #4
0
    def load_sources(self, context):
        # Load sources from runtimepath
        rtps = globruntime(context['runtimepath'],
                           'rplugin/python3/denite/source/base.py')
        rtps.extend(
            globruntime(context['runtimepath'],
                        'rplugin/python3/denite/source/*.py'))
        loaded_paths = [x.path for x in self.__sources.values()]
        for path in rtps:
            name = os.path.splitext(os.path.basename(path))[0]
            if name == 'base' or path in loaded_paths:
                continue

            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            source = module.Source(self.__vim)
            self.__sources[source.name] = source
            source.path = path

            if source.name in self.__custom['alias_source']:
                # Load alias
                for alias in self.__custom['alias_source'][source.name]:
                    self.__sources[alias] = module.Source(self.__vim)
                    self.__sources[alias].name = alias
                    self.__sources[alias].path = path
Example #5
0
    def load_filters(self, context):
        # Load filters from runtimepath
        rtps = globruntime(context['runtimepath'],
                           'rplugin/python3/denite/filter/base.py')
        rtps.extend(
            globruntime(context['runtimepath'],
                        'rplugin/python3/denite/filter/*.py'))
        loaded_paths = [x.path for x in self.__filters.values()]
        for path in rtps:
            name = os.path.splitext(os.path.basename(path))[0]
            if name == 'base' or path in loaded_paths:
                continue

            module = importlib.machinery.SourceFileLoader(
                'denite.filter.' + name, path).load_module()
            filter = module.Filter(self.__vim)
            filter.path = path
            self.__filters[name] = filter

            if name in self.__custom['alias_filter']:
                # Load alias
                for alias in self.__custom['alias_filter'][name]:
                    self.__filters[alias] = module.Filter(self.__vim)
                    self.__filters[alias].name = alias
                    self.__filters[alias].path = path
Example #6
0
    def filter(self, context):
        if not context['candidates'] or not context[
                'input'] or self.__disabled:
            return context['candidates']

        if not self.__initialized:
            # cpsm installation check
            if globruntime(context['runtimepath'], 'bin/cpsm_py.so'):
                # Add path
                sys.path.append(os.path.dirname(
                    globruntime(context['runtimepath'], 'bin/cpsm_py.so')[0]))
                self.__initialized = True
            else:
                error(self.vim, 'matcher_cpsm: bin/cpsm_py.so' +
                      ' is not found in your runtimepath.')
                error(self.vim, 'matcher_cpsm: You must install/build' +
                      ' Python3 support enabled cpsm.')
                self.__disabled = True
                return []

        import cpsm_py
        candidates = context['candidates']
        max = context['max_candidate_width']
        ispath = (os.path.exists(context['candidates'][0]['word']))
        for pattern in split_input(context['input']):
            cpsm_result = cpsm_py.ctrlp_match(
                (d['word'][:max] for d in candidates),
                pattern, limit=1000, ispath=ispath)[0]
            candidates = [x for x in candidates if x['word'] in cpsm_result]
        return candidates
Example #7
0
    def filter(self, context):
        if not context['candidates'] or not context['input'] or self.__disabled:
            return context['candidates']

        if not self.__initialized:
            # cpsm installation check
            ext = '.pyd' if context['is_windows'] else '.so'
            if globruntime(context['runtimepath'], 'bin/cpsm_py' + ext):
                # Add path
                sys.path.append(
                    os.path.dirname(
                        globruntime(context['runtimepath'],
                                    'bin/cpsm_py' + ext)[0]))
                self.__initialized = True
            else:
                error(
                    self.vim, 'matcher_cpsm: bin/cpsm_py' + ext +
                    ' is not found in your runtimepath.')
                error(
                    self.vim, 'matcher_cpsm: You must install/build' +
                    ' Python3 support enabled cpsm.')
                self.__disabled = True
                return []

        import cpsm_py
        candidates = context['candidates']
        ispath = (os.path.exists(context['candidates'][0]['word']))
        for pattern in split_input(context['input']):
            cpsm_result = cpsm_py.ctrlp_match((d['word'] for d in candidates),
                                              pattern,
                                              limit=1000,
                                              ispath=ispath)[0]
            candidates = [x for x in candidates if x['word'] in cpsm_result]
        return candidates
Example #8
0
    def load_filters(self, context):
        # Load filters from runtimepath
        rtps = globruntime(
            context['runtimepath'],
            'rplugin/python3/denite/filter/base.py')
        rtps.extend(globruntime(context['runtimepath'],
                                'rplugin/python3/denite/filter/*.py'))
        loaded_paths = [x.path for x in self.__filters.values()]
        for path in rtps:
            name = os.path.splitext(os.path.basename(path))[0]
            if name == 'base' or path in loaded_paths:
                continue

            module = importlib.machinery.SourceFileLoader(
                'denite.filter.' + name, path).load_module()
            filter = module.Filter(self.__vim)
            filter.path = path
            self.__filters[name] = filter

            if name in self.__custom['alias_filter']:
                # Load alias
                for alias in self.__custom['alias_filter'][name]:
                    self.__filters[alias] = module.Filter(self.__vim)
                    self.__filters[alias].name = alias
                    self.__filters[alias].path = path
Example #9
0
    def filter(self, context):
        if not context['candidates'] or not context[
                'input'] or self._disabled:
            return context['candidates']

        if not self._initialized:
            # cpsm installation check
            ext = '.pyd' if context['is_windows'] else '.so'
            if globruntime(context['runtimepath'], 'bin/cpsm_py' + ext):
                # Add path
                sys.path.append(os.path.dirname(
                    globruntime(context['runtimepath'],
                                'bin/cpsm_py' + ext)[0]))
                self._initialized = True
            else:
                self.error_message(context,
                                   'matcher/cpsm: bin/cpsm_py' + ext +
                                   ' is not found in your runtimepath.')
                self.error_message(context,
                                   'matcher/cpsm: You must install/build' +
                                   ' Python3 support enabled cpsm.')
                self._disabled = True
                return []

        ispath = (os.path.exists(context['candidates'][0]['word']))
        cpsm_result = self._get_cpsm_result(
            ispath, context['candidates'], context['input'])
        return [x for x in context['candidates'] if x['word'] in cpsm_result]
Example #10
0
    def load_sources(self, context):
        # Load sources from runtimepath
        rtps = globruntime(
            context['runtimepath'],
            'rplugin/python3/denite/source/base.py')
        rtps.extend(globruntime(context['runtimepath'],
                                'rplugin/python3/denite/source/*.py'))
        loaded_paths = [x.path for x in self.__sources.values()]
        for path in rtps:
            name = os.path.splitext(os.path.basename(path))[0]
            if name == 'base' or path in loaded_paths:
                continue

            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            source = module.Source(self.__vim)
            self.__sources[source.name] = source
            source.path = path
            syntax_name = 'deniteSource_' + source.name.replace('/', '_')
            if not source.syntax_name:
                source.syntax_name = syntax_name

            if source.name in self.__custom['alias_source']:
                # Load alias
                for alias in self.__custom['alias_source'][source.name]:
                    self.__sources[alias] = module.Source(self.__vim)
                    self.__sources[alias].name = alias
                    self.__sources[alias].path = path
                    self.__sources[alias].syntax_name = syntax_name
Example #11
0
 def load_filters(self):
     # Load filters from runtimepath
     for path in globruntime(
             self.__vim,
             'rplugin/python3/denite/filter/base.py') + globruntime(
                 self.__vim, 'rplugin/python3/denite/filter/*.py'):
         name = os.path.basename(path)[:-3]
         filter = importlib.machinery.SourceFileLoader(
             'denite.filter.' + name, path).load_module()
         if hasattr(filter, 'Filter') and name not in self.__filters:
             self.__filters[name] = filter.Filter(self.__vim)
Example #12
0
 def load_kinds(self):
     # Load kinds from runtimepath
     for path in globruntime(
             self.__vim,
             'rplugin/python3/denite/kind/base.py') + globruntime(
                 self.__vim, 'rplugin/python3/denite/kind/*.py'):
         name = os.path.basename(path)[:-3]
         kind = importlib.machinery.SourceFileLoader(
             'denite.kind.' + name, path).load_module()
         if hasattr(kind, 'Kind') and name not in self.__kinds:
             self.__kinds[name] = kind.Kind(self.__vim)
Example #13
0
 def load_filters(self, context):
     # Load filters from runtimepath
     rtps = globruntime(
         context['runtimepath'],
         'rplugin/python3/denite/filter/base.py')
     rtps.extend(globruntime(context['runtimepath'],
                             'rplugin/python3/denite/filter/*.py'))
     for path in rtps:
         name = os.path.basename(path)[: -3]
         filter = importlib.machinery.SourceFileLoader(
             'denite.filter.' + name, path).load_module()
         if hasattr(filter, 'Filter') and name not in self.__filters:
             self.__filters[name] = filter.Filter(self.__vim)
Example #14
0
 def load_kinds(self, context):
     # Load kinds from runtimepath
     rtps = globruntime(
         context['runtimepath'],
         'rplugin/python3/denite/kind/base.py')
     rtps.extend(globruntime(context['runtimepath'],
                             'rplugin/python3/denite/kind/*.py'))
     for path in rtps:
         name = os.path.basename(path)[: -3]
         kind = importlib.machinery.SourceFileLoader(
             'denite.kind.' + name, path).load_module()
         if hasattr(kind, 'Kind') and name not in self.__kinds:
             self.__kinds[name] = kind.Kind(self.__vim)
Example #15
0
    def load_kinds(self, context):
        # Load kinds from runtimepath
        rtps = globruntime(
            context['runtimepath'],
            'rplugin/python3/denite/kind/base.py')
        rtps.extend(globruntime(context['runtimepath'],
                                'rplugin/python3/denite/kind/*.py'))
        for path in rtps:
            name = os.path.basename(path)[: -3]
            if name == 'base' or name in self.__kinds:
                continue

            module = importlib.machinery.SourceFileLoader(
                'denite.kind.' + name, path).load_module()
            self.__kinds[name] = module.Kind(self.__vim)
Example #16
0
    def load_kinds(self, context):
        # Load kinds from runtimepath
        rtps = globruntime(context['runtimepath'],
                           'rplugin/python3/denite/kind/base.py')
        rtps.extend(
            globruntime(context['runtimepath'],
                        'rplugin/python3/denite/kind/*.py'))
        for path in rtps:
            name = os.path.basename(path)[:-3]
            if name == 'base' or name in self.__kinds:
                continue

            module = importlib.machinery.SourceFileLoader(
                'denite.kind.' + name, path).load_module()
            self.__kinds[name] = module.Kind(self.__vim)
Example #17
0
    def load_sources(self, context):
        # Load sources from runtimepath
        rtps = globruntime(
            context['runtimepath'],
            'rplugin/python3/denite/source/base.py')
        rtps.extend(globruntime(context['runtimepath'],
                                'rplugin/python3/denite/source/*.py'))
        for path in rtps:
            name = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)
            self.__sources[source.name] = source
Example #18
0
    def __init__(self, vim):
        super().__init__(vim)

        self.name = 'nerdfont'
        self.kind = 'word'

        # TODO Autodownload
        self.file_index = globruntime(vim.eval('&runtimepath'),
                                      'autoload/nerdfont-denite/icons.csv')[0]
Example #19
0
 def gather_candidates(self, context):
     candidates = []
     extend = candidates.extend
     for f in globruntime(context['runtimepath'], 'doc/tags'):
         with open(f, 'r') as ins:
             extend(list(map(lambda canidate: {
                 'word': canidate.split("\t", 1)[0],
                 'action__command': 'silent h ' + canidate.split("\t", 1)[0]
             }, ins)))
     return candidates
Example #20
0
    def gather_candidates(self, context: UserContext) -> Candidates:
        filetypes = {}

        for file in globruntime(context['runtimepath'], 'syntax/*.vim'):
            filetype = path.splitext(path.basename(file))[0]
            filetypes[filetype] = {
                'word': filetype,
                'action__command': 'set filetype=' + filetype
            }

        return sorted(filetypes.values(), key=lambda value: value['word'])
Example #21
0
    def gather_candidates(self, context):
        colorschemes = {}

        for file in globruntime(context['runtimepath'], 'colors/*.vim'):
            colorscheme = path.splitext(path.basename(file))[0]
            colorschemes[colorscheme] = {
                'word': colorscheme,
                'action__command': 'colorscheme ' + colorscheme
            }

        return sorted(colorschemes.values(), key=lambda value: value['word'])
Example #22
0
    def gather_candidates(self, context):
        colorschemes = {}

        for filename in globruntime(context['runtimepath'], 'colors/*.vim'):
            colorscheme = path.splitext(path.basename(filename))[0]
            colorschemes[colorscheme] = {
                'word': colorscheme,
                'action__command': 'colorscheme ' + colorscheme
            }

        return sorted(colorschemes.values(), key=lambda value: value['word'])
Example #23
0
    def gather_candidates(self, context):
        filetypes = {}

        for file in globruntime(context['runtimepath'], 'syntax/*.vim'):
            filetype = path.splitext(path.basename(file))[0]
            filetypes[filetype] = {
                'word': filetype,
                'action__command': 'set filetype=' + filetype
            }

        return sorted(filetypes.values(), key=lambda value: value['word'])
Example #24
0
    def gather_candidates(self, context):
        help_docs = {}
        for f in globruntime(context['runtimepath'], 'doc/tags'):
            with open(f, 'r') as ins:
                for line in ins:
                    name = line.split("\t", 1)[0]
                    help_docs[name] = {
                        'word': name,
                        'action__command': 'silent help ' + name
                    }

        return sorted(help_docs.values(), key=lambda value: value['word'])
Example #25
0
 def gather_candidates(self, context):
     for f in globruntime(context['runtimepath'], 'doc/tags'):
         with open(f, 'r') as ins:
             canidates = list(
                 map(
                     lambda canidate: {
                         'word':
                         canidate.split("\t", 1)[0],
                         'action__command':
                         'silent h ' + canidate.split("\t", 1)[0]
                     }, ins))
     return canidates
Example #26
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(
                self.__vim,
                'rplugin/python3/denite/source/base.py') + globruntime(
                    self.__vim, 'rplugin/python3/denite/source/*.py'):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.matchers = get_custom(self.__vim, source.name).get(
                'matchers', source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get(
                'sorters', source.sorters)
            source.converters = get_custom(self.__vim, source.name).get(
                'converters', source.converters)

            self.__sources[source.name] = source
Example #27
0
    def filter(self, context):
        if not context['candidates'] or not context['input']:
            return context['candidates']

        if not self.__initialized:
            # cpsm installation check
            if globruntime(context['runtimepath'], 'bin/cpsm_py.so'):
                # Add path
                sys.path.append(
                    os.path.dirname(
                        globruntime(context['runtimepath'],
                                    'bin/cpsm_py.so')[0]))
                self.__initialized = True
            else:
                return []

        import cpsm_py
        cpsm_result = cpsm_py.ctrlp_match(
            (d['word'] for d in context['candidates']),
            context['input'],
            limit=1000,
            highlight_mode='detailed',
            ispath=('action__path' in context['candidates'][0]))[0]
        return [x for x in context['candidates'] if x['word'] in cpsm_result]
Example #28
0
 def gather_candidates(self, context: UserContext) -> Candidates:
     candidates: Candidates = []
     extend = candidates.extend
     for f in globruntime(context['runtimepath'], 'doc/tags'):
         with open(f, 'r') as ins:
             root = str(Path(f).parent)
             extend(list(map(lambda candidate: {
                 'word': candidate.split("\t", 1)[0],
                 'action__path': (
                     root + sep + candidate.split("\t")[1]
                 ),
                 'action__pattern': (
                     r'\V' + candidate.split("\t")[2].rstrip('\n')[1:]
                 ),
             }, ins)))
     return candidates
Example #29
0
    def gather_candidates(self, context):
        candidates = []
        now = time.time()
        path = os.path.expanduser(self.vars['path'])

        for path in globruntime(path, self.vars['pattern']):
            mtime = os.stat(path).st_mtime
            name = os.path.splitext(os.path.basename(path))[0]
            candidates.append({
                'word': '%s (%s)' % (name, self._time_ago(now, mtime)),
                'action__path': path,
                'source_mtime': mtime,
            })

        return sorted(
            candidates,
            key=lambda x: x['source_mtime'],
            reverse=True)
Example #30
0
 def on_init(self, context):
     runtimepath = self.vim.eval('&runtimepath')
     self._helpfiles = globruntime(runtimepath, 'doc/index.txt')
Example #31
0
 def on_init(self, context: UserContext) -> None:
     runtimepath = self.vim.eval('&runtimepath')
     self._helpfiles = globruntime(runtimepath, 'doc/index.txt')
     self._commands = globruntime(runtimepath, 'doc/index.txt')
Example #32
0
 def on_init(self, context):
     runtimepath = self.vim.eval('&runtimepath')
     self._helpfiles = globruntime(runtimepath, 'doc/index.txt')