コード例 #1
0
ファイル: default.py プロジェクト: lilydjwg/dotvim
    def update_buffer(self):
        if self._bufnr != self._vim.current.buffer.number:
            return

        self.update_status()

        if self._vim.call('hlexists', 'deniteMatchedRange'):
            self._vim.command('silent! syntax clear deniteMatchedRange')
        if self._vim.call('hlexists', 'deniteMatchedChar'):
            self._vim.command('silent! syntax clear deniteMatchedChar')
        if self._matched_pattern != '':
            self._vim.command(
                r'silent! syntax match deniteMatchedRange /\c%s/ contained' %
                (regex_convert_py_vim(self._matched_pattern))
            )
            self._vim.command((
                'silent! syntax match deniteMatchedChar /[%s]/ '
                'containedin=deniteMatchedRange contained'
            ) % re.sub(
                r'([\[\]\\^-])',
                r'\\\1',
                self._context['input'].replace(' ', '')
            ))

        self._vim.current.buffer[:] = self._displayed_texts
        self.resize_buffer()

        self.move_cursor()
コード例 #2
0
ファイル: default.py プロジェクト: isJone99/dotvim
    def update_buffer(self):
        if self._bufnr != self._vim.current.buffer.number:
            return

        self.update_status()

        if self._vim.call('hlexists', 'deniteMatchedRange'):
            self._vim.command('silent! syntax clear deniteMatchedRange')
        if self._vim.call('hlexists', 'deniteMatchedChar'):
            self._vim.command('silent! syntax clear deniteMatchedChar')
        if self._matched_pattern != '':
            self._vim.command(
                'silent! syntax match deniteMatchedRange /%s/ contained' % (
                    regex_convert_py_vim(self._matched_pattern),
                )
            )
            self._vim.command((
                'silent! syntax match deniteMatchedChar /[%s]/ '
                'containedin=deniteMatchedRange contained'
            ) % re.sub(
                r'([[\]\\^-])',
                r'\\\1',
                self._context['input'].replace(' ', '')
            ))

        self._vim.current.buffer[:] = self._displayed_texts
        self.resize_buffer()

        if self._context['reversed']:
            self._vim.command('normal! zb')

        self.move_cursor()
コード例 #3
0
    def update_buffer(self):
        max_len = len(str(self._candidates_len))
        linenr = ('{:' + str(max_len) + '}/{:' + str(max_len) + '}').format(
            self._cursor + self._win_cursor, self._candidates_len)
        mode = '-- ' + self._current_mode.upper() + ' -- '
        self._bufvars['denite_statusline_mode'] = mode
        self._bufvars['denite_statusline_sources'] = self._statusline_sources
        self._bufvars['denite_statusline_path'] = ('[' +
                                                   self._context['path'] + ']')
        self._bufvars['denite_statusline_linenr'] = linenr

        self._vim.command('silent! syntax clear deniteMatchedRange')
        self._vim.command('silent! syntax clear deniteMatchedChar')
        if self._matched_pattern != '':
            self._vim.command(
                'silent! syntax match deniteMatchedRange /%s/ contained' %
                (regex_convert_py_vim(self._matched_pattern), ))
            self._vim.command(('silent! syntax match deniteMatchedChar /[%s]/ '
                               'containedin=deniteMatchedRange contained') %
                              re.sub(r'([[\]\\^-])', r'\\\1',
                                     self._context['input'].replace(' ', '')))

        del self._vim.current.buffer[:]
        self._vim.current.buffer.append([
            self.get_candidate_display_text(i) for i in range(
                self._cursor,
                min(self._candidates_len, self._cursor + self._winheight))
        ])
        del self._vim.current.buffer[0]
        self.resize_buffer()

        self._options['modified'] = False

        self.move_cursor()
コード例 #4
0
ファイル: default.py プロジェクト: hirsaeki/denite.nvim
    def _update_buffer(self) -> None:
        if self._bufnr != self._vim.current.buffer.number:
            return

        self._update_status()

        if self._vim.call('hlexists', 'deniteMatchedRange'):
            self._vim.command('silent! syntax clear deniteMatchedRange')
        if self._vim.call('hlexists', 'deniteMatchedChar'):
            self._vim.command('silent! syntax clear deniteMatchedChar')
        if self._matched_pattern != '':
            self._vim.command(
                r'silent! syntax match deniteMatchedRange /\c%s/ contained' %
                (regex_convert_py_vim(self._matched_pattern))
            )
            self._vim.command((
                'silent! syntax match deniteMatchedChar /[%s]/ '
                'containedin=deniteMatchedRange contained'
            ) % re.sub(
                r'([\[\]\\^-])',
                r'\\\1',
                self._context['input'].replace(' ', '')
            ))

        prev_linenr = self._vim.call('line', '.')
        prev_candidate = self._get_cursor_candidate()

        self._options['modifiable'] = True
        self._vim.vars['denite#_candidates'] = [
            x['word'] for x in self._candidates]
        self._vim.current.buffer[:] = self._displayed_texts
        self._options['modifiable'] = False
        self._resize_buffer()

        self._vim.call('cursor', [prev_linenr, 0])

        if self._updated and (self._context['reversed'] or
                              self._previous_text != self._context['input']):
            self._previous_text = self._context['input']
            self._init_cursor()
            self._move_to_pos(self._cursor)

        if (self._context['auto_action'] and
                prev_candidate != self._get_cursor_candidate()):
            self.do_action(self._context['auto_action'])

        self._updated = False
        self._stop_timer('update_buffer')
コード例 #5
0
    def update_buffer(self):
        self.update_status()

        self._vim.command('silent! syntax clear deniteMatchedRange')
        self._vim.command('silent! syntax clear deniteMatchedChar')
        if self._matched_pattern != '':
            self._vim.command(
                'silent! syntax match deniteMatchedRange /%s/ contained' %
                (regex_convert_py_vim(self._matched_pattern), ))
            self._vim.command(('silent! syntax match deniteMatchedChar /[%s]/ '
                               'containedin=deniteMatchedRange contained') %
                              re.sub(r'([[\]\\^-])', r'\\\1',
                                     self._context['input'].replace(' ', '')))

        del self._vim.current.buffer[:]
        self._vim.current.buffer.append(self._displayed_texts)
        del self._vim.current.buffer[0]
        self.resize_buffer()

        self._options['modified'] = False

        self.move_cursor()
コード例 #6
0
def test_regex_convert_py_vim():
    assert util.regex_convert_py_vim(r'/foo/') == r'\v\/foo\/'
    assert util.regex_convert_py_vim(r'~foo') == r'\v\~foo'
コード例 #7
0
def test_regex_convert_py_vim():
    assert util.regex_convert_py_vim(r'/foo/') == r'\v\/foo\/'
    assert util.regex_convert_py_vim(r'~foo') == r'\v\~foo'
コード例 #8
0
ファイル: default.py プロジェクト: take/denite.nvim
    def _update_buffer(self) -> None:
        is_current_buffer = self._bufnr == self._vim.current.buffer.number

        self._update_status()

        if self._check_matchdelete and self._context['match_highlight']:
            matches = [
                x['id'] for x in self._vim.call('getmatches', self._winid)
            ]
            if self._matched_range_id in matches:
                self._vim.call('matchdelete', self._matched_range_id,
                               self._winid)
                self._matched_range_id = -1
            if self._matched_char_id in matches:
                self._vim.call('matchdelete', self._matched_char_id,
                               self._winid)
                self._matched_char_id = -1

            if self._matched_pattern != '':
                self._matched_range_id = self._vim.call(
                    'matchadd', 'deniteMatchedRange',
                    r'\c' + regex_convert_py_vim(self._matched_pattern), 10,
                    -1, {'window': self._winid})
                matched_char_pattern = '[{}]'.format(
                    re.sub(r'([\[\]\\^-])', r'\\\1',
                           self._context['input'].replace(' ', '')))
                self._matched_char_id = self._vim.call('matchadd',
                                                       'deniteMatchedChar',
                                                       matched_char_pattern,
                                                       10, -1,
                                                       {'window': self._winid})

        prev_linenr = self._vim.call('line', '.')
        prev_candidate = self._get_cursor_candidate()

        buffer = self._vim.buffers[self._bufnr]
        buffer.options['modifiable'] = True
        self._vim.vars['denite#_candidates'] = [
            x['word'] for x in self._candidates
        ]
        buffer[:] = self._displayed_texts
        buffer.options['modifiable'] = False

        self._previous_text = self._context['input']

        self._resize_buffer(is_current_buffer)

        is_changed = (self._context['reversed']
                      or (is_current_buffer
                          and self._previous_text != self._context['input']))
        if self._updated and is_changed:
            if not is_current_buffer:
                save_winid = self._vim.call('win_getid')
                self._vim.call('win_gotoid', self._winid)
            self._init_cursor()
            self._move_to_pos(self._cursor)
            if not is_current_buffer:
                self._vim.call('win_gotoid', save_winid)
        elif is_current_buffer:
            self._vim.call('cursor', [prev_linenr, 0])

        if is_current_buffer:
            if (self._context['auto_action']
                    and prev_candidate != self._get_cursor_candidate()):
                self.do_action(self._context['auto_action'])

        self._updated = False
        self._stop_timer('update_buffer')