mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-24 05:20:04 +08:00
Fix signatures API (#1529)
This commit is contained in:
parent
4faf91fb88
commit
22450cbe4a
@ -1,21 +1,20 @@
|
||||
"=============================================================================
|
||||
" string.vim --- SpaceVim string API
|
||||
" init.vim --- Entry file for neovim
|
||||
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg at 163.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
let s:file = {}
|
||||
let s:self = {}
|
||||
|
||||
function! s:trim(str) abort
|
||||
function! s:self.trim(str) abort
|
||||
let str = substitute(a:str, '\s*$', '', 'g')
|
||||
return substitute(str, '^\s*', '', 'g')
|
||||
endfunction
|
||||
|
||||
let s:file['trim'] = function('s:trim')
|
||||
|
||||
function! s:fill(str, length) abort
|
||||
function! s:self.fill(str, length) abort
|
||||
if strwidth(a:str) <= a:length
|
||||
return a:str . repeat(' ', a:length - strwidth(a:str))
|
||||
else
|
||||
@ -32,9 +31,7 @@ function! s:fill(str, length) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:file['fill'] = function('s:fill')
|
||||
|
||||
function! s:fill_middle(str, length) abort
|
||||
function! s:self.fill_middle(str, length) abort
|
||||
if strwidth(a:str) <= a:length
|
||||
"return a:str . repeat(' ', a:length - strwidth(a:str))
|
||||
let n = a:length - strwidth(a:str)
|
||||
@ -57,30 +54,23 @@ function! s:fill_middle(str, length) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:file['fill_middle'] = function('s:fill_middle')
|
||||
|
||||
function! s:trim_start(str) abort
|
||||
function! s:self.trim_start(str) abort
|
||||
return substitute(a:str, '^\s*', '', 'g')
|
||||
endfunction
|
||||
|
||||
let s:file['trim_start'] = function('s:trim_start')
|
||||
|
||||
function! s:trim_end(str) abort
|
||||
function! s:self.trim_end(str) abort
|
||||
return substitute(a:str, '\s*$', '', 'g')
|
||||
endfunction
|
||||
|
||||
let s:file['trim_end'] = function('s:trim_end')
|
||||
|
||||
function! s:string2chars(str) abort
|
||||
function! s:self.string2chars(str) abort
|
||||
let chars = []
|
||||
for i in range(len(a:str))
|
||||
call add(chars, a:str[i : i])
|
||||
endfor
|
||||
return chars
|
||||
endfunction
|
||||
let s:file['string2chars'] = function('s:string2chars')
|
||||
|
||||
function! s:strAllIndex(str, need, use_expr) abort
|
||||
function! s:self.strAllIndex(str, need, use_expr) abort
|
||||
if a:use_expr
|
||||
let rst = []
|
||||
let idx = matchstrpos(a:str, a:need)
|
||||
@ -99,10 +89,44 @@ function! s:strAllIndex(str, need, use_expr) abort
|
||||
return rst
|
||||
endif
|
||||
endfunction
|
||||
let s:file['strAllIndex'] = function('s:strAllIndex')
|
||||
|
||||
function! s:self.strQ2B(str) abort
|
||||
let chars = self.string2chars(a:str)
|
||||
let bchars = []
|
||||
for char in chars
|
||||
let nr = char2nr(char)
|
||||
if nr == 12288
|
||||
call add(bchars, nr2char(32))
|
||||
elseif nr == 8216 && nr == 8217
|
||||
call add(bchars, nr2char(39))
|
||||
elseif nr >= 65281 && nr <= 65374
|
||||
call add(bchars, nr2char(nr - 65248))
|
||||
else
|
||||
call add(bchars, char)
|
||||
endif
|
||||
endfor
|
||||
return join(bchars, '')
|
||||
endfunction
|
||||
|
||||
function! s:self.strB2Q(str) abort
|
||||
let chars = self.string2chars(a:str)
|
||||
let bchars = []
|
||||
for char in chars
|
||||
let nr = char2nr(char)
|
||||
if nr == 32
|
||||
call add(bchars, nr2char(12288))
|
||||
elseif nr >= 32 && nr <= 126
|
||||
call add(bchars, nr2char(nr + 65248))
|
||||
else
|
||||
call add(bchars, char)
|
||||
endif
|
||||
endfor
|
||||
return join(bchars, '')
|
||||
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#api#data#string#get() abort
|
||||
return deepcopy(s:file)
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
||||
" vim:set et sw=2:
|
||||
|
@ -7,10 +7,11 @@
|
||||
"=============================================================================
|
||||
let s:self = {}
|
||||
let s:self.id = []
|
||||
let s:self._STRING = SpaceVim#api#import('data#string')
|
||||
function! s:self.info(line, col, message) abort
|
||||
let chars = SpaceVim#api#import('data#string').string2chars(a:message)
|
||||
let chars = self._STRING.string2chars(self._STRING.strQ2B(a:message))
|
||||
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, matchaddpos('Conceal', [[a:line, a:col + index, 1]], 10, -1, {'conceal' : chars[index]}))
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user