mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 10:30:05 +08:00
Fix Buffer api (#3136)
This commit is contained in:
parent
5ae3c415a5
commit
bd73871f6c
@ -36,7 +36,6 @@
|
|||||||
|
|
||||||
let s:self = {}
|
let s:self = {}
|
||||||
|
|
||||||
|
|
||||||
if exists('*getcmdwintype')
|
if exists('*getcmdwintype')
|
||||||
function! s:self.is_cmdwin() abort
|
function! s:self.is_cmdwin() abort
|
||||||
return getcmdwintype() !=# ''
|
return getcmdwintype() !=# ''
|
||||||
@ -130,11 +129,42 @@ function! s:self.buf_set_lines(buffer, start, end, strict_indexing, replacement)
|
|||||||
py3 lines = vim.eval("a:replacement")
|
py3 lines = vim.eval("a:replacement")
|
||||||
py3 vim.buffers[bufnr][start_line:end_line] = lines
|
py3 vim.buffers[bufnr][start_line:end_line] = lines
|
||||||
endif
|
endif
|
||||||
|
elseif has('lua') && 0
|
||||||
|
lua require("spacevim.api.vim.buffer").buf_set_lines(
|
||||||
|
\ vim.eval("a:winid"),
|
||||||
|
\ vim.eval("a:start"),
|
||||||
|
\ vim.eval("a:end"),
|
||||||
|
\ vim.eval("a:replacement")
|
||||||
|
\ )
|
||||||
elseif exists('*setbufline')
|
elseif exists('*setbufline')
|
||||||
let line = a:start
|
let lct = self.line_count(a:buffer)
|
||||||
for i in range(len(a:replacement))
|
if a:start > lct
|
||||||
call setbufline(bufname(a:buffer), line + i, a:replacement[i])
|
return
|
||||||
endfor
|
elseif a:start >= 0 && a:end > a:start
|
||||||
|
" in vim, setbufline will not load buffer automatically
|
||||||
|
" but in neovim, nvim_buf_set_lines will do it.
|
||||||
|
" @fixme vim issue #5044
|
||||||
|
" https://github.com/vim/vim/issues/5044
|
||||||
|
let endtext = a:end > lct ? [] : getbufline(a:buffer, a:end + 1, '$')
|
||||||
|
if !buflisted(a:buffer)
|
||||||
|
call bufload(a:buffer)
|
||||||
|
endif
|
||||||
|
" 0 start end $
|
||||||
|
if len(a:replacement) == a:end - a:start
|
||||||
|
for i in range(a:start, len(a:replacement) + a:start - 1)
|
||||||
|
call setbufline(a:buffer, i + 1, a:replacement[i - a:start])
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
let replacement = a:replacement + endtext
|
||||||
|
for i in range(a:start, len(replacement) + a:start - 1)
|
||||||
|
call setbufline(a:buffer, i + 1, replacement[i - a:start])
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
elseif a:start >= 0 && a:end < 0 && lct + a:end > a:start
|
||||||
|
call self.buf_set_lines(a:buffer, a:start, lct + a:end + 1, a:strict_indexing, a:replacement)
|
||||||
|
elseif a:start <= 0 && a:end > a:start && a:end < 0 && lct + a:start >= 0
|
||||||
|
call self.buf_set_lines(a:buffer, lct + a:start + 1, lct + a:end + 1, a:strict_indexing, a:replacement)
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
exe 'b' . a:buffer
|
exe 'b' . a:buffer
|
||||||
call setline(a:start - 1, a:replacement)
|
call setline(a:start - 1, a:replacement)
|
||||||
|
@ -22,6 +22,7 @@ let s:messletters = SpaceVim#api#import('messletters')
|
|||||||
let s:file = SpaceVim#api#import('file')
|
let s:file = SpaceVim#api#import('file')
|
||||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||||
let s:HI = SpaceVim#api#import('vim#highlight')
|
let s:HI = SpaceVim#api#import('vim#highlight')
|
||||||
|
let s:SYS = SpaceVim#api#import('system')
|
||||||
|
|
||||||
let g:_spacevim_tabline_loaded = 1
|
let g:_spacevim_tabline_loaded = 1
|
||||||
let s:buffers = s:BUFFER.listed_buffers()
|
let s:buffers = s:BUFFER.listed_buffers()
|
||||||
@ -96,7 +97,12 @@ function! SpaceVim#layers#core#tabline#get() abort
|
|||||||
endif
|
endif
|
||||||
let buflist = tabpagebuflist(i)
|
let buflist = tabpagebuflist(i)
|
||||||
let winnr = tabpagewinnr(i)
|
let winnr = tabpagewinnr(i)
|
||||||
let name = fnamemodify(bufname(buflist[winnr - 1]), ':t')
|
let bufname = bufname(buflist[winnr - 1])
|
||||||
|
if s:SYS.isWindows
|
||||||
|
let bufname = substitute(bufname, '\\[', '[', 'g')
|
||||||
|
let bufname = substitute(bufname, '\\]', ']', 'g')
|
||||||
|
endif
|
||||||
|
let name = fnamemodify(bufname, ':t')
|
||||||
let tabname = gettabvar(i, '_spacevim_tab_name', '')
|
let tabname = gettabvar(i, '_spacevim_tab_name', '')
|
||||||
if has('tablineat')
|
if has('tablineat')
|
||||||
let t .= '%' . index . '@SpaceVim#layers#core#tabline#jump@'
|
let t .= '%' . index . '@SpaceVim#layers#core#tabline#jump@'
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
local buffer = {}
|
||||||
|
|
||||||
|
function buffer.set_lines(bufnr, startindex, endindex, replacement)
|
||||||
|
print("hello")
|
||||||
|
end
|
||||||
|
|
||||||
|
return buffer
|
||||||
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
|||||||
Execute ( SpaceVim api: vim#buffer open ):
|
Execute ( SpaceVim api: vim#buffer open ):
|
||||||
new
|
|
||||||
let buffer = SpaceVim#api#import('vim#buffer')
|
let buffer = SpaceVim#api#import('vim#buffer')
|
||||||
call buffer.open({'bufname':'foo', 'cmd' : 'setl buftype=nofile bufhidden=wipe'})
|
call buffer.open({'bufname':'foo', 'cmd' : 'setl buftype=nofile bufhidden=wipe'})
|
||||||
AssertEqual bufname('%'), 'foo'
|
AssertEqual bufname('%'), 'foo'
|
||||||
@ -7,12 +6,14 @@ Execute ( SpaceVim api: vim#buffer open ):
|
|||||||
|
|
||||||
Execute ( SpaceVim api: vim#buffer buf_set_lines):
|
Execute ( SpaceVim api: vim#buffer buf_set_lines):
|
||||||
let buffer = SpaceVim#api#import('vim#buffer')
|
let buffer = SpaceVim#api#import('vim#buffer')
|
||||||
let os = SpaceVim#api#import('system')
|
let nr = bufadd('')
|
||||||
if os.isWindows
|
call setbufvar(nr, '&buftype', 'nofile')
|
||||||
finish
|
call setbufvar(nr, '&buflisted', 0)
|
||||||
endif
|
call buffer.buf_set_lines(nr, 0, 1, 0, ['line 1', 'line 2', 'line 3', 'line 4'])
|
||||||
new
|
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'line 2', 'line 3', 'line 4']
|
||||||
let nr = bufnr('%')
|
call buffer.buf_set_lines(nr, 1, 3, 0, ['replace 1', 'replace 2', 'replace 3'])
|
||||||
new
|
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'replace 1', 'replace 2', 'replace 3', 'line 4']
|
||||||
call buffer.buf_set_lines(nr, 0, 1, 0, ['line 1', 'line 2', 'line 3'])
|
call buffer.buf_set_lines(nr, -3, -1, 0, ['replace 1', 'replace 2', 'replace 3'])
|
||||||
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'line 2', 'line 3']
|
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'replace 1', 'replace 2', 'replace 1', 'replace 2', 'replace 3']
|
||||||
|
call buffer.buf_set_lines(nr, 2, -2, 0, ['replace 1', 'replace 2', 'replace 3'])
|
||||||
|
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'replace 1', 'replace 1', 'replace 2', 'replace 3', 'replace 3']
|
||||||
|
12
vimrc
12
vimrc
@ -10,14 +10,12 @@
|
|||||||
if 1
|
if 1
|
||||||
let g:_spacevim_if_lua = 0
|
let g:_spacevim_if_lua = 0
|
||||||
if has('lua')
|
if has('lua')
|
||||||
try
|
let s:plugin_dir = fnamemodify(expand('<sfile>'), ':h').'\lua'
|
||||||
let s:plugin_dir = fnamemodify(expand('<sfile>'), ':h').'\lua'
|
let s:str = s:plugin_dir . '\?.lua;' . s:plugin_dir . '\?\init.lua;'
|
||||||
let s:str = s:plugin_dir . '\?.lua;' . s:plugin_dir . '\?\init.lua;'
|
silent! lua package.path=vim.eval("s:str") .. package.path
|
||||||
lua package.path=vim.eval("s:str") .. package.path
|
if empty(v:errmsg)
|
||||||
let g:_spacevim_if_lua = 1
|
let g:_spacevim_if_lua = 1
|
||||||
catch
|
endif
|
||||||
let g:_spacevim_if_lua = 0
|
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
|
execute 'source' fnamemodify(expand('<sfile>'), ':h').'/config/main.vim'
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user