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

Add compatible API for matchaddpos (#1681)

* Fix #1679

* Fixup

* Fixup

* Fixup

* Fixup
This commit is contained in:
Wang Shidong 2018-05-01 21:12:16 +08:00 committed by GitHub
parent 2eb48ec0b3
commit 6dec60cc15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 14 deletions

View File

@ -15,6 +15,7 @@ let s:self._handle_inputs = {}
let s:self._is_quit = []
let s:self._handle_quit = {}
let s:self.noredraw = 0
let s:self._cmp = SpaceVim#api#import('vim#compatible')
function! s:self.open() abort
noautocmd botright split __transient_state__
@ -123,9 +124,9 @@ if has('nvim')
else
function! s:self.highlight_keys(exit, line, begin, end) abort
if a:exit
call matchaddpos('SpaceVim_Transient_State_Exit', [[a:line + 1, a:begin + 1, a:end - a:begin]])
call self._cmp.matchaddpom('SpaceVim_Transient_State_Exit', [[a:line + 1, a:begin + 1, a:end - a:begin]])
else
call matchaddpos('SpaceVim_Transient_State_Notexit', [[a:line + 1, a:begin + 1, a:end - a:begin]])
call self._cmp.matchaddpom('SpaceVim_Transient_State_Notexit', [[a:line + 1, a:begin + 1, a:end - a:begin]])
endif
endfunction
endif
@ -136,7 +137,7 @@ if has('nvim')
endfunction
else
function! s:self.highlight_title() abort
call matchaddpos('SpaceVim_Transient_State_Title', [1])
call self._cmp.matchaddpom('SpaceVim_Transient_State_Title', [1])
endfunction
endif

View File

@ -13,6 +13,7 @@ function! SpaceVim#api#vim#compatible#get() abort
\ 'version' : '',
\ 'has' : '',
\ 'globpath' : '',
\ 'matchaddpos' : '',
\ },
\ "function('s:' . v:key)"
\ )
@ -148,4 +149,61 @@ function! s:has(feature) abort
endif
endfunction
" - A number. This whole line will be highlighted. The first
" line has number 1.
" - A list with one number, e.g., [23]. The whole line with this
" number will be highlighted.
" - A list with two numbers, e.g., [23, 11]. The first number is
" the line number, the second one is the column number (first
" column is 1, the value must correspond to the byte index as
" |col()| would return). The character at this position will
" be highlighted.
" - A list with three numbers, e.g., [23, 11, 3]. As above, but
" the third number gives the length of the highlight in bytes.
if exists('*matchaddpos')
function! s:matchaddpos(group, pos, ...) abort
let priority = get(a:000, 0, 10)
let id = get(a:000, 1, -1)
let dict = get(a:000, 2, {})
return matchaddpos(a:group, a:pos, priority, id, dict)
endfunction
else
function! s:matchaddpos(group, pos, ...) abort
let priority = get(a:000, 0, 10)
let id = get(a:000, 1, -1)
let dict = get(a:000, 2, {})
let pos1 = a:pos[0]
if type(pos1) == 0
let id = matchadd(a:group, '\%' . pos1 . 'l', priority, id, dict)
elseif type(pos1) == 3
if len(pos1) == 1
let id = matchadd(a:group, '\%' . pos1[0] . 'l', priority, id, dict)
elseif len(pos1) == 2
let id = matchadd(a:group, '\%' . pos1[0] . 'l\%' . pos1[1] . 'c', priority, id, dict)
elseif len(pos1) == 3
let id = matchadd(a:group, '\%' . pos1[0] . 'l\%>' . pos1[1] . 'c\%<' . pos1[2] . 'c', priority, id, dict)
endif
endif
if len(a:pos) > 1
for pos1 in a:pos[1:]
if type(pos1) == 0
call matchadd(a:group, '\%' . pos1 . 'l', priority, id, dict)
elseif type(pos1) == 3
if len(pos1) == 1
call matchadd(a:group, '\%' . pos1[0] . 'l', priority, id, dict)
elseif len(pos1) == 2
call matchadd(a:group, '\%' . pos1[0] . 'l\%' . pos1[1] . 'c', priority, id, dict)
elseif len(pos1) == 3
call matchadd(a:group, '\%' . pos1[0] . 'l\%>' . pos1[1] . 'c\%<' . pos1[2] . 'c', priority, id, dict)
endif
endif
endfor
endif
return id
endfunction
endif
" vim:set et sw=2 cc=80:

View File

@ -8,11 +8,13 @@
let s:self = {}
let s:self.id = []
let s:self._STRING = SpaceVim#api#import('data#string')
let s:self._cmp = SpaceVim#api#import('vim#compatible')
function! s:self.info(line, col, message) abort
let chars = self._STRING.string2chars(self._STRING.strQ2B(a:message))
let chars = [' '] + chars
for index in range(len(chars))
call add(self.id, matchaddpos('Conceal', [[a:line, a:col - 1 + index, 1]], 10, -1, {'conceal' : chars[index]}))
call add(self.id, self._cmp.matchaddpos('Conceal', [[a:line, a:col - 1 + index, 1]], 10, -1, {'conceal' : chars[index]}))
endfor
endfunction
@ -32,7 +34,7 @@ function! s:self.clear() abort
endfunction
function! SpaceVim#api#vim#signatures#get()
function! SpaceVim#api#vim#signatures#get() abort
return deepcopy(s:self)

View File

@ -10,6 +10,10 @@ let s:save_cpo = &cpo
set cpo&vim
scriptencoding utf-8
" Load SpaceVim API
let s:CMP = SpaceVim#api#import('vim#compatible')
function! SpaceVim#mapping#guide#has_configuration() "{{{
return exists('s:desc_lookup')
endfunction "}}}
@ -325,7 +329,7 @@ function! s:highlight_cursor() abort
let begin = getpos("'<")
let end = getpos("'>")
if begin[1] == end[1]
let s:cursor_hi = matchaddpos('SpaceVimGuideCursor', [[begin[1], min([begin[2], end[2]]), abs(begin[2] - end[2]) + 1]])
let s:cursor_hi = s:CMP.matchaddpos('SpaceVimGuideCursor', [[begin[1], min([begin[2], end[2]]), abs(begin[2] - end[2]) + 1]])
else
let pos = [[begin[1], begin[2], len(getline(begin[1])) - begin[2] + 1],
\ [end[1], 1, end[2]],
@ -333,10 +337,10 @@ function! s:highlight_cursor() abort
for lnum in range(begin[1] + 1, end[1] - 1)
call add(pos, [lnum, 1, len(getline(lnum))])
endfor
let s:cursor_hi = matchaddpos('SpaceVimGuideCursor', pos)
let s:cursor_hi = s:CMP.matchaddpos('SpaceVimGuideCursor', pos)
endif
else
let s:cursor_hi = matchaddpos('SpaceVimGuideCursor', [[line('.'), col('.'), 1]])
let s:cursor_hi = s:CMP.matchaddpos('SpaceVimGuideCursor', [[line('.'), col('.'), 1]])
endif
endfunction

View File

@ -16,6 +16,7 @@
" Loadding SpaceVim api {{{
let s:VIMH = SpaceVim#api#import('vim#highlight')
let s:STRING = SpaceVim#api#import('data#string')
let s:CMP = SpaceVim#api#import('vim#compatible')
"}}}
" init local variable {{{
@ -37,8 +38,8 @@ function! s:range_logo() abort
call matchdelete(s:hi_range_index)
catch
endtry
let s:hi_range_id = matchaddpos('HiRrange' . s:current_range, [[3, begin, len(s:current_range) + 2]])
let s:hi_range_index = matchaddpos('HiRrangeIndex', [[3, begin + len(s:current_range) + 2, len(index) + 2]])
let s:hi_range_id = s:CMP.matchaddpos('HiRrange' . s:current_range, [[3, begin, len(s:current_range) + 2]])
let s:hi_range_index = s:CMP.matchaddpos('HiRrangeIndex', [[3, begin + len(s:current_range) + 2, len(index) + 2]])
redraw!
echon ' Change current range to:'
exe 'echohl HiRrange' . s:current_range
@ -286,9 +287,9 @@ endfunction
function! s:highlight() abort
let s:highlight_id = []
for item in s:stack
call add(s:highlight_id, matchaddpos('HiBlueBold', [ item ]))
call add(s:highlight_id, s:CMP.matchaddpos('HiBlueBold', [ item ]))
endfor
let s:highlight_id_c = matchaddpos('HiPurpleBold', [s:stack[s:index]])
let s:highlight_id_c = s:CMP.matchaddpos('HiPurpleBold', [s:stack[s:index]])
endfunction
" }}}

View File

@ -15,6 +15,7 @@ let s:Operator = ''
let s:VIMH = SpaceVim#api#import('vim#highlight')
let s:STRING = SpaceVim#api#import('data#string')
let s:CMP = SpaceVim#api#import('vim#compatible')
let s:cursor_stack = []
@ -49,9 +50,9 @@ function! s:highlight_cursor() abort
call s:VIMH.hi(info)
for i in range(len(s:stack))
if i == s:index
call matchaddpos('IeditPurpleBold', [s:stack[i]])
call s:CMP.matchaddpos('IeditPurpleBold', [s:stack[i]])
else
call matchaddpos('IeditBlueBold', [s:stack[i]])
call s:CMP.matchaddpos('IeditBlueBold', [s:stack[i]])
endif
call matchadd('SpaceVimGuideCursor', '\%' . s:stack[i][0] . 'l\%' . (s:stack[i][1] + len(s:cursor_stack[i].begin)) . 'c', 99999)
endfor