1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-12 17:55:41 +08:00

refactor(vim#highlight): add is_string() function

This commit is contained in:
wsdjeg 2022-03-28 12:03:17 +08:00
parent a8d183fdd9
commit 95e1f0e199
3 changed files with 17 additions and 27 deletions

View File

@ -161,6 +161,16 @@ function! s:self.syntax_at(...) abort
return synIDattr(synID(l:lnum, l:col, 1), 'name')
endfunction
let s:string_hi = {
\ 'c' : 'cCppString',
\ 'cpp' : 'cCppString',
\ 'python' : 'pythonString',
\ }
function! s:self.is_string(l, c) abort
return synIDattr(synID(a:l, a:c, 1), 'name') == get(s:string_hi, &filetype, &filetype . 'String')
endfunction
function! s:self.syntax_of(pattern, ...) abort
if a:0 < 1
let l:nth = 1

View File

@ -48,6 +48,7 @@ let s:FILE = SpaceVim#api#import('file')
let s:MESSAGE = SpaceVim#api#import('vim#message')
let s:CMP = SpaceVim#api#import('vim#compatible')
let s:NOTI = SpaceVim#api#import('notify')
let s:HI = SpaceVim#api#import('vim#highlight')
function! SpaceVim#layers#core#plugins() abort
@ -542,12 +543,12 @@ function! s:jump_last_change() abort
endfunction
function! s:split_string(newline) abort
if s:is_string(line('.'), col('.'))
if s:HI.is_string(line('.'), col('.'))
let save_cursor = getcurpos()
let c = col('.')
let sep = ''
while c > 0
if s:is_string(line('.'), c)
if s:HI.is_string(line('.'), c)
let c -= 1
else
if !empty(get(get(g:string_info, &filetype, {}), 'quotes_hi', []))
@ -579,18 +580,6 @@ function! s:split_string(newline) abort
endif
endfunction
" @toto add sting highlight for other filetype
let s:string_hi = {
\ 'c' : 'cCppString',
\ 'cpp' : 'cCppString',
\ 'python' : 'pythonString',
\ }
function! s:is_string(l, c) abort
return synIDattr(synID(a:l, a:c, 1), 'name') == get(s:string_hi, &filetype, &filetype . 'String')
endfunction
" function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort

View File

@ -60,6 +60,7 @@ let s:LIST = SpaceVim#api#import('data#list')
let s:VIM = SpaceVim#api#import('vim')
let s:CMP = SpaceVim#api#import('vim#compatible')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:HI = SpaceVim#api#import('vim#highlight')
let s:autosave_timeout = 0
let s:autosave_events = []
@ -798,13 +799,13 @@ endfunction
function! s:join_string_with() abort
if s:is_string(line('.'), col('.'))
if s:HI.is_string(line('.'), col('.'))
let c = col('.')
let a = 0
let b = 0
let _c = c
while c > 0
if s:is_string(line('.'), c)
if s:HI.is_string(line('.'), c)
let c -= 1
else
let a = c
@ -813,7 +814,7 @@ function! s:join_string_with() abort
endwhile
let c = _c
while c > 0
if s:is_string(line('.'), c)
if s:HI.is_string(line('.'), c)
let c += 1
else
let b = c
@ -827,16 +828,6 @@ function! s:join_string_with() abort
endif
endfunction
let s:string_hi = {
\ 'c' : 'cCppString',
\ 'cpp' : 'cCppString',
\ }
function! s:is_string(l, c) abort
return synIDattr(synID(a:l, a:c, 1), 'name') == get(s:string_hi, &filetype, &filetype . 'String')
endfunction
" function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort