mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 00:30:05 +08:00
Add compatible API for matchaddpos (#1681)
* Fix #1679 * Fixup * Fixup * Fixup * Fixup
This commit is contained in:
parent
2eb48ec0b3
commit
6dec60cc15
@ -15,6 +15,7 @@ let s:self._handle_inputs = {}
|
|||||||
let s:self._is_quit = []
|
let s:self._is_quit = []
|
||||||
let s:self._handle_quit = {}
|
let s:self._handle_quit = {}
|
||||||
let s:self.noredraw = 0
|
let s:self.noredraw = 0
|
||||||
|
let s:self._cmp = SpaceVim#api#import('vim#compatible')
|
||||||
|
|
||||||
function! s:self.open() abort
|
function! s:self.open() abort
|
||||||
noautocmd botright split __transient_state__
|
noautocmd botright split __transient_state__
|
||||||
@ -123,9 +124,9 @@ if has('nvim')
|
|||||||
else
|
else
|
||||||
function! s:self.highlight_keys(exit, line, begin, end) abort
|
function! s:self.highlight_keys(exit, line, begin, end) abort
|
||||||
if a:exit
|
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
|
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
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
@ -136,7 +137,7 @@ if has('nvim')
|
|||||||
endfunction
|
endfunction
|
||||||
else
|
else
|
||||||
function! s:self.highlight_title() abort
|
function! s:self.highlight_title() abort
|
||||||
call matchaddpos('SpaceVim_Transient_State_Title', [1])
|
call self._cmp.matchaddpom('SpaceVim_Transient_State_Title', [1])
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ function! SpaceVim#api#vim#compatible#get() abort
|
|||||||
\ 'version' : '',
|
\ 'version' : '',
|
||||||
\ 'has' : '',
|
\ 'has' : '',
|
||||||
\ 'globpath' : '',
|
\ 'globpath' : '',
|
||||||
|
\ 'matchaddpos' : '',
|
||||||
\ },
|
\ },
|
||||||
\ "function('s:' . v:key)"
|
\ "function('s:' . v:key)"
|
||||||
\ )
|
\ )
|
||||||
@ -148,4 +149,61 @@ function! s:has(feature) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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:
|
" vim:set et sw=2 cc=80:
|
||||||
|
@ -8,11 +8,13 @@
|
|||||||
let s:self = {}
|
let s:self = {}
|
||||||
let s:self.id = []
|
let s:self.id = []
|
||||||
let s:self._STRING = SpaceVim#api#import('data#string')
|
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
|
function! s:self.info(line, col, message) abort
|
||||||
let chars = self._STRING.string2chars(self._STRING.strQ2B(a:message))
|
let chars = self._STRING.string2chars(self._STRING.strQ2B(a:message))
|
||||||
let chars = [' '] + chars
|
let chars = [' '] + chars
|
||||||
for index in range(len(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
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ function! s:self.clear() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! SpaceVim#api#vim#signatures#get()
|
function! SpaceVim#api#vim#signatures#get() abort
|
||||||
|
|
||||||
return deepcopy(s:self)
|
return deepcopy(s:self)
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ let s:save_cpo = &cpo
|
|||||||
set cpo&vim
|
set cpo&vim
|
||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
|
|
||||||
|
" Load SpaceVim API
|
||||||
|
|
||||||
|
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||||
|
|
||||||
function! SpaceVim#mapping#guide#has_configuration() "{{{
|
function! SpaceVim#mapping#guide#has_configuration() "{{{
|
||||||
return exists('s:desc_lookup')
|
return exists('s:desc_lookup')
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
@ -325,7 +329,7 @@ function! s:highlight_cursor() abort
|
|||||||
let begin = getpos("'<")
|
let begin = getpos("'<")
|
||||||
let end = getpos("'>")
|
let end = getpos("'>")
|
||||||
if begin[1] == end[1]
|
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
|
else
|
||||||
let pos = [[begin[1], begin[2], len(getline(begin[1])) - begin[2] + 1],
|
let pos = [[begin[1], begin[2], len(getline(begin[1])) - begin[2] + 1],
|
||||||
\ [end[1], 1, end[2]],
|
\ [end[1], 1, end[2]],
|
||||||
@ -333,10 +337,10 @@ function! s:highlight_cursor() abort
|
|||||||
for lnum in range(begin[1] + 1, end[1] - 1)
|
for lnum in range(begin[1] + 1, end[1] - 1)
|
||||||
call add(pos, [lnum, 1, len(getline(lnum))])
|
call add(pos, [lnum, 1, len(getline(lnum))])
|
||||||
endfor
|
endfor
|
||||||
let s:cursor_hi = matchaddpos('SpaceVimGuideCursor', pos)
|
let s:cursor_hi = s:CMP.matchaddpos('SpaceVimGuideCursor', pos)
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let s:cursor_hi = matchaddpos('SpaceVimGuideCursor', [[line('.'), col('.'), 1]])
|
let s:cursor_hi = s:CMP.matchaddpos('SpaceVimGuideCursor', [[line('.'), col('.'), 1]])
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
" Loadding SpaceVim api {{{
|
" Loadding SpaceVim api {{{
|
||||||
let s:VIMH = SpaceVim#api#import('vim#highlight')
|
let s:VIMH = SpaceVim#api#import('vim#highlight')
|
||||||
let s:STRING = SpaceVim#api#import('data#string')
|
let s:STRING = SpaceVim#api#import('data#string')
|
||||||
|
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
" init local variable {{{
|
" init local variable {{{
|
||||||
@ -37,8 +38,8 @@ function! s:range_logo() abort
|
|||||||
call matchdelete(s:hi_range_index)
|
call matchdelete(s:hi_range_index)
|
||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
let s:hi_range_id = matchaddpos('HiRrange' . s:current_range, [[3, begin, len(s:current_range) + 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 = matchaddpos('HiRrangeIndex', [[3, begin + len(s:current_range) + 2, len(index) + 2]])
|
let s:hi_range_index = s:CMP.matchaddpos('HiRrangeIndex', [[3, begin + len(s:current_range) + 2, len(index) + 2]])
|
||||||
redraw!
|
redraw!
|
||||||
echon ' Change current range to:'
|
echon ' Change current range to:'
|
||||||
exe 'echohl HiRrange' . s:current_range
|
exe 'echohl HiRrange' . s:current_range
|
||||||
@ -286,9 +287,9 @@ endfunction
|
|||||||
function! s:highlight() abort
|
function! s:highlight() abort
|
||||||
let s:highlight_id = []
|
let s:highlight_id = []
|
||||||
for item in s:stack
|
for item in s:stack
|
||||||
call add(s:highlight_id, matchaddpos('HiBlueBold', [ item ]))
|
call add(s:highlight_id, s:CMP.matchaddpos('HiBlueBold', [ item ]))
|
||||||
endfor
|
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
|
endfunction
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ let s:Operator = ''
|
|||||||
|
|
||||||
let s:VIMH = SpaceVim#api#import('vim#highlight')
|
let s:VIMH = SpaceVim#api#import('vim#highlight')
|
||||||
let s:STRING = SpaceVim#api#import('data#string')
|
let s:STRING = SpaceVim#api#import('data#string')
|
||||||
|
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||||
|
|
||||||
let s:cursor_stack = []
|
let s:cursor_stack = []
|
||||||
|
|
||||||
@ -49,9 +50,9 @@ function! s:highlight_cursor() abort
|
|||||||
call s:VIMH.hi(info)
|
call s:VIMH.hi(info)
|
||||||
for i in range(len(s:stack))
|
for i in range(len(s:stack))
|
||||||
if i == s:index
|
if i == s:index
|
||||||
call matchaddpos('IeditPurpleBold', [s:stack[i]])
|
call s:CMP.matchaddpos('IeditPurpleBold', [s:stack[i]])
|
||||||
else
|
else
|
||||||
call matchaddpos('IeditBlueBold', [s:stack[i]])
|
call s:CMP.matchaddpos('IeditBlueBold', [s:stack[i]])
|
||||||
endif
|
endif
|
||||||
call matchadd('SpaceVimGuideCursor', '\%' . s:stack[i][0] . 'l\%' . (s:stack[i][1] + len(s:cursor_stack[i].begin)) . 'c', 99999)
|
call matchadd('SpaceVimGuideCursor', '\%' . s:stack[i][0] . 'l\%' . (s:stack[i][1] + len(s:cursor_stack[i].begin)) . 'c', 99999)
|
||||||
endfor
|
endfor
|
||||||
|
Loading…
Reference in New Issue
Block a user