> >Well, this works:
> >
> >def Fix_beginfigs()
> > g:index = 1
> > g/^beginfig(\d*);$/s//\='beginfig(' .. g:index .. ');'/ | g:index =
> > g:index + 1 unlet g:index
> >enddef
> >
> >However, using a legacy function would not be worse. The global
> >command does most of the work, what function it's in doesn't really
> >matter.
>
> Hi Bram,
>
> I try not to use global variables within functions. Is there an
> alternative enabling non-use of global variables?
>
> Also, I thought the new Vim9 Vimscript was getting rid of the need for
> g: and l: and a: etc. That stuff used to kill my brain.
Right, using global variables is not the best way. The thing is that
with a compiled function the local variables are on the stack, which
makes them unreachable for expressions that are not compiled.
Over time we have added these expressions in various places, which will
be evaluated in whatever context they are used. For a legacy function
the context is available, with dictionaries containing the local
variables. With compiled functions we have no such dictionaries, since
these add a lot of overhead.
The basic thing is, once you are in a compiled function, keep using
compiled expressions. When you escape to commands not using compiled
expressions, you run into trouble.
--
From "know your smileys":
*<|:-) Santa Claus (Ho Ho Ho)
/// Bram Moolenaar -- Bram@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/202107042207.164M7f9D2634760%40masaka.moolenaar.net.
Sunday, July 4, 2021
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment