mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:00:04 +08:00
parent
f8b5fca38c
commit
3b3c791c51
@ -1,39 +1,39 @@
|
||||
let s:self = {}
|
||||
|
||||
|
||||
let s:self.begin = ''
|
||||
let s:self.end = ''
|
||||
let s:self.content_func = ''
|
||||
let s:self.autoformat = 0
|
||||
|
||||
|
||||
function! s:self._find_position() abort
|
||||
let start = search(self.begin,'bwnc')
|
||||
let end = search(self.end,'bnwc')
|
||||
return sort([start, end], 'n')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:self.update(...) abort
|
||||
let [start, end] = self._find_position()
|
||||
if start != 0 && end != 0
|
||||
if end - start > 1
|
||||
exe (start + 1) . ',' . (end - 1) . 'delete'
|
||||
endif
|
||||
call append(start, call(self.content_func, a:000))
|
||||
if self.autoformat
|
||||
silent! Neoformat
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function! SpaceVim#api#dev#autodoc#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
let s:self = {}
|
||||
|
||||
|
||||
let s:self.begin = ''
|
||||
let s:self.end = ''
|
||||
let s:self.content_func = ''
|
||||
let s:self.autoformat = 0
|
||||
|
||||
|
||||
function! s:self._find_position() abort
|
||||
let start = search(self.begin,'bwnc')
|
||||
let end = search(self.end,'bnwc')
|
||||
return sort([start, end], 'n')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:self.update(...) abort
|
||||
let [start, end] = self._find_position()
|
||||
if start != 0 && end != 0
|
||||
if end - start > 1
|
||||
exe (start + 1) . ',' . (end - 1) . 'delete'
|
||||
endif
|
||||
call append(start, call(self.content_func, a:000))
|
||||
if self.autoformat
|
||||
silent! Neoformat
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function! SpaceVim#api#dev#autodoc#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
@ -1,94 +1,94 @@
|
||||
"=============================================================================
|
||||
" a.vim --- plugin for manager alternate file
|
||||
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg at 163.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
scriptencoding utf-8
|
||||
|
||||
|
||||
" Load SpaceVim API
|
||||
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
let s:JSON = SpaceVim#api#import('data#json')
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
let s:conf = '.project_alt.json'
|
||||
|
||||
let s:project_config = {}
|
||||
|
||||
function! SpaceVim#plugins#a#set_config_name(name)
|
||||
|
||||
let s:conf = a:name
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#a#alt()
|
||||
let conf_file = s:FILE.unify_path(s:conf, ':p')
|
||||
let file = s:FILE.unify_path(bufname('%'), ':.')
|
||||
let alt = SpaceVim#plugins#a#get_alt(file, conf_file)
|
||||
if !empty(alt)
|
||||
exe 'e ' . alt
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:paser(conf, root) abort
|
||||
for key in keys(a:conf)
|
||||
for file in s:CMP.globpath('.', substitute(key, '*', '**/*', 'g'))
|
||||
let file = s:FILE.unify_path(file, ':.')
|
||||
if has_key(a:conf, file)
|
||||
if has_key(a:conf[file], 'alternate')
|
||||
let s:project_config[a:root][file] = {'alternate' : a:conf[file]['alternate']}
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
let conf = a:conf[key]
|
||||
if has_key(conf, 'alternate')
|
||||
let begin_end = split(key, '*')
|
||||
if len(begin_end) == 2
|
||||
let s:project_config[a:root][file] = {'alternate' : s:add_alternate_file(begin_end, file, a:conf[key]['alternate'])}
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:add_alternate_file(a, f, b) abort
|
||||
let begin_len = strlen(a:a[0])
|
||||
let end_len = strlen(a:a[1])
|
||||
"docs/*.md": {"alternate": "docs/cn/{}.md"},
|
||||
"begin_end = 5
|
||||
"end_len = 3
|
||||
"docs/index.md
|
||||
return substitute(a:b, '{}', a:f[begin_len : (end_len+1) * -1], 'g')
|
||||
endfunction
|
||||
|
||||
function! Log() abort
|
||||
return s:project_config
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#a#get_alt(file, root)
|
||||
if !has_key(s:project_config, a:root)
|
||||
let altconfa = s:JSON.json_decode(join(readfile(a:root), "\n"))
|
||||
let s:project_config[a:root] = {}
|
||||
call s:paser(altconfa, a:root)
|
||||
endif
|
||||
try
|
||||
return s:project_config[a:root][a:file]['alternate']
|
||||
catch
|
||||
return ''
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#plugins#a#get_root()
|
||||
return s:FILE.unify_path(s:conf, ':p')
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et sw=2 cc=80:
|
||||
"=============================================================================
|
||||
" a.vim --- plugin for manager alternate file
|
||||
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg at 163.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
scriptencoding utf-8
|
||||
|
||||
|
||||
" Load SpaceVim API
|
||||
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
let s:JSON = SpaceVim#api#import('data#json')
|
||||
let s:FILE = SpaceVim#api#import('file')
|
||||
let s:conf = '.project_alt.json'
|
||||
|
||||
let s:project_config = {}
|
||||
|
||||
function! SpaceVim#plugins#a#set_config_name(name)
|
||||
|
||||
let s:conf = a:name
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#a#alt()
|
||||
let conf_file = s:FILE.unify_path(s:conf, ':p')
|
||||
let file = s:FILE.unify_path(bufname('%'), ':.')
|
||||
let alt = SpaceVim#plugins#a#get_alt(file, conf_file)
|
||||
if !empty(alt)
|
||||
exe 'e ' . alt
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:paser(conf, root) abort
|
||||
for key in keys(a:conf)
|
||||
for file in s:CMP.globpath('.', substitute(key, '*', '**/*', 'g'))
|
||||
let file = s:FILE.unify_path(file, ':.')
|
||||
if has_key(a:conf, file)
|
||||
if has_key(a:conf[file], 'alternate')
|
||||
let s:project_config[a:root][file] = {'alternate' : a:conf[file]['alternate']}
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
let conf = a:conf[key]
|
||||
if has_key(conf, 'alternate')
|
||||
let begin_end = split(key, '*')
|
||||
if len(begin_end) == 2
|
||||
let s:project_config[a:root][file] = {'alternate' : s:add_alternate_file(begin_end, file, a:conf[key]['alternate'])}
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:add_alternate_file(a, f, b) abort
|
||||
let begin_len = strlen(a:a[0])
|
||||
let end_len = strlen(a:a[1])
|
||||
"docs/*.md": {"alternate": "docs/cn/{}.md"},
|
||||
"begin_end = 5
|
||||
"end_len = 3
|
||||
"docs/index.md
|
||||
return substitute(a:b, '{}', a:f[begin_len : (end_len+1) * -1], 'g')
|
||||
endfunction
|
||||
|
||||
function! Log() abort
|
||||
return s:project_config
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#a#get_alt(file, root)
|
||||
if !has_key(s:project_config, a:root)
|
||||
let altconfa = s:JSON.json_decode(join(readfile(a:root), "\n"))
|
||||
let s:project_config[a:root] = {}
|
||||
call s:paser(altconfa, a:root)
|
||||
endif
|
||||
try
|
||||
return s:project_config[a:root][a:file]['alternate']
|
||||
catch
|
||||
return ''
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
function! SpaceVim#plugins#a#get_root()
|
||||
return s:FILE.unify_path(s:conf, ':p')
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et sw=2 cc=80:
|
||||
|
Loading…
Reference in New Issue
Block a user