From 0c91ad5ed251d1ca5320082e84b27e9c148a0aa7 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Thu, 28 Mar 2019 11:16:26 +0900 Subject: [PATCH 001/144] Add _main.py --- doc/denite.txt | 1 - rplugin/python3/denite/_main.py | 62 +++++++++++++++++++++++++++++++++ rplugin/python3/denite/async.py | 27 ++++++++++++++ rplugin/python3/denite/util.py | 14 ++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 rplugin/python3/denite/_main.py create mode 100644 rplugin/python3/denite/async.py diff --git a/doc/denite.txt b/doc/denite.txt index 27849c553..8d8d93faf 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -103,7 +103,6 @@ You can enable Python3 interface with pip > If you want to read for Neovim-python/python3 interface install documentation, you should read |nvim-python| and the Wiki. -https://github.com/zchee/deoplete-jedi/wiki/Setting-up-Python-for-Neovim You can check the Python3 installation |:checkhealth| command. diff --git a/rplugin/python3/denite/_main.py b/rplugin/python3/denite/_main.py new file mode 100644 index 000000000..72367ce95 --- /dev/null +++ b/rplugin/python3/denite/_main.py @@ -0,0 +1,62 @@ +# ============================================================================ +# FILE: _main.py +# AUTHOR: Shougo Matsushita +# License: MIT license +# ============================================================================ + +import sys +import io + +from importlib.util import find_spec +if find_spec('pynvim'): + from pynvim import attach +else: + from neovim import attach + + +def attach_vim(serveraddr): + if len(serveraddr.split(':')) == 2: + serveraddr, port = serveraddr.split(':') + port = int(port) + vim = attach('tcp', address=serveraddr, port=port) + else: + vim = attach('socket', path=serveraddr) + + # sync path + for path in vim.call( + 'globpath', vim.options['runtimepath'], + 'rplugin/python3', 1).split('\n'): + sys.path.append(path) + # Remove current path + del sys.path[0] + + return vim + + +class RedirectStream(io.IOBase): + def __init__(self, handler): + self.handler = handler + + def write(self, line): + self.handler(line) + + def writelines(self, lines): + self.handler('\n'.join(lines)) + + +def main(serveraddr): + vim = attach_vim(serveraddr) + from denite.child import Child + from denite.util import error_tb + stdout = sys.stdout + sys.stdout = RedirectStream(lambda data: vim.out_write(data)) + sys.stderr = RedirectStream(lambda data: vim.err_write(data)) + try: + child = Child(vim) + child.main_loop(stdout) + except Exception as exc: + error_tb(vim, 'Error in child: %r' % exc) + + +if __name__ == '__main__': + main(sys.argv[1]) diff --git a/rplugin/python3/denite/async.py b/rplugin/python3/denite/async.py new file mode 100644 index 000000000..4f4a2bca2 --- /dev/null +++ b/rplugin/python3/denite/async.py @@ -0,0 +1,27 @@ +# ============================================================================ +# FILE: async.py +# AUTHOR: Shougo Matsushita +# License: MIT license +# ============================================================================ + +import asyncio + + +class Process(asyncio.SubprocessProtocol): + + def __init__(self, plugin): + self._plugin = plugin + self._vim = plugin._vim + + def connection_made(self, transport): + self._unpacker = self._plugin._connect_stdin( + transport.get_pipe_transport(0)) + + def pipe_data_received(self, fd, data): + unpacker = self._unpacker + unpacker.feed(data) + for child_out in unpacker: + self._plugin._queue_out.put(child_out) + + def process_exited(self): + pass diff --git a/rplugin/python3/denite/util.py b/rplugin/python3/denite/util.py index 293bbb5bf..62a78acb4 100644 --- a/rplugin/python3/denite/util.py +++ b/rplugin/python3/denite/util.py @@ -9,6 +9,7 @@ import re import os import sys +import traceback from glob import glob from os.path import normpath, normcase, join, dirname, exists @@ -46,6 +47,19 @@ def error(vim, expr): vim.call('denite#util#print_error', string) +def error_tb(vim, msg): + lines = [] + t, v, tb = sys.exc_info() + if t and v and tb: + lines += traceback.format_exc().splitlines() + lines += ['%s. Use :messages / see above for error details.' % msg] + if hasattr(vim, 'err_write'): + vim.err_write('[denite] %s\n' % '\n'.join(lines)) + else: + for line in lines: + error(vim, line) + + def clear_cmdline(vim): vim.command('redraw | echo') From 42b3826fdff527db069cc0716f9a7a17afa3d606 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Fri, 29 Mar 2019 12:11:47 +0900 Subject: [PATCH 002/144] Improve child call --- autoload/denite/init.vim | 6 +++++ rplugin/python3/denite/child.py | 38 ++++++++++++++++++---------- rplugin/python3/denite/parent.py | 15 ++++++++++- rplugin/python3/denite/ui/default.py | 4 +-- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/autoload/denite/init.vim b/autoload/denite/init.vim index f55c7cacb..26ee0e8b2 100644 --- a/autoload/denite/init.vim +++ b/autoload/denite/init.vim @@ -49,6 +49,7 @@ function! denite#init#_initialize() abort endif call _denite_init() endif + call s:initialize_variables() catch if denite#util#has_yarp() if !has('nvim') && !exists('*neovim_rpc#serveraddr') @@ -69,6 +70,11 @@ function! denite#init#_initialize() abort return 1 endtry endfunction +function! s:initialize_variables() abort + let g:denite#_previewed_buffers = {} + let g:denite#_ret = {} + let g:denite#_async_ret = {} +endfunction function! denite#init#_user_options() abort return { diff --git a/rplugin/python3/denite/child.py b/rplugin/python3/denite/child.py index 5d8f5149f..ad13d213d 100644 --- a/rplugin/python3/denite/child.py +++ b/rplugin/python3/denite/child.py @@ -195,10 +195,10 @@ def filter_candidates(self, context): candidates.reverse() if self.is_async(): statuses.append('[async]') - return (pattern, statuses, candidates) + return [pattern, statuses, candidates] def do_action(self, context, action_name, targets): - action = self.get_action(context, action_name, targets) + action = self._get_action_targets(context, action_name, targets) if not action: return True @@ -216,16 +216,16 @@ def do_action(self, context, action_name, targets): action['kind'], action['name'], context) def get_action(self, context, action_name, targets): - actions = set() - action = None - for target in targets: - action = self._get_action(context, action_name, target) - if action: - actions.add(action['name']) - if len(actions) > 1: - self.error('Multiple actions are detected: ' + action_name) - return {} - return action if actions else {} + action = self._get_action_targets(context, action_name, targets) + if not action: + return action + + return { + 'name': action['name'], + 'kind': action['kind'], + 'is_quit': action['is_quit'], + 'is_redraw': action['is_redraw'], + } def get_action_names(self, context, targets): kinds = set() @@ -326,6 +326,18 @@ def _gather_source_candidates(self, context, source): candidate['word'] = candidate['word'][: max_len] return candidates + def _get_action_targets(self, context, action_name, targets): + actions = set() + action = None + for target in targets: + action = self._get_action_target(context, action_name, target) + if action: + actions.add(action['name']) + if len(actions) > 1: + self.error('Multiple actions are detected: ' + action_name) + return {} + return action if actions else {} + def _get_source_status(self, context, source, entire, partial): return (source.get_status(context) if not partial else f'{source.get_status(context)}' @@ -455,7 +467,7 @@ def _get_kind(self, context, target): return kind - def _get_action(self, context, action_name, target): + def _get_action_target(self, context, action_name, target): kind = self._get_kind(context, target) if not kind: return {} diff --git a/rplugin/python3/denite/parent.py b/rplugin/python3/denite/parent.py index 1f976caae..d0dafefe3 100644 --- a/rplugin/python3/denite/parent.py +++ b/rplugin/python3/denite/parent.py @@ -4,6 +4,8 @@ # License: MIT license # ============================================================================ +import time + class _Parent(object): def __init__(self, vim): @@ -50,4 +52,15 @@ def _start_process(self): self._child = Child(self._vim) def _put(self, name, args): - return self._child.main(name, args, queue_id=None) + queue_id = str(int(time.time() * 1000)) + self._vim.vars['denite#_ret'] = {} + + ret = self._child.main(name, args, queue_id=queue_id) + if not ret: + return + + _ret = self._vim.vars['denite#_ret'] + _ret[queue_id] = ret + self._vim.vars['denite#_ret'] = _ret + + return self._vim.vars['denite#_ret'][queue_id] diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 721fdbb7d..6d0914397 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -330,8 +330,8 @@ def init_cursor(self): self.move_to_last_line() def update_candidates(self): - (pattern, statuses, - self._candidates) = self._denite.filter_candidates(self._context) + [pattern, statuses, + self._candidates] = self._denite.filter_candidates(self._context) prev_matched_pattern = self._matched_pattern self._matched_pattern = pattern From d703b20a2d707ee6f019a71859527b0b5ea5d351 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Fri, 29 Mar 2019 12:21:46 +0900 Subject: [PATCH 003/144] Remove is_async() RPC --- rplugin/python3/denite/child.py | 4 +--- rplugin/python3/denite/parent.py | 3 --- rplugin/python3/denite/ui/default.py | 9 +++++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/rplugin/python3/denite/child.py b/rplugin/python3/denite/child.py index ad13d213d..a54130ffc 100644 --- a/rplugin/python3/denite/child.py +++ b/rplugin/python3/denite/child.py @@ -47,8 +47,6 @@ def main(self, name, args, queue_id): ret = self.get_action(args[0], args[1], args[2]) elif name == 'get_action_names': ret = self.get_action_names(args[0], args[1]) - elif name == 'is_async': - ret = self.is_async() return ret def start(self, context): @@ -195,7 +193,7 @@ def filter_candidates(self, context): candidates.reverse() if self.is_async(): statuses.append('[async]') - return [pattern, statuses, candidates] + return [self.is_async(), pattern, statuses, candidates] def do_action(self, context, action_name, targets): action = self._get_action_targets(context, action_name, targets) diff --git a/rplugin/python3/denite/parent.py b/rplugin/python3/denite/parent.py index d0dafefe3..654377c5c 100644 --- a/rplugin/python3/denite/parent.py +++ b/rplugin/python3/denite/parent.py @@ -42,9 +42,6 @@ def get_action(self, context, action_name, targets): def get_action_names(self, context, targets): return self._put('get_action_names', [context, targets]) - def is_async(self): - return self._put('is_async', []) - class SyncParent(_Parent): def _start_process(self): diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 6d0914397..16533dc97 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -20,7 +20,7 @@ class Default(object): @property def is_async(self): - return self._denite.is_async() + return self._is_async @property def current_mode(self): @@ -48,6 +48,7 @@ def __init__(self, vim): self._winminheight = -1 self._scroll = 0 self._is_multi = False + self._is_async = False self._matched_pattern = '' self._displayed_texts = [] self._statusline_sources = '' @@ -330,7 +331,7 @@ def init_cursor(self): self.move_to_last_line() def update_candidates(self): - [pattern, statuses, + [self._is_async, pattern, statuses, self._candidates] = self._denite.filter_candidates(self._context) prev_matched_pattern = self._matched_pattern @@ -344,7 +345,7 @@ def update_candidates(self): updated = (self._displayed_texts != prev_displayed_texts or self._matched_pattern != prev_matched_pattern) - if updated and self._denite.is_async() and self._context['reversed']: + if updated and self._is_async and self._context['reversed']: self.init_cursor() return updated @@ -501,7 +502,7 @@ def check_option(self): self.do_immediately() return True return not (self._context['empty'] or - self._denite.is_async() or self._candidates) + self._is_async or self._candidates) def do_immediately(self): goto = self._winid > 0 and self._vim.call( From 05f68fb2583ab9e49ca5d2ce525da447b231b6e1 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 31 Mar 2019 20:43:26 +0900 Subject: [PATCH 004/144] WIP: add _main.py --- {rplugin/python3 => autoload}/denite/_main.py | 0 autoload/denite/init.vim | 7 + .../python3/denite/{async.py => aprocess.py} | 2 +- rplugin/python3/denite/child.py | 34 +++++ rplugin/python3/denite/parent.py | 125 +++++++++++++++++- rplugin/python3/denite/ui/default.py | 5 +- 6 files changed, 166 insertions(+), 7 deletions(-) rename {rplugin/python3 => autoload}/denite/_main.py (100%) rename rplugin/python3/denite/{async.py => aprocess.py} (97%) diff --git a/rplugin/python3/denite/_main.py b/autoload/denite/_main.py similarity index 100% rename from rplugin/python3/denite/_main.py rename to autoload/denite/_main.py diff --git a/autoload/denite/init.vim b/autoload/denite/init.vim index 26ee0e8b2..878a0c50a 100644 --- a/autoload/denite/init.vim +++ b/autoload/denite/init.vim @@ -74,6 +74,13 @@ function! s:initialize_variables() abort let g:denite#_previewed_buffers = {} let g:denite#_ret = {} let g:denite#_async_ret = {} + let g:denite#_serveraddr = + \ denite#util#has_yarp() ? + \ neovim_rpc#serveraddr() : v:servername + if g:denite#_serveraddr ==# '' + " Use NVIM_LISTEN_ADDRESS + let g:denite#_serveraddr = $NVIM_LISTEN_ADDRESS + endif endfunction function! denite#init#_user_options() abort diff --git a/rplugin/python3/denite/async.py b/rplugin/python3/denite/aprocess.py similarity index 97% rename from rplugin/python3/denite/async.py rename to rplugin/python3/denite/aprocess.py index 4f4a2bca2..ad7ddb403 100644 --- a/rplugin/python3/denite/async.py +++ b/rplugin/python3/denite/aprocess.py @@ -1,5 +1,5 @@ # ============================================================================ -# FILE: async.py +# FILE: aprocess.py # AUTHOR: Shougo Matsushita # License: MIT license # ============================================================================ diff --git a/rplugin/python3/denite/child.py b/rplugin/python3/denite/child.py index a54130ffc..bffe1f3bf 100644 --- a/rplugin/python3/denite/child.py +++ b/rplugin/python3/denite/child.py @@ -9,8 +9,10 @@ import_rplugins, expand, split_input, abspath) import copy +import msgpack import os import re +import sys import time from os.path import normpath, normcase from collections import ChainMap @@ -26,6 +28,38 @@ def __init__(self, vim): self._kinds = {} self._runtimepath = '' self._current_sources = [] + self._unpacker = msgpack.Unpacker( + encoding='utf-8', + unicode_errors='surrogateescape') + self._packer = msgpack.Packer( + use_bin_type=True, + encoding='utf-8', + unicode_errors='surrogateescape') + + def main_loop(self, stdout): + while True: + feed = sys.stdin.buffer.raw.read(102400) + if feed is None: + continue + if feed == b'': + # EOF + return + + self._unpacker.feed(feed) + + for child_in in self._unpacker: + name = child_in['name'] + args = child_in['args'] + queue_id = child_in['queue_id'] + + self.debug('hello') + ret = self.main(name, args, queue_id) + if ret: + # self._write(stdout, ret) + _ret = self._vim.vars['denite#_ret'] + _ret[queue_id] = ret + self._vim.vars['denite#_ret'] = _ret + self.debug(_ret) def main(self, name, args, queue_id): ret = None diff --git a/rplugin/python3/denite/parent.py b/rplugin/python3/denite/parent.py index 654377c5c..ece4790d1 100644 --- a/rplugin/python3/denite/parent.py +++ b/rplugin/python3/denite/parent.py @@ -4,7 +4,17 @@ # License: MIT license # ============================================================================ +import asyncio import time +import os +import msgpack +import subprocess +from functools import partial +from pathlib import Path +from queue import Queue + +from denite.aprocess import Process +from denite.util import error_tb, error class _Parent(object): @@ -31,16 +41,16 @@ def init_syntax(self, context, is_multi): self._put('init_syntax', [context, is_multi]) def filter_candidates(self, context): - return self._put('filter_candidates', [context]) + return self._get('filter_candidates', [context]) def do_action(self, context, action_name, targets): - return self._put('do_action', [context, action_name, targets]) + return self._get('do_action', [context, action_name, targets]) def get_action(self, context, action_name, targets): - return self._put('get_action', [context, action_name, targets]) + return self._get('get_action', [context, action_name, targets]) def get_action_names(self, context, targets): - return self._put('get_action_names', [context, targets]) + return self._get('get_action_names', [context, targets]) class SyncParent(_Parent): @@ -61,3 +71,110 @@ def _put(self, name, args): self._vim.vars['denite#_ret'] = _ret return self._vim.vars['denite#_ret'][queue_id] + + def _get(self, name, args): + return self._put(name, args) + + +class ASyncParent(_Parent): + def _start_process(self): + self._stdin = None + self._queue_id = '' + self._queue_in = Queue() + self._queue_out = Queue() + self._packer = msgpack.Packer( + use_bin_type=True, + encoding='utf-8', + unicode_errors='surrogateescape') + self._unpacker = msgpack.Unpacker( + encoding='utf-8', + unicode_errors='surrogateescape') + + startupinfo = None + if os.name == 'nt': + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + + main = str(Path(__file__).parent.parent.parent.parent.joinpath( + 'autoload', 'denite', '_main.py')) + + self._hnd = self._vim.loop.create_task( + self._vim.loop.subprocess_exec( + partial(Process, self), + self._vim.vars.get('python3_host_prog', 'python3'), + main, + self._vim.vars['denite#_serveraddr'], + stderr=None, + startupinfo=startupinfo)) + + def _connect_stdin(self, stdin): + self._stdin = stdin + return self._unpacker + + def filter_candidates(self, context): + if self._queue_id: + # Use previous id + queue_id = self._queue_id + else: + queue_id = self._put('filter_candidates', [context]) + if not queue_id: + return (False, []) + + get = self._get(queue_id, True) + if not get: + # Skip the next merge_results + self._queue_id = queue_id + return [True, '', [], []] + self._queue_id = '' + results = get[0] + return results if results else [False, '', [], []] + + def _put(self, name, args): + if not self._hnd: + return None + + queue_id = str(time.time()) + msg = self._packer.pack({ + 'name': name, 'args': args, 'queue_id': queue_id + }) + self._queue_in.put(msg) + + if self._stdin: + try: + while not self._queue_in.empty(): + self._stdin.write(self._queue_in.get_nowait()) + except BrokenPipeError: + error_tb(self._vim, 'Crash in child process') + error(self._vim, 'stderr=' + str(self._proc.read_error())) + self._hnd = None + return queue_id + + # def _get(self, queue_id, is_async=False): + # if not self._hnd: + # return [] + # + # outs = [] + # while not self._queue_out.empty(): + # outs.append(self._queue_out.get_nowait()) + # try: + # return [x for x in outs if x['queue_id'] == queue_id] + # except TypeError: + # error_tb(self._vim, + # '"stdout" seems contaminated by sources. ' + # '"stdout" is used for RPC; Please pipe or discard') + # return [] + + def _get(self, name, args): + return None + + if not self._hnd: + return + + self._vim.vars['denite#_ret'] = {} + + queue_id = self._put(name, args) + + while queue_id not in self._vim.vars['denite#_ret']: + time.sleep(0.1) + + return self._vim.vars['denite#_ret'][queue_id] diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 16533dc97..945489eac 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -13,7 +13,7 @@ clear_cmdline, echo, error, regex_convert_py_vim, clearmatch) from .action import DEFAULT_ACTION_KEYMAP from .prompt import DenitePrompt -from denite.parent import SyncParent +from denite.parent import ASyncParent, SyncParent from ..prompt.prompt import STATUS_ACCEPT, STATUS_INTERRUPT @@ -69,7 +69,8 @@ def __init__(self, vim): def start(self, sources, context): if not self._denite: - self._denite = SyncParent(self._vim) + # self._denite = SyncParent(self._vim) + self._denite = ASyncParent(self._vim) self._result = [] context['sources_queue'] = [sources] From 490675cd0f2b6aee06c12db2dd912bcd6a0a3ca8 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 24 Apr 2019 08:40:30 +0900 Subject: [PATCH 005/144] Fix for merge --- rplugin/python3/denite/parent.py | 13 +------------ rplugin/python3/denite/ui/default.py | 4 ++-- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/rplugin/python3/denite/parent.py b/rplugin/python3/denite/parent.py index ece4790d1..5e9b32c71 100644 --- a/rplugin/python3/denite/parent.py +++ b/rplugin/python3/denite/parent.py @@ -59,18 +59,7 @@ def _start_process(self): self._child = Child(self._vim) def _put(self, name, args): - queue_id = str(int(time.time() * 1000)) - self._vim.vars['denite#_ret'] = {} - - ret = self._child.main(name, args, queue_id=queue_id) - if not ret: - return - - _ret = self._vim.vars['denite#_ret'] - _ret[queue_id] = ret - self._vim.vars['denite#_ret'] = _ret - - return self._vim.vars['denite#_ret'][queue_id] + return self._child.main(name, args, queue_id=None) def _get(self, name, args): return self._put(name, args) diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 945489eac..9d4820dcd 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -69,8 +69,8 @@ def __init__(self, vim): def start(self, sources, context): if not self._denite: - # self._denite = SyncParent(self._vim) - self._denite = ASyncParent(self._vim) + self._denite = SyncParent(self._vim) + # self._denite = ASyncParent(self._vim) self._result = [] context['sources_queue'] = [sources] From eaf26778d5e54eb847349ce978c1a59d4cdec12f Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 24 Apr 2019 08:43:17 +0900 Subject: [PATCH 006/144] Fix lint --- rplugin/python3/denite/parent.py | 1 - rplugin/python3/denite/ui/default.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/rplugin/python3/denite/parent.py b/rplugin/python3/denite/parent.py index 5e9b32c71..753f50bcc 100644 --- a/rplugin/python3/denite/parent.py +++ b/rplugin/python3/denite/parent.py @@ -4,7 +4,6 @@ # License: MIT license # ============================================================================ -import asyncio import time import os import msgpack diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 9d4820dcd..b71e60eab 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -13,7 +13,7 @@ clear_cmdline, echo, error, regex_convert_py_vim, clearmatch) from .action import DEFAULT_ACTION_KEYMAP from .prompt import DenitePrompt -from denite.parent import ASyncParent, SyncParent +from denite.parent import SyncParent from ..prompt.prompt import STATUS_ACCEPT, STATUS_INTERRUPT From 4e1accb2a16a047a6aac34ff72084467e5d1871d Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 09:34:06 +0900 Subject: [PATCH 007/144] WIP: remove prompt --- autoload/denite/init.vim | 1 - doc/denite.txt | 16 ++--- rplugin/python3/denite/ui/default.py | 94 +++++++--------------------- 3 files changed, 27 insertions(+), 84 deletions(-) diff --git a/autoload/denite/init.vim b/autoload/denite/init.vim index 878a0c50a..98ac5b950 100644 --- a/autoload/denite/init.vim +++ b/autoload/denite/init.vim @@ -132,7 +132,6 @@ function! denite#init#_user_options() abort \ 'updatetime': 100, \ 'skiptime': 500, \ 'unique': v:false, - \ 'use_default_mappings': v:true, \ 'vertical_preview': v:false, \ 'wincol': &columns / 4, \ 'winheight': 20, diff --git a/doc/denite.txt b/doc/denite.txt index 8d8d93faf..c73784fe7 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -1355,18 +1355,6 @@ OPTIONS *denite-options* Specify the buffer updatetime when narrowing. Default: 100 - *denite-option-use-default-mappings* --use-default-mappings - Enable default key mappings. - - Note: that fundamental mappings including or are - also provided by the default key mappings. So disabling this - option without proper custom mappings would make denite - useless. Use to quit the denite if you accidentally - disable this option. - - Default: true - *denite-option-vertical-preview* -vertical-preview Open the preview window vertically. @@ -2383,6 +2371,10 @@ https://github.com/raghur/fruzzy ============================================================================== COMPATIBILITY *denite-compatibility* +2019.05.01 +* Remove prompt.nvim +* "-use-default-mappings" option is deprecated. + 2019.03.24 * "-auto-highlight" and "-auto-preview" options are deprecated. Please use "-auto-action" option instead. diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index b71e60eab..e209b16bc 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -6,15 +6,12 @@ import copy import re -import weakref from itertools import groupby, takewhile from denite.util import ( clear_cmdline, echo, error, regex_convert_py_vim, clearmatch) -from .action import DEFAULT_ACTION_KEYMAP -from .prompt import DenitePrompt from denite.parent import SyncParent -from ..prompt.prompt import STATUS_ACCEPT, STATUS_INTERRUPT +from ..prompt.prompt import STATUS_ACCEPT class Default(object): @@ -52,11 +49,6 @@ def __init__(self, vim): self._matched_pattern = '' self._displayed_texts = [] self._statusline_sources = '' - self._prompt = DenitePrompt( - self._vim, - self._context, - weakref.proxy(self) - ) self._guicursor = '' self._titlestring = '' self._ruler = False @@ -75,23 +67,21 @@ def start(self, sources, context): self._result = [] context['sources_queue'] = [sources] self._sources_history = [] - try: - while context['sources_queue']: - prev_history = copy.copy(self._sources_history) - prev_path = context['path'] - self._start(context['sources_queue'][0], context) + while context['sources_queue']: + prev_history = copy.copy(self._sources_history) + prev_path = context['path'] - if prev_history == self._sources_history: - self._sources_history.append({ - 'sources': context['sources_queue'][0], - 'path': prev_path, - }) + self._start(context['sources_queue'][0], context) + + if prev_history == self._sources_history: + self._sources_history.append({ + 'sources': context['sources_queue'][0], + 'path': prev_path, + }) - context['sources_queue'].pop(0) - context['path'] = self._context['path'] - finally: - self.cleanup() + context['sources_queue'].pop(0) + context['path'] = self._context['path'] return self._result @@ -156,16 +146,6 @@ def _start(self, sources, context): if self._context['quick_move'] and self.quick_move(): return - # Make sure that the caret position is ok - self._prompt.caret.locus = self._prompt.caret.tail - status = self._prompt.start() - if status == STATUS_INTERRUPT: - # STATUS_INTERRUPT is returned when user hit and the loop has - # interrupted. - # In this case, denite cancel any operation and close its window. - self.quit() - return - def init_buffer(self): self._prev_status = dict() self._displayed_texts = [] @@ -364,9 +344,7 @@ def update_displayed_texts(self): self._displayed_texts = [ self.get_candidate_display_text(i) - for i in range(self._cursor, - min(self._candidates_len, - self._cursor + self._winheight)) + for i in range(self._cursor, self._candidates_len) ] def update_buffer(self): @@ -400,11 +378,7 @@ def update_buffer(self): def update_status(self): raw_mode = self._current_mode.upper() - cursor_location = self._cursor + self._win_cursor max_len = len(str(self._candidates_len)) - linenr = ('{:'+str(max_len)+'}/{:'+str(max_len)+'}').format( - cursor_location, - self._candidates_len) mode = '-- ' + raw_mode + ' -- ' if self._context['error_messages']: mode = '[ERROR] ' + mode @@ -414,11 +388,9 @@ def update_status(self): 'mode': mode, 'sources': self._statusline_sources, 'path': path, - 'linenr': linenr, # Extra 'raw_mode': raw_mode, 'buffer_name': self._context['buffer_name'], - 'line_cursor': cursor_location, 'line_total': self._candidates_len, } if status != self._prev_status: @@ -426,14 +398,20 @@ def update_status(self): self._vim.command('redrawstatus') self._prev_status = status + linenr = "printf('%'.(len(line('$'))+2).'d/%d',line('.'),line('$'))" + if self._context['statusline']: status = ( "%#deniteMode#%{denite#get_status('mode')}%* " + "%{denite#get_status('sources')} %=" + - "%#deniteStatusLinePath# %{denite#get_status('path')} %*" + - "%#deniteStatusLineNumber#%{denite#get_status('linenr')}%*") + "%#deniteStatusLinePath# %{denite#get_status('path')}%*" + + "%#deniteStatusLineNumber#%{" + linenr + "}%*") if self._context['split'] == 'floating': - self._vim.options['titlestring'] = status + self._vim.options['titlestring'] = ( + "%{denite#get_status('mode')}%* " + + "%{denite#get_status('sources')} " + + " %{denite#get_status('path')}%*" + + "%{" + linenr + "}%*") else: self._window_options['statusline'] = status @@ -541,39 +519,14 @@ def move_cursor(self): def change_mode(self, mode): self._current_mode = mode - custom = self._context['custom']['map'] - use_default_mappings = self._context['use_default_mappings'] highlight = 'highlight_mode_' + mode if highlight in self._context: self._vim.command('highlight! link CursorLine ' + self._context[highlight]) - # Clear current keymap - self._prompt.keymap.registry.clear() - - # Apply mode independent mappings - if use_default_mappings: - self._prompt.keymap.register_from_rules( - self._vim, - DEFAULT_ACTION_KEYMAP.get('_', []) - ) - self._prompt.keymap.register_from_rules( - self._vim, - custom.get('_', []) - ) - # Apply mode depend mappings mode = self._current_mode - if use_default_mappings: - self._prompt.keymap.register_from_rules( - self._vim, - DEFAULT_ACTION_KEYMAP.get(mode, []) - ) - self._prompt.keymap.register_from_rules( - self._vim, - custom.get(mode, []) - ) # Update mode context self._context['mode'] = mode @@ -678,7 +631,6 @@ def restore_sources(self, context): def init_denite(self): self._mode_stack = [] - self._prompt.history.reset() self._denite.start(self._context) self._denite.on_init(self._context) self._initialized = True From 36c60389a55234d9ba5f892fd242d98317cd1aca Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 09:43:30 +0900 Subject: [PATCH 008/144] Remove unused code --- rplugin/python3/denite/ui/action.py | 251 --------------------------- rplugin/python3/denite/ui/default.py | 9 +- 2 files changed, 4 insertions(+), 256 deletions(-) diff --git a/rplugin/python3/denite/ui/action.py b/rplugin/python3/denite/ui/action.py index 5b52b14e0..e099297b8 100644 --- a/rplugin/python3/denite/ui/action.py +++ b/rplugin/python3/denite/ui/action.py @@ -1,9 +1,7 @@ import re -from datetime import timedelta, datetime from denite.util import debug from os.path import dirname -from denite.prompt.util import build_keyword_pattern_set def _redraw(prompt, params): @@ -26,151 +24,6 @@ def _choose_action(prompt, params): return prompt.denite.choose_action() -def _move_to_next_line(prompt, params): - for cnt in range(0, _accel_count(prompt.denite)): - prompt.denite.move_to_next_line() - return prompt.denite.move_to_next_line() - - -def _move_to_previous_line(prompt, params): - for cnt in range(0, _accel_count(prompt.denite)): - prompt.denite.move_to_prev_line() - return prompt.denite.move_to_prev_line() - - -def _accel_count(denite): - if not denite._context['auto_accel']: - return 0 - now = datetime.now() - if not hasattr(denite, '_accel_timeout'): - denite._accel_timeout = now - timeout = denite._accel_timeout - denite._accel_timeout = now + timedelta(milliseconds=100) - return 2 if timeout > now else 0 - - -def _move_to_top(prompt, params): - return prompt.denite.move_to_top() - - -def _move_to_middle(prompt, params): - return prompt.denite.move_to_middle() - - -def _move_to_bottom(prompt, params): - return prompt.denite.move_to_bottom() - - -def _move_to_first_line(prompt, params): - return prompt.denite.move_to_first_line() - - -def _move_to_last_line(prompt, params): - return prompt.denite.move_to_last_line() - - -def _scroll_window_upwards(prompt, params): - return prompt.denite.scroll_window_upwards() - - -def _scroll_window_up_one_line(prompt, params): - return prompt.denite.scroll_window_up_one_line() - - -def _scroll_window_downwards(prompt, params): - return prompt.denite.scroll_window_downwards() - - -def _scroll_window_down_one_line(prompt, params): - return prompt.denite.scroll_window_down_one_line() - - -def _scroll_page_forwards(prompt, params): - return prompt.denite.scroll_page_forwards() - - -def _scroll_page_backwards(prompt, params): - return prompt.denite.scroll_page_backwards() - - -def _scroll_up(prompt, params): - return prompt.denite.scroll_up(int(params)) - - -def _scroll_down(prompt, params): - return prompt.denite.scroll_down(int(params)) - - -def _scroll_cursor_to_top(prompt, params): - return prompt.denite.scroll_cursor_to_top() - - -def _scroll_cursor_to_middle(prompt, params): - return prompt.denite.scroll_cursor_to_middle() - - -def _scroll_cursor_to_bottom(prompt, params): - return prompt.denite.scroll_cursor_to_bottom() - - -def _jump_to_next_by(prompt, params): - return prompt.denite.jump_to_next_by(params) - - -def _jump_to_previous_by(prompt, params): - return prompt.denite.jump_to_prev_by(params) - - -def _jump_to_next_source(prompt, params): - return prompt.denite.jump_to_next_by('source_name') - - -def _jump_to_previous_source(prompt, params): - return prompt.denite.jump_to_prev_by('source_name') - - -def _input_command_line(prompt, params): - prompt.nvim.command('redraw | echo') - text = prompt.nvim.call('input', prompt.prefix) - prompt.update_text(text) - - -def _insert_word(prompt, params): - prompt.update_text(params) - - -def _enter_mode(prompt, params): - return prompt.denite.enter_mode(params) - - -def _leave_mode(prompt, params): - return prompt.denite.leave_mode() - - -def _suspend(prompt, params): - return prompt.denite.suspend() - - -def _wincmd(prompt, params): - mapping = { - 'h': 'wincmd h', - 'j': 'wincmd j', - 'k': 'wincmd k', - 'l': 'wincmd l', - 'w': 'wincmd w', - 'W': 'wincmd W', - 't': 'wincmd t', - 'b': 'wincmd b', - 'p': 'wincmd p', - 'P': 'wincmd P', - } - if params not in mapping: - return - ret = prompt.denite.suspend() - prompt.nvim.command(mapping[params]) - return ret - - def _restart(prompt, params): return prompt.denite.restart() @@ -248,36 +101,6 @@ def _move_up_path(prompt, params): return prompt.denite.restart() -def _change_word(prompt, params): - # NOTE: Respect the behavior of 'w' in Normal mode. - if prompt.caret.locus == prompt.caret.tail: - return prompt.denite.change_mode('insert') - pattern_set = build_keyword_pattern_set(prompt.nvim) - pattern = re.compile( - r'^(?:%s+|%s+|[^\s\x20-\xff]+|)\s*' % pattern_set - ) - forward_text = pattern.sub('', prompt.caret.get_forward_text()) - prompt.text = ''.join([ - prompt.caret.get_backward_text(), - forward_text - ]) - prompt.denite.change_mode('insert') - - -def _change_line(prompt, params): - prompt.text = '' - prompt.caret.locus = 0 - prompt.denite.change_mode('insert') - - -def _change_char(prompt, params): - prompt.text = ''.join([ - prompt.caret.get_backward_text(), - prompt.caret.get_forward_text(), - ]) - prompt.denite.change_mode('insert') - - def _move_caret_to_next_word(prompt, params): pattern = re.compile(r'^\S+\s+\S') original_text = prompt.caret.get_forward_text() @@ -296,78 +119,20 @@ def _move_caret_to_end_of_word(prompt, params): prompt.caret.locus += len(original_text) - len(substituted_text) -def _append(prompt, params): - prompt.caret.locus += 1 - prompt.denite.change_mode('insert') - - -def _append_to_line(prompt, params): - prompt.caret.locus = prompt.caret.tail - prompt.denite.change_mode('insert') - - -def _insert_to_head(prompt, params): - prompt.caret.locus = prompt.caret.head - prompt.denite.change_mode('insert') - - def _quick_move(prompt, params): prompt.denite.quick_move() -def _multiple_mappings(prompt, params): - ret = None - for mapping in params.split(','): - ret = prompt.action.call(prompt, mapping) - return ret - - -def _smart_delete_char_before_caret(prompt, params): - text = ''.join([ - prompt.caret.get_backward_text(), - prompt.caret.get_forward_text(), - ]) - if text: - return prompt.action.call(prompt, 'denite:delete_char_before_caret') - else: - return _quit(prompt, params) - - def _nop(prompt, params): pass DEFAULT_ACTION_RULES = [ - ('denite:append', _append), - ('denite:append_to_line', _append_to_line), - ('denite:change_char', _change_char), - ('denite:change_line', _change_line), ('denite:change_path', _change_path), ('denite:change_sorters', _change_sorters), - ('denite:change_word', _change_word), ('denite:choose_action', _choose_action), ('denite:do_action', _do_action), ('denite:do_previous_action', _do_previous_action), - ('denite:enter_mode', _enter_mode), - ('denite:input_command_line', _input_command_line), - ('denite:insert_to_head', _insert_to_head), - ('denite:insert_word', _insert_word), - ('denite:jump_to_next_by', _jump_to_next_by), - ('denite:jump_to_next_source', _jump_to_next_source), - ('denite:jump_to_previous_by', _jump_to_previous_by), - ('denite:jump_to_previous_source', _jump_to_previous_source), - ('denite:leave_mode', _leave_mode), - ('denite:move_caret_to_end_of_word', _move_caret_to_end_of_word), - ('denite:move_caret_to_next_word', _move_caret_to_next_word), - ('denite:move_to_bottom', _move_to_bottom), - ('denite:move_to_first_line', _move_to_first_line), - ('denite:move_to_last_line', _move_to_last_line), - ('denite:move_to_middle', _move_to_middle), - ('denite:move_to_next_line', _move_to_next_line), - ('denite:move_to_previous_line', _move_to_previous_line), - ('denite:move_to_top', _move_to_top), - ('denite:move_up_path', _move_up_path), - ('denite:multiple_mappings', _multiple_mappings), ('denite:nop', _nop), ('denite:print_messages', _print_messages), ('denite:quick_move', _quick_move), @@ -375,26 +140,11 @@ def _nop(prompt, params): ('denite:redraw', _redraw), ('denite:restart', _restart), ('denite:restore_sources', _restore_sources), - ('denite:scroll_cursor_to_bottom', _scroll_cursor_to_bottom), - ('denite:scroll_cursor_to_middle', _scroll_cursor_to_middle), - ('denite:scroll_cursor_to_top', _scroll_cursor_to_top), - ('denite:scroll_down', _scroll_down), - ('denite:scroll_page_backwards', _scroll_page_backwards), - ('denite:scroll_page_forwards', _scroll_page_forwards), - ('denite:scroll_up', _scroll_up), - ('denite:scroll_window_down_one_line', _scroll_window_down_one_line), - ('denite:scroll_window_downwards', _scroll_window_downwards), - ('denite:scroll_window_up_one_line', _scroll_window_up_one_line), - ('denite:scroll_window_upwards', _scroll_window_upwards), - ('denite:smart_delete_char_before_caret', - _smart_delete_char_before_caret), - ('denite:suspend', _suspend), ('denite:toggle_matchers', _toggle_matchers), ('denite:toggle_select', _toggle_select), ('denite:toggle_select_all', _toggle_select_all), ('denite:toggle_select_down', _toggle_select_down), ('denite:toggle_select_up', _toggle_select_up), - ('denite:wincmd', _wincmd), ] DEFAULT_ACTION_KEYMAP = { @@ -402,7 +152,6 @@ def _nop(prompt, params): ('', '', 'noremap'), ('', '', 'noremap'), ('', '', 'noremap'), - ('', '', 'noremap'), ('', '', 'noremap'), ], 'insert': [ diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index e209b16bc..8d9eff638 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -378,7 +378,6 @@ def update_buffer(self): def update_status(self): raw_mode = self._current_mode.upper() - max_len = len(str(self._candidates_len)) mode = '-- ' + raw_mode + ' -- ' if self._context['error_messages']: mode = '[ERROR] ' + mode @@ -408,10 +407,10 @@ def update_status(self): "%#deniteStatusLineNumber#%{" + linenr + "}%*") if self._context['split'] == 'floating': self._vim.options['titlestring'] = ( - "%{denite#get_status('mode')}%* " + - "%{denite#get_status('sources')} " + - " %{denite#get_status('path')}%*" + - "%{" + linenr + "}%*") + "%{denite#get_status('mode')}%* " + + "%{denite#get_status('sources')} " + + " %{denite#get_status('path')}%*" + + "%{" + linenr + "}%*") else: self._window_options['statusline'] = status From 04b6f5b57197089b10d76fc2b92cd9182fbec10a Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 09:46:49 +0900 Subject: [PATCH 009/144] Remove suspend --- doc/denite.txt | 15 +------- rplugin/python3/denite/ui/default.py | 56 ++++++++-------------------- 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/doc/denite.txt b/doc/denite.txt index c73784fe7..6c39663f7 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -640,11 +640,6 @@ are on the neovim-prompt's builtin actions/mappings. Move back to the previous sources. Note: It does not restore the cursor position. - *denite-map-suspend* - - Suspend current Denite buffer. - You can resume the Denite buffer by mapping. - *denite-map-scroll_window_downwards* Scroll the window downwards. @@ -721,11 +716,6 @@ are on the neovim-prompt's builtin actions/mappings. Change |denite-option-matchers| to {arg}. If |denite-option-matchers| is {arg}, it will be disabled. - *denite-map-wincmd* - - Suspend and execute 'wincmd %arg%' - Note: 'arg' supports only h,j,k,l,w,W,t,b,p. - *denite-map-yank_to_register* Yank a text into a specified register. @@ -745,7 +735,6 @@ All mode mappings (override by mode mappings). {key} {mapping} -------- ----------------------------- - @@ -1246,7 +1235,6 @@ OPTIONS *denite-options* "quit": quit the denite buffer. "open": open the denite buffer. - "suspend": suspend the denite buffer. Otherwise: nothing. Default: "none" @@ -2372,8 +2360,9 @@ https://github.com/raghur/fruzzy COMPATIBILITY *denite-compatibility* 2019.05.01 -* Remove prompt.nvim +* Remove prompt.nvim. * "-use-default-mappings" option is deprecated. +* Remove suspend feature. 2019.03.24 * "-auto-highlight" and "-auto-preview" options are deprecated. diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 8d9eff638..20615207b 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -55,7 +55,6 @@ def __init__(self, vim): self._prev_action = '' self._prev_status = {} self._prev_curpos = [] - self._is_suspend = False self._save_window_options = {} self._sources_history = [] @@ -95,15 +94,14 @@ def _start(self, sources, context): if self._initialized and context['resume']: # Skip the initialization - if not self._is_suspend: - if context['mode']: - self._current_mode = context['mode'] + if context['mode']: + self._current_mode = context['mode'] - update = ('immediately', 'immediately_1', - 'cursor_wrap', 'cursor_pos', 'prev_winid', - 'quick_move') - for key in update: - self._context[key] = context[key] + update = ('immediately', 'immediately_1', + 'cursor_wrap', 'cursor_pos', 'prev_winid', + 'quick_move') + for key in update: + self._context[key] = context[key] if self.check_option(): return @@ -138,7 +136,6 @@ def _start(self, sources, context): self.init_buffer() - self._is_suspend = False self.update_displayed_texts() self.change_mode(self._current_mode) self.update_buffer() @@ -150,12 +147,11 @@ def init_buffer(self): self._prev_status = dict() self._displayed_texts = [] - if not self._is_suspend: - self._prev_bufnr = self._vim.current.buffer.number - self._prev_curpos = self._vim.call('getcurpos') - self._prev_wininfo = self._get_wininfo() - self._prev_winid = int(self._context['prev_winid']) - self._winrestcmd = self._vim.call('winrestcmd') + self._prev_bufnr = self._vim.current.buffer.number + self._prev_curpos = self._vim.call('getcurpos') + self._prev_wininfo = self._get_wininfo() + self._prev_winid = int(self._context['prev_winid']) + self._winrestcmd = self._vim.call('winrestcmd') self._scroll = int(self._context['scroll']) if self._scroll == 0: @@ -225,8 +221,7 @@ def _switch_buffer(self): split = self._context['split'] if (split != 'no' and self._winid > 0 and self._vim.call('win_gotoid', self._winid)): - if (not self._is_suspend and - split != 'vertical' and split != 'floating'): + if split != 'vertical' and split != 'floating': # Move the window to bottom self._vim.command('wincmd J') self._winrestcmd = '' @@ -496,12 +491,10 @@ def do_immediately(self): candidate.get('abbr', candidate['word']))) if goto: # Move to the previous window - self.suspend() self._vim.command('wincmd p') def do_command(self, command): self.init_cursor() - self._context['post_action'] = 'suspend' while self._cursor + self._win_cursor < self._candidates_len: self.do_action('default', command) self.move_to_next_line() @@ -535,7 +528,7 @@ def change_mode(self, mode): def cleanup(self): # Clear previewed buffers - if not self._is_suspend and not self._context['has_preview_window']: + if not self._context['has_preview_window']: self._vim.command('pclose!') for bufnr in self._vim.vars['denite#_previewed_buffers'].keys(): if not self._vim.call('win_findbuf', bufnr): @@ -662,7 +655,7 @@ def do_action(self, action_name, command=''): if command != '': self._vim.command(command) - if is_quit and (post_action == 'open' or post_action == 'suspend'): + if is_quit and post_action == 'open': # Re-open denite buffer self.init_buffer() @@ -676,11 +669,6 @@ def do_action(self, action_name, command=''): self._selected_candidates = [] self.redraw(action['is_redraw']) - if post_action == 'suspend': - self.suspend() - self._vim.command('wincmd p') - return STATUS_ACCEPT - return STATUS_ACCEPT if is_quit else None def choose_action(self): @@ -971,17 +959,3 @@ def leave_mode(self): self._current_mode = self._mode_stack[-1] self._mode_stack = self._mode_stack[:-1] self.change_mode(self._current_mode) - - def suspend(self): - if self._bufnr == self._vim.current.buffer.number: - if self._context['auto_resume']: - self._vim.command('autocmd denite WinEnter ' + - 'Denite -resume -buffer_name=' + - self._context['buffer_name']) - for mapping in ['i', 'a', '']: - self._vim.command(f'nnoremap {mapping} ' + - ':Denite -resume -buffer_name=' + - f"{self._context['buffer_name']}") - self._is_suspend = True - self._options['modifiable'] = False - return STATUS_ACCEPT From 0fe8f63680e9cc3515e210704ce0b89eb3843e92 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 10:56:05 +0900 Subject: [PATCH 010/144] Change rpcrequest --- autoload/denite.vim | 4 ++-- autoload/denite/util.vim | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/autoload/denite.vim b/autoload/denite.vim index 1d9170500..0675524db 100644 --- a/autoload/denite.vim +++ b/autoload/denite.vim @@ -46,10 +46,10 @@ function! s:start(sources, user_context) abort call setpos('.', pos) let args = [a:sources, a:user_context] - return denite#util#rpcrequest('_denite_start', args) + return denite#util#rpcrequest('_denite_start', args, v:false) endfunction function! denite#do_action(context, action_name, targets) abort let args = [a:context, a:action_name, a:targets] - return denite#util#rpcrequest('_denite_do_action', args) + return denite#util#rpcrequest('_denite_do_action', args, v:false) endfunction diff --git a/autoload/denite/util.vim b/autoload/denite/util.vim index 6349339e2..a67cdc2fb 100644 --- a/autoload/denite/util.vim +++ b/autoload/denite/util.vim @@ -222,7 +222,7 @@ endfunction function! denite#util#has_yarp() abort return !has('nvim') endfunction -function! denite#util#rpcrequest(method, args) abort +function! denite#util#rpcrequest(method, args, is_async) abort if !denite#init#_check_channel() return -1 endif @@ -231,8 +231,16 @@ function! denite#util#rpcrequest(method, args) abort if g:denite#_yarp.job_is_dead return -1 endif - return g:denite#_yarp.request(a:method, a:args) + if a:is_async + return g:defx#_yarp.notify(a:method, a:args) + else + return g:defx#_yarp.request(a:method, a:args) + endif else - return rpcrequest(g:denite#_channel_id, a:method, a:args) + if a:is_async + return rpcnotify(g:denite#_channel_id, a:method, a:args) + else + return rpcrequest(g:denite#_channel_id, a:method, a:args) + endif endif endfunction From a5fb65efe17bf4885236b50baab80b8106d66679 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 11:20:10 +0900 Subject: [PATCH 011/144] Add map --- autoload/denite.vim | 19 ++ autoload/denite/util.vim | 4 +- rplugin/python3/denite/__init__.py | 4 + rplugin/python3/denite/ui/action.py | 260 --------------------------- rplugin/python3/denite/ui/default.py | 4 +- rplugin/python3/denite/ui/map.py | 128 +++++++++++++ 6 files changed, 155 insertions(+), 264 deletions(-) delete mode 100644 rplugin/python3/denite/ui/action.py create mode 100644 rplugin/python3/denite/ui/map.py diff --git a/autoload/denite.vim b/autoload/denite.vim index 0675524db..08f9ac3d1 100644 --- a/autoload/denite.vim +++ b/autoload/denite.vim @@ -53,3 +53,22 @@ function! denite#do_action(context, action_name, targets) abort let args = [a:context, a:action_name, a:targets] return denite#util#rpcrequest('_denite_do_action', args, v:false) endfunction + +function! denite#do_map(action, ...) abort + if &l:filetype !=# 'denite' + return '' + endif + + let args = denite#util#convert2list(get(a:000, 0, [])) + return printf(":\call denite#call_map(%s, %s)\", + \ string(a:action), string(args)) +endfunction +function! denite#call_map(action, ...) abort + if &l:filetype !=# 'denite' + return + endif + + let args = denite#util#convert2list(get(a:000, 0, [])) + call denite#util#rpcrequest( + \ '_denite_do_map', [a:action, args], v:false) +endfunction diff --git a/autoload/denite/util.vim b/autoload/denite/util.vim index a67cdc2fb..9f78ebf51 100644 --- a/autoload/denite/util.vim +++ b/autoload/denite/util.vim @@ -232,9 +232,9 @@ function! denite#util#rpcrequest(method, args, is_async) abort return -1 endif if a:is_async - return g:defx#_yarp.notify(a:method, a:args) + return g:denite#_yarp.notify(a:method, a:args) else - return g:defx#_yarp.request(a:method, a:args) + return g:denite#_yarp.request(a:method, a:args) endif else if a:is_async diff --git a/rplugin/python3/denite/__init__.py b/rplugin/python3/denite/__init__.py index f42a8aae1..6c8a2b9fc 100644 --- a/rplugin/python3/denite/__init__.py +++ b/rplugin/python3/denite/__init__.py @@ -36,6 +36,10 @@ def start(self, args): def take_action(self, args): return self._rplugin.take_action(args) + @vim.rpc_export('_denite_do_map', sync=True) + def do_map(self, args): + return self._rplugin.do_map(args) + if find_spec('yarp'): global_denite = Rplugin(vim) diff --git a/rplugin/python3/denite/ui/action.py b/rplugin/python3/denite/ui/action.py deleted file mode 100644 index e099297b8..000000000 --- a/rplugin/python3/denite/ui/action.py +++ /dev/null @@ -1,260 +0,0 @@ -import re - -from denite.util import debug -from os.path import dirname - - -def _redraw(prompt, params): - return prompt.denite.redraw() - - -def _quit(prompt, params): - return prompt.denite.quit() - - -def _do_action(prompt, params): - return prompt.denite.do_action(params) - - -def _do_previous_action(prompt, params): - return prompt.denite.do_action(prompt.denite._prev_action) - - -def _choose_action(prompt, params): - return prompt.denite.choose_action() - - -def _restart(prompt, params): - return prompt.denite.restart() - - -def _restore_sources(prompt, params): - return prompt.denite.restore_sources(prompt.denite._context) - - -def _toggle_select(prompt, params): - index = prompt.denite._cursor + prompt.denite._win_cursor - 1 - _toggle_select_candidate(prompt, index) - prompt.denite.update_displayed_texts() - return prompt.denite.update_buffer() - - -def _toggle_select_candidate(prompt, index): - if index in prompt.denite._selected_candidates: - prompt.denite._selected_candidates.remove(index) - else: - prompt.denite._selected_candidates.append(index) - - -def _toggle_select_all(prompt, params): - for index in range(0, prompt.denite._candidates_len): - _toggle_select_candidate(prompt, index) - prompt.denite.update_displayed_texts() - return prompt.denite.update_buffer() - - -def _toggle_select_down(prompt, params): - _toggle_select(prompt, params) - return prompt.denite.move_to_next_line() - - -def _toggle_select_up(prompt, params): - _toggle_select(prompt, params) - return prompt.denite.move_to_prev_line() - - -def _toggle_matchers(prompt, params): - matchers = ''.join(params) - context = prompt.denite._context - if context['matchers'] != matchers: - context['matchers'] = matchers - else: - context['matchers'] = '' - return prompt.denite.redraw() - - -def _change_sorters(prompt, params): - sorters = ''.join(params) - context = prompt.denite._context - if context['sorters'] != sorters: - context['sorters'] = sorters - else: - context['sorters'] = '' - return prompt.denite.redraw() - - -def _print_messages(prompt, params): - for mes in prompt.denite._context['messages']: - debug(prompt.nvim, mes) - prompt.nvim.call('denite#util#getchar') - - -def _change_path(prompt, params): - path = prompt.nvim.call('input', 'Path: ', - prompt.denite._context['path'], 'dir') - prompt.denite._context['path'] = path - return prompt.denite.restart() - - -def _move_up_path(prompt, params): - prompt.denite._context['path'] = dirname(prompt.denite._context['path']) - return prompt.denite.restart() - - -def _move_caret_to_next_word(prompt, params): - pattern = re.compile(r'^\S+\s+\S') - original_text = prompt.caret.get_forward_text() - substituted_text = pattern.sub('', original_text) - prompt.caret.locus += len(original_text) - len(substituted_text) - - -def _move_caret_to_end_of_word(prompt, params): - pattern = re.compile(r'^\S+') - original_text = prompt.caret.get_forward_text() - if original_text and original_text[0] == ' ': - _move_caret_to_next_word(prompt, params) - _move_caret_to_end_of_word(prompt, params) - else: - substituted_text = pattern.sub('', original_text) - prompt.caret.locus += len(original_text) - len(substituted_text) - - -def _quick_move(prompt, params): - prompt.denite.quick_move() - - -def _nop(prompt, params): - pass - - -DEFAULT_ACTION_RULES = [ - ('denite:change_path', _change_path), - ('denite:change_sorters', _change_sorters), - ('denite:choose_action', _choose_action), - ('denite:do_action', _do_action), - ('denite:do_previous_action', _do_previous_action), - ('denite:nop', _nop), - ('denite:print_messages', _print_messages), - ('denite:quick_move', _quick_move), - ('denite:quit', _quit), - ('denite:redraw', _redraw), - ('denite:restart', _restart), - ('denite:restore_sources', _restore_sources), - ('denite:toggle_matchers', _toggle_matchers), - ('denite:toggle_select', _toggle_select), - ('denite:toggle_select_all', _toggle_select_all), - ('denite:toggle_select_down', _toggle_select_down), - ('denite:toggle_select_up', _toggle_select_up), -] - -DEFAULT_ACTION_KEYMAP = { - '_': [ - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ], - 'insert': [ - # Behave like Vim's builtin command-line - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - # Denite specific actions - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ], - 'normal': [ - ('i', '', 'noremap'), - ('j', '', 'noremap'), - ('k', '', 'noremap'), - ('gg', '', 'noremap'), - ('G', '', 'noremap'), - ('H', '', 'noremap'), - ('L', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('zt', '', 'noremap'), - ('zz', '', 'noremap'), - ('zb', '', 'noremap'), - ('q', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('.', '', 'noremap'), - ('*', '', 'noremap'), - ('M', '', 'noremap'), - ('P', '', 'noremap'), - ('U', '', 'noremap'), - ('b', '', 'noremap'), - ('w', '', 'noremap'), - ('0', '', 'noremap'), - ('u', '', 'noremap'), - ('$', '', 'noremap'), - ('cc', '', 'noremap'), - ('S', '', 'noremap'), - ('cw', '', 'noremap'), - ('S', '', 'noremap'), - ('s', '', 'noremap'), - ('x', '', 'noremap'), - ('h', '', 'noremap'), - ('l', '', 'noremap'), - ('a', '', 'noremap'), - ('A', '', 'noremap'), - ('I', '', 'noremap'), - ('X', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - ('', '', 'noremap'), - - # Denite specific actions - ('e', '', 'noremap'), - ('p', '', 'noremap'), - ('d', '', 'noremap'), - ('n', '', 'noremap'), - ('t', '', 'noremap'), - ('y', '', 'noremap'), - ('h', '', 'noremap'), - ('j', '', 'noremap'), - ('k', '', 'noremap'), - ('l', '', 'noremap'), - ('w', '', 'noremap'), - ('W', '', 'noremap'), - ('t', '', 'noremap'), - ('b', '', 'noremap'), - ('p', '', 'noremap'), - ('P', '', 'noremap'), - ], -} diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 20615207b..01c9f9d45 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -98,8 +98,8 @@ def _start(self, sources, context): self._current_mode = context['mode'] update = ('immediately', 'immediately_1', - 'cursor_wrap', 'cursor_pos', 'prev_winid', - 'quick_move') + 'cursor_wrap', 'cursor_pos', 'prev_winid', + 'quick_move') for key in update: self._context[key] = context[key] diff --git a/rplugin/python3/denite/ui/map.py b/rplugin/python3/denite/ui/map.py new file mode 100644 index 000000000..2f3e9fdc1 --- /dev/null +++ b/rplugin/python3/denite/ui/map.py @@ -0,0 +1,128 @@ +from denite.util import debug +from os.path import dirname + + +def _redraw(denite, params): + return denite.redraw() + + +def _quit(denite, params): + return denite.quit() + + +def _do_action(denite, params): + return denite.do_action(params) + + +def _do_previous_action(denite, params): + return denite.do_action(denite._prev_action) + + +def _choose_action(denite, params): + return denite.choose_action() + + +def _restart(denite, params): + return denite.restart() + + +def _restore_sources(denite, params): + return denite.restore_sources(denite._context) + + +def _toggle_select(denite, params): + index = denite._cursor + denite._win_cursor - 1 + _toggle_select_candidate(denite, index) + denite.update_displayed_texts() + return denite.update_buffer() + + +def _toggle_select_candidate(denite, index): + if index in denite._selected_candidates: + denite._selected_candidates.remove(index) + else: + denite._selected_candidates.append(index) + + +def _toggle_select_all(denite, params): + for index in range(0, denite._candidates_len): + _toggle_select_candidate(denite, index) + denite.update_displayed_texts() + return denite.update_buffer() + + +def _toggle_select_down(denite, params): + _toggle_select(denite, params) + return denite.move_to_next_line() + + +def _toggle_select_up(denite, params): + _toggle_select(denite, params) + return denite.move_to_prev_line() + + +def _toggle_matchers(denite, params): + matchers = ''.join(params) + context = denite._context + if context['matchers'] != matchers: + context['matchers'] = matchers + else: + context['matchers'] = '' + return denite.redraw() + + +def _change_sorters(denite, params): + sorters = ''.join(params) + context = denite._context + if context['sorters'] != sorters: + context['sorters'] = sorters + else: + context['sorters'] = '' + return denite.redraw() + + +def _print_messages(denite, params): + for mes in denite._context['messages']: + debug(denite._vim, mes) + denite._vim.call('denite#util#getchar') + + +def _change_path(denite, params): + path = denite._vim.call('input', 'Path: ', + denite._context['path'], 'dir') + denite._context['path'] = path + return denite.restart() + + +def _move_up_path(denite, params): + denite._context['path'] = dirname(denite._context['path']) + return denite.restart() + + +def _quick_move(denite, params): + denite.quick_move() + + +def _nop(denite, params): + pass + + +MAPPINGS = { + 'change_path': _change_path, + 'change_sorters': _change_sorters, + 'choose_action': _choose_action, + 'do_action': _do_action, + 'do_previous_action': _do_previous_action, + 'nop': _nop, + 'print_messages': _print_messages, + 'quick_move': _quick_move, + 'quit': _quit, + 'redraw': _redraw, + 'restart': _restart, + 'restore_sources': _restore_sources, + 'toggle_matchers': _toggle_matchers, + 'toggle_select': _toggle_select, + 'toggle_select_all': _toggle_select_all, + 'toggle_select_down': _toggle_select_down, + 'toggle_select_up': _toggle_select_up, +} From 14cb9609d2b54f6926da9eaee0445ed6415ed504 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 11:59:28 +0900 Subject: [PATCH 012/144] Improve mapping implementation --- autoload/denite.vim | 8 +- autoload/denite/init.vim | 1 - doc/denite.txt | 68 ---------------- rplugin/python3/denite/__init__.py | 4 +- rplugin/python3/denite/rplugin.py | 15 +++- rplugin/python3/denite/ui/default.py | 98 ++++------------------- rplugin/python3/denite/ui/map.py | 113 +++++++++++++++------------ 7 files changed, 96 insertions(+), 211 deletions(-) diff --git a/autoload/denite.vim b/autoload/denite.vim index 08f9ac3d1..518e1f4eb 100644 --- a/autoload/denite.vim +++ b/autoload/denite.vim @@ -54,21 +54,21 @@ function! denite#do_action(context, action_name, targets) abort return denite#util#rpcrequest('_denite_do_action', args, v:false) endfunction -function! denite#do_map(action, ...) abort +function! denite#do_map(name, ...) abort if &l:filetype !=# 'denite' return '' endif let args = denite#util#convert2list(get(a:000, 0, [])) return printf(":\call denite#call_map(%s, %s)\", - \ string(a:action), string(args)) + \ string(a:name), string(args)) endfunction -function! denite#call_map(action, ...) abort +function! denite#call_map(name, ...) abort if &l:filetype !=# 'denite' return endif let args = denite#util#convert2list(get(a:000, 0, [])) call denite#util#rpcrequest( - \ '_denite_do_map', [a:action, args], v:false) + \ '_denite_do_map', [a:name, args], v:false) endfunction diff --git a/autoload/denite/init.vim b/autoload/denite/init.vim index 98ac5b950..9a4d11f90 100644 --- a/autoload/denite/init.vim +++ b/autoload/denite/init.vim @@ -123,7 +123,6 @@ function! denite#init#_user_options() abort \ 'resume': v:false, \ 'reversed': v:false, \ 'root_markers': '', - \ 'scroll': 0, \ 'smartcase': v:false, \ 'sorters': '', \ 'split': 'horizontal', diff --git a/doc/denite.txt b/doc/denite.txt index 6c39663f7..c04298dc1 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -640,50 +640,6 @@ are on the neovim-prompt's builtin actions/mappings. Move back to the previous sources. Note: It does not restore the cursor position. - *denite-map-scroll_window_downwards* - - Scroll the window downwards. - - *denite-map-scroll_window_down_one_line* - - Scroll the window one line down like |CTRL-E|. - - *denite-map-scroll_window_upwards* - - Scroll the window upwards. - - *denite-map-scroll_window_up_one_line* - - Scroll the window one line up like |CTRL-Y|. - - *denite-map-scroll_page_forwards* - - Scroll the page forwards. - - *denite-map-scroll_page_backwards* - - Scroll the page backwards. - - *denite-map-scroll_down* - - Scroll down. - - *denite-map-scroll_up* - - Scroll up. - - *denite-map-scroll_cursor_to_top* - - Scroll the cursor to the top of the window like |zt|. - - *denite-map-scroll_cursor_to_middle* - - Scroll the cursor to the middle of the window like |zz|. - - *denite-map-scroll_cursor_to_bottom* - - Scroll the cursor to the bottom of the window like |zb|. - *denite-map-smart_delete_char_before_caret* If no character being typed, |denite-map-quit|. @@ -2308,30 +2264,6 @@ Q: Can I make denite window always use 40% of the current window? A: > Denite file -winheight=`40*winheight(0)/100` -Q: Alt keymappings does not work. -> - call denite#custom#map( - \ 'insert', - \ '', - \ '', - \ 'noremap' - \) - -A: -> - function! s:getchar() abort - redraw | echo 'Press any key: ' - let c = getchar() - while c ==# "\" - redraw | echo 'Press any key: ' - let c = getchar() - endwhile - redraw | echomsg printf('Raw: "%s" | Char: "%s"', c, nr2char(c)) - endfunction - command! GetChar call s:getchar() -< -Please execute :GetChar and press . -If it is the same of g, your environment does not support . Q: I want to narrow by path in grep source. diff --git a/rplugin/python3/denite/__init__.py b/rplugin/python3/denite/__init__.py index 6c8a2b9fc..44ca4cb7d 100644 --- a/rplugin/python3/denite/__init__.py +++ b/rplugin/python3/denite/__init__.py @@ -33,8 +33,8 @@ def start(self, args): self._rplugin.start(args) @vim.rpc_export('_denite_do_action', sync=True) - def take_action(self, args): - return self._rplugin.take_action(args) + def do_action(self, args): + return self._rplugin.do_action(args) @vim.rpc_export('_denite_do_map', sync=True) def do_map(self, args): diff --git a/rplugin/python3/denite/rplugin.py b/rplugin/python3/denite/rplugin.py index ce155c89f..60a9c4805 100644 --- a/rplugin/python3/denite/rplugin.py +++ b/rplugin/python3/denite/rplugin.py @@ -31,7 +31,7 @@ def start(self, args): denite.util.error(self._vim, 'Please execute :messages command.') - def take_action(self, args): + def do_action(self, args): try: ui = self.get_ui(args[0]['buffer_name']) return ui._denite.do_action(args[0], args[1], args[2]) @@ -43,6 +43,19 @@ def take_action(self, args): denite.util.error(self._vim, 'Please execute :messages command.') + def do_map(self, args): + bufvars = self._vim.current.buffer.vars + try: + ui = self.get_ui(bufvars['denite']['buffer_name']) + return ui.do_map(args[0], args[1]) + except Exception: + import traceback + import denite.util + for line in traceback.format_exc().splitlines(): + denite.util.error(self._vim, line) + denite.util.error(self._vim, + 'Please execute :messages command.') + def get_ui(self, buffer_name): if buffer_name not in self._uis: self._uis[buffer_name] = Default(self._vim) diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 01c9f9d45..8d1f49264 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -11,7 +11,7 @@ from denite.util import ( clear_cmdline, echo, error, regex_convert_py_vim, clearmatch) from denite.parent import SyncParent -from ..prompt.prompt import STATUS_ACCEPT +from denite.ui.map import do_map class Default(object): @@ -26,8 +26,8 @@ def current_mode(self): def __init__(self, vim): self._vim = vim self._denite = None - self._cursor = 0 self._win_cursor = 1 + self._cursor = 0 self._selected_candidates = [] self._candidates = [] self._candidates_len = 0 @@ -43,7 +43,6 @@ def __init__(self, vim): self._winheight = 0 self._winwidth = 0 self._winminheight = -1 - self._scroll = 0 self._is_multi = False self._is_async = False self._matched_pattern = '' @@ -153,9 +152,6 @@ def init_buffer(self): self._prev_winid = int(self._context['prev_winid']) self._winrestcmd = self._vim.call('winrestcmd') - self._scroll = int(self._context['scroll']) - if self._scroll == 0: - self._scroll = round(self._winheight / 2) if self._context['cursor_shape']: self._guicursor = self._vim.options['guicursor'] self._vim.options['guicursor'] = 'a:None' @@ -207,6 +203,9 @@ def init_buffer(self): self._bufnr = self._vim.current.buffer.number self._winid = self._vim.call('win_getid') + self._bufvars['denite'] = { + 'buffer_name': self._context['buffer_name'], + } self._bufvars['denite_statusline'] = {} self._vim.vars['denite#_previewed_buffers'] = {} @@ -301,7 +300,6 @@ def init_syntax(self): self._denite.init_syntax(self._context, self._is_multi) def init_cursor(self): - self._win_cursor = 1 self._cursor = 0 if self._context['reversed']: self.move_to_last_line() @@ -487,7 +485,7 @@ def do_immediately(self): self.do_action('default') candidate = self.get_cursor_candidate() echo(self._vim, 'Normal', '[{}/{}] {}'.format( - self._cursor + self._win_cursor, self._candidates_len, + self._cursor, self._candidates_len, candidate.get('abbr', candidate['word']))) if goto: # Move to the previous window @@ -576,9 +574,10 @@ def quit_buffer(self): self._vim.command(self._winrestcmd) def get_cursor_candidate(self): - if self._cursor + self._win_cursor > self._candidates_len: + cursor = self._vim.call('line', '.') + if cursor > self._candidates_len: return {} - return self._candidates[self._cursor + self._win_cursor - 1] + return self._candidates[cursor - 1] def get_selected_candidates(self): if not self._selected_candidates: @@ -600,7 +599,7 @@ def quit(self): self._denite.on_close(self._context) self.quit_buffer() self._result = [] - return STATUS_ACCEPT + return def restart(self): self.quit_buffer() @@ -619,7 +618,7 @@ def restore_sources(self, context): context['sources_queue'].append(history['sources']) context['path'] = history['path'] self._sources_history.pop() - return STATUS_ACCEPT + return def init_denite(self): self._mode_stack = [] @@ -669,7 +668,7 @@ def do_action(self, action_name, command=''): self._selected_candidates = [] self.redraw(action['is_redraw']) - return STATUS_ACCEPT if is_quit else None + return def choose_action(self): candidates = self.get_selected_candidates() @@ -685,6 +684,9 @@ def choose_action(self): return return self.do_action(action) + def do_map(self, name, args): + return do_map(self, name, args) + def move_to_pos(self, pos): self._cursor = int(pos / self._winheight) * self._winheight self._win_cursor = (pos % self._winheight) + 1 @@ -739,75 +741,6 @@ def move_to_bottom(self): self._win_cursor = self._winheight self.update_cursor() - def scroll_window_upwards(self): - self.scroll_up(self._scroll) - - def scroll_window_downwards(self): - self.scroll_down(self._scroll) - - def scroll_page_backwards(self): - self.scroll_up(self._winheight - 1) - - def scroll_page_forwards(self): - self.scroll_down(self._winheight - 1) - - def scroll_down(self, scroll): - if self._win_cursor + self._cursor < self._candidates_len: - if self._win_cursor <= 1: - self._win_cursor = 1 - self._cursor = min(self._cursor + scroll, - self._candidates_len) - elif self._win_cursor < self._winheight: - self._win_cursor = min( - self._win_cursor + scroll, - self._candidates_len, - self._winheight) - else: - self._cursor = min( - self._cursor + scroll, - self._candidates_len - self._win_cursor) - else: - return - self.update_cursor() - - def scroll_up(self, scroll): - if self._win_cursor > 1: - self._win_cursor = max(self._win_cursor - scroll, 1) - elif self._cursor > 0: - self._cursor = max(self._cursor - scroll, 0) - else: - return - self.update_cursor() - - def scroll_window_up_one_line(self): - if self._cursor < 1: - return self.scroll_up(1) - self._cursor -= 1 - self._win_cursor += 1 - self.update_cursor() - - def scroll_window_down_one_line(self): - if self._win_cursor <= 1 and self._cursor > 0: - return self.scroll_down(1) - self._cursor += 1 - self._win_cursor -= 1 - self.update_cursor() - - def scroll_cursor_to_top(self): - self._cursor += self._win_cursor - 1 - self._win_cursor = 1 - self.update_cursor() - - def scroll_cursor_to_middle(self): - self.scroll_cursor_to_top() - while self._cursor >= 1 and self._win_cursor < self._winheight // 2: - self.scroll_window_up_one_line() - - def scroll_cursor_to_bottom(self): - self.scroll_cursor_to_top() - while self._cursor >= 1 and self._win_cursor < self._winheight: - self.scroll_window_up_one_line() - def jump_to_next_by(self, key): keyfunc = self._keyfunc(key) keys = [keyfunc(candidate) for candidate in self._candidates] @@ -928,7 +861,6 @@ def quick_move_redraw(table, is_define): quick_move_table[char] > self._winheight): return - self._win_cursor = quick_move_table[char] self.update_cursor() if self._context['quick_move'] == 'immediately': diff --git a/rplugin/python3/denite/ui/map.py b/rplugin/python3/denite/ui/map.py index 2f3e9fdc1..31894af86 100644 --- a/rplugin/python3/denite/ui/map.py +++ b/rplugin/python3/denite/ui/map.py @@ -2,24 +2,68 @@ from os.path import dirname -def _redraw(denite, params): +def do_map(denite, name, params): + if name not in MAPPINGS: + return + return MAPPINGS[name](denite, params) + + +def _change_path(denite, params): + path = denite._vim.call('input', 'Path: ', + denite._context['path'], 'dir') + denite._context['path'] = path + return denite.restart() + + +def _change_sorters(denite, params): + sorters = ''.join(params) + context = denite._context + if context['sorters'] != sorters: + context['sorters'] = sorters + else: + context['sorters'] = '' return denite.redraw() -def _quit(denite, params): - return denite.quit() +def _choose_action(denite, params): + return denite.choose_action() def _do_action(denite, params): - return denite.do_action(params) + if not params: + return + return denite.do_action(params[0]) def _do_previous_action(denite, params): return denite.do_action(denite._prev_action) -def _choose_action(denite, params): - return denite.choose_action() +def _move_up_path(denite, params): + denite._context['path'] = dirname(denite._context['path']) + return denite.restart() + + +def _nop(denite, params): + pass + + +def _print_messages(denite, params): + for mes in denite._context['messages']: + debug(denite._vim, mes) + denite._vim.call('denite#util#getchar') + + +def _quick_move(denite, params): + denite.quick_move() + + +def _quit(denite, params): + return denite.quit() + + +def _redraw(denite, params): + return denite.redraw() def _restart(denite, params): @@ -30,6 +74,16 @@ def _restore_sources(denite, params): return denite.restore_sources(denite._context) +def _toggle_matchers(denite, params): + matchers = ''.join(params) + context = denite._context + if context['matchers'] != matchers: + context['matchers'] = matchers + else: + context['matchers'] = '' + return denite.redraw() + + def _toggle_select(denite, params): index = denite._cursor + denite._win_cursor - 1 _toggle_select_candidate(denite, index) @@ -61,58 +115,13 @@ def _toggle_select_up(denite, params): return denite.move_to_prev_line() -def _toggle_matchers(denite, params): - matchers = ''.join(params) - context = denite._context - if context['matchers'] != matchers: - context['matchers'] = matchers - else: - context['matchers'] = '' - return denite.redraw() - - -def _change_sorters(denite, params): - sorters = ''.join(params) - context = denite._context - if context['sorters'] != sorters: - context['sorters'] = sorters - else: - context['sorters'] = '' - return denite.redraw() - - -def _print_messages(denite, params): - for mes in denite._context['messages']: - debug(denite._vim, mes) - denite._vim.call('denite#util#getchar') - - -def _change_path(denite, params): - path = denite._vim.call('input', 'Path: ', - denite._context['path'], 'dir') - denite._context['path'] = path - return denite.restart() - - -def _move_up_path(denite, params): - denite._context['path'] = dirname(denite._context['path']) - return denite.restart() - - -def _quick_move(denite, params): - denite.quick_move() - - -def _nop(denite, params): - pass - - MAPPINGS = { 'change_path': _change_path, 'change_sorters': _change_sorters, 'choose_action': _choose_action, 'do_action': _do_action, 'do_previous_action': _do_previous_action, + 'move_up_path': _move_up_path, 'nop': _nop, 'print_messages': _print_messages, 'quick_move': _quick_move, From ef1faefb0e5a7b6999102cbc4e5a4f18ae535d79 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 12:13:21 +0900 Subject: [PATCH 013/144] Update the documentation --- doc/denite.txt | 612 ++++--------------------------------------------- 1 file changed, 40 insertions(+), 572 deletions(-) diff --git a/doc/denite.txt b/doc/denite.txt index c04298dc1..083096457 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -13,7 +13,6 @@ Configuration Examples |denite-examples| Interface |denite-interface| Commands |denite-commands| Key mappings |denite-key-mappings| - Default key mappings |denite-default-key-mappings| Functions |denite-functions| Options |denite-options| Sources |denite-sources| @@ -140,20 +139,6 @@ EXAMPLES *denite-examples* " Read bellow on this file to learn more about scantree.py call denite#custom#var('file/rec', 'command', ['scantree.py']) - " Change mappings. - call denite#custom#map( - \ 'insert', - \ '', - \ '', - \ 'noremap' - \) - call denite#custom#map( - \ 'insert', - \ '', - \ '', - \ 'noremap' - \) - " Change matchers. call denite#custom#source( \ 'file_mru', 'matchers', ['matcher/fuzzy', 'matcher/project_files']) @@ -320,481 +305,80 @@ COMMANDS *denite-commands* ------------------------------------------------------------------------------ KEY MAPPINGS *denite-key-mappings* -The denite use the lambdalisue/neovim-prompt to provide a rich command-line -like interface. -Report issues to https://github.com/lambdalisue/neovim-prompt when the issues -are on the neovim-prompt's builtin actions/mappings. - - *denite-map-append* - - Append, like |a| in normal mode in vim buffer. - - *denite-map-append_to_line* - - Append to line, like |A| in normal mode in vim buffer. - - *denite-map-assign_next_matched_text* - - Recall next command-line from history that matches pattern in - front of the cursor. - Like |c_| in a native Vim's command-line. - Note: this is a neovim-prompt's builtin action. - - *denite-map-assign_next_text* - - Recall next command-line from history. - Like |c_| in a native Vim's command-line. - Note: this is a neovim-prompt's builtin action. - - *denite-map-assign_previous_matched_text* - - Recall previous command-line from history that matches - pattern in front of the cursor. - Like |c_| in a native Vim's command-line. - Note: this is a neovim-prompt's builtin action. - - *denite-map-assign_previous_text* - - Recall previous command-line from history. - Like |c_| in a native Vim's command-line. - Note: this is a neovim-prompt's builtin action. - - *denite-map-change_line* - - Change line, like |cc| in normal mode in vim buffer. - - *denite-map-change_char* - - Change character like |s| in normal mode in vim buffer. - - *denite-map-change_path* - - Change and restart Denite buffer. - - *denite-map-change_sorters* - + *denite-map-change_sorters* +change_sorters:{arg} Change |denite-option-sorters| to {arg}. If |denite-option-sorters| is {arg}, it will be disabled. - *denite-map-change_word* - - Change word, like |cw| in normal mode in vim buffer. - - *denite-map-choose_action* - + *denite-map-choose_action* +choose_action Choose and fire the action. - *denite-map-delete_char_after_caret* - - Delete a character after the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_char_before_caret* - - Delete a character before the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_char_under_caret* - - Delete a character under the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_word_after_caret* - - Delete a word after the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_word_before_caret* - - Delete a word before the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_word_under_caret* - - Delete a word under the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_text_after_caret* - - Delete a text after the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_text_before_caret* - - Delete a text before the caret. - Note: this is a neovim-prompt's builtin action. - - *denite-map-delete_entire_text* - - Delete an entire text. - Note: this is a neovim-prompt's builtin action. - - *denite-map-do_action* - + *denite-map-do_action* +do_action:{action} Close current Denite buffer and fire {action} action. You can find the actions list in |denite-kinds|. - *denite-map-do_previous_action* - + *denite-map-do_previous_action* +do_previous_action Fire the previous action. - *denite-map-enter_mode* - - Enter to {mode} mode. - - *denite-map-input_command_line* - - Input or overstrike a text through the Vim's native - command-line. - See also |denite-map-toggle_insert_mode|. - - *denite-map-insert_digraph* - - Insert or overstrike a |digraph| at the caret. - Like |c_| in a Vim's native command-line. - See also |denite-map-toggle_insert_mode|. - Note: this is a neovim-prompt's builtin action. - - *denite-map-insert_to_head* - - Insert at head of line, like |I| in normal mode in vim buffer. - - *denite-map-insert_special* - - Insert or overstrike a special character at the caret. - Like |c_| in a Vim's native command-line. - See also |denite-map-toggle_insert_mode|. - Note: this is a neovim-prompt's builtin action. - - *denite-map-insert_word* - - Insert {word} characters. Use this mapping action to define - a mode independent mapping. If you need a mapping which insert - {word} only in insert mode, directly assign {word} like: -> - call denite#custom#map('insert', '', 'hello!', 'noremap') -< - *denite-map-jump_to_next_by* - - Jump to the next candidate with a different value of {word}. - For example, -> - -< - will jump to the next result in a different file in grep. - - *denite-map-jump_to_previous_by* - - Jump to the previous candidate with a different value of - {word}. - - *denite-map-jump_to_next_source* - - Jump to the first candidate of the next source. - - *denite-map-jump_to_previous_source* - - Jump to the first candidate of the previous source. - - *denite-map-leave_mode* - - Return to the previous mode or close current Denite buffer. - - *denite-map-caret_to_end_of_word* - - Move caret to end of word, like |e| in normal mode in vim - buffer. - - *denite-map-caret_to_next_word* - - Move caret to beginning of next word, like |w| in normal mode - in vim buffer. - - *denite-map-move_caret_to_left* - - Move the caret to a one character left. - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_one_word_left* - - Move the caret to a one word left. - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_left_anchor* - - Move the caret like |F| in Vim's normal mode. - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_right* - - Move the caret to a one character right. - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_one_word_right* - - Move the caret to a one word right. - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_right_anchor* - - Move the caret like |f| in Vim's normal mode. - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_head* - - Move the caret to the head (a start of the text.) - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_lead* - - Move the caret to the lead (a first printable character). - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_caret_to_tail* - - Move the caret to the tail (a end of the text). - Note: this is a neovim-prompt's builtin action. - - *denite-map-move_to_first_line* - - Move to first line. - - *denite-map-move_to_last_line* - - Move to last line. - - *denite-map-move_to_next_line* - - Move to next line. - - *denite-map-move_to_previous_line* - - Move to previous line. - - *denite-map-move_to_top* - - Move to the top visible candidate like |H|. - - *denite-map-move_to_middle* - - Move to the middle visible candidate like |M|. - - *denite-map-move_to_bottom* - - Move to the bottom visible candidate like |L|. - - *denite-map-move_up_path* - + *denite-map-move_up_path* +move_up_path Move to the upper path and restart Denite buffer. - *denite-map-multiple_mappings* - - Fire the multiple {mappings} mappings. - {mappings} must be separated by ",". - And you must remove "<" and ">" from mappings. - - Example: > - call denite#custom#map('normal', '', - \ '', 'noremap') -< - *denite-map-nop* - + *denite-map-nop* +nop No operation. - *denite-map-paste_from_register* - - Paste the text from a specified register. - Like |c_| in a Vim's native command-line. - Note: this is a neovim-prompt's builtin action. - - *denite-map-paste_from_default_register* - - Paste the text from a default register (|v:register|). - Note: this is a neovim-prompt's builtin action. - - *denite-map-print_messages* - + *denite-map-print_messages* +print_messages Output denite messages to |:messages|. Note: You cannot read the messages in Denite window. It is for debug only. - *denite-map-quick_move* - + *denite-map-quick_move* +quick_move Move to the selected candidate with using quick match. - *denite-map-quit* - + *denite-map-quit* +quit Close current Denite buffer. - *denite-map-redraw* - + *denite-map-redraw* +redraw Clear the cache and redraw the candidates. - *denite-map-restart* - + *denite-map-restart* +restart Restart Denite buffer. - *denite-map-restore_sources* - + *denite-map-restore_sources* +restore_sources Move back to the previous sources. Note: It does not restore the cursor position. - *denite-map-smart_delete_char_before_caret* - - If no character being typed, |denite-map-quit|. - Otherwise, |denite-map-delete_char_before_caret|. - - *denite-map-toggle_insert_mode* - - Toggle insert mode (insert or overstrike). - Like |c_| in a Vim's native command-line. - Note: this is a neovim-prompt's builtin action. - - *denite-map-toggle_select* - + *denite-map-toggle_select* +toggle_select Toggle cursor candidate select. - *denite-map-toggle_select_all* - + *denite-map-toggle_select_all* +toggle_select_all Toggle all candidates. - *denite-map-toggle_select_down* - + *denite-map-toggle_select_down* +toggle_select_down Toggle cursor candidate select and move to next line. - *denite-map-toggle_select_up* - + *denite-map-toggle_select_up* +toggle_select_up Toggle cursor candidate select and move to previous line. - *denite-map-toggle_matchers* - + *denite-map-toggle_matchers* +toggle_matchers:{arg} Change |denite-option-matchers| to {arg}. If |denite-option-matchers| is {arg}, it will be disabled. - *denite-map-yank_to_register* - - Yank a text into a specified register. - Note: this is a neovim-prompt's builtin action. - - *denite-map-yank_to_default_register* - - Yank a text into a default register (|v:register|). - Note: this is a neovim-prompt's builtin action. - - *denite-default-key-mappings* -Following keymappings are the default keymappings. - -Note: when user hit , denite stop any operations and close its window. - -All mode mappings (override by mode mappings). -{key} {mapping} --------- ----------------------------- - - - - - -"insert" mode mappings. -{key} {mapping} --------- ----------------------------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"normal" mode mappings. -{key} {mapping} --------- ----------------------------- -$ -* -. -0 - - - - - - - - -P -W -b -h -j -k -l -p -t -w - -A -G -H -I -L -M -P -S -U -X -a -b -cc -cw -d -e -gg -h -i -j -k -l -n -p -q -s -t -u -w -x -y -zb -zt -zz - - - ------------------------------------------------------------------------------ FUNCTIONS *denite-functions* @@ -834,111 +418,6 @@ denite#custom#option({buffer-name}, {dict}) \ 'short_source_names': v:true \ }) - *denite#custom#map()* -denite#custom#map({mode}, {lhs}, {rhs}[, {params}]) - Set {lhs} mapping to {rhs} in {mode} mode. - If {mode} is "_", the mapping is used in any mode with lower - priority than a mode specific mappings. - The {params} is a space separated |String| which may contain - - "noremap" - Like a Vim's |noremap|. Without this param, {rhs} will - recursively solved. - - "expr" - Like a Vim's |:map-|, {rhs} is assumed as an expression. - The expression is evaluated to obtain an actual {rhs}. - - "nowait" - Like a Vim's |:map-|, return {rhs} immediately when - the mapping has registered with "nowait" params. - - The followings are example usages: -> - " Use existing map to define a custom map - call denite#custom#map('insert', '', '') - call denite#custom#map('insert', '', '') - call denite#custom#map('insert', '', '') - call denite#custom#map('insert', '', '') - - " Use mapping action directly - call denite#custom#map( - \ 'insert', - \ '', - \ '', - \ 'noremap' - \) - - " Insert a current date by expr mapping - function! Date() abort - return strftime("%Y-%m-%d %a") - endfunction - call denite#custom#map( - \ 'insert', - \ '', - \ 'Date()', - \ 'noremap expr' - \) - - " become 'Ctrl-wCtrl-w' instead of 'Fail' - " become 'Success' instead of 'Ctrl-yCtrl-y' - " Because of 'nowait' - call denite#custom#map( - \ 'insert', - \ '', - \ 'Ctrl-w', - \ 'noremap nowait' - \) - call denite#custom#map( - \ 'insert', - \ '', - \ 'Fail', - \ 'noremap' - \) - call denite#custom#map( - \ 'insert', - \ '', - \ 'Ctrl-y', - \ 'noremap' - \) - call denite#custom#map( - \ 'insert', - \ '', - \ 'Success', - \ 'noremap' - \) - call denite#custom#map( - \ 'insert', - \ '%', - \ 'bufname(b:denite_context["bufnr"])', - \ 'noremap expr' - \) - - function! ToggleSorter(sorter) abort - let sorters = split(b:denite_context.sorters, ',') - let idx = index(sorters, a:sorter) - if idx < 0 - call add(sorters, a:sorter) - else - call remove(sorters, idx) - endif - let b:denite_new_context = {} - let b:denite_new_context.sorters = join(sorters, ',') - return '' - endfunction - call denite#custom#map('insert', '', - \ 'ToggleSorter("sorter/reverse")', 'noremap expr nowait') -< - Note: the posterior mappings have higher priority. - Note: cannot be used while is equal to in - neovim-prompt internally. - Note: cannot be used in custom mapping. - See |denite-key-mappings|. - Note: the mapping can get the context by "b:denite_context" - variable. - Note: the mapping can change the context by - "b:denite_new_context" variable. - *denite#custom#source()* denite#custom#source({source-name}, {option-name}, {value}) Set {source-name} source specialized {option-name} to {value}. @@ -978,6 +457,12 @@ denite#do_action({context}, {action-name}, {targets}) Runs an action {action-name} against {targets}. This will mainly be used in |denite#custom#action()|. +denite#do_map({map-name}[, {args}]) *denite#do_map()* + Fire {map-name} mapping with {args}. You can find the + mappings list in |denite-mappings|. + {args} behavior depends on {map-name}. + Note: It is only used to define mappings. + denite#get_status({name}) *denite#get_status()* Returns the {name} part of the status string. It is useful to customize the statusline. @@ -2223,23 +1708,6 @@ optimized for modern multi core processors. It uses 4 processes heavily. More than a quad core CPU is recommended. A dual core CPU is very slow. And you can change |denite-option-updatetime| option. -Q: I want to use the cursor keys to move the candidates. - -A: > - call denite#custom#map( - \ 'insert', - \ '', - \ '', - \ 'noremap' - \) - call denite#custom#map( - \ 'insert', - \ '', - \ '', - \ 'noremap' - \) - - Q: I want to use grep source as interactive mode. The interactive mode gives you a prompt, and searches once the input is complete like helm-swoop.el. From e06ea3f7604adeeadc15d27d86094ce9c6830413 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 12:47:24 +0900 Subject: [PATCH 014/144] Version up --- doc/denite.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/denite.txt b/doc/denite.txt index 083096457..b01413975 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -1,6 +1,6 @@ *denite.txt* Dark powered asynchronous unite all interfaces for NeoVim/Vim. -Version: 2.1 +Version: 3.0 Author: Shougo License: MIT license @@ -123,6 +123,15 @@ You must install "pynvim" module with pip > ============================================================================== EXAMPLES *denite-examples* > + " Define mappings + autocmd FileType denite call s:denite_my_settings() + function! s:denite_my_settings() abort + nnoremap + \ denite#do_map('do_action', 'open') + nnoremap q + \ denite#do_map('quit') + endfunction + " Change file/rec command. call denite#custom#var('file/rec', 'command', \ ['ag', '--follow', '--nocolor', '--nogroup', '-g', '']) From 1747b49746ff9034f203e7e9d5c1dd08d79e49d4 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 14:12:22 +0900 Subject: [PATCH 015/144] Change statusline behavior --- autoload/denite.vim | 12 ------------ doc/denite.txt | 24 ++++++++---------------- rplugin/python3/denite/ui/default.py | 15 ++++++++------- rplugin/python3/denite/ui/map.py | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/autoload/denite.vim b/autoload/denite.vim index 518e1f4eb..c51c4427c 100644 --- a/autoload/denite.vim +++ b/autoload/denite.vim @@ -22,18 +22,6 @@ function! denite#get_status(name) abort return !exists('b:denite_statusline') ? '' : \ get(b:denite_statusline, a:name, '') endfunction -function! denite#get_status_mode() abort - return denite#get_status('mode') -endfunction -function! denite#get_status_sources() abort - return denite#get_status('sources') -endfunction -function! denite#get_status_path() abort - return denite#get_status('path') -endfunction -function! denite#get_status_linenr() abort - return denite#get_status('linenr') -endfunction function! s:start(sources, user_context) abort if denite#initialize() diff --git a/doc/denite.txt b/doc/denite.txt index b01413975..46644cc12 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -332,6 +332,11 @@ do_action:{action} do_previous_action Fire the previous action. + *denite-map-filter* +filter:{string} + Filter the candidates by {string}. + Note: It is used for filtering UI. + *denite-map-move_up_path* move_up_path Move to the upper path and restart Denite buffer. @@ -477,27 +482,12 @@ denite#get_status({name}) *denite#get_status()* customize the statusline. The available status names: - "mode": Current mode + "input": Current filtering text "sources": Current sources and candidates number "path": Specified |denite-option-path| - "linenr": Equivalent to "line_cursor/line_total" - "raw_mode": Current mode, without any processing "buffer_name": Current |denite-option-buffer-name| - "line_cursor": Cursor position. Part of "linenr". "line_total": Total candidates. Part of "linenr". -denite#get_status_mode() *denite#get_status_mode()* - Please use |denite#get_status()| instead. - -denite#get_status_sources() *denite#get_status_sources()* - Please use |denite#get_status()| instead. - -denite#get_status_path() *denite#get_status_path()* - Please use |denite#get_status()| instead. - -denite#get_status_linenr() *denite#get_status_linenr()* - Please use |denite#get_status()| instead. - *denite#initialize()* denite#initialize() Initialize denite and sources. @@ -1769,9 +1759,11 @@ https://github.com/raghur/fruzzy COMPATIBILITY *denite-compatibility* 2019.05.01 +* Version 3.0 * Remove prompt.nvim. * "-use-default-mappings" option is deprecated. * Remove suspend feature. +* Change status names in denite#get_status(). 2019.03.24 * "-auto-highlight" and "-auto-preview" options are deprecated. diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 8d1f49264..ad19645c5 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -56,6 +56,7 @@ def __init__(self, vim): self._prev_curpos = [] self._save_window_options = {} self._sources_history = [] + self._previous_text = '' def start(self, sources, context): if not self._denite: @@ -370,18 +371,18 @@ def update_buffer(self): self.move_cursor() def update_status(self): - raw_mode = self._current_mode.upper() - mode = '-- ' + raw_mode + ' -- ' + inpt = '' + if self._context['input']: + inpt = self._context['input'] + ' ' if self._context['error_messages']: - mode = '[ERROR] ' + mode + inpt = '[ERROR] ' + inpt path = '[' + self._context['path'] + ']' status = { - 'mode': mode, + 'input': inpt, 'sources': self._statusline_sources, 'path': path, # Extra - 'raw_mode': raw_mode, 'buffer_name': self._context['buffer_name'], 'line_total': self._candidates_len, } @@ -394,13 +395,13 @@ def update_status(self): if self._context['statusline']: status = ( - "%#deniteMode#%{denite#get_status('mode')}%* " + + "%#deniteMode#%{denite#get_status('input')}%* " + "%{denite#get_status('sources')} %=" + "%#deniteStatusLinePath# %{denite#get_status('path')}%*" + "%#deniteStatusLineNumber#%{" + linenr + "}%*") if self._context['split'] == 'floating': self._vim.options['titlestring'] = ( - "%{denite#get_status('mode')}%* " + + "%{denite#get_status('input')}%* " + "%{denite#get_status('sources')} " + " %{denite#get_status('path')}%*" + "%{" + linenr + "}%*") diff --git a/rplugin/python3/denite/ui/map.py b/rplugin/python3/denite/ui/map.py index 31894af86..2acc55e12 100644 --- a/rplugin/python3/denite/ui/map.py +++ b/rplugin/python3/denite/ui/map.py @@ -39,6 +39,23 @@ def _do_previous_action(denite, params): return denite.do_action(denite._prev_action) +def _filter(denite, params): + text = params[0] if params else '' + if not denite.is_async and denite._previous_text == text: + return + + denite._context['input'] = text + + if denite.update_candidates(): + denite.update_buffer() + else: + denite.update_status() + + if denite._previous_text != text: + denite._previous_text = text + denite.init_cursor() + + def _move_up_path(denite, params): denite._context['path'] = dirname(denite._context['path']) return denite.restart() @@ -121,6 +138,7 @@ def _toggle_select_up(denite, params): 'choose_action': _choose_action, 'do_action': _do_action, 'do_previous_action': _do_previous_action, + 'filter': _filter, 'move_up_path': _move_up_path, 'nop': _nop, 'print_messages': _print_messages, From cbe1a22583586411bc43686fb6905a46e6854f05 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 14:45:52 +0900 Subject: [PATCH 016/144] Improve do_action behavior --- doc/denite.txt | 1 + rplugin/python3/denite/ui/map.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/denite.txt b/doc/denite.txt index 46644cc12..1c5f7d32a 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -327,6 +327,7 @@ choose_action do_action:{action} Close current Denite buffer and fire {action} action. You can find the actions list in |denite-kinds|. + If {action} is empty, "default" will be used. *denite-map-do_previous_action* do_previous_action diff --git a/rplugin/python3/denite/ui/map.py b/rplugin/python3/denite/ui/map.py index 2acc55e12..ec6cbab0b 100644 --- a/rplugin/python3/denite/ui/map.py +++ b/rplugin/python3/denite/ui/map.py @@ -30,9 +30,8 @@ def _choose_action(denite, params): def _do_action(denite, params): - if not params: - return - return denite.do_action(params[0]) + name = params[0] if params else 'default' + return denite.do_action(name) def _do_previous_action(denite, params): From 8451117d634cf5224a7e2ef9b778fd78c6981747 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 15:05:01 +0900 Subject: [PATCH 017/144] Remove cursor --- doc/denite.txt | 8 -- rplugin/python3/denite/ui/default.py | 165 ++++----------------------- rplugin/python3/denite/ui/map.py | 12 -- 3 files changed, 20 insertions(+), 165 deletions(-) diff --git a/doc/denite.txt b/doc/denite.txt index 1c5f7d32a..0f67163e9 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -381,14 +381,6 @@ toggle_select toggle_select_all Toggle all candidates. - *denite-map-toggle_select_down* -toggle_select_down - Toggle cursor candidate select and move to next line. - - *denite-map-toggle_select_up* -toggle_select_up - Toggle cursor candidate select and move to previous line. - *denite-map-toggle_matchers* toggle_matchers:{arg} Change |denite-option-matchers| to {arg}. diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index ad19645c5..13760437c 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -6,7 +6,6 @@ import copy import re -from itertools import groupby, takewhile from denite.util import ( clear_cmdline, echo, error, regex_convert_py_vim, clearmatch) @@ -26,8 +25,6 @@ def current_mode(self): def __init__(self, vim): self._vim = vim self._denite = None - self._win_cursor = 1 - self._cursor = 0 self._selected_candidates = [] self._candidates = [] self._candidates_len = 0 @@ -301,9 +298,10 @@ def init_syntax(self): self._denite.init_syntax(self._context, self._is_multi) def init_cursor(self): - self._cursor = 0 if self._context['reversed']: self.move_to_last_line() + else: + self.move_to_first_line() def update_candidates(self): [self._is_async, pattern, statuses, @@ -338,7 +336,7 @@ def update_displayed_texts(self): self._displayed_texts = [ self.get_candidate_display_text(i) - for i in range(self._cursor, self._candidates_len) + for i in range(0, self._candidates_len) ] def update_buffer(self): @@ -368,7 +366,8 @@ def update_buffer(self): self._vim.current.buffer[:] = self._displayed_texts self.resize_buffer() - self.move_cursor() + if self._context['auto_action']: + self.do_action(self._context['auto_action']) def update_status(self): inpt = '' @@ -482,11 +481,10 @@ def do_immediately(self): if goto: # Jump to denite window self.init_buffer() - self.update_cursor() self.do_action('default') candidate = self.get_cursor_candidate() echo(self._vim, 'Normal', '[{}/{}] {}'.format( - self._cursor, self._candidates_len, + self._vim.call('line', '.'), self._candidates_len, candidate.get('abbr', candidate['word']))) if goto: # Move to the previous window @@ -494,20 +492,12 @@ def do_immediately(self): def do_command(self, command): self.init_cursor() - while self._cursor + self._win_cursor < self._candidates_len: + cursor = 1 + while cursor < self._candidates_len: self.do_action('default', command) self.move_to_next_line() self.quit_buffer() - def move_cursor(self): - if self._win_cursor > self._vim.call('line', '$'): - self._win_cursor = self._vim.call('line', '$') - if self._win_cursor != self._vim.call('line', '.'): - self._vim.call('cursor', [self._win_cursor, 1]) - - if self._context['auto_action']: - self.do_action(self._context['auto_action']) - def change_mode(self, mode): self._current_mode = mode @@ -689,139 +679,39 @@ def do_map(self, name, args): return do_map(self, name, args) def move_to_pos(self, pos): - self._cursor = int(pos / self._winheight) * self._winheight - self._win_cursor = (pos % self._winheight) + 1 - self.update_cursor() + self._vim.call('cursor', pos, 0) def move_to_next_line(self): - if self._win_cursor + self._cursor < self._candidates_len: - if self._win_cursor < self._winheight: - self._win_cursor += 1 - else: - self._cursor += 1 + cursor = self._vim.call('line', '.') + if cursor < self._candidates_len: + cursor += 1 elif self._context['cursor_wrap']: self.move_to_first_line() else: return - self.update_cursor() + self._vim.call('cursor', cursor, 0) def move_to_prev_line(self): - if self._win_cursor > 1: - self._win_cursor -= 1 - elif self._cursor >= 1: - self._cursor -= 1 + cursor = self._vim.call('line', '.') + if cursor >= 1: + cursor -= 1 elif self._context['cursor_wrap']: self.move_to_last_line() else: return - self.update_cursor() + self._vim.call('cursor', cursor, 0) def move_to_first_line(self): - if self._win_cursor > 1 or self._cursor > 0: - self._win_cursor = 1 - self._cursor = 0 - self.update_cursor() + self._vim.call('cursor', 1, 0) def move_to_last_line(self): - win_max = min(self._candidates_len, self._winheight) - cur_max = self._candidates_len - win_max - if self._win_cursor < win_max or self._cursor < cur_max: - self._win_cursor = win_max - self._cursor = cur_max - self.update_cursor() - - def move_to_top(self): - self._win_cursor = 1 - self.update_cursor() - - def move_to_middle(self): - self._win_cursor = self._winheight // 2 - self.update_cursor() - - def move_to_bottom(self): - self._win_cursor = self._winheight - self.update_cursor() - - def jump_to_next_by(self, key): - keyfunc = self._keyfunc(key) - keys = [keyfunc(candidate) for candidate in self._candidates] - if not keys or len(set(keys)) == 1: - return - - current_index = self._cursor + self._win_cursor - 1 - forward_candidates = self._candidates[current_index:] - forward_sources = groupby(forward_candidates, keyfunc) - forward_times = len(list(next(forward_sources)[1])) - if not forward_times: - return - remaining_candidates = (self._candidates_len - current_index - - forward_times) - if next(forward_sources, None) is None: - # If the cursor is on the last source - self._cursor = 0 - self._win_cursor = 1 - elif self._candidates_len < self._winheight: - # If there is a space under the candidates - self._cursor = 0 - self._win_cursor += forward_times - elif remaining_candidates < self._winheight: - self._cursor = self._candidates_len - self._winheight + 1 - self._win_cursor = self._winheight - remaining_candidates - else: - self._cursor += forward_times + self._win_cursor - 1 - self._win_cursor = 1 - - self.update_cursor() - - def jump_to_prev_by(self, key): - keyfunc = self._keyfunc(key) - keys = [keyfunc(candidate) for candidate in self._candidates] - if not keys or len(set(keys)) == 1: - return - - current_index = self._cursor + self._win_cursor - 1 - backward_candidates = reversed(self._candidates[:current_index + 1]) - backward_sources = groupby(backward_candidates, keyfunc) - current_source = list(next(backward_sources)[1]) - try: - prev_source = list(next(backward_sources)[1]) - except StopIteration: # If the cursor is on the first source - last_source = takewhile( - lambda candidate: - keyfunc(candidate) == keyfunc(self._candidates[-1]), - reversed(self._candidates) - ) - len_last_source = len(list(last_source)) - if self._candidates_len < self._winheight: - self._cursor = 0 - self._win_cursor = self._candidates_len - len_last_source + 1 - elif len_last_source < self._winheight: - self._cursor = self._candidates_len - self._winheight + 1 - self._win_cursor = self._winheight - len_last_source - else: - self._cursor = self._candidates_len - len_last_source - self._win_cursor = 1 - else: - back_times = len(current_source) - 1 + len(prev_source) - remaining_candidates = (self._candidates_len - current_index - + back_times) - if self._candidates_len < self._winheight: - self._cursor = 0 - self._win_cursor -= back_times - elif remaining_candidates < self._winheight: - self._cursor = self._candidates_len - self._winheight + 1 - self._win_cursor = self._winheight - remaining_candidates - else: - self._cursor -= back_times - self._win_cursor + 1 - self._win_cursor = 1 - - self.update_cursor() + self._vim.call('cursor', 1, self._vim.call('line', '$')) def quick_move(self): def get_quick_move_table(): table = {} context = self._context - base = self._win_cursor + base = self._vim.call('winline') for [key, number] in context['quick_move_table'].items(): number = int(number) pos = ((base - number) if context['reversed'] @@ -877,18 +767,3 @@ def wrapped(candidate): pass return '' return wrapped - - def enter_mode(self, mode): - if mode == self._current_mode: - return - - self._mode_stack.append(self._current_mode) - self.change_mode(mode) - - def leave_mode(self): - if not self._mode_stack: - return self.quit() - - self._current_mode = self._mode_stack[-1] - self._mode_stack = self._mode_stack[:-1] - self.change_mode(self._current_mode) diff --git a/rplugin/python3/denite/ui/map.py b/rplugin/python3/denite/ui/map.py index ec6cbab0b..67f5d583e 100644 --- a/rplugin/python3/denite/ui/map.py +++ b/rplugin/python3/denite/ui/map.py @@ -121,16 +121,6 @@ def _toggle_select_all(denite, params): return denite.update_buffer() -def _toggle_select_down(denite, params): - _toggle_select(denite, params) - return denite.move_to_next_line() - - -def _toggle_select_up(denite, params): - _toggle_select(denite, params) - return denite.move_to_prev_line() - - MAPPINGS = { 'change_path': _change_path, 'change_sorters': _change_sorters, @@ -149,6 +139,4 @@ def _toggle_select_up(denite, params): 'toggle_matchers': _toggle_matchers, 'toggle_select': _toggle_select, 'toggle_select_all': _toggle_select_all, - 'toggle_select_down': _toggle_select_down, - 'toggle_select_up': _toggle_select_up, } From ea679bd08ed0f5607e0da3645913f6e0fc9ea493 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 15:06:52 +0900 Subject: [PATCH 018/144] Update examples --- doc/denite.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/denite.txt b/doc/denite.txt index 0f67163e9..6e2bd47f8 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -127,9 +127,11 @@ EXAMPLES *denite-examples* autocmd FileType denite call s:denite_my_settings() function! s:denite_my_settings() abort nnoremap - \ denite#do_map('do_action', 'open') + \ denite#do_map('do_action') nnoremap q \ denite#do_map('quit') + nnoremap i + \ denite#do_map('filter', input('Filter: ')) endfunction " Change file/rec command. From 651db9fa7012fc2157672b0e67f47d20f8afd1ae Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 15:11:28 +0900 Subject: [PATCH 019/144] Remove mode --- autoload/denite/init.vim | 3 --- doc/denite.txt | 16 +----------- rplugin/python3/denite/child.py | 4 +-- rplugin/python3/denite/ui/default.py | 39 ++-------------------------- 4 files changed, 4 insertions(+), 58 deletions(-) diff --git a/autoload/denite/init.vim b/autoload/denite/init.vim index 9a4d11f90..c46dc9507 100644 --- a/autoload/denite/init.vim +++ b/autoload/denite/init.vim @@ -102,8 +102,6 @@ function! denite#init#_user_options() abort \ 'highlight_cursor': 'Cursor', \ 'highlight_matched_range': 'Underlined', \ 'highlight_matched_char': 'Search', - \ 'highlight_mode_normal': 'WildMenu', - \ 'highlight_mode_insert': 'CursorLine', \ 'highlight_preview_line': 'Search', \ 'highlight_window_background': 'NormalFloat', \ 'ignorecase': v:true, @@ -112,7 +110,6 @@ function! denite#init#_user_options() abort \ 'input': '', \ 'matchers': '', \ 'max_candidate_width': 200, - \ 'mode': '', \ 'path': getcwd(), \ 'previewheight': &previewheight, \ 'prompt': '#', diff --git a/doc/denite.txt b/doc/denite.txt index 6e2bd47f8..282fa82df 100644 --- a/doc/denite.txt +++ b/doc/denite.txt @@ -603,13 +603,6 @@ OPTIONS *denite-options* Matched range highlight. Default: "Underlined" - *denite-option-highlight-mode-{mode}* --highlight-mode-{mode} - Change |hl-CursorLine| in {mode}. - Default: - "CursorLine" in "insert" mode - "WildMenu" in "normal" mode - *denite-option-highlight-preview-line* -highlight-preview-line Previewed line highlight. @@ -654,11 +647,6 @@ OPTIONS *denite-options* Note: Denite skip the match after the width. Default: 200 - *denite-option-mode* --mode={mode} - Specify the default mode. - Default: "insert" - *denite-option-path* -path={input-text} Specify an initial narrowing path. @@ -1645,9 +1633,7 @@ A: Yes. Q: I want to change the cursor line color in Denite buffer. A: denite uses 'cursorline' feature. -So you can change the color by |hl-CursorLine| highlight or -|denite-option-highlight-mode-{mode}|. > - Denite file/rec -highlight-mode-insert=Search +So you can change the color by |hl-CursorLine| highlight. > Q: I want to use unite source in denite. diff --git a/rplugin/python3/denite/child.py b/rplugin/python3/denite/child.py index bffe1f3bf..38c8370c5 100644 --- a/rplugin/python3/denite/child.py +++ b/rplugin/python3/denite/child.py @@ -108,7 +108,6 @@ def gather_candidates(self, context): ctx['is_redraw'] = context['is_redraw'] ctx['messages'] = context['messages'] ctx['error_messages'] = context['error_messages'] - ctx['mode'] = context['mode'] ctx['input'] = context['input'] ctx['prev_input'] = context['input'] ctx['event'] = 'gather' @@ -296,8 +295,7 @@ def _filter_candidates(self, context): 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 + ctx['async_timeout'] = 0.03 if ctx['prev_input'] != ctx['input']: ctx['prev_time'] = time.time() if ctx['is_interactive']: diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index 13760437c..a310fc43e 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -18,10 +18,6 @@ class Default(object): def is_async(self): return self._is_async - @property - def current_mode(self): - return self._current_mode - def __init__(self, vim): self._vim = vim self._denite = None @@ -30,8 +26,6 @@ def __init__(self, vim): self._candidates_len = 0 self._result = [] self._context = {} - self._current_mode = '' - self._mode_stack = [] self._current_mappings = {} self._bufnr = -1 self._winid = -1 @@ -91,9 +85,6 @@ def _start(self, sources, context): if self._initialized and context['resume']: # Skip the initialization - if context['mode']: - self._current_mode = context['mode'] - update = ('immediately', 'immediately_1', 'cursor_wrap', 'cursor_pos', 'prev_winid', 'quick_move') @@ -107,15 +98,10 @@ def _start(self, sources, context): if context['refresh']: self.redraw() else: - if not context['mode']: - # Default mode - context['mode'] = 'insert' - self._context.clear() self._context.update(context) self._context['sources'] = sources self._context['is_redraw'] = False - self._current_mode = context['mode'] self._is_multi = len(sources) > 1 if not sources: @@ -134,7 +120,6 @@ def _start(self, sources, context): self.init_buffer() self.update_displayed_texts() - self.change_mode(self._current_mode) self.update_buffer() if self._context['quick_move'] and self.quick_move(): @@ -276,7 +261,7 @@ def _switch_prev_buffer(self): def init_syntax(self): self._vim.command('syntax case ignore') - self._vim.command('highlight default link deniteMode ModeMsg') + self._vim.command('highlight default link deniteInput ModeMsg') self._vim.command('highlight link deniteMatchedRange ' + self._context['highlight_matched_range']) self._vim.command('highlight link deniteMatchedChar ' + @@ -394,7 +379,7 @@ def update_status(self): if self._context['statusline']: status = ( - "%#deniteMode#%{denite#get_status('input')}%* " + + "%#deniteInput#%{denite#get_status('input')}%* " + "%{denite#get_status('sources')} %=" + "%#deniteStatusLinePath# %{denite#get_status('path')}%*" + "%#deniteStatusLineNumber#%{" + linenr + "}%*") @@ -498,23 +483,6 @@ def do_command(self, command): self.move_to_next_line() self.quit_buffer() - def change_mode(self, mode): - self._current_mode = mode - - highlight = 'highlight_mode_' + mode - if highlight in self._context: - self._vim.command('highlight! link CursorLine ' + - self._context[highlight]) - - # Apply mode depend mappings - mode = self._current_mode - - # Update mode context - self._context['mode'] = mode - - # Update mode indicator - self.update_status() - def cleanup(self): # Clear previewed buffers if not self._context['has_preview_window']: @@ -598,7 +566,6 @@ def restart(self): self.gather_candidates() self.init_buffer() self.update_candidates() - self.change_mode(self._current_mode) self.update_buffer() def restore_sources(self, context): @@ -612,7 +579,6 @@ def restore_sources(self, context): return def init_denite(self): - self._mode_stack = [] self._denite.start(self._context) self._denite.on_init(self._context) self._initialized = True @@ -649,7 +615,6 @@ def do_action(self, action_name, command=''): # Re-open denite buffer self.init_buffer() - self.change_mode(self._current_mode) self.redraw(False) # Disable quit flag From c8b804a15156a201a30e5738cca652688549bcb8 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 15:14:07 +0900 Subject: [PATCH 020/144] Remove unused option --- rplugin/python3/denite/ui/default.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rplugin/python3/denite/ui/default.py b/rplugin/python3/denite/ui/default.py index a310fc43e..bd0d6a5f4 100644 --- a/rplugin/python3/denite/ui/default.py +++ b/rplugin/python3/denite/ui/default.py @@ -26,7 +26,6 @@ def __init__(self, vim): self._candidates_len = 0 self._result = [] self._context = {} - self._current_mappings = {} self._bufnr = -1 self._winid = -1 self._winrestcmd = '' From ca09c29607cf16d054cde86a4ea688c9f885bd8e Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 May 2019 15:23:01 +0900 Subject: [PATCH 021/144] Remove prompt.nvim --- autoload/denite/init.vim | 1 - rplugin/python3/denite/prompt/.gitignore | 3 - rplugin/python3/denite/prompt/.travis.yml | 52 -- rplugin/python3/denite/prompt/LICENSE.md | 21 - rplugin/python3/denite/prompt/README.md | 213 -------- rplugin/python3/denite/prompt/__init__.py | 3 - rplugin/python3/denite/prompt/action.py | 464 ------------------ rplugin/python3/denite/prompt/action.pyi | 28 -- rplugin/python3/denite/prompt/caret.py | 165 ------- rplugin/python3/denite/prompt/caret.pyi | 29 -- rplugin/python3/denite/prompt/digraph.py | 74 --- rplugin/python3/denite/prompt/digraph.pyi | 11 - rplugin/python3/denite/prompt/docs/Makefile | 225 --------- rplugin/python3/denite/prompt/docs/conf.py | 451 ----------------- rplugin/python3/denite/prompt/docs/index.rst | 21 - rplugin/python3/denite/prompt/docs/make.bat | 281 ----------- .../python3/denite/prompt/docs/modules.rst | 7 - rplugin/python3/denite/prompt/docs/prompt.rst | 94 ---- .../denite/prompt/docs/requirements-docs.txt | 5 - rplugin/python3/denite/prompt/history.py | 136 ----- rplugin/python3/denite/prompt/history.pyi | 21 - rplugin/python3/denite/prompt/key.py | 240 --------- rplugin/python3/denite/prompt/key.pyi | 29 -- rplugin/python3/denite/prompt/keymap.py | 429 ---------------- rplugin/python3/denite/prompt/keymap.pyi | 63 --- rplugin/python3/denite/prompt/keystroke.py | 67 --- rplugin/python3/denite/prompt/keystroke.pyi | 20 - rplugin/python3/denite/prompt/prompt.py | 305 ------------ rplugin/python3/denite/prompt/prompt.pyi | 89 ---- rplugin/python3/denite/prompt/util.py | 245 --------- rplugin/python3/denite/prompt/util.pyi | 37 -- rplugin/python3/denite/ui/default.py | 3 - setup.cfg | 2 +- 33 files changed, 1 insertion(+), 3833 deletions(-) delete mode 100644 rplugin/python3/denite/prompt/.gitignore delete mode 100644 rplugin/python3/denite/prompt/.travis.yml delete mode 100644 rplugin/python3/denite/prompt/LICENSE.md delete mode 100644 rplugin/python3/denite/prompt/README.md delete mode 100644 rplugin/python3/denite/prompt/__init__.py delete mode 100644 rplugin/python3/denite/prompt/action.py delete mode 100644 rplugin/python3/denite/prompt/action.pyi delete mode 100644 rplugin/python3/denite/prompt/caret.py delete mode 100644 rplugin/python3/denite/prompt/caret.pyi delete mode 100644 rplugin/python3/denite/prompt/digraph.py delete mode 100644 rplugin/python3/denite/prompt/digraph.pyi delete mode 100644 rplugin/python3/denite/prompt/docs/Makefile delete mode 100644 rplugin/python3/denite/prompt/docs/conf.py delete mode 100644 rplugin/python3/denite/prompt/docs/index.rst delete mode 100644 rplugin/python3/denite/prompt/docs/make.bat delete mode 100644 rplugin/python3/denite/prompt/docs/modules.rst delete mode 100644 rplugin/python3/denite/prompt/docs/prompt.rst delete mode 100644 rplugin/python3/denite/prompt/docs/requirements-docs.txt delete mode 100644 rplugin/python3/denite/prompt/history.py delete mode 100644 rplugin/python3/denite/prompt/history.pyi delete mode 100644 rplugin/python3/denite/prompt/key.py delete mode 100644 rplugin/python3/denite/prompt/key.pyi delete mode 100644 rplugin/python3/denite/prompt/keymap.py delete mode 100644 rplugin/python3/denite/prompt/keymap.pyi delete mode 100644 rplugin/python3/denite/prompt/keystroke.py delete mode 100644 rplugin/python3/denite/prompt/keystroke.pyi delete mode 100644 rplugin/python3/denite/prompt/prompt.py delete mode 100644 rplugin/python3/denite/prompt/prompt.pyi delete mode 100644 rplugin/python3/denite/prompt/util.py delete mode 100644 rplugin/python3/denite/prompt/util.pyi diff --git a/autoload/denite/init.vim b/autoload/denite/init.vim index c46dc9507..8f04db8c9 100644 --- a/autoload/denite/init.vim +++ b/autoload/denite/init.vim @@ -113,7 +113,6 @@ function! denite#init#_user_options() abort \ 'path': getcwd(), \ 'previewheight': &previewheight, \ 'prompt': '#', - \ 'prompt_highlight': 'Statement', \ 'post_action': 'none', \ 'quick_move': '', \ 'refresh': v:false, diff --git a/rplugin/python3/denite/prompt/.gitignore b/rplugin/python3/denite/prompt/.gitignore deleted file mode 100644 index 5dc6b925d..000000000 --- a/rplugin/python3/denite/prompt/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -docs/_build -ci-test -module diff --git a/rplugin/python3/denite/prompt/.travis.yml b/rplugin/python3/denite/prompt/.travis.yml deleted file mode 100644 index 72c67bb80..000000000 --- a/rplugin/python3/denite/prompt/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ -dist: trusty -sudo: false -language: python -python: - - 3.3 - - 3.4 - - 3.5 - - 3.6 -#os: -# - linux -# - osx -#osx_image: xcode8 - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-trusty-4.0 - packages: - - autoconf - - automake - - apport - - build-essential - - clang-4.0 - - cmake - - cscope - - g++-5-multilib - - g++-multilib - - gcc-5-multilib - - gcc-multilib - - gdb - - language-pack-tr - - libc6-dev-i386 - - libtool - - llvm-4.0-dev - - locales - - pkg-config - - unzip - - valgrind - - xclip - -install: - - curl -sL git.io/v18DU | bash - - git clone --depth 1 --single-branch -b ci-test https://github.com/lambdalisue/neovim-prompt ci-test - - pip install coveralls - -script: - - cd ci-test - - PATH="$HOME/neovim/bin:$PATH" sh ./scripts/test.sh - -after_success: - - coveralls diff --git a/rplugin/python3/denite/prompt/LICENSE.md b/rplugin/python3/denite/prompt/LICENSE.md deleted file mode 100644 index f02464156..000000000 --- a/rplugin/python3/denite/prompt/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) since 2016 Alisue, hashnote.net - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/rplugin/python3/denite/prompt/README.md b/rplugin/python3/denite/prompt/README.md deleted file mode 100644 index ca75502d0..000000000 --- a/rplugin/python3/denite/prompt/README.md +++ /dev/null @@ -1,213 +0,0 @@ -neovim-prompt -=============================================================================== -[![Travis CI](https://img.shields.io/travis/lambdalisue/neovim-prompt/master.svg?style=flat-square&label=Travis%20CI)](https://travis-ci.org/lambdalisue/neovim-prompt) -[![Coverage Status](https://coveralls.io/repos/github/lambdalisue/neovim-prompt/badge.svg?branch=master)](https://coveralls.io/github/lambdalisue/neovim-prompt?branch=master) -[![Code Quality](https://img.shields.io/scrutinizer/g/lambdalisue/neovim-prompt/master.svg)](https://scrutinizer-ci.com/g/lambdalisue/neovim-prompt/?branch=master) -![Version 1.0.0](https://img.shields.io/badge/version-1.0.0-yellow.svg?style=flat-square) -![Support Neovim 0.1.6 or above](https://img.shields.io/badge/support-Neovim%200.1.6%20or%20above-green.svg?style=flat-square) -![Support Vim 8.0 or above](https://img.shields.io/badge/support-Vim%208.0.0%20or%20above-yellowgreen.svg?style=flat-square) -[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.md) -[![Documentation Status](https://readthedocs.org/projects/neovim-prompt/badge/?version=latest)](http://neovim-prompt.readthedocs.io/en/latest/?badge=latest) - - -A customizable command-line prompt module for Neovim/Vim. -This repository is assumed to used as a submodule/subtree package. - - -Usage -------------------------------------------------------------------------------- - -Assume you are 'PETER' and you are making 'my-awesome-vim-plugin'. - -### git submodule - -If you won't touch the code in neovim-prompt, this is a best way to use neovim-prompt in your plugin. - -```sh -git clone https://github.com/PETER/my-awesome-vim-plugin -cd my-awesome-vim-plugin -git submodule add https://github.com/lambdalisue/neovim-prompt rplugin/python3/my_awesome_vim_plugin/prompt -``` - -### git subtree - -It is complicated so if you are not really familiar with git subtree, you should use git submodule instead. - -First of all, fork https://github.com/lambdalisue/neovim-prompt to GitHub. -Then clone your neovim-prompt to the same parent directory to the your plugin like - -```sh -git clone https://github.com/PETER/my-awesome-vim-plugin -git clone https://github.com/PETER/neovim-prompt -``` - -Then, add cloned local repository as a remote repository of 'my-awesome-vim-plugin' like - -```sh -cd my-awesome-vim-plugin -git remote add neovim-prompt ../neovim-prompt -``` - -Then perform the following. Note that following is used for update neovim-prompt to the latest as well. - -```sh -git fetch neovim-prompt -git subtree pull --prefix=rplugin/python3/my_awesome_vim_plugin/prompt neovim-prompt master --squash -``` - -When you change the neovim-prompt code and you think it's valuable for other peoples, make a PR with - -```sh -git fetch neovim-prompt -git subtree push --prefix=rplugin/python3/my_awesome_vim_plugin/prompt neovim-prompt some-awesome-implementation --squash -cd ../neovim-prompt -git checkout some-awesome-implementation -git push -u origin -``` - -Then send me a PR. I'll check the implementations and concepts. -Please try to make clear commits before sending me a PR. - - -### Python code - -If you followed the above, you can use neovim-prompt as like the following. - -```python3 -from .prompt.prompt import ( - Prompt, - STATUS_ACCEPT, - STATUS_CANCEL, - STATUS_INTERRUPT, -) - -# ... - - prompt = Prompt() - status = prompt.start() - if status == STATUS_ACCEPT: - result = prompt.text - # Do what ever you want - elif status == STATUS_CANCEL: - # User hit (or whatever which is mapped to ) - elif status == STATUS_INTERRUPT: - # User hit to interrupt - -# ... -``` - -See [API document](http://neovim-prompt.readthedocs.io/en/latest/?badge=latest) or real world examples for more detail. - - -Tests ----------------------------------------------------------- - -While neovim-prompt is assumed to be used as a git submodule/subtree, the 'master' branch does not contain any code for testing but 'ci-test' branch. - -First of all, clone 'ci-test' branch of neovim-prompt in neovim-prompt repository as - -```sh -git clone https://github.com/lambdalisue/neovim-prompt -cd neovim-prompt -git clone https://github.com/lambdalisue/neovim-prompt --branch ci-test ci-test -``` - -Then cd to 'ci-test' and run `scripts/test.sh` to perform tests. - -```sh -cd ci-test -./scripts/test.sh -``` - -If you implement features, do not forget to add tests in ci-test branch. - - -Builtin actions ----------------------------------------------------------- - -neovim-prompt provides the following builtin actions. - -Name | Description ----- | ----------- -`` | Accept the input and return `STATUS_ACCEPT`. -`` | Cancel the input and return `STATUS_CANCEL`. -`` | Toggle insert mode (insert/overstrike) -`` | Delete a character before the caret -`` | Delete a word before the caret (respect `iskeyword` in Vim) -`` | Delete a character after the caret -`` | Delete a word after the caret (respect `iskeyword` in Vim) -`` | Delete a character under the caret -`` | Delete a word under the caret (respect `iskeyword` in Vim) -`` | Delete test before the caret -`` | Delete test after the caret -`` | Delete entire text -`` | Move the caret to one character left -`` | Move the caret to one word left -`` | Move the caret like `F` in Vim's normal mode -`` | Move the caret to one character right -`` | Move the caret to one word right -`` | Move the caret like `f` in Vim's normal mode -`` | Move the caret to the head -`` | Move the caret to the start of the printable character -`` | Move the caret to the tail -`` | Recall previous command-line from history -`` | Recall next command-line from history -`` | Recall previous command-line from history that matches pattern in front of the caret -`` | Recall next command-line from history that matches pattern in front of the caret -`` | Paste text from a specified register -`` | Paste text from `v:register` -`` | Copy text to a specified register -`` | Copy text to `v:register` -`` | Specify and insert a special character (e.g. `^V`, `^M`) -`` | Specify and insert a digraph character (See `:help digraph`) - -The above actions are defined in [action.py](./action.py) - -Default mappings ----------------------------------------------------------- - -The default mapping is determined from a Vim's native command-line (`:help ex-edit-index`.) - -Key | Action | Params ----- | ----------- | ----- -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` -`` | `` | `noremap` - -The above actions are defined in [keymap.py](./kaymap.py) - -Plugins which use neovim-prompt ----------------------------------------------------------- - -- [lambdalisue/lista.nvim](https://github.com/lambdalisue/lista.nvim) -- [Shougo/denite.nvim](https://github.com/Shougo/denite.nvim) diff --git a/rplugin/python3/denite/prompt/__init__.py b/rplugin/python3/denite/prompt/__init__.py deleted file mode 100644 index f7bcfddcc..000000000 --- a/rplugin/python3/denite/prompt/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -"""A prompt library for rplugin in Neovim.""" -__author__ = 'lambdalisue' -__license__ = 'MIT' diff --git a/rplugin/python3/denite/prompt/action.py b/rplugin/python3/denite/prompt/action.py deleted file mode 100644 index 1497d7453..000000000 --- a/rplugin/python3/denite/prompt/action.py +++ /dev/null @@ -1,464 +0,0 @@ -"""Prompt action module.""" -import re -from .digraph import Digraph -from .util import getchar, int2char, int2repr, build_keyword_pattern_set - - -ACTION_PATTERN = re.compile( - r'(?P(?:\w+):(?P