1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 01:00:05 +08:00

Add pastebin and fix_install for plugin manager (#3457)

This commit is contained in:
Wang Shidong 2020-04-18 16:18:20 +08:00 committed by GitHub
parent a4fe1351db
commit 5ebbec752f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 7 deletions

View File

@ -152,7 +152,6 @@ function! SpaceVim#default#keyBindings() abort
" yank and paste
if has('unnamedplus')
xnoremap <Leader>y "+y
xnoremap <Leader>d "+d
nnoremap <Leader>p "+p
let g:_spacevim_mappings.p = ['normal! "+p', 'paste after here']
nnoremap <Leader>P "+P
@ -161,7 +160,6 @@ function! SpaceVim#default#keyBindings() abort
xnoremap <Leader>P "+P
else
xnoremap <Leader>y "*y
xnoremap <Leader>d "*d
nnoremap <Leader>p "*p
let g:_spacevim_mappings.p = ['normal! "*p', 'paste after here']
nnoremap <Leader>P "*P
@ -170,6 +168,8 @@ function! SpaceVim#default#keyBindings() abort
xnoremap <Leader>P "*P
endif
xnoremap <silent><Leader>Y :call SpaceVim#plugins#pastebin#paste()<CR>
" call SpaceVim#mapping#guide#register_displayname(':call SpaceVim#plugins#pastebin#paste()<CR>', 'copy to pastebin')
" quickfix list movement
let g:_spacevim_mappings.q = {'name' : '+Quickfix movement'}

View File

@ -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<cr>$', '', '')
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')

View File

@ -644,21 +644,21 @@ function! s:new_window() abort
setf SpaceVimPlugManager
nnoremap <silent> <buffer> q :bd<CR>
nnoremap <silent> <buffer> gf :call <SID>open_plugin_dir()<cr>
nnoremap <silent> <buffer> gr :call <SID>fix_install()<cr>
" 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('%')

View File

@ -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

View File

@ -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.