Saturday, April 9, 2022

Re: Embed langage print when sourcing vim9script


Thank you Bram!

Maybe it's because I forgot to say I have an autocommand. 
I am surprised to see out of print('LuaXmlParser') when I source this vim9script.

Thank you again Bram.
NV

# Syntax / Filetype - Helper {{{
def g:SwitchFtHelper(arg: string): void

  if (arg == 'leave')
    au!
  endif

  if ( !exists('g:cachebufnr') )
    g:cachebufnr = bufnr('%')
    g:cacheft = &ft
    StampedEcho( 'Cached filetype is ' .. g:cacheft .. ' and bufnr is ' .. g:cachebufnr )

    def Scan(timerID: any): number

      # g:embedRegions = {
      # [beg, end]  # linenos of embed langage regions' begin, end
      # ..
      # }
      g:begs = []
      g:ends = []
      exe "g/\\w\\+\\s\\+<<\\s\\+EOF/call add(g:begs, line('.'))"
      exe "g/^EOF/call add(g:ends, line('.'))"

      var foo = []

      var idx: number = 0
      while idx < len(g:begs)
        call add(foo, [g:begs[idx], g:ends[idx]])
        idx = idx + 1
      endwhile
      # StampedEcho( 'Scan begin EOF: ' .. string(g:foo))
      return 1
    enddef

    timer_start(1200, Scan, {'repeat': 20} )

  endif

  lua << EOF
EOF
  lua << EOF

print('LuaXmlParser')

EOF

enddef
augroup FOOBAR
  au! CursorHold  *.vim ++nested call g:SwitchFtHelper('')
  # au! BufLeave *.vim aug! FOOB
augroup END




Le samedi 9 avril 2022 à 12:01:47 UTC+2, Bram Moolenaar a écrit :

> Is it normal to get print of embed langage when I source vim9script ?
>
> Thank you
> NV
>
> def g:SwitchFtHelper(): void # Syntax / Filetype - Helper {{{
>
> if ( !exists('g:cachebufnr') )
> g:cachebufnr = bufnr('%')
> g:cacheft = &ft
> StampedEcho( 'Cached filetype is ' .. g:cacheft .. ' and bufnr is ' ..
> g:cachebufnr )
> endif
>
> lua << EOF
>
> print('foo')
>
> EOF
>
> enddef

When I source this I see nothing. Only when calling g:SwitchFtHelper()
(commenting out what doesn't work) I see "foo" printed. Looks fine to
me.

--
A M00se once bit my sister ...
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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/7750feed-70a9-4d38-9de6-3e3ffd1dd5e5n%40googlegroups.com.

No comments:

Post a Comment