Embed langage print when sourcing vim9script

27 views
Skip to first unread message

Ni Va

unread,
Apr 9, 2022, 2:40:52 AM4/9/22
to vim_use
Hi,

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   

Bram Moolenaar

unread,
Apr 9, 2022, 6:01:47 AM4/9/22
to vim...@googlegroups.com, Ni Va
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 ///

Ni Va

unread,
Apr 9, 2022, 3:20:17 PM4/9/22
to vim_use

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
Reply all
Reply to author
Forward
0 new messages