diff src/vim9script.c @ 24533:9c404d78d767 v8.2.2806

patch 8.2.2806: Vim9: using "++nr" as a command might not work Commit: https://github.com/vim/vim/commit/bdc0f1c6986e5d64f647e0924a4de795b47c549a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 24 19:08:24 2021 +0200 patch 8.2.2806: Vim9: using "++nr" as a command might not work Problem: Vim9: using "++nr" as a command might not work. Solution: Do not recognize "++" and "--" in a following line as addition or subtraction.
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Apr 2021 19:15:04 +0200
parents 3bfec39ce31c
children bf8feac8a89a
line wrap: on
line diff
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -160,6 +160,28 @@ vim9_comment_start(char_u *p)
 #if defined(FEAT_EVAL) || defined(PROTO)
 
 /*
+ * "++nr" and "--nr" commands.
+ */
+    void
+ex_incdec(exarg_T *eap)
+{
+    char_u	*cmd = eap->cmd;
+    size_t	len = STRLEN(eap->cmd) + 6;
+
+    // This works like "nr += 1" or "nr -= 1".
+    eap->cmd = alloc(len);
+    if (eap->cmd == NULL)
+	return;
+    vim_snprintf((char *)eap->cmd, len, "%s %c= 1", cmd + 2,
+				     eap->cmdidx == CMD_increment ? '+' : '-');
+    eap->arg = eap->cmd;
+    eap->cmdidx = CMD_var;
+    ex_let(eap);
+    vim_free(eap->cmd);
+    eap->cmd = cmd;
+}
+
+/*
  * ":export let Name: type"
  * ":export const Name: type"
  * ":export def Name(..."