-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaTeXtoUnicode
files are not loaded lazily
#269
Comments
The design also makes it so I can't lazy-load the plugin myself (e.g., using https://github.com/wbthomason/packer.nvim on I understand that it can be useful to expose the L2U substitution for other filetypes as well (and have used it in Markdown on occasion myself), but it feels very wrong when a filetype plugin like this one "spills out" to other files. |
Specifically, I'd be interesting in hearing what the rationale is for registering these autocommands for all buffers instead of only Julia (and Julia Markdown) buffers: Lines 10 to 13 in 6ff9e99
Replacing |
...which is related to @wbthomason's suggestion in #263 (comment) -- checking |
The reason for the |
I see where you are coming from, yes. I understand that the current setup is very convenient; it'd just be great if there was more choice (short of patching the plugin) :) It would probably be possible to use the |
Is there any workaround to disable the L2U for non-julia files? I don't need to type unicode anywhere else and the delay in startup is almost half a second, which feels very long when editing some config file quickly. |
AFAIK,
Here's my workaround for lazy loading. You can either use the this fork or this diff file. I'm not a Vim package developer so this is probably not the "correct" way to do this. diff --git a/autoload/LaTeXtoUnicode.vim b/autoload/LaTeXtoUnicode.vim
index f6237dc..b4d6547 100644
--- a/autoload/LaTeXtoUnicode.vim
+++ b/autoload/LaTeXtoUnicode.vim
@@ -3,6 +3,10 @@
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:L2U_Setup()
+ let b:l2u_did_buffer_setup = get(b:, "l2u_did_buffer_setup", 0)
+ if b:l2u_did_buffer_setup
+ return ''
+ endif
call s:L2U_SetupGlobal()
@@ -28,7 +32,8 @@ function! s:L2U_Setup()
let b:l2u_tab_completing = 0
" Are we calling the tab fallback?
let b:l2u_in_fallback = 0
-
+ " Do not call setup the second time
+ let b:l2u_did_buffer_setup = 1
endfunction
function! s:L2U_SetupGlobal()
@@ -96,8 +101,10 @@ function! LaTeXtoUnicode#Refresh()
endif
endfunction
+
function! LaTeXtoUnicode#Enable(...)
let auto_set = a:0 > 0 ? a:1 : 0
+ call s:L2U_Setup()
if b:l2u_enabled
return ''
@@ -723,6 +730,7 @@ 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
if !wait_insert_enter
@@ -738,6 +746,7 @@ function! LaTeXtoUnicode#Init(...)
call s:L2U_SetTab(wait_insert_enter)
call s:L2U_SetAutoSub(wait_insert_enter)
call s:L2U_SetKeymap()
+
return ''
endfunction
diff --git a/ftdetect/julia.vim b/ftdetect/julia.vim
index 9a4e8cb..8ab89ad 100644
--- a/ftdetect/julia.vim
+++ b/ftdetect/julia.vim
@@ -7,20 +7,18 @@ endif
autocmd BufRead,BufNewFile *.jl set filetype=julia
-autocmd FileType * call LaTeXtoUnicode#Refresh()
-autocmd BufNew * call LaTeXtoUnicode#Refresh()
-autocmd BufEnter * call LaTeXtoUnicode#Refresh()
-autocmd CmdwinEnter * call LaTeXtoUnicode#Refresh()
+" Use latex to unicode on these pattern only
+let s:l2u_patterns = get(g:, "latex_to_unicode_file_types", "*.jl,*.jmd")
" This autocommand is used to postpone the first initialization of LaTeXtoUnicode as much as possible,
" by calling LaTeXtoUnicode#SetTab and LaTeXtoUnicode#SetAutoSub only at InsertEnter or later
function! s:L2UTrigger()
augroup L2UInit
autocmd!
- autocmd InsertEnter * let g:did_insert_enter = 1 | call LaTeXtoUnicode#Init(0)
+ execute 'autocmd InsertEnter ' . s:l2u_patterns . ' let g:did_insert_enter = 1 | call LaTeXtoUnicode#Enable()'
augroup END
endfunction
-autocmd BufEnter * call s:L2UTrigger()
+execute 'autocmd BufEnter ' . s:l2u_patterns . ' call s:L2UTrigger()'
function! s:HighlightJuliaMarkdown()
if !exists('g:markdown_fenced_languages') Configuration (this have to be set before the package is loaded): vim.g.latex_to_unicode_file_types = "*.jl,*.jmd,*.py" or let g:latex_to_unicode_file_types = '*.jl,*.jmd,*.py' Demo: |
I have (long since) dropped this plugin in favor of builtin filetype support and a separate unicode symbol inserter (based on Telescope). (Excessive use of unicode identifiers in Julia is a scourge anyway, since it makes it really tedious to search and replace. And don't get me started on the "Language Server"...) |
What separate unicode symbol inserter? |
https://github.com/arthurxavierx/vim-unicoder seems to work well. |
For |
In
ftdetect/julia.vim
there are some autocommands that callLaTeXtoUnicode#Refresh()
for all filetypes, meaning that the files inautoload/
are loaded every time at startup and then every time a buffer opens.This makes julia-vim one of the slowest plugins to load in my config, and the slowest filetype plugin by quite some margin (measured with tweekmonster/startuptime.vim).
It'd be great if this could be improved in the near future.
The text was updated successfully, but these errors were encountered: