Skip to content

Commit aa29918

Browse files
committed
L2U: special-case remapping of <CR>
1 parent f34337a commit aa29918

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

autoload/LaTeXtoUnicode.vim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ function! LaTeXtoUnicode#PutLiteral(k)
339339
return ''
340340
endfunction
341341

342+
function! LaTeXtoUnicode#PutLiteralCR()
343+
call feedkeys('', 'ni')
344+
return ''
345+
endfunction
346+
342347
" Function which saves the current insert-mode mapping of a key sequence `s`
343348
" and associates it with another key sequence `k` (e.g. stores the current
344349
" <Tab> mapping into the Fallback trigger)
@@ -360,9 +365,20 @@ function! s:L2U_SetFallbackMapping(s, k)
360365
else
361366
let cmd = 'imap '
362367
" This is a nasty hack used to prevent infinite recursion. It's not a
363-
" general solution.
368+
" general solution. Also, it doesn't work with <CR> since that stops
369+
" parsing of the <C-R>=... expression, so we need to special-case it.
370+
" Also, if the original mapping was intended to be recursive, this
371+
" will break it.
364372
if mmdict["expr"]
365-
let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteral('" . a:s . "')\<CR>", 'g')
373+
if a:s != "<CR>"
374+
let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteral('" . a:s . "')\<CR>", 'g')
375+
else
376+
let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteralCR()\<CR>", 'g')
377+
endif
378+
" Make the mapping silent even if it wasn't originally
379+
if !mmdict["silent"]
380+
let pre = pre . '<silent>'
381+
endif
366382
endif
367383
endif
368384
exe cmd . pre . ' ' . a:k . ' ' . rhs

0 commit comments

Comments
 (0)