mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
feat(guide): rewrite leader guide in lua
This commit is contained in:
parent
100aa31e52
commit
7e81ce1019
@ -6,7 +6,6 @@
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
scriptencoding utf-8
|
||||
|
||||
if exists('s:save_cpo')
|
||||
finish
|
||||
endif
|
||||
@ -14,50 +13,96 @@ endif
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Load SpaceVim API
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
let s:STR = SpaceVim#api#import('data#string')
|
||||
let s:KEY = SpaceVim#api#import('vim#key')
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
if has('nvim')
|
||||
let s:FLOATING = SpaceVim#api#import('neovim#floating')
|
||||
if has('nvim-0.9.0')
|
||||
|
||||
function! SpaceVim#mapping#guide#parse_mappings() abort " {{{
|
||||
lua require("spacevim.plugin.guide").parse_mappings()
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#start(vis, dict) abort " {{{
|
||||
lua require("spacevim.plugin.guide").start(
|
||||
\ require("spacevim").eval("a:vis"),
|
||||
\ require("spacevim").eval("a:dict")
|
||||
\ )
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#has_configuration() abort "{{{
|
||||
return luaeval('require("spacevim.plugin.guide").has_configuration()')
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#start_by_prefix(vis, key) abort " {{{
|
||||
lua require("spacevim.plugin.guide").start_by_prefix(
|
||||
\ require("spacevim").eval("a:vis"),
|
||||
\ require("spacevim").eval("a:key")
|
||||
\ )
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#register_displayname(lhs, name) abort
|
||||
lua require("spacevim.plugin.guide").register_displayname(
|
||||
\ require("spacevim").eval("a:lhs"),
|
||||
\ require("spacevim").eval("a:name")
|
||||
\ )
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#populate_dictionary(key, dictname) abort " {{{
|
||||
lua require("spacevim.plugin.guide").populate_dictionary(
|
||||
\ require("spacevim").eval("a:key"),
|
||||
\ require("spacevim").eval("a:dictname")
|
||||
\ )
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#register_prefix_descriptions(key, dictname) abort " {{{
|
||||
lua require("spacevim.plugin.guide").register_prefix_descriptions(
|
||||
\ require("spacevim").eval("a:key"),
|
||||
\ require("spacevim").eval("a:dictname")
|
||||
\ )
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#displayfunc() abort
|
||||
lua require("spacevim.plugin.guide").displayfunc()
|
||||
endfunction
|
||||
else
|
||||
|
||||
|
||||
" Load SpaceVim API
|
||||
let s:CMP = SpaceVim#api#import('vim#compatible')
|
||||
let s:STR = SpaceVim#api#import('data#string')
|
||||
let s:KEY = SpaceVim#api#import('vim#key')
|
||||
let s:VIM = SpaceVim#api#import('vim')
|
||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||
if has('nvim')
|
||||
let s:FLOATING = SpaceVim#api#import('neovim#floating')
|
||||
else
|
||||
let s:FLOATING = SpaceVim#api#import('vim#floating')
|
||||
endif
|
||||
let s:SL = SpaceVim#api#import('vim#statusline')
|
||||
endif
|
||||
let s:SL = SpaceVim#api#import('vim#statusline')
|
||||
let s:LOG =SpaceVim#logger#derive('guide')
|
||||
|
||||
" guide specific var
|
||||
let s:winid = -1
|
||||
let s:bufnr = -1
|
||||
let s:prefix_key_inp = []
|
||||
let s:lmap = {}
|
||||
" this should be the history of s:lmap and s:guide_group
|
||||
let s:undo_history = []
|
||||
" guide specific var
|
||||
let s:winid = -1
|
||||
let s:bufnr = -1
|
||||
let s:prefix_key_inp = []
|
||||
let s:lmap = {}
|
||||
" this should be the history of s:lmap and s:guide_group
|
||||
let s:undo_history = []
|
||||
let s:registered_name = {}
|
||||
|
||||
function! SpaceVim#mapping#guide#has_configuration() abort "{{{
|
||||
function! SpaceVim#mapping#guide#has_configuration() abort "{{{
|
||||
return exists('s:desc_lookup')
|
||||
endfunction "}}}
|
||||
endfunction "}}}
|
||||
|
||||
function! SpaceVim#mapping#guide#register_prefix_descriptions(key, dictname) abort " {{{
|
||||
function! SpaceVim#mapping#guide#register_prefix_descriptions(key, dictname) abort " {{{
|
||||
let key = a:key ==? '<Space>' ? ' ' : a:key
|
||||
if !exists('s:desc_lookup')
|
||||
call s:create_cache()
|
||||
endif
|
||||
if strlen(key) == 0
|
||||
let s:desc_lookup['top'] = a:dictname
|
||||
return
|
||||
endif
|
||||
if !has_key(s:desc_lookup, key)
|
||||
elseif !has_key(s:desc_lookup, key)
|
||||
let s:desc_lookup[key] = a:dictname
|
||||
endif
|
||||
endfunction "}}}
|
||||
function! s:create_cache() abort " {{{
|
||||
call s:LOG.debug('desc_lookup is:' . string(s:desc_lookup))
|
||||
endfunction "}}}
|
||||
function! s:create_cache() abort " {{{
|
||||
let s:desc_lookup = {}
|
||||
let s:cached_dicts = {}
|
||||
endfunction " }}}
|
||||
function! s:create_target_dict(key) abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:create_target_dict(key) abort " {{{
|
||||
if has_key(s:desc_lookup, 'top')
|
||||
" use {expr} to eval viml value
|
||||
let toplevel = deepcopy({s:desc_lookup['top']})
|
||||
let tardict = s:toplevel ? toplevel : get(toplevel, a:key, {})
|
||||
let mapdict = s:cached_dicts[a:key]
|
||||
@ -70,8 +115,8 @@ function! s:create_target_dict(key) abort " {{{
|
||||
let tardict = s:cached_dicts[a:key]
|
||||
endif
|
||||
return tardict
|
||||
endfunction " }}}
|
||||
function! s:merge(dict_t, dict_o) abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:merge(dict_t, dict_o) abort " {{{
|
||||
let target = a:dict_t
|
||||
let other = a:dict_o
|
||||
for k in keys(target)
|
||||
@ -93,22 +138,22 @@ function! s:merge(dict_t, dict_o) abort " {{{
|
||||
endif
|
||||
endfor
|
||||
call extend(target, other, 'keep')
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
" @vimlint(EVL103, 1, a:dictname)
|
||||
function! SpaceVim#mapping#guide#populate_dictionary(key, dictname) abort " {{{
|
||||
" @vimlint(EVL103, 1, a:dictname)
|
||||
function! SpaceVim#mapping#guide#populate_dictionary(key, dictname) abort " {{{
|
||||
call s:start_parser(a:key, s:cached_dicts[a:key])
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL103, 0, a:dictname)
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL103, 0, a:dictname)
|
||||
|
||||
function! SpaceVim#mapping#guide#parse_mappings() abort " {{{
|
||||
function! SpaceVim#mapping#guide#parse_mappings() abort " {{{
|
||||
for [k, v] in items(s:cached_dicts)
|
||||
call s:start_parser(k, v)
|
||||
endfor
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
|
||||
function! s:start_parser(key, dict) abort " {{{
|
||||
function! s:start_parser(key, dict) abort " {{{
|
||||
if a:key ==# '[KEYs]'
|
||||
return
|
||||
endif
|
||||
@ -144,9 +189,9 @@ function! s:start_parser(key, dict) abort " {{{
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
function! s:add_map_to_dict(map, level, dict) abort " {{{
|
||||
function! s:add_map_to_dict(map, level, dict) abort " {{{
|
||||
if len(a:map.lhs) > a:level+1
|
||||
let curkey = a:map.lhs[a:level]
|
||||
let nlevel = a:level+1
|
||||
@ -184,9 +229,9 @@ function! s:add_map_to_dict(map, level, dict) abort " {{{
|
||||
let a:dict[a:map.lhs[a:level]] = [cmd, a:map.display]
|
||||
endif
|
||||
endif
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL111, 1, Fun)
|
||||
function! s:format_displaystring(map) abort " {{{
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL111, 1, Fun)
|
||||
function! s:format_displaystring(map) abort " {{{
|
||||
let g:leaderGuide#displayname = a:map
|
||||
for Fun in g:leaderGuide_displayfunc
|
||||
call Fun()
|
||||
@ -194,9 +239,9 @@ function! s:format_displaystring(map) abort " {{{
|
||||
let display = g:leaderGuide#displayname
|
||||
unlet g:leaderGuide#displayname
|
||||
return display
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL111, 0, Fun)
|
||||
function! s:flattenmap(dict, str) abort " {{{
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL111, 0, Fun)
|
||||
function! s:flattenmap(dict, str) abort " {{{
|
||||
let ret = {}
|
||||
for kv in keys(a:dict)
|
||||
if type(a:dict[kv]) == type([])
|
||||
@ -208,17 +253,17 @@ function! s:flattenmap(dict, str) abort " {{{
|
||||
endif
|
||||
endfor
|
||||
return ret
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
|
||||
function! s:escape_mappings(mapping) abort " {{{
|
||||
function! s:escape_mappings(mapping) abort " {{{
|
||||
let rstring = substitute(a:mapping.rhs, '\', '\\\\', 'g')
|
||||
let rstring = substitute(rstring, '<\([^<>]*\)>', '\\<\1>', 'g')
|
||||
let rstring = substitute(rstring, '"', '\\"', 'g')
|
||||
let rstring = 'call feedkeys("'.rstring.'", "'.a:mapping.feedkeyargs.'")'
|
||||
return rstring
|
||||
endfunction " }}}
|
||||
function! s:string_to_keys(input) abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:string_to_keys(input) abort
|
||||
" Avoid special case: <>
|
||||
let retlist = []
|
||||
if match(a:input, '<.\+>') != -1
|
||||
@ -238,9 +283,9 @@ function! s:string_to_keys(input) abort " {{{
|
||||
let go = 0
|
||||
elseif a:input[si] ==? '>'
|
||||
let go = 1
|
||||
end
|
||||
endif
|
||||
let si += 1
|
||||
endw
|
||||
endwhile
|
||||
else
|
||||
for it in split(a:input, '\zs')
|
||||
if it ==# ' '
|
||||
@ -251,13 +296,13 @@ function! s:string_to_keys(input) abort " {{{
|
||||
endfor
|
||||
endif
|
||||
return retlist
|
||||
endfunction " }}}
|
||||
function! s:escape_keys(inp) abort " {{{
|
||||
endfunction
|
||||
function! s:escape_keys(inp) abort " {{{
|
||||
let ret = substitute(a:inp, '<', '<lt>', '')
|
||||
return substitute(ret, '|', '<Bar>', '')
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
function! s:calc_layout() abort " {{{
|
||||
function! s:calc_layout() abort " {{{
|
||||
let ret = {}
|
||||
let smap = filter(copy(s:lmap), 'v:key !=# "name"')
|
||||
let ret.n_items = len(smap)
|
||||
@ -265,6 +310,7 @@ function! s:calc_layout() abort " {{{
|
||||
\ 'strdisplaywidth(repeat(" ", 8 - strlen(v:key)) . "[".v:key."]".'.
|
||||
\ '(type(v:val) == type({}) ? v:val["name"] : v:val[1]))'))
|
||||
let maxlength = max(length) + g:leaderGuide_hspace
|
||||
call s:LOG.debug('maxlength is:' . maxlength)
|
||||
if g:leaderGuide_vertical
|
||||
let ret.n_rows = winheight(0) - 2
|
||||
let ret.n_cols = ret.n_items / ret.n_rows + (ret.n_items != ret.n_rows)
|
||||
@ -276,16 +322,17 @@ function! s:calc_layout() abort " {{{
|
||||
let ret.n_rows = ret.n_items / ret.n_cols + (fmod(ret.n_items,ret.n_cols) > 0 ? 1 : 0)
|
||||
let ret.win_dim = ret.n_rows
|
||||
endif
|
||||
call s:LOG.debug('layout is:' . string(ret))
|
||||
return ret
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
" icon -> number -> A-Za-z
|
||||
" 65-90 97-122
|
||||
function! s:get_key_number(key) abort
|
||||
" icon -> number -> A-Za-z
|
||||
" 65-90 97-122
|
||||
function! s:get_key_number(key) abort
|
||||
return char2nr(a:key ==# '[SPC]' ? ' ' : a:key ==? '<Tab>' ? "\t" : a:key)
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:compare_key(i1, i2) abort
|
||||
function! s:compare_key(i1, i2) abort
|
||||
let a = s:get_key_number(a:i1)
|
||||
let b = s:get_key_number(a:i2)
|
||||
if a - b == 32 && a >= 97 && a <= 122
|
||||
@ -302,9 +349,9 @@ function! s:compare_key(i1, i2) abort
|
||||
return s:compare_key(nr2char(a), nr2char(b - 32))
|
||||
endif
|
||||
return a == b ? 0 : a > b ? 1 : -1
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:create_string(layout) abort " {{{
|
||||
function! s:create_string(layout) abort " {{{
|
||||
let l = a:layout
|
||||
let l.capacity = l.n_rows * l.n_cols
|
||||
let overcap = l.capacity - l.n_items
|
||||
@ -362,10 +409,10 @@ function! s:create_string(layout) abort " {{{
|
||||
endfor
|
||||
let output = join(r, "\n")
|
||||
return output
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
let s:VIMH = SpaceVim#api#import('vim#highlight')
|
||||
function! s:highlight_cursor() abort
|
||||
let s:VIMH = SpaceVim#api#import('vim#highlight')
|
||||
function! s:highlight_cursor() abort
|
||||
let info = {
|
||||
\ 'name' : 'SpaceVimGuideCursor',
|
||||
\ 'guibg' : synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'guifg'),
|
||||
@ -393,17 +440,17 @@ function! s:highlight_cursor() abort
|
||||
else
|
||||
let s:cursor_hi = s:CMP.matchaddpos('SpaceVimGuideCursor', [[line('.'), col('.'), 1]])
|
||||
endif
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:remove_cursor_highlight() abort
|
||||
function! s:remove_cursor_highlight() abort
|
||||
try
|
||||
call matchdelete(s:cursor_hi)
|
||||
catch
|
||||
endtry
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
" @vimlint(EVL102, 1, l:string)
|
||||
function! s:start_buffer() abort " {{{
|
||||
" @vimlint(EVL102, 1, l:string)
|
||||
function! s:start_buffer() abort " {{{
|
||||
let s:winv = winsaveview()
|
||||
let s:winnr = winnr()
|
||||
let s:winres = winrestcmd()
|
||||
@ -442,10 +489,10 @@ function! s:start_buffer() abort " {{{
|
||||
call setbufvar(s:bufnr, '&modifiable', 0)
|
||||
redraw!
|
||||
call s:wait_for_input()
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL102, 0, l:string)
|
||||
endfunction " }}}
|
||||
" @vimlint(EVL102, 0, l:string)
|
||||
|
||||
function! s:handle_input(input) abort " {{{
|
||||
function! s:handle_input(input) abort " {{{
|
||||
call s:winclose()
|
||||
if type(a:input) ==? type({})
|
||||
let s:lmap = a:input
|
||||
@ -460,10 +507,10 @@ function! s:handle_input(input) abort " {{{
|
||||
unsilent echom v:exception
|
||||
endtry
|
||||
endif
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
" wait for in input sub function should be not block vim
|
||||
function! s:wait_for_input() abort " {{{
|
||||
" wait for in input sub function should be not block vim
|
||||
function! s:wait_for_input() abort " {{{
|
||||
redraw!
|
||||
let inp = s:VIM.getchar()
|
||||
if inp ==# "\<Esc>"
|
||||
@ -506,9 +553,9 @@ function! s:wait_for_input() abort " {{{
|
||||
let s:guide_help_mode = 0
|
||||
endif
|
||||
endif
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
function! s:build_mpt(mpt) abort
|
||||
function! s:build_mpt(mpt) abort
|
||||
normal! :
|
||||
echohl Comment
|
||||
if type(a:mpt) == 1
|
||||
@ -517,12 +564,12 @@ function! s:build_mpt(mpt) abort
|
||||
echon join(a:mpt)
|
||||
endif
|
||||
echohl NONE
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
|
||||
" change this func, do not focus to the new windows, and return winid.
|
||||
" change this func, do not focus to the new windows, and return winid.
|
||||
|
||||
function! s:winopen() abort " {{{
|
||||
function! s:winopen() abort " {{{
|
||||
call s:highlight_cursor()
|
||||
let pos = g:leaderGuide_position ==? 'topleft' ? 'topleft' : 'botright'
|
||||
if s:FLOATING.exists()
|
||||
@ -590,9 +637,9 @@ function! s:winopen() abort " {{{
|
||||
call s:updateStatusline()
|
||||
call s:toggle_hide_cursor()
|
||||
return [s:winid, s:bufnr]
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
if s:SL.support_float()
|
||||
if s:SL.support_float()
|
||||
function! s:updateStatusline() abort
|
||||
call SpaceVim#mapping#guide#theme#hi()
|
||||
let gname = get(s:guide_group, 'name', '')
|
||||
@ -617,7 +664,7 @@ if s:SL.support_float()
|
||||
call SpaceVim#logger#debug('close float statusline winid:' . s:SL.__winid)
|
||||
call s:SL.close_float()
|
||||
endfunction
|
||||
else
|
||||
else
|
||||
function! s:updateStatusline() abort
|
||||
call SpaceVim#mapping#guide#theme#hi()
|
||||
let gname = get(s:guide_group, 'name', '')
|
||||
@ -633,30 +680,30 @@ else
|
||||
\ . ' %#LeaderGuiderSep2#' . s:lsep . '%#LeaderGuiderFill#'
|
||||
\ . s:guide_help_msg(0))
|
||||
endfunction
|
||||
endif
|
||||
endif
|
||||
|
||||
function! Test_st() abort
|
||||
function! Test_st() abort
|
||||
call s:updateStatusline()
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
function! s:guide_help_msg(escape) abort
|
||||
function! s:guide_help_msg(escape) abort
|
||||
if s:guide_help_mode == 1
|
||||
let msg = ' n -> next-page, p -> previous-page, u -> undo-key'
|
||||
else
|
||||
let msg = ' [C-h paging/help]'
|
||||
endif
|
||||
return a:escape ? substitute(msg,' ', '\\ ', 'g') : msg
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
let s:t_ve = ''
|
||||
function! s:toggle_hide_cursor() abort
|
||||
let s:t_ve = ''
|
||||
function! s:toggle_hide_cursor() abort
|
||||
let t_ve = &t_ve
|
||||
let &t_ve = s:t_ve
|
||||
let s:t_ve = t_ve
|
||||
endfunction
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:winclose() abort " {{{
|
||||
function! s:winclose() abort " {{{
|
||||
call s:toggle_hide_cursor()
|
||||
if s:FLOATING.exists()
|
||||
call s:FLOATING.win_close(s:winid, 1)
|
||||
@ -678,14 +725,14 @@ function! s:winclose() abort " {{{
|
||||
endif
|
||||
endif
|
||||
call s:remove_cursor_highlight()
|
||||
endfunction " }}}
|
||||
function! s:page_down() abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:page_down() abort " {{{
|
||||
call feedkeys("\<c-c>", 'n')
|
||||
call feedkeys("\<c-d>", 'x')
|
||||
redraw!
|
||||
call s:wait_for_input()
|
||||
endfunction " }}}
|
||||
function! s:page_undo() abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:page_undo() abort " {{{
|
||||
call s:winclose()
|
||||
if len(s:prefix_key_inp) > 0
|
||||
call remove(s:prefix_key_inp, -1)
|
||||
@ -694,15 +741,15 @@ function! s:page_undo() abort " {{{
|
||||
let s:lmap = remove(s:undo_history, -1)
|
||||
endif
|
||||
call s:start_buffer()
|
||||
endfunction " }}}
|
||||
function! s:page_up() abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:page_up() abort " {{{
|
||||
call feedkeys("\<c-c>", 'n')
|
||||
call feedkeys("\<c-u>", 'x')
|
||||
redraw!
|
||||
call s:wait_for_input()
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
function! s:handle_submode_mapping(cmd) abort " {{{
|
||||
function! s:handle_submode_mapping(cmd) abort " {{{
|
||||
let s:guide_help_mode = 0
|
||||
call s:updateStatusline()
|
||||
if a:cmd ==# 'n'
|
||||
@ -714,11 +761,11 @@ function! s:handle_submode_mapping(cmd) abort " {{{
|
||||
else
|
||||
call s:winclose()
|
||||
endif
|
||||
endfunction " }}}
|
||||
function! s:submode_mappings(key) abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:submode_mappings(key) abort " {{{
|
||||
silent call s:handle_submode_mapping(a:key)
|
||||
endfunction " }}}
|
||||
function! s:mapmaparg(maparg) abort " {{{
|
||||
endfunction " }}}
|
||||
function! s:mapmaparg(maparg) abort " {{{
|
||||
let noremap = a:maparg.noremap ? 'noremap' : 'map'
|
||||
let buffer = a:maparg.buffer ? '<buffer> ' : ''
|
||||
let silent = a:maparg.silent ? '<silent> ' : ''
|
||||
@ -726,9 +773,9 @@ function! s:mapmaparg(maparg) abort " {{{
|
||||
let st = a:maparg.mode . '' . noremap . ' ' . nowait . silent . buffer
|
||||
\ . '' .a:maparg.lhs . ' ' . a:maparg.rhs
|
||||
execute st
|
||||
endfunction " }}}
|
||||
endfunction " }}}
|
||||
|
||||
function! s:get_register() abort "{{{
|
||||
function! s:get_register() abort "{{{
|
||||
if match(&clipboard, 'unnamedplus') >= 0
|
||||
let clip = '+'
|
||||
elseif match(&clipboard, 'unnamed') >= 0
|
||||
@ -737,8 +784,8 @@ function! s:get_register() abort "{{{
|
||||
let clip = '"'
|
||||
endif
|
||||
return clip
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#start_by_prefix(vis, key) abort " {{{
|
||||
endfunction "}}}
|
||||
function! SpaceVim#mapping#guide#start_by_prefix(vis, key) abort " {{{
|
||||
if a:key ==# ' ' && exists('b:spacevim_lang_specified_mappings')
|
||||
let g:_spacevim_mappings_space.l = b:spacevim_lang_specified_mappings
|
||||
endif
|
||||
@ -767,28 +814,29 @@ function! SpaceVim#mapping#guide#start_by_prefix(vis, key) abort " {{{
|
||||
let rundict = s:cached_dicts[a:key]
|
||||
endif
|
||||
let s:lmap = rundict
|
||||
call s:LOG.debug('lmap is:' . string(s:lmap))
|
||||
call s:start_buffer()
|
||||
endfunction " }}}
|
||||
function! SpaceVim#mapping#guide#start(vis, dict) abort " {{{
|
||||
endfunction " }}}
|
||||
function! SpaceVim#mapping#guide#start(vis, dict) abort " {{{
|
||||
let s:vis = a:vis ? 'gv' : 0
|
||||
let s:lmap = a:dict
|
||||
call s:start_buffer()
|
||||
endfunction " }}}
|
||||
|
||||
if !exists('g:leaderGuide_displayfunc')
|
||||
function! s:leaderGuide_display() abort
|
||||
endfunction " }}}
|
||||
function! SpaceVim#mapping#guide#register_displayname(lhs, name) abort
|
||||
call extend(s:registered_name, {a:lhs : a:name})
|
||||
endfunction
|
||||
function! SpaceVim#mapping#guide#displayfunc() abort
|
||||
if has_key(s:registered_name, g:leaderGuide#displayname)
|
||||
return s:registered_name[g:leaderGuide#displayname]
|
||||
endif
|
||||
let g:leaderGuide#displayname = substitute(g:leaderGuide#displayname, '\c<cr>$', '', '')
|
||||
endfunction
|
||||
let g:leaderGuide_displayfunc = [function('s:leaderGuide_display')]
|
||||
endif
|
||||
|
||||
let s:registered_name = {}
|
||||
function! SpaceVim#mapping#guide#register_displayname(lhs, name) abort
|
||||
call extend(s:registered_name, {a:lhs : a:name})
|
||||
endfunction
|
||||
if !exists('g:leaderGuide_displayfunc')
|
||||
let g:leaderGuide_displayfunc = [function('SpaceVim#mapping#guide#displayfunc')]
|
||||
endif
|
||||
|
||||
|
||||
if get(g:, 'mapleader', '\') ==# ' '
|
||||
call SpaceVim#mapping#guide#register_prefix_descriptions(' ',
|
||||
|
2
bundle/neodev.nvim/types/nightly/vim.fn.lua
vendored
2
bundle/neodev.nvim/types/nightly/vim.fn.lua
vendored
@ -5655,7 +5655,7 @@ function vim.fn.matchadd(group, pattern, priority, id, dict) end
|
||||
-- ```vim
|
||||
-- GetGroup()->matchaddpos([23, 11])
|
||||
-- ```
|
||||
--- @param pos number
|
||||
--- @param pos number|table
|
||||
--- @param priority? any
|
||||
--- @param id? any
|
||||
--- @param dict? table<string, any>
|
||||
|
@ -23,6 +23,10 @@ function M.getchar(...)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setbufvar(buf, opts)
|
||||
|
||||
end
|
||||
|
||||
function M.getchar2nr(...)
|
||||
local status, ret = pcall(vim.fn.getchar, ...)
|
||||
if not status then
|
||||
|
@ -8,6 +8,10 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.create_buf(listed, scratch)
|
||||
return vim.api.nvim_create_buf(listed, scratch)
|
||||
end
|
||||
|
||||
function M.set_lines(bufnr, startindex, endindex, replacement)
|
||||
if startindex < 0 then
|
||||
startindex = #vim.buffer(bufnr) + 1 + startindex
|
||||
|
@ -1,11 +1,12 @@
|
||||
--!/usr/bin/lua
|
||||
local M = {}
|
||||
|
||||
local specified_keys = {}
|
||||
|
||||
function M.t(str)
|
||||
if vim.api ~= nil and vim.api.nvim_replace_termcodes ~= nil then
|
||||
-- https://github.com/neovim/neovim/issues/17369
|
||||
local ret = vim.api.nvim_replace_termcodes(str, false, true, true):gsub("\128\254X", "\128")
|
||||
local ret = vim.api.nvim_replace_termcodes(str, false, true, true):gsub('\128\254X', '\128')
|
||||
return ret
|
||||
else
|
||||
-- local ret = vim.fn.execute('echon "\\' .. str .. '"')
|
||||
@ -15,4 +16,33 @@ function M.t(str)
|
||||
end
|
||||
end
|
||||
|
||||
function M.char2name(c)
|
||||
if #c == 1 then
|
||||
return M.nr2name(vim.fn.char2nr(c))
|
||||
end
|
||||
return specified_keys[c] or c
|
||||
end
|
||||
|
||||
function M.nr2name(nr)
|
||||
if type(nr) == 'number' then
|
||||
if nr == 32 then
|
||||
return 'SPC'
|
||||
elseif nr == 4 then
|
||||
return '<C-d>'
|
||||
elseif nr == 3 then
|
||||
return '<C-c>'
|
||||
elseif nr == 9 then
|
||||
return '<Tab>'
|
||||
elseif nr == 92 then
|
||||
return '<Leader>'
|
||||
elseif nr == 27 then
|
||||
return '<Esc>'
|
||||
else
|
||||
return vim.fn.nr2char(nr)
|
||||
end
|
||||
else
|
||||
return specified_keys[nr] or ''
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user