mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:50:04 +08:00
feat(projectmanager): make reg_callback support description
This commit is contained in:
parent
031a6a2497
commit
ea76ba75aa
@ -34,10 +34,17 @@ if has('nvim-0.5.0')
|
|||||||
function! SpaceVim#plugins#projectmanager#RootchandgeCallback() abort
|
function! SpaceVim#plugins#projectmanager#RootchandgeCallback() abort
|
||||||
lua require("spacevim.plugin.projectmanager").RootchandgeCallback()
|
lua require("spacevim.plugin.projectmanager").RootchandgeCallback()
|
||||||
endfunction
|
endfunction
|
||||||
function! SpaceVim#plugins#projectmanager#reg_callback(func) abort
|
function! SpaceVim#plugins#projectmanager#reg_callback(func, ...) abort
|
||||||
lua require("spacevim.plugin.projectmanager").reg_callback(
|
if a:0 == 0
|
||||||
\ require("spacevim").eval("string(a:func)")
|
lua require("spacevim.plugin.projectmanager").reg_callback(
|
||||||
\ )
|
\ require("spacevim").eval("string(a:func)")
|
||||||
|
\ )
|
||||||
|
else
|
||||||
|
lua require("spacevim.plugin.projectmanager").reg_callback(
|
||||||
|
\ require("spacevim").eval("string(a:func)"),
|
||||||
|
\ require("spacevim").eval("a:1")
|
||||||
|
\ )
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
function! SpaceVim#plugins#projectmanager#current_root() abort
|
function! SpaceVim#plugins#projectmanager#current_root() abort
|
||||||
return luaeval('require("spacevim.plugin.projectmanager").current_root()')
|
return luaeval('require("spacevim.plugin.projectmanager").current_root()')
|
||||||
@ -333,11 +340,12 @@ else
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:project_callback = []
|
let s:project_callback = []
|
||||||
function! SpaceVim#plugins#projectmanager#reg_callback(func) abort
|
function! SpaceVim#plugins#projectmanager#reg_callback(func, ...) abort
|
||||||
|
" support second argv
|
||||||
if type(a:func) == 2
|
if type(a:func) == 2
|
||||||
call add(s:project_callback, a:func)
|
call add(s:project_callback, a:func)
|
||||||
else
|
else
|
||||||
call SpaceVim#logger#warn('can not register the project callback: ' . string(a:func))
|
call SpaceVim#logger#warn('can not register the project callback: ' . get(a:000, 0, string(a:func)))
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -384,13 +392,13 @@ else
|
|||||||
if name !=# ''
|
if name !=# ''
|
||||||
call s:BUFFER.filter_do(
|
call s:BUFFER.filter_do(
|
||||||
\ {
|
\ {
|
||||||
\ 'expr' : [
|
\ 'expr' : [
|
||||||
\ 'buflisted(v:val)',
|
\ 'buflisted(v:val)',
|
||||||
\ 'getbufvar(v:val, "_spacevim_project_name") == "' . name . '"',
|
\ 'getbufvar(v:val, "_spacevim_project_name") == "' . name . '"',
|
||||||
\ ],
|
\ ],
|
||||||
\ 'do' : 'bd %d'
|
\ 'do' : 'bd %d'
|
||||||
\ }
|
\ }
|
||||||
\ )
|
\ )
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -276,7 +276,7 @@ end
|
|||||||
|
|
||||||
function M.open()
|
function M.open()
|
||||||
if not project_manager_registered then
|
if not project_manager_registered then
|
||||||
require('spacevim.plugin.projectmanager').reg_callback(M.on_cwd_changed)
|
require('spacevim.plugin.projectmanager').reg_callback(M.on_cwd_changed, 'git_remote_on_cwd_changed')
|
||||||
project_manager_registered = true
|
project_manager_registered = true
|
||||||
end
|
end
|
||||||
if bufnr ~= -1 and vim.api.nvim_buf_is_valid(bufnr) then
|
if bufnr ~= -1 and vim.api.nvim_buf_is_valid(bufnr) then
|
||||||
|
@ -343,29 +343,38 @@ function M.RootchandgeCallback()
|
|||||||
-- let b:_spacevim_project_name = g:_spacevim_project_name
|
-- let b:_spacevim_project_name = g:_spacevim_project_name
|
||||||
fn.setbufvar('%', '_spacevim_project_name', project.name)
|
fn.setbufvar('%', '_spacevim_project_name', project.name)
|
||||||
for _, Callback in pairs(project_callback) do
|
for _, Callback in pairs(project_callback) do
|
||||||
if type(Callback) == 'string' then
|
if type(Callback.func) == 'string' then
|
||||||
logger.debug(' run callback:' .. Callback)
|
if Callback.desc then
|
||||||
fn.call(Callback, {})
|
logger.debug(' run callback:' .. Callback.desc)
|
||||||
elseif type(Callback) == 'function' then
|
else
|
||||||
logger.debug(' run callback:' .. tostring(Callback))
|
logger.debug(' run callback:' .. Callback.func)
|
||||||
pcall(Callback)
|
end
|
||||||
|
fn.call(Callback.func, {})
|
||||||
|
elseif type(Callback.func) == 'function' then
|
||||||
|
if Callback.desc then
|
||||||
|
logger.debug(' run callback:' .. Callback.desc)
|
||||||
|
else
|
||||||
|
logger.debug(' run callback:' .. tostring(Callback.func))
|
||||||
|
end
|
||||||
|
pcall(Callback.func)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.reg_callback(func)
|
function M.reg_callback(func, ...)
|
||||||
if type(func) == 'string' then
|
local callback = { func = func }
|
||||||
if string.match(func, '^function%(') ~= nil then
|
local argv = { ... }
|
||||||
table.insert(project_callback, string.sub(func, 11, -3))
|
if argv[1] then
|
||||||
else
|
callback.desc = argv[1]
|
||||||
table.insert(project_callback, func)
|
end
|
||||||
|
if type(callback.func) == 'string' or type(callback.func) == 'function' then
|
||||||
|
if type(callback.func) == 'string' and string.match(callback.func, '^function%(') ~= nil then
|
||||||
|
callback.func = string.sub(callback.func, 11, -3)
|
||||||
end
|
end
|
||||||
elseif type(func) == 'function' then
|
table.insert(project_callback, callback)
|
||||||
-- support lua function
|
|
||||||
table.insert(project_callback, func)
|
|
||||||
else
|
else
|
||||||
logger.warn('type of func is:' .. type(func))
|
logger.warn('type of func is:' .. type(callback.func))
|
||||||
logger.warn('can not register the project callback: ' .. fn.string(func))
|
logger.warn('can not register the project callback: ' .. fn.string(callback.func))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user