diff src/ex_cmds2.c @ 16223:abb67309c1ca v8.1.1116

patch 8.1.1116: cannot enforce a Vim script style commit https://github.com/vim/vim/commit/558ca4ae55096f8763ab8515a304cda9c57f18a7 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 4 18:15:38 2019 +0200 patch 8.1.1116: cannot enforce a Vim script style Problem: Cannot enforce a Vim script style. Solution: Add the :scriptversion command. (closes https://github.com/vim/vim/issues/3857)
author Bram Moolenaar <Bram@vim.org>
date Thu, 04 Apr 2019 18:30:05 +0200
parents ddd82b1c9e9d
children 9cbc5ff516ee
line wrap: on
line diff
--- 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.