1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-13 13:39:09 +08:00

perf(a.vim): improve alternate plugin

This commit is contained in:
wsdjeg 2023-06-22 22:34:18 +08:00
parent b737573667
commit 3874042593
4 changed files with 98 additions and 7 deletions

View File

@ -73,7 +73,8 @@ function! SpaceVim#commands#load() abort
""
" Switch to alternate file based on {type}.
" Switch to alternate file based on {type}. for more info about alternate
" file configuration, checkout @section(plugins-alternate)
command! -nargs=? -complete=custom,SpaceVim#plugins#a#complete -bang A :call SpaceVim#plugins#a#alt(<bang>0,<f-args>)
endfunction

View File

@ -10,6 +10,45 @@ let s:save_cpo = &cpo
set cpo&vim
scriptencoding utf-8
""
" @section alternate, plugins-alternate
" @parentsection plugins
" To manage the alternate file of the project, you need to create a `.project_alt.json` file
" in the root of your project. Then you can use the command `:A` to jump to the alternate file of
" current file. You can also specific the type of alternate file, for example `:A doc`.
" With a bang `:A!`, SpaceVim will parse the configuration file additionally. If no type is specified,
" the default type `alternate` will be used.
"
" here is an example of `.project_alt.json`:
"
" >
" {
" "autoload/SpaceVim/layers/lang/*.vim": {
" "doc": "docs/layers/lang/{}.md",
" "test": "test/layer/lang/{}.vader"
" }
" }
" <
"
" instead of using `.project_alt.json`, `b:alternate_file_config`
" can be used in bootstrap function, for example:
"
" >
" 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
" <
if has('nvim-0.5.0')
function! SpaceVim#plugins#a#alt(request_parse, ...) abort

View File

@ -253,11 +253,12 @@ CONTENTS *SpaceVim-contents*
8. undo-tree...................................|SpaceVim-usage-undotree|
9. windows-and-tabs....................|SpaceVim-usage-windows-and-tabs|
8. Plugins................................................|SpaceVim-plugins|
1. autosave..................................|SpaceVim-plugins-autosave|
2. iedit........................................|SpaceVim-plugins-iedit|
3. runner......................................|SpaceVim-plugins-runner|
4. tab manager.............................|SpaceVim-plugins-tabmanager|
5. todo manager...........................|SpaceVim-plugins-todomanager|
1. alternate................................|SpaceVim-plugins-alternate|
2. autosave..................................|SpaceVim-plugins-autosave|
3. iedit........................................|SpaceVim-plugins-iedit|
4. runner......................................|SpaceVim-plugins-runner|
5. tab manager.............................|SpaceVim-plugins-tabmanager|
6. todo manager...........................|SpaceVim-plugins-todomanager|
9. API........................................................|SpaceVim-api|
1. clock............................................|SpaceVim-api-clock|
2. cmdlinemenu................................|SpaceVim-api-cmdlinemenu|
@ -1578,7 +1579,8 @@ COMMANDS *SpaceVim-commands*
Open specific project in |SpaceVim-options-src_root|
:A[!] {type} *:A*
Switch to alternate file based on {type}.
Switch to alternate file based on {type}. for more info about alternate file
configuration, checkout |SpaceVim-plugins-alternate|
==============================================================================
PUBLIC FUNCTIONS *SpaceVim-functions*
@ -6266,6 +6268,49 @@ PLUGINS *SpaceVim-plugins*
This is a list of builtin plugins.
==============================================================================
ALTERNATE *SpaceVim-plugins-alternate*
To manage the alternate file of the project, you need to create a
`.project_alt.json` file in the root of your project. Then you can use the
command `:A` to jump to the alternate file of current file. You can also
specific the type of alternate file, for example `:A doc`. With a bang `:A!`,
SpaceVim will parse the configuration file additionally. If no type is
specified, the default type `alternate` will be used.
here is an example of `.project_alt.json`:
>
{
"autoload/SpaceVim/layers/lang/*.vim": {
"doc": "docs/layers/lang/{}.md",
"test": "test/layer/lang/{}.vader"
}
}
<
instead of using `.project_alt.json`, `b:alternate_file_config` can be used in
bootstrap function, for example:
>
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
<
==============================================================================
AUTOSAVE *SpaceVim-plugins-autosave*

View File

@ -61,6 +61,12 @@ function M.alt(request_parse, ...)
local alt = nil
if fn.exists('b:alternate_file_config') ~= 1 then
local conf_file_path = M.getConfigPath()
if vim.fn.filereadable(conf_file_path) ~= 1 then
vim.api.nvim_eval(
'SpaceVim#api#notify#get().notify("no alternate config file!", "WarningMsg")'
)
return
end
local file = sp_file.unify_path(fn.bufname('%'), ':.')
alt = M.get_alt(file, conf_file_path, request_parse, alt_type)
end