Question summary
Currently I'm writing a pull request for this vim plugin which should set commas and semicolons automatically.
At the moment it looks if it should set a comma/semicolon/double point or not everytime the user presses any key . This makes the plugin a little bit heavy (in my opinion) so I want to call a function only when the user presses the return key and not for every key.
What I have now at this moment
This is currently in the plugin:
autocmd BufEnter * call cosco_autocmds#RefreshAutocmds()
This cosco_autocmd#RefreshAutocmds()
enables the auto-setting for the current buffer:
autocmd TextChangedI <buffer> call cosco#AdaptCode()
Now I've tried this:
inoremap <CR> <C-O>:call cosco#AdaptCode()<CR>
But it looks like that the mapping doesn't call the function (you can try to add a echom "Test"
in the cosco#AdaptCode()
function). Do you have an idea how I can fix this?
Test it on your own
If you want to test it on your own, add my pull request to your plugin manager. For vim-plug it should be:
Plug 'TornaxO7/cosco.vim'
This is the line where I want to put the inoremap
. If you need more information, how this plugin works in general, take a look into its CONTRIBUTING.md file.
Error detected while processing TextChangedI Autocommands for "<buffer=1>"..function cosco#AdaptCode[41]..cosco_eval#ShouldNotSkip: line 56: E121: Undefined variable: g:cosco_ignore_comment_lines
but if I start with:let g:cosco_ignore_comment_lines = 0
then it seems to work for me... I do seem to have theTextChangedI
autocmd set, so it seems your fork isn't really removing that, is it?<CR>
mapping to also produce an actual<CR>
, soinoremap <CR> <C-O>:call cosco#AdaptCode()<CR><CR>
is a start. It doesn't really work very well though, because it only adds the semi-colon for the preceding lines, so autoindent thinks the new line is a continuation line...