diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2018-12-26 10:41:57 +0100 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2018-12-26 10:41:57 +0100 |
commit | d43b70d93987c94d15a352cf0026fb93d3317cc8 (patch) | |
tree | 74470b6cc30ddb4ef8ceb2ec557bc32ccccb5ebb /autoload/LaTeXtoUnicode.vim | |
parent | ec1c94306953b678bb36572897bd218fe6c76506 (diff) | |
download | vim-polyglot-d43b70d93987c94d15a352cf0026fb93d3317cc8.tar.gz vim-polyglot-d43b70d93987c94d15a352cf0026fb93d3317cc8.zip |
Update
Diffstat (limited to 'autoload/LaTeXtoUnicode.vim')
-rw-r--r-- | autoload/LaTeXtoUnicode.vim | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/autoload/LaTeXtoUnicode.vim b/autoload/LaTeXtoUnicode.vim index 581dec1e..75fa4f82 100644 --- a/autoload/LaTeXtoUnicode.vim +++ b/autoload/LaTeXtoUnicode.vim @@ -21,6 +21,9 @@ function! s:L2U_Setup() if !has_key(b:, "l2u_cmdtab_set") let b:l2u_cmdtab_set = 0 endif + if !has_key(b:, "l2u_keymap_set") + let b:l2u_keymap_set = 0 + endif " Did we activate the L2U as-you-type substitutions? if !has_key(b:, "l2u_autosub_set") @@ -76,11 +79,7 @@ function! s:L2U_SetupGlobal() " A hack to forcibly get out of completion mode: feed " this string with feedkeys() if has("win32") || has("win64") - if has("gui_running") - let s:l2u_esc_sequence = "\u0006" - else - let s:l2u_esc_sequence = "\u0006\b" - endif + let s:l2u_esc_sequence = "\u0006" else let s:l2u_esc_sequence = "\u0091\b" end @@ -409,8 +408,8 @@ function! LaTeXtoUnicode#FallbackCallback() return endfunction -" This is the function which is mapped to <S-Tab> in command-line mode -function! LaTeXtoUnicode#CmdTab() +" This is the function that performs the substitution in command-line mode +function! LaTeXtoUnicode#CmdTab(triggeredbytab) " first stage " analyse command line let col1 = getcmdpos() - 1 @@ -419,6 +418,9 @@ function! LaTeXtoUnicode#CmdTab() let b:l2u_singlebslash = (match(l[0:col1-1], '\\$') >= 0) " completion not found if col0 == -1 + if a:triggeredbytab + call feedkeys("\<Tab>", 'nt') " fall-back to the default <Tab> + endif return l endif let base = l[col0 : col1-1] @@ -434,6 +436,9 @@ function! LaTeXtoUnicode#CmdTab() endif endfor if len(partmatches) == 0 + if a:triggeredbytab + call feedkeys("\<Tab>", 'nt') " fall-back to the default <Tab> + endif return l endif " exact matches are replaced with Unicode @@ -463,8 +468,13 @@ endfunction " Setup the L2U tab mapping function! s:L2U_SetTab(wait_insert_enter) if !b:l2u_cmdtab_set && get(g:, "latex_to_unicode_tab", 1) && b:l2u_enabled - cmap <buffer> <S-Tab> <Plug>L2UCmdTab - cnoremap <buffer> <Plug>L2UCmdTab <C-\>eLaTeXtoUnicode#CmdTab()<CR> + let b:l2u_cmdtab_keys = get(g:, "latex_to_unicode_cmd_mapping", ['<Tab>','<S-Tab>']) + if type(b:l2u_cmdtab_keys) != type([]) " avoid using v:t_list for backward compatibility + let b:l2u_cmdtab_keys = [b:l2u_cmdtab_keys] + endif + for k in b:l2u_cmdtab_keys + exec 'cnoremap <buffer> '.k.' <C-\>eLaTeXtoUnicode#CmdTab('.(k ==? '<Tab>').')<CR>' + endfor let b:l2u_cmdtab_set = 1 endif if b:l2u_tab_set @@ -500,7 +510,9 @@ endfunction " Revert the LaTeX-to-Unicode tab mapping settings function! s:L2U_UnsetTab() if b:l2u_cmdtab_set - cunmap <buffer> <S-Tab> + for k in b:l2u_cmdtab_keys + exec 'cunmap <buffer> '.k + endfor let b:l2u_cmdtab_set = 0 endif if !b:l2u_tab_set @@ -593,6 +605,21 @@ function! s:L2U_UnsetAutoSub() let b:l2u_autosub_set = 0 endfunction +function! s:L2U_SetKeymap() + if !b:l2u_keymap_set && get(g:, "latex_to_unicode_keymap", 0) && b:l2u_enabled + setlocal keymap=latex2unicode + let b:l2u_keymap_set = 1 + endif +endfunction + +function! s:L2U_UnsetKeymap() + if !b:l2u_keymap_set + return + endif + setlocal keymap= + let b:l2u_keymap_set = 0 +endfunction + " Initialization. Can be used to re-init when global settings have changed. function! LaTeXtoUnicode#Init(...) let wait_insert_enter = a:0 > 0 ? a:1 : 1 @@ -605,9 +632,11 @@ function! LaTeXtoUnicode#Init(...) call s:L2U_UnsetTab() call s:L2U_UnsetAutoSub() + call s:L2U_UnsetKeymap() call s:L2U_SetTab(wait_insert_enter) call s:L2U_SetAutoSub(wait_insert_enter) + call s:L2U_SetKeymap() endfunction function! LaTeXtoUnicode#Toggle() |