Tuesday, March 31, 2020

How to avoid autocmd CursorMoved to lag ?

Hi,

I use this func to switch filetype when cursor is moving outside/inside embed section:

fun! helper#SwitchFileType() "{{{
  if !exists('b:busy')
  let b:busy=1
let start = str2nr(search( '^\w\+\s\+<<\s\+EOF', 'n' ))
if start > 0
  let end    = str2nr(search( '^EOF', 'n' ))
  let curpos = getcurpos()[1]
  let lang   = split(getline(start), '<<')[0]->substitute('\s', '', "g") 
  if (curpos > start) && (curpos < end)
exe 'set ft='.lang
  else
exe 'set ft=vim'
  end
"echo 'Filetype switched to ' . &ft
end
  unlet b:busy
  end
endfun "}}}

  autocmd CursorMoved    *.vim   call helper#SwitchFileType()
  autocmd CursorMovedI   *.vim   call helper#SwitchFileType()
 


The func is called on event cursormoved and lag cursor effectively moving action.

how to avoid this lag ?
Thank you

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/d2d25dc4-1516-41a2-b7fb-14a48f4c69e6%40googlegroups.com.

No comments:

Post a Comment