コード例 #1
0
ファイル: bookmark.py プロジェクト: ywncmt/projectile.nvim
    def on_init(self, context):
        """Parse and accept user settings."""
        context['data_file'] = expand(self.vars['data_dir'] +
                                      '/bookmarks.json')

        if not exists(context['data_file']):
            bookmark_template = [{
                'name':
                'MYVIMRC',
                'path':
                self.vim.eval('$MYVIMRC'),
                'line':
                1,
                'col':
                1,
                'timestamp':
                str(datetime.datetime.now().isoformat()),
                'description':
                ""
            }]

            if not exists(self.vars['data_dir']):
                try:
                    makedirs(self.vars['data_dir'])
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise
            with open(context['data_file'], 'w+') as nf:
                dump(bookmark_template, nf, indent=2)
コード例 #2
0
    def action_add(self, context):
        """Add a project to ``projectile#data_dir``/projects.json."""
        data_file = expand(self.vars['data_dir'] + '/projects.json')
        root_dir = self.vim.call('getcwd')
        boofer = self.vim.current.buffer.name
        pj_root = path2project(self.vim, boofer, ['.git', '.svn', '.hg'])
        pj_name = basename(normpath(pj_root))
        new_data = {}

        project_root = input(self.vim, context, 'Project Root: ', pj_root)
        if not len(project_root):
            project_root = pj_root

        project_name = input(self.vim, context, 'Project Name: ', pj_name)
        if not len(project_name):
            project_name = pj_name

        new_data = {
            'name': project_name,
            'root': project_root,
            'timestamp': str(datetime.datetime.now().isoformat()),
            'description': '',
            'vcs': isdir("{}/.git".format(
                root_dir))  # TODO: Also check for .hg/ and .svn
        }

        with open(data_file, 'r') as g:
            try:
                json_info = json.load(g)
            except json.JSONDecodeError:
                json_info = []
            json_info.append(new_data)

        with open(data_file, 'w') as f:
            json.dump(json_info, f, indent=2)
コード例 #3
0
    def on_init(self, context):
        """Parse and accept user settings; gather file information from `context`."""
        context['data_file'] = expand(self.vars['data_dir'] + '/projects.json')
        self._get_icons()

        if not exists(
                context['data_file']
        ):  # FIXME: Pull `projects.json` creation into its own function
            project_template = [{
                'name':
                'MYVIMRC',
                'root':
                self.vim.eval('$VIMRUNTIME'),
                'timestamp':
                str(datetime.datetime.now().isoformat()),
                'vcs':
                False,
                'description':
                "",
            }]
            if not exists(self.vars['data_dir']):
                try:
                    makedirs(self.vars['data_dir'])
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise
            with open(context['data_file'], 'w+') as nf:
                dump(project_template, nf, indent=2)
コード例 #4
0
ファイル: __init__.py プロジェクト: skeept/dotvim
 def gather_candidates(self, context):
     context['is_interactive'] = True
     candidates = []
     path = (context['args'][1] if len(context['args']) > 1
             else context['path'])
     path = abspath(self.vim, path)
     inp = expand(context['input'])
     filename = (inp if os.path.isabs(inp) else os.path.join(path, inp))
     if context['args'] and context['args'][0] == 'new':
         candidates.append({
             'word': filename,
             'abbr': '[new] ' + filename,
             'action__path': abspath(self.vim, filename),
         })
     else:
         glb = os.path.dirname(filename) if os.path.dirname(
             filename) != '/' else ''
         glb += '/.*' if os.path.basename(
             filename).startswith('.') else '/*'
         for f in glob.glob(glb):
             fullpath = abspath(self.vim, f)
             candidates.append({
                 'word': f,
                 'abbr': (os.path.relpath(f, path) if fullpath != path
                          else os.path.normpath(f)) + (
                              '/' if os.path.isdir(f) else ''),
                 'kind': ('directory' if os.path.isdir(f) else 'file'),
                 'action__path': fullpath,
             })
     return candidates
コード例 #5
0
 def filter(self, context: UserContext) -> Candidates:
     oldfiles = {
         expand(x): i
         for i, x in enumerate(self.vim.call('denite#helper#_get_oldfiles'))
     }
     return sorted(context['candidates'],
                   key=lambda x: oldfiles.get(x['action__path'], math.inf))
コード例 #6
0
 def gather_candidates(self, context):
     context['is_interactive'] = True
     candidates = []
     path = (context['args'][1] if len(context['args']) > 1
             else context['path'])
     path = abspath(self.vim, path)
     inp = expand(context['input'])
     filename = (inp if os.path.isabs(inp) else os.path.join(path, inp))
     if context['args'] and context['args'][0] == 'new':
         candidates.append({
             'word': filename,
             'abbr': '[new] ' + filename,
             'action__path': abspath(self.vim, filename),
         })
     else:
         glb = os.path.dirname(filename) if os.path.dirname(
             filename) != '/' else ''
         glb += '/.*' if os.path.basename(
             filename).startswith('.') else '/*'
         for f in glob.glob(glb):
             fullpath = abspath(self.vim, f)
             candidates.append({
                 'word': f,
                 'abbr': (os.path.relpath(f, path) if fullpath != path
                          else os.path.normpath(f)) + (
                              '/' if os.path.isdir(f) else ''),
                 'kind': ('directory' if os.path.isdir(f) else 'file'),
                 'action__path': fullpath,
             })
     return candidates
コード例 #7
0
ファイル: old.py プロジェクト: zoshigayan/denite.nvim
 def gather_candidates(self, context: UserContext) -> Candidates:
     oldfiles = [
         expand(x) for x in self.vim.call('denite#helper#_get_oldfiles')
         if not self.vim.call('bufexists', x)
         or self.vim.call('getbufvar', x, '&buftype') == ''
     ]
     return [{'word': x, 'action__path': x} for x in oldfiles]
コード例 #8
0
    def action_add(self, context):
        """Add a bookmark to ``projectile#data_dir``/bookmarks.json"""
        data_file = util.expand(self.vars['data_dir'] + '/bookmarks.json')
        boofer = self.vim.current.buffer.name
        linenr = self.vim.current.window.cursor[0]

        bookmark_path = util.input(self.vim, context, 'Bookmark Path: ',
                                   boofer)
        if not len(bookmark_path):
            bookmark_path = boofer

        bookmark_name = util.input(self.vim, context, 'Bookmark Name: ')
        if not len(bookmark_name):
            bookmark_name = ''
            return

        new_data = {
            'name': bookmark_name,
            'path': bookmark_path,
            'line': linenr,
            'col': 1,  # TODO: get column number when adding bookmarks
            'timestamp': str(datetime.datetime.now().isoformat()),
        }

        with open(data_file, 'r') as g:
            try:
                json_info = json.load(g)
            except json.JSONDecodeError:
                json_info = []
            json_info.append(new_data)

        with open(data_file, 'w') as f:
            json.dump(json_info, f, indent=2)
コード例 #9
0
 def gather_candidates(self, context):
     return [
         {
             'word': x,
             'action__path': x
         } for x in
         [expand(x) for x in self.vim.call('denite#helper#_get_oldfiles')]
     ]
コード例 #10
0
ファイル: projectile.py プロジェクト: ywncmt/projectile.nvim
 def action_custom(self, context):
     """Execute a custom action defined by ``g:projectile#directory_command``."""
     target = context['targets'][0]
     user_cmd = self.vim.vars.get('projectile#directory_command')
     if not isdir(target['action__path']):
         return
     destination = expand(target['action__path'])
     self.vim.call('execute', '{} {}'.format(user_cmd, destination))
コード例 #11
0
 def on_init(self, context):
     """Check for local *todo.txt files."""
     boofer = self.vim.current.buffer.name
     context['cur_pj_root'] = path2project(self.vim, boofer,
                                           str(['.git', '.svn', '.hg']))
     for file in listdir(context['cur_pj_root']):
         if fnmatch.fnmatch(file, '*todo.txt'):
             context['todo_file'] = expand(context['cur_pj_root'] + '/' +
                                           file)
コード例 #12
0
ファイル: projectile.py プロジェクト: ywncmt/projectile.nvim
    def action_add(self, context):
        """Add a project to ``projectile#data_dir``/projects.json."""
        data_file = expand(self.vars['data_dir'] + '/projects.json')
        root_dir = self.vim.call('getcwd')
        boofer = self.vim.current.buffer.name
        pj_root = neopath2project(boofer,
                                  ['.git', '.svn', '.hg', '.projectile'])
        pj_name = basename(normpath(pj_root))
        new_data = {}

        # project_root = input(self.vim, context, 'Project Root: ', pj_root)

        project_root = str(
            self.vim.call('denite#util#input', 'Project Root: ', pj_root, '')
        )  # fix the input method problem according to another pull request

        if not len(project_root):
            project_root = pj_root

        # project_name = input(self.vim, context, 'Project Name: ', pj_name)

        project_name = str(
            self.vim.call('denite#util#input', 'Project Name: ', pj_name, '')
        )  # fix the input method problem according to another pull request

        if not len(project_name):
            project_name = pj_name

        new_data = {
            'name': project_name,
            'root': project_root,
            'timestamp': str(datetime.datetime.now().isoformat()),
            'description': '',
            'vcs': isdir("{}/.git".format(
                root_dir))  # TODO: Also check for .hg/ and .svn
        }

        with open(data_file, 'r') as g:
            try:
                json_info = json.load(g)
            except json.JSONDecodeError:
                json_info = []
            json_info.append(new_data)

        # learn from another fork: remove old project information
        projects = json_info[:]
        for i in range(len(projects)):
            if projects[i]['root'] == project_root and projects[i][
                    'name'] == project_name:
                projects.pop(i)
                break

        projects.append(new_data)

        with open(data_file, 'w') as f:
            json.dump(projects, f, indent=4)
コード例 #13
0
    def _filter_candidates(
        self, context: UserContext
    ) -> typing.Generator[typing.Tuple[str, Candidates, typing.Any, int], None,
                          None]:
        for source in self._current_sources:
            ctx = source.context
            ctx['matchers'] = context['matchers']
            ctx['input'] = context['input']
            if context['expand']:
                ctx['input'] = expand(ctx['input'])
            if context['smartcase']:
                ctx['ignorecase'] = re.search(r'[A-Z]', ctx['input']) is None
            ctx['async_timeout'] = 0.03
            prev_input = ctx['prev_input']
            if prev_input != ctx['input']:
                ctx['prev_time'] = time.time()
                if ctx['is_interactive']:
                    ctx['event'] = 'interactive'
                    ctx['all_candidates'] = self._gather_source_candidates(
                        ctx, source)
            ctx['prev_input'] = ctx['input']
            if ctx['is_async']:
                ctx['event'] = 'async'
                ctx['all_candidates'] += self._gather_source_candidates(
                    ctx, source)
            if not ctx['all_candidates']:
                yield self._get_source_status(ctx, source,
                                              ctx['all_candidates'],
                                              []), [], [], 0
                continue

            candidates = self._filter_source_candidates(ctx, source)

            partial = candidates[:source.max_candidates]

            for c in partial:
                c['source_name'] = source.name
                c['source_index'] = source.index

            patterns = filterfalse(
                lambda x: x == '',
                (  # type: ignore
                    self._filters[x].convert_pattern(ctx['input'])
                    for x in source.matchers if self._filters[x]))

            status = self._get_source_status(ctx, source,
                                             ctx['all_candidates'], partial)
            # Free memory
            ctx['candidates'] = []

            yield status, partial, patterns, len(ctx['all_candidates'])
コード例 #14
0
    def gather_candidates(self, context: UserContext) -> Candidates:
        context['is_interactive'] = True
        candidates = []

        arg = context['args'][0] if context['args'] else ''
        if arg and arg != 'new' and arg != 'hidden':
            self.error_message(context, f'invalid argument: "{arg}"')

        path = (context['args'][1]
                if len(context['args']) > 1 else context['path'])
        path = abspath(self.vim, path)

        inp = Path(expand(context['input']))
        filename = (str(inp) if inp.is_absolute() else str(
            Path(path).joinpath(inp)))
        if arg == 'new':
            candidates.append({
                'word': filename,
                'abbr': '[new] ' + filename,
                'action__path': abspath(self.vim, filename),
            })
        else:
            file_path = Path(filename)
            glb = str(file_path if file_path.is_dir() else file_path.parent)
            # Note: Path('../.').name convert to ".."
            hidden = arg == 'hidden' or re.match(
                r'\.([^.]|$)',
                str(self.vim.call('fnamemodify', context['input'], ':t')))
            glb += '/.*' if hidden else '/*'
            glb = re.sub(r'//', r'/', glb)
            for f in glob.glob(glb):
                f = re.sub(r'\n', r'\\n', f)

                fullpath = abspath(self.vim, f)
                f_path = Path(f)
                abbr = (str(f_path.relative_to(path))
                        if fullpath != path and f.startswith(path + sep) else
                        fullpath) + (sep if f_path.is_dir() else '')
                candidates.append({
                    'word':
                    f,
                    'abbr':
                    abbr,
                    'kind': ('directory' if f_path.is_dir() else 'file'),
                    'action__path':
                    fullpath,
                })
        return candidates
コード例 #15
0
ファイル: external.py プロジェクト: viniarck/denite.nvim
    def _init_args(self, context: UserContext) -> typing.List[str]:
        patterns = ['.*'.join(util.split_input(context['input']))]

        args = [util.expand(self.vars['command'][0])]
        args += self.vars['command'][1:]
        args += self.vars['default_opts']
        if self.vars['pattern_opt']:
            for pattern in patterns:
                args += self.vars['pattern_opt'] + [pattern]
            args += self.vars['separator']
        else:
            args += self.vars['separator']
            args += patterns
        args.append(context['__path'])
        args += self.vars['final_opts']
        return args
コード例 #16
0
ファイル: grep.py プロジェクト: octaltree/denite.nvim
 def _init_grep_args(self, context: UserContext) -> typing.List[str]:
     args = [util.expand(self.vars['command'][0])]
     args += self.vars['command'][1:]
     args += self.vars['default_opts']
     args += self.vars['recursive_opts']
     args += context['__arguments']
     if self.vars['pattern_opt']:
         for pattern in context['__patterns']:
             args += self.vars['pattern_opt'] + [pattern]
         args += self.vars['separator']
     else:
         args += self.vars['separator']
         args += context['__patterns']
     if context['__paths']:
         args += context['__paths']
     args += self.vars['final_opts']
     return args
コード例 #17
0
    def gather_candidates(self, context: UserContext) -> Candidates:
        context['is_interactive'] = True
        candidates = []

        new = context['args'][0] if context['args'] else ''
        if new and new != 'new':
            self.error_message(context, f'invalid argument: "{new}"')

        path = (context['args'][1]
                if len(context['args']) > 1 else context['path'])
        path = abspath(self.vim, path)

        inp = Path(expand(context['input']))
        filename = (str(inp) if inp.is_absolute() else str(
            Path(path).joinpath(inp)))
        if new == 'new':
            candidates.append({
                'word': filename,
                'abbr': '[new] ' + filename,
                'action__path': abspath(self.vim, filename),
            })
        else:
            file_path = Path(filename)
            glb = str(file_path)
            glb += '/.*' if str(file_path.name).startswith('.') else '/*'
            for f in glob.glob(glb):
                fullpath = abspath(self.vim, f)
                f = re.sub(r'\n', r'\\n', f)
                f_path = Path(f)
                abbr = (str(f_path.relative_to(path)) if fullpath != path
                        and f.startswith(path + '/') else str(f_path.resolve())
                        ) + ('/' if f_path.is_dir() else '')
                candidates.append({
                    'word':
                    f,
                    'abbr':
                    abbr,
                    'kind': ('directory' if f_path.is_dir() else 'file'),
                    'action__path':
                    fullpath,
                })
        return candidates
コード例 #18
0
ファイル: grep.py プロジェクト: unikuragit/denite.nvim
    def gather_candidates(self, context):
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if (not context['input'] or len(context['input']) <
                    self.vars['min_interactive_pattern']):
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))
            ]

        if context['__proc']:
            return self._async_gather_candidates(context,
                                                 context['async_timeout'])

        if not context['__patterns'] or not self.vars['command']:
            return []

        args = [util.expand(self.vars['command'][0])]
        args += self.vars['command'][1:]
        args += self.vars['default_opts']
        args += self.vars['recursive_opts']
        args += context['__arguments']
        if self.vars['pattern_opt']:
            for pattern in context['__patterns']:
                args += self.vars['pattern_opt'] + [pattern]
            args += self.vars['separator']
        else:
            args += self.vars['separator']
            args += context['__patterns']
        if context['__paths']:
            args += context['__paths']
        else:
            args += self.vars['final_opts']

        self.print_message(context, args)

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
コード例 #19
0
    def init_grep_args(self, context: UserContext) -> typing.List[str]:
        patterns = ['.*'.join(split_input(context['input']))]

        # Backwards compatibility for `ack`
        if (self.vars['grep_command'] and self.vars['grep_command'][0] == 'ack'
                and self.vars['grep_pattern_opt'] == ['-e']):
            self.vars['grep_pattern_opt'] = ['--match']

        args = [expand(self.vars['grep_command'][0])]
        args += self.vars['grep_command'][1:]
        args += self.vars['grep_default_opts']
        if self.vars['grep_pattern_opt']:
            for pattern in patterns:
                args += self.vars['grep_pattern_opt'] + [pattern]
            args += self.vars['grep_separator']
        else:
            args += self.vars['grep_separator']
            args += patterns
        args.append(context['__path'])
        args += self.vars['grep_final_opts']
        return args
コード例 #20
0
ファイル: grep.py プロジェクト: arvinddeshpande/dotvim
    def gather_candidates(self, context):
        if context['event'] == 'interactive':
            # Update input
            self.on_close(context)

            if (not context['input'] or
                    len(context['input']) <
                    self.vars['min_interactive_pattern']):
                return []

            context['__patterns'] = [
                '.*'.join(util.split_input(context['input']))]

        if context['__proc']:
            return self._async_gather_candidates(
                context, context['async_timeout'])

        if not context['__patterns'] or not self.vars['command']:
            return []

        args = [util.expand(self.vars['command'][0])]
        args += self.vars['command'][1:]
        args += self.vars['default_opts']
        args += self.vars['recursive_opts']
        args += context['__arguments']
        if self.vars['pattern_opt']:
            for pattern in context['__patterns']:
                args += self.vars['pattern_opt'] + [pattern]
            args += self.vars['separator']
        else:
            args += self.vars['separator']
            args += context['__patterns']
        if context['__paths']:
            args += context['__paths']
        args += self.vars['final_opts']

        self.print_message(context, args)

        context['__proc'] = process.Process(args, context, context['path'])
        return self._async_gather_candidates(context, 0.5)
コード例 #21
0
ファイル: projectile.py プロジェクト: ywncmt/projectile.nvim
    def action_delete(self, context):
        """Remove a project from *projects.json*."""
        target = context['targets'][0]
        target_date = target['timestamp']
        target_name = target['name']
        data_file = expand(self.vars['data_dir'] + '/projects.json')
        confirmation = self.vim.call('confirm',
                                     "Remove {}?".format(target_name),
                                     "&Yes\n&No")
        if confirmation == 2:
            return
        else:
            with open(data_file, 'r') as g:
                content = json.load(g)
                projects = content[:]
                for i in range(len(projects)):
                    if projects[i]['timestamp'] == target_date:
                        projects.pop(i)
                        break

                with open(data_file, 'w') as f:
                    json.dump(projects, f, indent=2)
コード例 #22
0
    def action_delete(self, context):
        """Remove a bookmark from `projectile#data_dir`/bookmarks.json."""
        target = context['targets'][0]
        target_date = target['timestamp']
        target_name = target['name']
        data_file = util.expand(self.vars['data_dir'] + '/bookmarks.json')

        confirmation = self.vim.call('confirm', "Delete bookmark: '{}' ?",
                                     "&Yes\n&No".format(target_name))
        if confirmation == 2:
            return
        else:
            with open(data_file, 'r') as g:
                content = json.load(g)
                bookmarks = content[:]
                for i in range(len(bookmarks)):
                    if bookmarks[i]['timestamp'] == target_date:
                        bookmarks.pop(i)
                        break

            with open(data_file, 'w') as f:
                json.dump(bookmarks, f, indent=2)
コード例 #23
0
    def gather_candidates(self, context: UserContext) -> Candidates:
        context['is_interactive'] = True
        candidates = []

        new = context['args'][0] if context['args'] else ''
        if new and new != 'new':
            self.error_message(context, f'invalid argument: "{new}"')

        path = (context['args'][1] if len(context['args']) > 1
                else context['path'])
        path = abspath(self.vim, path)

        inp = expand(context['input'])
        filename = (inp if os.path.isabs(inp) else os.path.join(path, inp))
        if new == 'new':
            candidates.append({
                'word': filename,
                'abbr': '[new] ' + filename,
                'action__path': abspath(self.vim, filename),
            })
        else:
            glb = os.path.dirname(filename) if os.path.dirname(
                filename) != '/' else ''
            glb += '/.*' if os.path.basename(
                filename).startswith('.') else '/*'
            for f in glob.glob(glb):
                fullpath = abspath(self.vim, f)
                f = re.sub(r'\n', r'\\n', f)
                isdir = os.path.isdir(f)
                candidates.append({
                    'word': f,
                    'abbr': (os.path.relpath(f, path) if fullpath != path
                             else os.path.normpath(f)) + (
                                 '/' if isdir else ''),
                    'kind': ('directory' if isdir else 'file'),
                    'action__path': fullpath,
                })
        return candidates
コード例 #24
0
ファイル: hoogle.py プロジェクト: Vftdan/denite-hoogle.nvim
    def gather_candidates(self, context):
        if context["event"] == "interactive":
            self.on_close(context)
            context["__query"] = context["input"]

        if context["__proc"]:
            return self._async_gather_candidates(context,
                                                 context["async_timeout"])

        if not self.vars["command"]:
            return [{"word": "No hoogle command configured."}]

        args = [util.expand(self.vars["command"][0])]
        args += self.vars["command"][1:]
        args += self.vars["default_opts"]
        args.append("--")
        if context["__query"]:
            args += util.split_input(context["__query"])

        self.print_message(context, args)

        context["__proc"] = process.Process(args, context, context["path"])
        return self._async_gather_candidates(context, 0.5)
コード例 #25
0
ファイル: expand_input.py プロジェクト: ujihisa/denite.nvim
 def filter(self, context: UserContext) -> Candidates:
     context['input'] = expand(context['input'])
     return list(context['candidates'])
コード例 #26
0
ファイル: project.py プロジェクト: arvinddeshpande/dotvim
 def on_init(self, context):
     folders = self.vim.vars.get('project_folders', [])
     context['__folders'] = [util.expand(normpath(x)) for x in folders]
コード例 #27
0
ファイル: old.py プロジェクト: nitomoki/dotfiles
 def gather_candidates(self, context):
     return [{'word': x, 'action__path': x}
             for x in [expand(x) for x in
                       self.vim.call('denite#helper#_get_oldfiles')]]
コード例 #28
0
 def gather_candidates(self, context):
     return [{'word': x, 'action__path': x}
             for x in [expand(x) for x in self.vim.eval('v:oldfiles')]
             if path.isfile(x) or self.vim.call('buflisted', x)]
コード例 #29
0
ファイル: file_old.py プロジェクト: sy4may0/neovim-init.vim
 def gather_candidates(self, context):
     return [{
         'word': x,
         'action__path': x
     } for x in [expand(x) for x in self.vim.eval('v:oldfiles')]
             if path.isfile(x) or self.vim.call('buflisted', x)]
コード例 #30
0
ファイル: commands.py プロジェクト: arvinddeshpande/dotvim
 def on_init(self, context):
     context['__config'] = util.expand(self.vars['config'])
コード例 #31
0
 def on_init(self, context):
     folders = self.vim.vars.get('project_folders', [])
     context['__folders'] = [util.expand(normpath(x)) for x in folders]
コード例 #32
0
ファイル: file_point.py プロジェクト: shouyu/denite.nvim
 def on_init(self, context):
     context['__line'] = self.vim.current.line
     context['__cfile'] = expand(self.vim.call('expand', '<cfile>'))
コード例 #33
0
ファイル: old.py プロジェクト: lilydjwg/dotvim
 def gather_candidates(self, context):
     oldfiles = [
         expand(x) for x in self.vim.call('denite#helper#_get_oldfiles')
         if not self.vim.call('bufexists', x) or
         self.vim.call('getbufvar', x, '&buftype') == '']
     return [{'word': x, 'action__path': x} for x in oldfiles]
コード例 #34
0
ファイル: child.py プロジェクト: kan-bayashi/denite.nvim
    def _filter_candidates(self, context):
        for source in self._current_sources:
            ctx = source.context
            ctx['matchers'] = context['matchers']
            ctx['input'] = context['input']
            if context['expand']:
                ctx['input'] = expand(ctx['input'])
            if context['smartcase']:
                ctx['ignorecase'] = re.search(r'[A-Z]', ctx['input']) is None
            ctx['mode'] = context['mode']
            ctx['async_timeout'] = 0.03 if ctx['mode'] != 'insert' else 0.02
            if ctx['prev_input'] != ctx['input']:
                ctx['prev_time'] = time.time()
                if ctx['is_interactive']:
                    ctx['event'] = 'interactive'
                    ctx['all_candidates'] = self._gather_source_candidates(
                        ctx, source)
            ctx['prev_input'] = ctx['input']
            entire = ctx['all_candidates']
            if ctx['is_async']:
                ctx['event'] = 'async'
                entire += self._gather_source_candidates(ctx, source)
            if len(entire) > 20000 and (time.time() - ctx['prev_time'] <
                                        int(context['skiptime']) / 1000.0):
                ctx['is_skipped'] = True
                yield self._get_source_status(ctx, source, entire, []), [], []
                continue
            if not entire:
                yield self._get_source_status(ctx, source, entire, []), [], []
                continue

            ctx['is_skipped'] = False
            partial = []
            ctx['candidates'] = entire
            for i in range(0, len(entire), 1000):
                ctx['candidates'] = entire[i:i + 1000]
                matchers = [
                    self._filters[x]
                    for x in (ctx['matchers'].split(',')
                              if ctx['matchers'] else source.matchers)
                    if x in self._filters
                ]
                self._match_candidates(ctx, matchers)
                partial += ctx['candidates']
                if len(partial) >= source.max_candidates:
                    break
            ctx['candidates'] = partial
            for f in [
                    self._filters[x]
                    for x in source.sorters + source.converters
                    if x in self._filters
            ]:
                ctx['candidates'] = f.filter(ctx)
            partial = ctx['candidates'][:source.max_candidates]
            for c in partial:
                c['source_name'] = source.name
                c['source_index'] = source.index
            ctx['candidates'] = []

            patterns = filterfalse(
                lambda x: x == '',
                (self._filters[x].convert_pattern(ctx['input'])
                 for x in source.matchers if self._filters[x]))

            yield self._get_source_status(ctx, source, entire,
                                          partial), partial, patterns
コード例 #35
0
 def on_init(self, context):
     context['__line'] = self.vim.call('getline', '.')
     context['__cfile'] = expand(self.vim.call('expand', '<cfile>'))
コード例 #36
0
ファイル: commands.py プロジェクト: arvinddeshpande/dotvim
 def on_init(self, context):
     context['__config'] = util.expand(self.vars['config'])
コード例 #37
0
 def on_init(self, context):
     context['__line'] = self.vim.current.line
     context['__cfile'] = expand(self.vim.call('expand', '<cfile>'))