Hum, considering this autocommand below, 
I notice that it calls imported def function  UnderLineHeaders() only on 
the first entering file.h, not the others.
Don"t understand why ?

Thank you for help
Nicolas


------------------------------------------------------


* _vimrc: *
  import autoload 
'./vimfiles/plugged/foobarhelper.vim/autoload/foobarhelper.vim' as *that*
  autocmd BufEnter *.cpp,*.hpp,*.h,*.c  call *that*.UnderLineHeaders() 

:autocmd
--- Autocommands ---
.. some other stuff
*BufEnter*
    *.cpp     call *that*.UnderLineHeaders()
    *.hpp     call *that*.UnderLineHeaders()
    *.h       call *that*.UnderLineHeaders()                 > > >> >>> works 
only on first entering *.h buffer. 
    *.c       call *that*.UnderLineHeaders()



*_autoload/myhelper/myhelper.vim: *
*export def UnderLineHeaders*(): void

  echomsg 'UnderLineHeaders called for buffer ' .. expand("%:p")

   some stuff....
  
  if !exists('*g:OpeningHeader')   
   * def g:OpeningHeader*(): void
      some other stuff
  *enddef*
*enddef*




Le vendredi 14 octobre 2022 à 22:34:07 UTC+2, N V a écrit :

> Solved by this prevent conditionnal test
>
> if !exists('*MyFunction') fun MyFunction ... endfun endif as described 
> https://stackoverflow.com/questions/31663750/function-already-exists-vim
>
> Le vendredi 14 octobre 2022 à 22:25:29 UTC+2, N V a écrit :
>
>> Hi,
>>
>> I got reentrancy side effect with a bufenter autocommand on header 
>> considering these feature.
>>
>>
>>    - First def func1 is processing current buffer (cpp, h) to add 
>>    text_prop on header file and underline them. => works Fin
>>    - Inside this   func1  declare  func2 to search and open underlined 
>>    header double cliked.
>>
>>
>> The vim9script that do the job :
>> *export def* UnderLineHeaders(): void
>>
>>   var *headers*: dict<string> = {}
>>       .. some stuff
>>       .. some stuff
>>
>>
>>   *def* *g:OpeningHeader*(): void
>>       .. some stuff 
>>       .. some stuff
>>   *enddef*
>>
>>   nnoremap <buffer> <2-Leftmouse> :call *g:OpeningHeader*()<CR>
>> *enddef*
>>
>>
>>
>> The error I got when double clik on header :
>> Error detected while processing function OpeningHeader[21]..BufEnter 
>> Autocommands for "*.h"..function nvhelper#UnderLineHeaders:
>> line   28:
>> *E122: *Function OpeningHeader *already exists, add ! *to replace it    
>>      
>>
>>
>> How can I force the g:OpeningHeader def func ?
>> Thank you
>> Nicolas
>>
>>
>> *The complete code *
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *export def UnderLineHeaders(): void  var patterns: dict<string> = { 
>> 'header': '\w\+\.h' }  var headers: dict<string> = {}  var list_of_line: 
>> list<string> = getline(1, '$')  var lineno: number = 1  var res: string = 
>> ''  # identify headers' lines  for line in list_of_line    res = 
>> matchstr(line, patterns.header)    if res != ""      headers[lineno] = res  
>>   endif    lineno = lineno + 1  endfor  # some declarations before adding 
>> text prop  call prop_type_delete('header')  hi Underlined_Header   
>>  ctermbg=NONE ctermfg=NONE  cterm=UNDERLINE guibg=NONE    guifg=NONE     
>>  gui=UNDERLINE  call prop_type_add('header', {'highlight': 
>> 'Underlined_Header'})  # add prop on headers  var col: number = -1  for key 
>> in keys(headers)    lineno = key->str2nr()    col = stridx(getline(lineno), 
>> headers[key]) + 1    call prop_add(lineno, col, {'length': 
>> headers[key]->len(), 'type': 'header'})  endfor  def g:OpeningHeader(): 
>> void    var curlnum: number = getcurpos()[1]    var key: string = 
>> getcurpos()[1]->string()    if has_key(headers, key)      var searchedfile: 
>> string = headers[getcurpos()[1]->string()]      echomsg 'File to search for 
>> is ' .. searchedfile      var currentpath: list<string> = 
>> expand("%:p:h")->split('\\')      var idxfolder: number = 1      var 
>> maxfolders: number = currentpath->len()      var foundedfile: string = ''  
>>     while  idxfolder < maxfolders        foundedfile = globpath( 
>> currentpath[ : -1 * idxfolder ]->join('\'), "**/" .. searchedfile )        
>> if foundedfile != ''          break        endif        idxfolder += 1      
>> endwhile      echomsg foundedfile      exe 'e ' .. foundedfile    else      
>> echomsg 'Sorry no File to search for.'    endif  enddef  # add double 
>> clickable feature => opening header  nnoremap <buffer> <2-Leftmouse> :call 
>> g:OpeningHeader()<CR>enddef*
>>
>>

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/b9e27fbe-c5e7-4a51-a78e-ae82391b97a4n%40googlegroups.com.

Reply via email to