Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions autoload/SpaceVim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2007,8 +2007,9 @@ function! SpaceVim#begin() abort
endif
if has('nvim-0.7')
try
" @fixme unknown font error
lua require('spacevim.default').options()
" https://github.com/vim/vim/issues/7191
" patch 8.2.1908: Lua is initialized even when not used
silent! lua require('spacevim.default').options()
catch

endtry
Expand Down
33 changes: 33 additions & 0 deletions autoload/SpaceVim/api/vim/buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,39 @@ EOF
call setbufvar(a:buffer,'&ma', ma)
endfunction

function! s:self.buf_set_lines2(buffer, start, end, strict_indexing, replacement) abort
if !bufexists(a:buffer)
return
endif
let ma = getbufvar(a:buffer, '&ma')
call setbufvar(a:buffer,'&ma', 1)
" if the function `nvim_buf_set_lines` exists
exe 'b' . a:buffer
let lct = line('$')
if a:start > lct
return
elseif a:start >= 0 && a:end > a:start
let endtext = a:end >= lct ? [] : getline(a:end + 1, '$')
" 0 start end $
if len(a:replacement) == a:end - a:start
for i in range(a:start, len(a:replacement) + a:start - 1)
call setline(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 setline(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
call setbufvar(a:buffer,'&ma', ma)

endfunction


function! s:self.displayArea() abort
return [
Expand Down
2 changes: 1 addition & 1 deletion autoload/SpaceVim/layers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ let s:CMP = SpaceVim#api#import('vim#compatible')
function! SpaceVim#layers#load(layer, ...) abort
if a:layer ==# '-l'
if has('nvim')
lua require('spacevim.layer').load('-l')
silent! lua require('spacevim.layer').load('-l')
else
call s:list_layers()
endif
Expand Down
14 changes: 8 additions & 6 deletions test/api/vim/buffer.vader
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ Execute ( SpaceVim api: vim#buffer open ):

Execute ( SpaceVim api: vim#buffer buf_set_lines):
let buffer = SpaceVim#api#import('vim#buffer')
Log 'has("nvim"):' . has('nvim')
Log 'if_py:' . has('python')
Log 'if_py3:' . has('python3')
Log 'if_lua:' . has('lua')
Log 'spacevim_if_lua:' . get(g:, '_spacevim_if_lua', 0)
let nr = buffer.bufadd('')
call setbufvar(nr, '&buftype', 'nofile')
call setbufvar(nr, '&buflisted', 0)
Log 'The value of g:_spacevim_if_lua is ' . get(g:, '_spacevim_if_lua', 0)
call buffer.buf_set_lines(nr, 0, 1, 0, ['line 1', 'line 2', 'line 3', 'line 4'])
call buffer.buf_set_lines2(nr, 0, 1, 0, ['line 1', 'line 2', 'line 3', 'line 4'])
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'line 2', 'line 3', 'line 4']
call buffer.buf_set_lines(nr, 1, 3, 0, ['replace 1', 'replace 2', 'replace 3'])
call buffer.buf_set_lines2(nr, 1, 3, 0, ['replace 1', 'replace 2', 'replace 3'])
AssertEqual getbufline(nr, 1, '$'), ['line 1', 'replace 1', 'replace 2', 'replace 3', 'line 4']
call buffer.buf_set_lines(nr, -3, -1, 0, ['replace 1', 'replace 2', 'replace 3'])
call buffer.buf_set_lines2(nr, -3, -1, 0, ['replace 1', 'replace 2', 'replace 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'])
call buffer.buf_set_lines2(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']
call buffer.buf_set_lines(nr, 0, -1, 0, ['xx 1'])
call buffer.buf_set_lines2(nr, 0, -1, 0, ['xx 1'])
AssertEqual getbufline(nr, 1, '$'), ['xx 1']
exe 'bd!' nr
unlet nr
Expand Down
Loading