Skip to content

Commit

Permalink
Merge pull request #624 from Shougo/ui
Browse files Browse the repository at this point in the history
[RFC] Replace UI
  • Loading branch information
Shougo authored Jun 1, 2019
2 parents 67475c7 + 4573296 commit f1d40d0
Show file tree
Hide file tree
Showing 65 changed files with 1,519 additions and 6,003 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sudo: false
dist: trusty
dist: xenial

language: python

python:
- 3.6
- 3.7

install:
- eval "$(curl -Ss https://raw.githubusercontent.com/neovim/bot-ci/master/scripts/travis-setup.sh) nightly-x64"
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export THEMIS_HOME := ./vim-themis


install: vim-themis
pip install pynvim --upgrade
pip install pytest --upgrade
pip install flake8 --upgrade
pip install mypy --upgrade
pip install vim-vint --upgrade
pip install --upgrade -r test/requirements.txt

lint:
vint --version
Expand Down
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ denite.nvim

[![Build Status](https://travis-ci.org/Shougo/denite.nvim.svg?branch=master)](https://travis-ci.org/Shougo/denite.nvim)

Note: Denite.nvim does not define any of default mappings. You need to define
them.


## About

Expand Down Expand Up @@ -88,9 +91,28 @@ You must install "pynvim" module with pip
**Note:** You need to do 1. and 2. with the common-arch files (x86 or x64).


## Examples

```vim
" Define mappings
autocmd FileType denite call s:denite_my_settings()
function! s:denite_my_settings() abort
nnoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
nnoremap <silent><buffer><expr> d
\ denite#do_map('do_action', 'delete')
nnoremap <silent><buffer><expr> p
\ denite#do_map('do_action', 'preview')
nnoremap <silent><buffer><expr> q
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> i
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <Space>
\ denite#do_map('toggle_select').'j'
endfunction
```


## Screenshots

![file/rec source](https://user-images.githubusercontent.com/13142418/34324674-b8ddd5b8-e840-11e7-9b77-d94e1b084bda.gif)
![SpaceVim Guide](https://user-images.githubusercontent.com/13142418/34324752-e5a89900-e842-11e7-9f87-6d8789ba3871.gif)
![colorscheme source](https://user-images.githubusercontent.com/13142418/34324786-f4dd39a2-e843-11e7-97ef-7a48ee04d27b.gif)
![floating window](https://user-images.githubusercontent.com/1239245/54329573-8b047380-4655-11e9-8b9a-ab4a91f4768f.gif)
![denite new UI](https://user-images.githubusercontent.com/1239245/58742567-a155ea80-8460-11e9-9925-09082def2c80.gif)
58 changes: 44 additions & 14 deletions autoload/denite.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -46,10 +34,52 @@ 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

function! denite#do_map(name, ...) abort
let args = denite#util#convert2list(get(a:000, 0, []))
let esc = (mode() ==# 'i' ? "\<C-o>" : '')
return printf(esc . ":\<C-u>call denite#_call_map(%s, %s, %s)\<CR>",
\ string(a:name), 'v:false', string(args))
endfunction
function! denite#_call_map(name, is_async, args) abort
let is_filter = &l:filetype ==# 'denite-filter'

if is_filter
call denite#filter#_move_to_parent(a:is_async)
endif

if &l:filetype !=# 'denite'
return
endif

let args = denite#util#convert2list(a:args)

call denite#util#rpcrequest(
\ (a:is_async ? '_denite_do_async_map' : '_denite_do_map'),
\ [bufnr('%'), a:name, args], a:is_async)

if is_filter
let denite_statusline = get(b:, 'denite_statusline', {})

call win_gotoid(g:denite#_filter_winid)

if &l:filetype ==# 'denite-filter'
let b:denite_statusline = denite_statusline
else
stopinsert
endif
endif
endfunction
function! denite#call_map(name, ...) abort
call denite#_call_map(a:name, v:false, get(a:000, 0, []))
endfunction
function! denite#call_async_map(name, ...) abort
call denite#_call_map(a:name, v:true, get(a:000, 0, []))
endfunction
62 changes: 62 additions & 0 deletions autoload/denite/_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ============================================================================
# FILE: _main.py
# AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
# 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])
5 changes: 4 additions & 1 deletion autoload/denite/custom.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ endfunction
function! denite#custom#_call_action(kind, name, context) abort
let custom = denite#custom#_get().action

let new_context = {}
for key in denite#util#split(a:kind)
if has_key(custom, key) && has_key(custom[key], a:name)
call call(custom[key][a:name][0], [a:context])
let new_context = call(custom[key][a:name][0], [a:context])
endif
endfor

return new_context
endfunction

function! s:set_custom(dest, name_or_dict, value) abort
Expand Down
Loading

0 comments on commit f1d40d0

Please sign in to comment.