feat(version): support multiple Vim versions

Group up to 15 vimpatch numbers in 1 line to guard against
'make formatc'.
1-liner for vim_versions, num_patches.

Automate '*Version' to remove version.h macros.

'-V1 -v' lists merged Vim versions.
This commit is contained in:
Jan Edmund Lazo
2025-11-20 01:29:39 -05:00
parent 361671870e
commit 5196162540
8 changed files with 4373 additions and 2495 deletions

View File

@@ -3800,14 +3800,15 @@ static int chk_modeline(linenr_T lnum, int flags)
continue;
}
const int vim_version = min_vim_version();
if (*e == ':'
&& (s[0] != 'V'
|| strncmp(skipwhite(e + 1), "set", 3) == 0)
&& (s[3] == ':'
|| (VIM_VERSION_100 >= vers && isdigit((uint8_t)s[3]))
|| (VIM_VERSION_100 < vers && s[3] == '<')
|| (VIM_VERSION_100 > vers && s[3] == '>')
|| (VIM_VERSION_100 == vers && s[3] == '='))) {
|| (vim_version >= vers && isdigit((uint8_t)s[3]))
|| (vim_version < vers && s[3] == '<')
|| (vim_version > vers && s[3] == '>')
|| (vim_version == vers && s[3] == '='))) {
break;
}
}

View File

@@ -2812,14 +2812,10 @@ static void f_has(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
int minor = atoi(end + 1);
// Expect "patch-9.9.01234".
n = (major < VIM_VERSION_MAJOR
|| (major == VIM_VERSION_MAJOR
&& (minor < VIM_VERSION_MINOR
|| (minor == VIM_VERSION_MINOR
&& has_vim_patch(atoi(end + 3))))));
n = has_vim_patch(atoi(end + 3), major * 100 + minor);
}
} else if (ascii_isdigit(name[5])) {
n = has_vim_patch(atoi(name + 5));
n = has_vim_patch(atoi(name + 5), 0);
}
} else if (STRNICMP(name, "nvim-", 5) == 0) {
// Expect "nvim-x.y.z"

View File

@@ -281,8 +281,9 @@ void evalvars_init(void)
hash_add(&compat_hashtab, p->vv_di.di_key);
}
}
set_vim_var_nr(VV_VERSION, VIM_VERSION_100);
set_vim_var_nr(VV_VERSIONLONG, VIM_VERSION_100 * 10000 + highest_patch());
const int vim_version = min_vim_version();
set_vim_var_nr(VV_VERSION, vim_version);
set_vim_var_nr(VV_VERSIONLONG, vim_version * 10000 + highest_patch());
dict_T *const msgpack_types_dict = tv_dict_alloc();
for (size_t i = 0; i < ARRAY_SIZE(msgpack_type_names); i++) {

View File

@@ -330,7 +330,7 @@ int ml_open(buf_T *buf)
b0p->b0_magic_int = B0_MAGIC_INT;
b0p->b0_magic_short = (int16_t)B0_MAGIC_SHORT;
b0p->b0_magic_char = B0_MAGIC_CHAR;
xstrlcpy(xstpcpy(b0p->b0_version, "VIM "), Version, 6);
xstrlcpy(xstpcpy(b0p->b0_version, "VIM "), Versions[0], 6);
long_to_char((long)mfp->mf_page_size, b0p->b0_page_size);
if (!buf->b_spell) {

File diff suppressed because it is too large Load Diff

View File

@@ -5,26 +5,10 @@
#include "nvim/macros_defs.h"
// defined in version.c
extern char *Version;
extern char *Versions[];
extern char *longVersion;
#ifndef NDEBUG
extern char *version_cflags;
#endif
//
// Vim version number, name, etc. Patchlevel is defined in version.c.
//
// Values that change for a new release
#define VIM_VERSION_MAJOR 8
#define VIM_VERSION_MINOR 1
// Values based on the above
#define VIM_VERSION_MAJOR_STR STR(VIM_VERSION_MAJOR)
#define VIM_VERSION_MINOR_STR STR(VIM_VERSION_MINOR)
#define VIM_VERSION_100 (VIM_VERSION_MAJOR * 100 + VIM_VERSION_MINOR)
// swap file compatibility (max. length is 6 chars)
#define VIM_VERSION_SHORT VIM_VERSION_MAJOR_STR "." VIM_VERSION_MINOR_STR
#include "version.h.generated.h"