diff options
Diffstat (limited to 'autoload/LaTeXtoUnicode.vim')
-rw-r--r-- | autoload/LaTeXtoUnicode.vim | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/autoload/LaTeXtoUnicode.vim b/autoload/LaTeXtoUnicode.vim index 2be1a492..86420cca 100644 --- a/autoload/LaTeXtoUnicode.vim +++ b/autoload/LaTeXtoUnicode.vim @@ -73,9 +73,6 @@ function! s:L2U_SetupGlobal() " Trigger for the previous mapping of <CR> let s:l2u_fallback_trigger_cr = "\u0091L2UFallbackCR" - " Trigger for autosub completion cleanup autocommand - let s:l2u_autosub_cleanup_trigger = "\u0091L2UAutosubCleanup" - endfunction " Each time the filetype changes, we may need to enable or @@ -371,16 +368,14 @@ function! s:L2U_SetFallbackMapping(s, k) " parsing of the <C-R>=... expression, so we need to special-case it. " Also, if the original mapping was intended to be recursive, this " will break it. - if mmdict["expr"] - if a:s != "<CR>" - let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteral('" . a:s . "')\<CR>", 'g') - else - let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteralCR()\<CR>", 'g') - endif - " Make the mapping silent even if it wasn't originally - if !mmdict["silent"] - let pre = pre . '<silent>' - endif + if a:s != "<CR>" + let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteral('" . a:s . "')\<CR>", 'g') + else + let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteralCR()\<CR>", 'g') + endif + " Make the mapping silent even if it wasn't originally + if !mmdict["silent"] + let pre = pre . '<silent>' endif endif exe cmd . pre . ' ' . a:k . ' ' . rhs @@ -631,7 +626,7 @@ function! LaTeXtoUnicode#AutoSub(...) let lnum = line('.') if col1 == 1 if a:0 > 1 - call feedkeys(a:2, 't') + call feedkeys(a:2, 'mi') endif let b:l2u_in_autosub = 0 return '' @@ -641,7 +636,7 @@ function! LaTeXtoUnicode#AutoSub(...) let col0 = match(l, '\\\%([_^]\?[A-Za-z]\+\%' . col1 . 'c\%([^A-Za-z]\|$\)\|[_^]\%([0-9()=+-]\)\%' . col1 .'c\%(.\|$\)\)') if col0 == -1 if a:0 > 1 - call feedkeys(a:2, 't') + call feedkeys(a:2, 'mi') endif let b:l2u_in_autosub = 0 return '' @@ -650,33 +645,22 @@ function! LaTeXtoUnicode#AutoSub(...) let unicode = get(g:l2u_symbols_dict, base, '') if empty(unicode) if a:0 > 1 - call feedkeys(a:2, 't') + call feedkeys(a:2, 'mi') endif let b:l2u_in_autosub = 0 return '' endif - " create a temporary mapping to reset b:l2u_in_autosub when done - " (when invoked, it removes itself) - exec 'imap <buffer> ' . s:l2u_autosub_cleanup_trigger . ' <Plug>L2UAutosubReset' - inoremap <buffer><expr> <Plug>L2UAutosubReset <SID>L2U_AutosubReset() - " perform the substitution, wrapping it in undo breakpoints so that " we can revert it as a whole - call feedkeys("\<C-G>u", 'n') - call feedkeys(repeat("\b", len(base) + bs) . unicode . vc . s:l2u_esc_sequence, 'nt') - call feedkeys("\<C-G>u", 'n') - " enqueue the reset mechanism - call feedkeys(s:l2u_autosub_cleanup_trigger) - return '' -endfunction - -function! s:L2U_AutosubReset() - " no longer doing substitution - let b:l2u_in_autosub = 0 - " remove the mapping that triggered this function - exec 'iunmap <buffer> ' . s:l2u_autosub_cleanup_trigger - iunmap <buffer> <Plug>L2UAutosubReset + " at the end, reset the l2u_in_autosub variable without leaving insert mode + " the 'i' mode is the only one that works correctly when executing macros + " the 'n' mode is to avoid user-defined mappings of \b, <C-G> and <C-\><C-O> + call feedkeys("\<C-G>u" . + \ repeat("\b", len(base) + bs) . unicode . vc . s:l2u_esc_sequence . + \ "\<C-G>u" . + \ "\<C-\>\<C-O>:let b:l2u_in_autosub = 0\<CR>", + \ 'ni') return '' endfunction |