time for import command?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

time for import command?

Hari Krishna Dara

Now that vim7 is adding so many features into VimL, which would allow
for writing more powerful and complex plugins, how about adding a feature
such as python's "from <module> import" statement in VimL? The reason is
that it makes Vim scripts more modularized, and easier to share among
multiple plugins.

--
Thank you,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: time for import command?

Bram Moolenaar

Hari Krishna Dara wrote:

> Now that vim7 is adding so many features into VimL, which would allow
> for writing more powerful and complex plugins, how about adding a feature
> such as python's "from <module> import" statement in VimL? The reason is
> that it makes Vim scripts more modularized, and easier to share among
> multiple plugins.

You can ":source" a script or use ":runtime" to find it in one of the
runtime directories.  ":runtime" is similar to the import statement.
Except for the naming, of course.

The autoload mechanism is also helpful.  It avoids having to source a
script before it's used.  I'm now using it in runtime/plugin/gzip.vim,
for example.  Should make startup a bit quicker.

--
hundred-and-one symptoms of being an internet addict:
6. You refuse to go to a vacation spot with no electricity and no phone lines.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: time for import command?

Hari Krishna Dara
In reply to this post by Hari Krishna Dara

On Fri, 5 Aug 2005 at 10:44pm, Bram Moolenaar wrote:

>
> Hari Krishna Dara wrote:
>
> > Now that vim7 is adding so many features into VimL, which would allow
> > for writing more powerful and complex plugins, how about adding a feature
> > such as python's "from <module> import" statement in VimL? The reason is
> > that it makes Vim scripts more modularized, and easier to share among
> > multiple plugins.
>
> You can ":source" a script or use ":runtime" to find it in one of the
> runtime directories.  ":runtime" is similar to the import statement.
> Except for the naming, of course.
>
> The autoload mechanism is also helpful.  It avoids having to source a
> script before it's used.  I'm now using it in runtime/plugin/gzip.vim,
> for example.  Should make startup a bit quicker.

The script being sourced can't impact the namespace of the calling
script. With "from .. import", you can basically import a set or all of
names from another script into the current script. Useful for code
reuse and providing extension mechanism. It provided functionality that
is a super set of what the source command does.

When I wrote a couple of scripts called ntservices.vim and
ntprocesses.vim long back, the scripts were so much alike that having a
pythong like import functionality would have helped me to avoid so much
duplication, and would have made creating newer utilities like this much
more simpler. Using source would have been a lot tougher. Remember,
source doesn't provide unique namespace for each script sourcing it, so
you need to go out of your way to support multiple clients. I hope I am
more clear on what the advantages of import is going to be over source
command.

--
Thanks,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com