if exists( "g:__AL_XPT_MSVR_VIM__" ) && g:__AL_XPT_MSVR_VIM__ >= XPT#ver finish endif let g:__AL_XPT_MSVR_VIM__ = XPT#ver let s:oldcpo = &cpo set cpo-=< cpo+=B let s:log = xpt#debug#Logger( 'warn' ) snoremap selectToInsert d let g:globalStack = [] fun! s:_GetAlighWidth() nmap 1 2 let line = xpt#util#getCmdOutput("silent nmap 1") nunmap 1 let line = split(line, "\n")[0] return len(matchstr(line, '^n.*\ze2$')) endfunction let s:alignWidth = s:_GetAlighWidth() delfunction s:_GetAlighWidth fun! xpt#msvr#New(isLocal) return { 'keys':[], 'saved':[], } endfunction fun! xpt#msvr#Add(inst,mode,key) if a:inst.saved != [] throw "keys are already saved and can not be added" endif let a:inst.keys += [[a:mode,a:key]] endfunction fun! xpt#msvr#AddList(inst,...) if a:0 > 0 && type(a:1) == type([]) let list = a:1 else let list = a:000 endif for item in list let [ mode, key ] = split( item, '^\w\zs_' ) call xpt#msvr#Add(a:inst,mode,key) endfor endfunction fun! xpt#msvr#UnmapAll(inst) if a:inst.saved == [] throw "keys are not saved, can not unmap all" endif let localStr = ' ' for [mode,key] in a:inst.keys exe 'silent! ' . mode . 'unmap ' . localStr . key endfor endfunction fun! xpt#msvr#Save(inst) if a:inst.saved != [] return endif for [mode,key] in a:inst.keys call insert(a:inst.saved,xpt#msvr#MapInfo(key,mode)) endfor let stack = s:GetStack() call add(stack,a:inst) endfunction fun! xpt#msvr#Literalize(inst,...) if a:inst.saved == [] throw "keys are not saved yet, can not literalize" endif let option = a:0 == 1 ? a:1 : {} let insertAsSelect = get(option, 'insertAsSelect', 0) let localStr = ' ' let nowait = v:version >= 704 ? '' : '' for [mode,key] in a:inst.keys if mode == 's' && insertAsSelect exe 'silent! ' . mode . 'map ' . nowait . localStr . key . ' selectToInsert' . key else exe 'silent! ' . mode . 'noremap ' . nowait . localStr . key . ' ' . key endif endfor endfunction fun! xpt#msvr#Restore(inst) if a:inst.saved == [] return endif let stack = s:GetStack() if empty(stack) || stack[-1] != a:inst throw "MapSaver: Incorrect Restore of MapSaver:" . s:String( stack ) . ' but ' . string( a:inst.keys ) endif for info in a:inst.saved call s:MappingPop(info) endfor let a:inst.saved = [] call remove(stack,-1) endfunction fun! s:GetStack() if !exists( 'b:__map_saver_stack__' ) let b:__map_saver_stack__ = [] endif return b:__map_saver_stack__ endfunction if v:version >= 704 fun! xpt#msvr#MapInfo(key,mode) let arg = maparg(a:key,a:mode,0,1) if arg == {} || arg.buffer == 0 return { 'mode' : a:mode, 'key':a:key, 'nore':'', 'isexpr':'', 'isscript':'', 'isbuf':' ', 'cont':''} endif let rhs = substitute( arg.rhs, '\V\C', '' . arg.sid . '_', 'g' ) let line = s:GetMappingLine(a:key,a:mode) let flag = line[0 : 1] return { 'mode' : a:mode, 'key':a:key, 'nore':arg.noremap ? 'nore' : '', 'isexpr':arg.expr ? '' : '', 'isscript':flag[0] == '&' ? '