Continuing work on vim9 import/export

34 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 19, 2020, 4:00:08 PM1/19/20
to vim...@googlegroups.com

I have implemented the basics of the import and export commands.
Trying it out shows that it works well. Anyone familiar with JavaScript
(ES6) will immediately see how it works. For others it's easy to
explain.

As an illustration, I have written help for how to use import with
autoload to make startup fast:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Import in an autoload script ~

For optimal startup speed, loading scripts should be postponed until they are
actually needed. A recommended mechamism:

1. In the plugin define user commands, functions and/or mappings that refer to
an autoload script. >
command -nargs=1 SearchForStuff call searchfor#Stuff(<f-args>)

< This goes in .../plugin/anyname.vim. "anyname.vim" can be freely chosen.

2. In the autocommand script do the actual work. You can import items from
other files to split up functionality in appropriate pieces. >
vim9script
import FilterFunc from "../import/someother.vim"
def searchfor#Stuff(arg: string)
let filtered = FilterFunc(arg)
...
< This goes in .../autoload/searchfor.vim. "searchfor" in the file name
must be exactly the same as the prefix for the function name, that is how
Vim finds the file.

3. Other functionality, possibly shared between plugins, contains the exported
items and any private items. >
vim9script
let localVar = 'local'
export def FilterFunc(arg: string): string
...
< This goes in .../import/someother.vim.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

For the context, see
https://github.com/brammool/vim9/blob/master/runtime/doc/vim9.txt


--
If all you have is a hammer, everything looks like a nail.
When your hammer is C++, everything begins to look like a thumb.
-- Steve Hoflich, comp.lang.c++

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages