Thursday, October 20, 2022

Re: Share variables between Two vim9 def functions

I don't get what you mean really, I'd use a g:global variable personally, and not think more of it.

Hth

Tommy

tir. 18. okt. 2022, 6:50 p.m. skrev Nicolas <nivaemail@gmail.com>:
Hi,

All written in vim9script, I wonder how sharing variable between two def vim9 functions out of declaring these funcs as this :    
  • the first one imported and used throught _vimrc autocommand on BufEnter
  • the second one is declared inside the first one and is mapped just after in the code on event such as mouse double click.
The second one func, it needs variable dict computed by the first one on each BufEnter event.


In vimfiles/helper/autoload/helper.vim I got 
export def UnderLineHeaders(): void
  var headers: dict<string> = {}      
   .. some stuff
   ..  

  def g:OpeningHeader(): void       
     exe 'edit ' .. headers['goodIdxHeader'] ~path to the header file.
  enddef
  nnoremap <buffer> <2-Leftmouse> :call g:OpeningHeader()<CR>     <<< be carefull :)
enddef

In _vimrc i got:
  import autoload './vimfiles/plugged/helper.vim/autoload/helper.vim' as that
  autocmd BufEnter *.cpp,*.h thatUnderLineHeaders()                  <<< be carefull :)



Out of global var, I think there is a better way  to share something between first exported func and triggered on BufEnter and second one which needs variable computed of this triggered func, second one which occurs and called on mapped double click mouse event .


Thank you for your help
I can share the entire vimscript if needed.
Nicolas

--
--
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/86cfe413-7cc8-43b1-bc2c-446398bba367n%40googlegroups.com.

--
--
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/CAL3odWzSHJNW3R0Jb469L%3DVhtF%2BWLunZu297bu5sEKzqr2%3Drvg%40mail.gmail.com.

No comments:

Post a Comment