summaryrefslogtreecommitdiffstats
path: root/autoload/LaTeXtoUnicode.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-03-02 00:34:02 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2020-03-02 00:34:02 +0100
commit6b540d7db030e4110aa3a31dd06c6c41387444db (patch)
tree1cd1da5b35cf1c34b38d7506ff93aabf861747bf /autoload/LaTeXtoUnicode.vim
parent35ea4d2b9072594b6c0ccf87bde7978ed9f94755 (diff)
downloadvim-polyglot-6b540d7db030e4110aa3a31dd06c6c41387444db.tar.gz
vim-polyglot-6b540d7db030e4110aa3a31dd06c6c41387444db.zip
Update
Diffstat (limited to 'autoload/LaTeXtoUnicode.vim')
-rw-r--r--autoload/LaTeXtoUnicode.vim96
1 files changed, 49 insertions, 47 deletions
diff --git a/autoload/LaTeXtoUnicode.vim b/autoload/LaTeXtoUnicode.vim
index 045ebb9c..8e6714dc 100644
--- a/autoload/LaTeXtoUnicode.vim
+++ b/autoload/LaTeXtoUnicode.vim
@@ -13,6 +13,9 @@ function! s:L2U_Setup()
if !has_key(b:, "l2u_enabled")
let b:l2u_enabled = 0
endif
+ if !has_key(b:, "l2u_autodetect_enable")
+ let b:l2u_autodetect_enable = 1
+ endif
" Did we install the L2U tab mappings?
if !has_key(b:, "l2u_tab_set")
@@ -92,34 +95,39 @@ endfunction
" Each time the filetype changes, we may need to enable or
" disable the LaTeX-to-Unicode functionality
function! LaTeXtoUnicode#Refresh()
-
call s:L2U_Setup()
+ " skip if manually overridden
+ if !b:l2u_autodetect_enable
+ return ''
+ endif
+
" by default, LaTeX-to-Unicode is only active on julia files
let file_types = s:L2U_file_type_regex(get(g:, "latex_to_unicode_file_types", "julia"))
let file_types_blacklist = s:L2U_file_type_regex(get(g:, "latex_to_unicode_file_types_blacklist", "$^"))
if match(&filetype, file_types) < 0 || match(&filetype, file_types_blacklist) >= 0
if b:l2u_enabled
- call LaTeXtoUnicode#Disable()
+ call LaTeXtoUnicode#Disable(1)
else
- return
+ return ''
endif
elseif !b:l2u_enabled
- call LaTeXtoUnicode#Enable()
+ call LaTeXtoUnicode#Enable(1)
endif
-
endfunction
-function! LaTeXtoUnicode#Enable()
+function! LaTeXtoUnicode#Enable(...)
+ let auto_set = a:0 > 0 ? a:1 : 0
if b:l2u_enabled
- return
+ return ''
end
call s:L2U_ResetLastCompletionInfo()
let b:l2u_enabled = 1
+ let b:l2u_autodetect_enable = auto_set
" If we're editing the first file upon opening vim, this will only init the
" command line mode mapping, and the full initialization will be performed by
@@ -127,18 +135,18 @@ function! LaTeXtoUnicode#Enable()
" Otherwise, if we're opening a file from within a running vim session, this
" will actually initialize all the LaTeX-to-Unicode substitutions.
call LaTeXtoUnicode#Init()
-
- return
-
+ return ''
endfunction
-function! LaTeXtoUnicode#Disable()
+function! LaTeXtoUnicode#Disable(...)
+ let auto_set = a:0 > 0 ? a:1 : 0
if !b:l2u_enabled
- return
+ return ''
endif
let b:l2u_enabled = 0
+ let b:l2u_autodetect_enable = auto_set
call LaTeXtoUnicode#Init()
- return
+ return ''
endfunction
" Translate old options to their new equivalents
@@ -246,7 +254,6 @@ function! LaTeXtoUnicode#omnifunc(findstart, base)
endif
let b:l2u_in_fallback = 0
" set info for the callback
- let b:l2u_tab_completing = 1
let b:l2u_found_completion = 1
" analyse current line
let col1 = col('.')
@@ -375,6 +382,7 @@ function! LaTeXtoUnicode#Tab()
endif
" reset the in_fallback info
let b:l2u_in_fallback = 0
+ let b:l2u_tab_completing = 1
" temporary change to completeopt to use the `longest` setting, which is
" probably the only one which makes sense given that the goal of the
" completion is to substitute the final string
@@ -383,7 +391,8 @@ function! LaTeXtoUnicode#Tab()
set completeopt-=noinsert
" invoke omnicompletion; failure to perform LaTeX-to-Unicode completion is
" handled by the CompleteDone autocommand.
- return "\<C-X>\<C-O>"
+ call feedkeys("\<C-X>\<C-O>", 'n')
+ return ""
endfunction
" This function is called at every CompleteDone event, and is meant to handle
@@ -409,7 +418,7 @@ function! LaTeXtoUnicode#FallbackCallback()
endfunction
" This is the function that performs the substitution in command-line mode
-function! LaTeXtoUnicode#CmdTab(triggeredbytab)
+function! LaTeXtoUnicode#CmdTab(trigger)
" first stage
" analyse command line
let col1 = getcmdpos() - 1
@@ -418,10 +427,12 @@ function! LaTeXtoUnicode#CmdTab(triggeredbytab)
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>
+ if a:trigger == &wildchar
+ call feedkeys(nr2char(a:trigger), 'nt') " fall-back to the default wildchar
+ elseif a:trigger == char2nr("\<S-Tab>")
+ call feedkeys("\<S-Tab>", 'nt') " fall-back to the default <S-Tab>
endif
- return l
+ return ''
endif
let base = l[col0 : col1-1]
" search for matches
@@ -430,39 +441,28 @@ function! LaTeXtoUnicode#CmdTab(triggeredbytab)
for k in keys(g:l2u_symbols_dict)
if k ==# base
let exact_match = 1
- endif
- if len(k) >= len(base) && k[0 : len(base)-1] ==# base
+ break
+ elseif len(k) >= len(base) && k[0 : len(base)-1] ==# base
call add(partmatches, k)
endif
endfor
- if len(partmatches) == 0
- if a:triggeredbytab
- call feedkeys("\<Tab>", 'nt') " fall-back to the default <Tab>
+ if !exact_match && len(partmatches) == 0
+ " no matches, call fallbacks
+ if a:trigger == &wildchar
+ call feedkeys(nr2char(a:trigger), 'nt') " fall-back to the default wildchar
+ elseif a:trigger == char2nr("\<S-Tab>")
+ call feedkeys("\<S-Tab>", 'nt') " fall-back to the default <S-Tab>
endif
- return l
- endif
- " exact matches are replaced with Unicode
- if exact_match
+ elseif exact_match
+ " exact matches are replaced with Unicode
let unicode = g:l2u_symbols_dict[base]
- if col0 > 0
- let pre = l[0 : col0 - 1]
- else
- let pre = ''
- endif
- let posdiff = col1-col0 - len(unicode)
- call setcmdpos(col1 - posdiff + 1)
- return pre . unicode . l[col1 : -1]
- endif
- " no exact match: complete with the longest common prefix
- let common = s:L2U_longest_common_prefix(partmatches)
- if col0 > 0
- let pre = l[0 : col0 - 1]
+ call feedkeys(repeat("\b", len(base)) . unicode, 'nt')
else
- let pre = ''
+ " no exact match: complete with the longest common prefix
+ let common = s:L2U_longest_common_prefix(partmatches)
+ call feedkeys(common[len(base):], 'nt')
endif
- let posdiff = col1-col0 - len(common)
- call setcmdpos(col1 - posdiff + 1)
- return pre . common . l[col1 : -1]
+ return ''
endfunction
" Setup the L2U tab mapping
@@ -473,7 +473,8 @@ function! s:L2U_SetTab(wait_insert_enter)
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>'
+ exec 'let trigger = char2nr("'.(k[0] == '<' ? '\' : '').k.'")'
+ exec 'cnoremap <buffer><expr> '.k.' LaTeXtoUnicode#CmdTab('.trigger.')'
endfor
let b:l2u_cmdtab_set = 1
endif
@@ -637,6 +638,7 @@ function! LaTeXtoUnicode#Init(...)
call s:L2U_SetTab(wait_insert_enter)
call s:L2U_SetAutoSub(wait_insert_enter)
call s:L2U_SetKeymap()
+ return ''
endfunction
function! LaTeXtoUnicode#Toggle()
@@ -648,7 +650,7 @@ function! LaTeXtoUnicode#Toggle()
call LaTeXtoUnicode#Enable()
echo "LaTeX-to-Unicode enabled"
endif
- return
+ return ''
endfunction
endif