Last active
April 21, 2018 16:47
-
-
Save marcotrosi/e2918579bce82613c504e7d1cae2e3c0 to your computer and use it in GitHub Desktop.
nested custom insert completion menus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:InitMenu = 'Font' | |
let s:NextMenu = '' | |
function! LatexFont(findstart, base) | |
if a:findstart | |
let line = getline('.') | |
let start = col('.') - 1 | |
while start > 0 && line[start - 1] =~ '\a' | |
let start -= 1 | |
endwhile | |
return start | |
else | |
let menus = { | |
\ 'Font':[{'word':a:base, 'abbr':'Font Family', 'dup':1, 'user_data':'FontFamily'}, | |
\ {'word':a:base, 'abbr':'Font Style' , 'dup':1, 'user_data':'FontStyle' }, | |
\ {'word':a:base, 'abbr':'Font Size' , 'dup':1, 'user_data':'FontSize' }], | |
\ | |
\ 'FontFamily':[{'word':'\textrm{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\textsf{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\texttt{'.a:base.'}', 'user_data':'_END_'}], | |
\ | |
\ 'FontStyle':[{'word':'\textmd{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\textbf{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\textup{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\textit{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\textsl{'.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'\textsc{'.a:base.'}', 'user_data':'_END_'}], | |
\ | |
\ 'FontSize':[{'word':'{\tiny '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\scriptsize '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\footnotesize '.a:base.'}', 'user_data':'_END_'}, | |
\ {'word':'{\small '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\normalsize '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\large '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\Large '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\LARGE '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\huge '.a:base.'}' , 'user_data':'_END_'}, | |
\ {'word':'{\Huge '.a:base.'}' , 'user_data':'_END_'}] | |
\ } | |
if s:NextMenu == '' | |
let s:NextMenu = s:InitMenu | |
endif | |
return {'words':menus[s:NextMenu], 'refresh':'always'} | |
endif | |
endfunction | |
function! LatexFontContinue() | |
let l:NextMenu = get(v:completed_item, 'user_data', '') | |
if (l:NextMenu == '') || (l:NextMenu == '_END_') | |
let s:NextMenu = '' | |
else | |
let s:NextMenu = l:NextMenu | |
call feedkeys("\<BS>\<C-x>\<C-u>") | |
endif | |
endfunction | |
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>" | |
augroup COMPLETE | |
autocmd! | |
autocmd CompleteDone <buffer> call LatexFontContinue() | |
augroup END | |
set completefunc=LatexFont | |
inoremap <S-SPACE> <C-X><C-U> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment