diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-02-17 21:57:03 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-02-17 21:57:03 +0100 |
commit | d3f8a9ee65b249d073343e43e423bc3348dd09d0 (patch) | |
tree | 6e811ccffd1330383158ad2f9fe2a3727370353a /runtime | |
parent | c7dac8534ee7f7a49e9d7a37330397c64455cdd7 (diff) | |
download | vim-git-d3f8a9ee65b249d073343e43e423bc3348dd09d0.tar.gz |
patch 8.2.2529: Vim9: Not possible to use legacy and Vim9 script in one filev8.2.2529
Problem: Vim9: Not possible to use legacy and Vim9 script in one file.
Solution: Vim9: allow for "if false" before :vim9script. (closes #7851)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/vim9.txt | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/runtime/doc/vim9.txt b/runtime/doc/vim9.txt index beec86fd3..def68d312 100644 --- a/runtime/doc/vim9.txt +++ b/runtime/doc/vim9.txt @@ -1051,9 +1051,9 @@ that you don't do that. Namespace ~ *vim9-namespace* To recognize a file that can be imported the `vim9script` statement must -appear as the first statement in the file. It tells Vim to interpret the -script in its own namespace, instead of the global namespace. If a file -starts with: > +appear as the first statement in the file (see |vim9-mix| for an exception). +It tells Vim to interpret the script in its own namespace, instead of the +global namespace. If a file starts with: > vim9script var myvar = 'yes' Then "myvar" will only exist in this file. While without `vim9script` it would @@ -1073,6 +1073,27 @@ Vim default value, like with: > One of the effects is that |line-continuation| is always enabled. The original value of 'cpoptions' is restored at the end of the script. + *vim9-mix* +There is one way to use both legacy and Vim9 syntax in one script file: > + " comments may go here + if !has('vim9script') + " legacy script commands go here + finish + endif + vim9script + # Vim9 script commands go here +This allows for writing a script that takes advantage of the Vim9 script +syntax if possible, but will also work on an Vim version without it. + +This can only work in two ways: +1. The "if" statement evaluates to false, the commands up to `endif` are + skipped and `vim9script` is then the first command actually executed. +2. The "if" statement evaluates to true, the commands up to `endif` are + executed and `finish` bails out before reaching `vim9script`. + +TODO: The "vim9script" feature does not exist yet, it will only be added once +the Vim9 script syntax has been fully implemented. + Export ~ *:export* *:exp* |