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