nvim-ipy icon indicating copy to clipboard operation
nvim-ipy copied to clipboard

Fire autocommand on IPyConnect

Open miseran opened this issue 9 years ago • 2 comments

It would be useful if we were able to create mapping or set other options (such as omnifunc) only once IPyConnect is started. With this patch, an autocommand is fired as soon as IPyConnect is run, which allows the user to do just that.

For example,

autocmd User ipy-connect call SetIPyOptions()
function SetIPyOptions()
  map <silent> <CR> <Plug>(IPy-Run)
  set omnifunc=IPyOmniFunc
endfunction

I hope this is the right place to fire it.

miseran avatar Apr 08 '16 19:04 miseran

I don't think this is very useful as is, because you could just as well define a function that calls IPyConnect and does the setup. I have in my nvimrc:

function! IpyLaunch(...)
    call call("IPyConnect", a:000)
    call NvimIPyMappings()
    let g:hasipy = 1
endfunction
command! -nargs=* IP :call IpyLaunch(<f-args>)
command! IJ :call IpyLaunch("--kernel", "julia-0.4")

if exists('g:hasipy')
    " when reloading nvimrc
    call NvimIPyMappings()
endif

what could be useful though, is to fire an autocommand towards the end of def connect(). At this point the kernel is fully initialized (so commands can be sent to it) and the kernel info (most importantly the language) is known.

bfredl avatar Apr 09 '16 21:04 bfredl

Thanks for your reply. Defining a new command would be an alternative, yes. I may just do it that way.

I did consider firing the autocommand at the end of def connect(), but I wasn't sure if there would be any problems due to asynchrony. It would certainly be nice if one could e.g. set the filetype of the main buffer appropriately, right now I just set it to python since that's the one I use.

I assume there's no need for me to update the pull request?

miseran avatar Apr 09 '16 22:04 miseran