mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 22:40:06 +08:00
Improve alternate file config (#3493)
This commit is contained in:
parent
49663f002b
commit
1b8c5dd443
@ -27,8 +27,8 @@ function! s:language_specified_mappings() abort
|
||||
\ 'Vader',
|
||||
\ 'execute current file', 1)
|
||||
endfunction
|
||||
call SpaceVim#mapping#space#regesit_lang_mappings('vader', function('s:language_specified_mappings'))
|
||||
call SpaceVim#plugins#a#set_config_name(getcwd(), '.projections.json')
|
||||
call SpaceVim#mapping#space#regesit_lang_mappings('vader', function('s:language_specified_mappings'))
|
||||
command! -nargs=1 IssueEdit call SpaceVim#dev#issuemanager#edit(<f-args>)
|
||||
command! -nargs=1 PullCreate call SpaceVim#dev#pull#create(<f-args>)
|
||||
command! -nargs=1 PullMerge call SpaceVim#dev#pull#merge(<f-args>)
|
||||
|
@ -48,14 +48,11 @@ function! s:load_cache() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
" when this function is called, the project_config file name is changed, and
|
||||
" the project_config info is cleared.
|
||||
function! SpaceVim#plugins#a#set_config_name(path, name) abort
|
||||
let s:alternate_conf[a:path] = a:name
|
||||
endfunction
|
||||
|
||||
function! s:get_project_config(conf_file) abort
|
||||
call s:LOGGER.info('read context from: '. a:conf_file)
|
||||
let context = join(readfile(a:conf_file), "\n")
|
||||
@ -77,9 +74,12 @@ endfunction
|
||||
|
||||
function! SpaceVim#plugins#a#alt(request_parse,...) abort
|
||||
let type = get(a:000, 0, 'alternate')
|
||||
let conf_file_path = SpaceVim#plugins#a#getConfigPath()
|
||||
let file = s:FILE.unify_path(bufname('%'), ':.')
|
||||
let alt = SpaceVim#plugins#a#get_alt(file, conf_file_path, a:request_parse, type)
|
||||
if !exists('b:alternate_file_config')
|
||||
let conf_file_path = SpaceVim#plugins#a#getConfigPath()
|
||||
let file = s:FILE.unify_path(bufname('%'), ':.')
|
||||
let alt = SpaceVim#plugins#a#get_alt(file, conf_file_path, a:request_parse, type)
|
||||
else
|
||||
endif
|
||||
if !empty(alt)
|
||||
exe 'e ' . alt
|
||||
else
|
||||
|
@ -1925,6 +1925,26 @@ Denite/Unite 是一个强大的信息筛选浏览器,这类似于 Emacs 中的
|
||||
}
|
||||
```
|
||||
|
||||
除了使用 `.project_alt.json` 文件以外,还可以在启动函数中设置 `b:alternate_file_config`,
|
||||
例如:
|
||||
|
||||
```vim
|
||||
augroup myspacevim
|
||||
autocmd!
|
||||
autocmd BufNewFile,BufEnter *.c let b:alternate_file_config = {
|
||||
\ "src/*.c" : {
|
||||
\ "doc" : "docs/{}.md",
|
||||
\ "alternate" : "include/{}.h",
|
||||
\ }
|
||||
\ }
|
||||
autocmd BufNewFile,BufEnter *.h let b:alternate_file_config = {
|
||||
\ "include/*.h" : {
|
||||
\ "alternate" : "scr/{}.c",
|
||||
\ }
|
||||
\ }
|
||||
augroup END
|
||||
```
|
||||
|
||||
### 标签管理
|
||||
|
||||
在浏览代码时,通常需要给指定位置添加标签,方便快速跳转,在 SpaceVim
|
||||
|
@ -2039,6 +2039,26 @@ here is an example of `.project_alt.json`:
|
||||
}
|
||||
```
|
||||
|
||||
instead of using `.project_alt.json`, `b:alternate_file_config`
|
||||
can be used in bootstrap function, for example:
|
||||
|
||||
```vim
|
||||
augroup myspacevim
|
||||
autocmd!
|
||||
autocmd BufNewFile,BufEnter *.c let b:alternate_file_config = {
|
||||
\ "src/*.c" : {
|
||||
\ "doc" : "docs/{}.md",
|
||||
\ "alternate" : "include/{}.h",
|
||||
\ }
|
||||
\ }
|
||||
autocmd BufNewFile,BufEnter *.h let b:alternate_file_config = {
|
||||
\ "include/*.h" : {
|
||||
\ "alternate" : "scr/{}.c",
|
||||
\ }
|
||||
\ }
|
||||
augroup END
|
||||
```
|
||||
|
||||
### Bookmarks management
|
||||
|
||||
Bookmarks manager is included in `tools` layer, to use following key bindings, you need to enable
|
||||
|
@ -1,6 +1,5 @@
|
||||
Execute ( SpaceVim plugin: a.vim ):
|
||||
call SpaceVim#plugins#a#set_config_name(getcwd(), '.projections.json')
|
||||
let root = SpaceVim#plugins#a#getConfigPath()
|
||||
let root = SpaceVim#plugins#a#get_root()
|
||||
AssertEqual SpaceVim#plugins#a#get_alt('docs/index.md', root, 1), 'docs/cn/index.md'
|
||||
AssertEqual SpaceVim#plugins#a#get_alt('docs/cn/index.md', root, 1), 'docs/index.md'
|
||||
AssertEqual SpaceVim#plugins#a#get_alt('docs/api/job.md', root, 1), 'docs/cn/api/job.md'
|
||||
|
Loading…
Reference in New Issue
Block a user