Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support older vim #8

Merged
merged 1 commit into from
Dec 7, 2019
Merged
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
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ vsnip can integrate some other plugins via [vim-vsnip-integ](https://github.com/
- Some LSP client integration.


# Requirements

- nvim: v0.4.0 or higher.
- vim: v8.1.0039 or higher.


# Usage

### 1. Install
Expand Down
24 changes: 11 additions & 13 deletions autoload/vsnip/edits/text_edit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ function! vsnip#edits#text_edit#apply(bufnr, edits) abort
\ 'character': col('.')
\ }
for l:edit in reverse(copy(l:edits))
call s:edit(a:bufnr, l:edit, l:position)
call s:edit(l:edit, l:position)
endfor

if bufnr('%') == a:bufnr
" adjust curops.
call setpos('.', [a:bufnr, l:position.line, l:position.character])
endif
" adjust curops.
call setpos('.', [a:bufnr, l:position.line, l:position.character])
endfunction

"
" s:edit
"
function! s:edit(bufnr, edit, position) abort
let l:start_line = getbufline(a:bufnr, a:edit.range.start.line)[0]
function! s:edit(edit, position) abort
let l:start_line = getline(a:edit.range.start.line)
let l:before_line = strcharpart(l:start_line, 0, a:edit.range.start.character - 1)
let l:end_line = get(getbufline(a:bufnr, a:edit.range.end.line), 0, '')
let l:end_line = getline(a:edit.range.end.line)
let l:after_line = strcharpart(l:end_line, a:edit.range.end.character - 1, strchars(l:end_line) - (a:edit.range.end.character - 1))

let l:lines = split(a:edit.newText, "\n", v:true)
Expand All @@ -38,7 +36,7 @@ function! s:edit(bufnr, edit, position) abort
let l:lines_len = len(l:lines)
let l:range_len = a:edit.range.end.line - a:edit.range.start.line

let l:total_lines = len(getbufline(a:bufnr, '^', '$'))
let l:total_lines = len(getline('^', '$'))

" fix cursor pos
if a:edit.range.end.line <= a:position.line
Expand All @@ -59,11 +57,11 @@ function! s:edit(bufnr, edit, position) abort
while l:i < l:lines_len
let l:lnum = a:edit.range.start.line + l:i
if l:i <= l:range_len && l:i < l:total_lines
if get(getbufline(a:bufnr, l:lnum), 0) !=# l:lines[l:i]
call setbufline(a:bufnr, l:lnum, l:lines[l:i])
if getline(l:lnum) !=# l:lines[l:i]
call setline(l:lnum, l:lines[l:i])
endif
else
call appendbufline(a:bufnr, l:lnum - 1, l:lines[l:i])
call append(l:lnum - 1, l:lines[l:i])
endif
let l:i += 1
endwhile
Expand All @@ -72,7 +70,7 @@ function! s:edit(bufnr, edit, position) abort
if l:lines_len <= l:range_len
let l:start = a:edit.range.end.line - (l:range_len - l:lines_len)
let l:end = a:edit.range.end.line
call deletebufline(a:bufnr, l:start, l:end)
execute printf('normal! %s,%sdelete _', l:start, l:end)
endif
endfunction

Expand Down
15 changes: 3 additions & 12 deletions plugin/vsnip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@ if exists('g:loaded_vsnip')
endif
let g:loaded_vsnip = 1

" version check.
if !exists('*getbufline')
\ || !exists('*setbufline')
\ || !exists('*appendbufline')
\ || !exists('*deletebufline')
echomsg '[vim-vsnip] `vim-vsnip` was disabled.'
echomsg '[vim-vsnip] `vim-vsnip` required getbufline/setbufline/appendbufline/deletebufline.'
echomsg '[vim-vsnip] Please use nvim >= v0.4.0 or vim >= v8.1.0039'
finish
endif

"
" variable.
"
let g:vsnip_extra_mapping = get(g:, 'vsnip_extra_mapping', v:true)
let g:vsnip_snippet_dir = get(g:, 'vsnip_snippet_dir', expand('~/.vsnip'))
let g:vsnip_snippet_dirs = get(g:, 'vsnip_snippet_dirs', [])
let g:vsnip_sync_delay = get(g:, 'vsnip_sync_delay', 0)
let g:vsnip_choice_delay = get(g:, 'vsnip_choice_delay', 500)
let g:vsnip_namespace = get(g:, 'vsnip_namespace', 'vsnip:')


"
" command.
"
Expand Down