diff --git a/autoload/SpaceVim/default.vim b/autoload/SpaceVim/default.vim index df992f0e4..981f522d6 100644 --- a/autoload/SpaceVim/default.vim +++ b/autoload/SpaceVim/default.vim @@ -152,7 +152,6 @@ function! SpaceVim#default#keyBindings() abort " yank and paste if has('unnamedplus') xnoremap y "+y - xnoremap d "+d nnoremap p "+p let g:_spacevim_mappings.p = ['normal! "+p', 'paste after here'] nnoremap P "+P @@ -161,7 +160,6 @@ function! SpaceVim#default#keyBindings() abort xnoremap P "+P else xnoremap y "*y - xnoremap d "*d nnoremap p "*p let g:_spacevim_mappings.p = ['normal! "*p', 'paste after here'] nnoremap P "*P @@ -170,6 +168,8 @@ function! SpaceVim#default#keyBindings() abort xnoremap P "*P endif + xnoremap Y :call SpaceVim#plugins#pastebin#paste() + " call SpaceVim#mapping#guide#register_displayname(':call SpaceVim#plugins#pastebin#paste()', 'copy to pastebin') " quickfix list movement let g:_spacevim_mappings.q = {'name' : '+Quickfix movement'} diff --git a/autoload/SpaceVim/mapping/guide.vim b/autoload/SpaceVim/mapping/guide.vim index b4fd05f6e..b853b7087 100644 --- a/autoload/SpaceVim/mapping/guide.vim +++ b/autoload/SpaceVim/mapping/guide.vim @@ -702,11 +702,19 @@ endfunction " }}} if !exists('g:leaderGuide_displayfunc') function! s:leaderGuide_display() abort + if has_key(s:registered_name, g:leaderGuide#displayname) + return s:registered_name[g:leaderGuide#displayname] + endif let g:leaderGuide#displayname = substitute(g:leaderGuide#displayname, '\c$', '', '') endfunction let g:leaderGuide_displayfunc = [function('s:leaderGuide_display')] endif +let s:registered_name = {} +function! SpaceVim#mapping#guide#register_displayname(lhs, name) + call extend(s:registered_name, {a:lhs : a:name}) +endfunction + if get(g:, 'mapleader', '\') ==# ' ' call SpaceVim#mapping#guide#register_prefix_descriptions(' ', \ 'g:_spacevim_mappings') diff --git a/autoload/SpaceVim/plugins/manager.vim b/autoload/SpaceVim/plugins/manager.vim index b989f7de3..9f5069a6f 100644 --- a/autoload/SpaceVim/plugins/manager.vim +++ b/autoload/SpaceVim/plugins/manager.vim @@ -644,21 +644,21 @@ function! s:new_window() abort setf SpaceVimPlugManager nnoremap q :bd nnoremap gf :call open_plugin_dir() + nnoremap gr :call fix_install() " process has finished or does not start. return 2 endif endfunction function! s:open_plugin_dir() abort - let line = line('.') - 3 - let plugin = filter(copy(s:ui_buf), 's:ui_buf[v:key] == line') + let plugin = get(split(getline('.')), 1, ':')[:-2] if !empty(plugin) let shell = empty($SHELL) ? SpaceVim#api#import('system').isWindows ? 'cmd.exe' : 'bash' : $SHELL let path = '' if g:spacevim_plugin_manager ==# 'dein' - let path = dein#get(keys(plugin)[0]).path + let path = dein#get(plugin).path elseif g:spacevim_plugin_manager ==# 'neobundle' - let path = neobundle#get(keys(plugin)[0]).path + let path = neobundle#get(plugin).path elseif g:spacevim_plugin_manager ==# 'vim-plug' endif if isdirectory(path) @@ -684,6 +684,38 @@ function! s:open_plugin_dir() abort endif endfunction +function! s:fix_install() abort + let plugin = get(split(getline('.')), 1, ':')[:-2] + if !empty(plugin) + if g:spacevim_plugin_manager ==# 'dein' + let repo = dein#get(plugin) + elseif g:spacevim_plugin_manager ==# 'neobundle' + let repo = neobundle#get(plugin) + else + let repo = {} + endif + if has_key(repo, 'path') && isdirectory(repo.path) + if index(s:failed_plugins, plugin) > 0 + call remove(s:failed_plugins, plugin) + endif + let argv = 'git checkout . && git pull --progress' + let jobid = s:JOB.start(argv,{ + \ 'on_stderr' : function('s:on_install_stdout'), + \ 'cwd' : repo.path, + \ 'on_exit' : function('s:on_pull_exit') + \ }) + if jobid != 0 + let s:pulling_repos[jobid] = repo + call s:msg_on_start(repo.name) + endif + else + echohl WarningMsg + echo 'Plugin(' . plugin . ') has not been installed!' + echohl None + endif + endif +endfunction + function! s:resume_window() abort execute get(g:, 'spacevim_window', 'vertical topleft new') let s:plugin_manager_buffer = bufnr('%') diff --git a/autoload/SpaceVim/plugins/pastebin.vim b/autoload/SpaceVim/plugins/pastebin.vim new file mode 100644 index 000000000..dfafe0279 --- /dev/null +++ b/autoload/SpaceVim/plugins/pastebin.vim @@ -0,0 +1,56 @@ +"============================================================================= +" pastebin.vim --- Pastebin support for SpaceVim +" Copyright (c) 2016-2019 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg@outlook.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + + +let s:JOB = SpaceVim#api#import('job') +let s:job_id = -1 + +function! SpaceVim#plugins#pastebin#paste() + let s:url = '' + let context = s:get_visual_selection() + " let ft = &filetype + let cmd = 'curl -s -F "content=<-" http://dpaste.com/api/v2/' + let s:job_id = s:JOB.start(cmd,{ + \ 'on_stdout' : function('s:on_stdout'), + \ 'on_stderr' : function('s:on_stderr'), + \ 'on_exit' : function('s:on_exit'), + \ }) + call s:JOB.send(s:job_id, split(context, "\n")) + call s:JOB.chanclose(s:job_id, 'stdin') +endfunction +function! s:on_stdout(job_id, data, event) abort + " echom 'stdout:' . string(a:data) + for url in filter(a:data, '!empty(v:val)') + let s:url = url + endfor +endfunction + +function! s:on_stderr(job_id, data, event) abort + " echom 'stderr:' . string(a:data) +endfunction + +function! s:on_exit(job_id, data, event) abort + if a:data ==# 0 && !empty(s:url) + let @+ = s:url . '.txt' + echo 'Pastbin: ' . s:url . '.txt' + endif +endfunction + +" ref: https://stackoverflow.com/a/6271254 +function! s:get_visual_selection() + " Why is this not a built-in Vim script function?! + let [line_start, column_start] = getpos("'<")[1:2] + let [line_end, column_end] = getpos("'>")[1:2] + let lines = getline(line_start, line_end) + if len(lines) == 0 + return '' + endif + let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)] + let lines[0] = lines[0][column_start - 1:] + return join(lines, "\n") +endfunction diff --git a/docs/_posts/2017-08-11-Asynchronous-plugin-manager.md b/docs/_posts/2017-08-11-Asynchronous-plugin-manager.md index 885dfeda7..516fcbd7f 100644 --- a/docs/_posts/2017-08-11-Asynchronous-plugin-manager.md +++ b/docs/_posts/2017-08-11-Asynchronous-plugin-manager.md @@ -17,4 +17,6 @@ SpaceVim use dein as default plugin manager, and implement a UI for dein. ![dein ui](https://user-images.githubusercontent.com/13142418/34907332-903ae968-f842-11e7-8ac9-07fcc9940a53.gif) -when plugin is failed to update, the error message will be shown after the plugin name, you can move cursor to the line of that plugin, then press `gf` to open a terminal with path of that plugin. +when plugin is failed to update, the error message will be shown after the plugin name, +you can move cursor to the line of that plugin, +then press `g r` to fix the installation, or press `gf` to open a terminal with path of that plugin.