summaryrefslogtreecommitdiff
path: root/src/ex_cmds2.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-04-04 18:15:38 +0200
committerBram Moolenaar <Bram@vim.org>2019-04-04 18:15:38 +0200
commit558ca4ae55096f8763ab8515a304cda9c57f18a7 (patch)
tree3eeff81990411749a97a0684dde7b8ba5e28acdf /src/ex_cmds2.c
parent8f4aeb5572d604d1540ee0cb7e721b5f0cc6d612 (diff)
downloadvim-git-558ca4ae55096f8763ab8515a304cda9c57f18a7.tar.gz
patch 8.1.1116: cannot enforce a Vim script stylev8.1.1116
Problem: Cannot enforce a Vim script style. Solution: Add the :scriptversion command. (closes #3857)
Diffstat (limited to 'src/ex_cmds2.c')
-rw-r--r--src/ex_cmds2.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index a8040a71b..97bf14358 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -2321,7 +2321,7 @@ check_changed_any(
else
#endif
/* Try auto-writing the buffer. If this fails but the buffer no
- * longer exists it's not changed, that's OK. */
+ * longer exists it's not changed, that's OK. */
if (check_changed(buf, (p_awa ? CCGD_AW : 0)
| CCGD_MULTWIN
| CCGD_ALLBUF) && bufref_valid(&bufref))
@@ -4501,12 +4501,14 @@ do_source(
* Also starts profiling timer for nested script. */
save_funccal(&funccalp_entry);
+ save_current_sctx = current_sctx;
+ current_sctx.sc_lnum = 0;
+ current_sctx.sc_version = 1;
+
// Check if this script was sourced before to finds its SID.
// If it's new, generate a new SID.
// Always use a new sequence number.
- save_current_sctx = current_sctx;
current_sctx.sc_seq = ++last_current_SID_seq;
- current_sctx.sc_lnum = 0;
# ifdef UNIX
stat_ok = (mch_stat((char *)fname_exp, &st) >= 0);
# endif
@@ -5077,10 +5079,9 @@ script_line_end(void)
/*
* ":scriptencoding": Set encoding conversion for a sourced script.
- * Without the multi-byte feature it's simply ignored.
*/
void
-ex_scriptencoding(exarg_T *eap UNUSED)
+ex_scriptencoding(exarg_T *eap)
{
struct source_cookie *sp;
char_u *name;
@@ -5108,6 +5109,29 @@ ex_scriptencoding(exarg_T *eap UNUSED)
vim_free(name);
}
+/*
+ * ":scriptversion": Set Vim script version for a sourced script.
+ */
+ void
+ex_scriptversion(exarg_T *eap UNUSED)
+{
+ int nr;
+
+ if (!getline_equal(eap->getline, eap->cookie, getsourceline))
+ {
+ emsg(_("E984: :scriptversion used outside of a sourced file"));
+ return;
+ }
+
+ nr = getdigits(&eap->arg);
+ if (nr == 0 || *eap->arg != NUL)
+ emsg(_(e_invarg));
+ else if (nr > 2)
+ semsg(_("E999: scriptversion not supported: %d"), nr);
+ else
+ current_sctx.sc_version = nr;
+}
+
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* ":finish": Mark a sourced file as finished.