Skip to content
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

Can't assign custom auto commands without the insert versions #90

Open
dylan-chong opened this issue Jul 1, 2018 · 3 comments
Open

Comments

@dylan-chong
Copy link

dylan-chong commented Jul 1, 2018

I want to assign custom auto commands: TextChanged,InsertLeave without the insert versions of them.

Why?

  • Insert leave is not good enough by itself, because when you edit code without going into insert mode, codi does not get updated
  • the plug-in lessspace is stripping the whitespace as I type it seemingly because Codi is running (does not happen when autocmd is set to InsertLeave)
  • one may find it distracting - for example seeing lots of syntax errors because you haven't finished typing yet
  • reduced battery usage???
@dylan-chong dylan-chong changed the title Can't assign custom auto commands Can't assign custom auto commands without the insert versions Jul 1, 2018
@thirtythreeforty
Copy link

I am the author of LessSpace from the linked issue. My plugin strips whitespace when leaving insert mode, or after normal mode edits. I am having trouble integrating with Codi's behavior of quickly leaving insert mode during Codi updates. The CodiUpdatePre and CodiUpdatePost hooks normally would allow me to disable the plugin for the duration of the Codi update, but based on a cursory reading of the code, it appears the Post hook may not be called? Correct me if I'm wrong.

codi.vim/autoload/codi.vim

Lines 352 to 355 in 26fdafe

" Only trigger post if sync
if !s:get_opt('async')
call s:user_au('CodiUpdatePost')
endif

Alternatively, Codi could be set to run on CursorHold events, but it needs to be possible to exclude CursorHoldI events for the reasons @dylan-chong gave in the original issue.

@taylorskalyo
Copy link

This is what I use to assign custom auto commands for codi without the insert version.

" vimrc/init.vim

let g:codi#autocmd = 'None'
augroup codi_update
  autocmd!
  autocmd TextChanged,InsertLeave <buffer> call codi#update()
augroup END

@lukelbd
Copy link
Contributor

lukelbd commented Oct 14, 2019

@taylorskalyo

The problem with your solution is that codi#update will get called on every file, even when codi is not even active on that file. I suppose when codi#update is called while codi is inactive, it just exits, but this seems clunky to me.

The below works only when codi is active, using the CodiEnterPre and CodiLeavePost autocommands (see :help codi). Just add these lines to your .vimrc.

let g:codi#autocmd = 'None'
augroup codi
  au!
  au User CodiEnterPre call s:codi_enter()
  au User CodiLeavePost call s:codi_leave()
augroup END
function! s:codi_enter()
  exe 'augroup codi_' . bufnr('%')
    au!
    au InsertLeave,TextChanged <buffer> call codi#update()
  augroup END
endfunction
function! s:codi_leave()
  exe 'augroup codi_' . bufnr('%')
    au!
  augroup END
endfunction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants