# HG changeset patch # User Bram Moolenaar # Date 1560516306 -7200 # Node ID d5fa04016df04f890a65d5c68b9ce23a33c1198c # Parent 4f290fef4173a51f3cfa2661fff9e53746ef148f patch 8.1.1526: no numerical value for the patchlevel commit https://github.com/vim/vim/commit/37df9a4401f6737d6216306ea77a7e080c942aea Author: Bram Moolenaar Date: Fri Jun 14 14:39:51 2019 +0200 patch 8.1.1526: no numerical value for the patchlevel Problem: No numerical value for the patchlevel. Solution: Add v:versionlong. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2173,6 +2173,17 @@ v:version Version number of Vim: Major v version 5.0 and 5.1 may have a patch 123, but these are completely different. + *v:versionlong* *versionlong-variable* +v:versionlong Like v:version, but also including the patchlevel. Version + 8.1 with patch 1234 has value 8011234. This can be used like + this: > + if v:versionlong >= 8011234 +< However, if there are gaps in the list of patches included + this will not work well. This can happen if a recent patch + was included into an older version, e.g. for a security fix. + Use the has() function to make sure the patch is actually + included. + *v:vim_did_enter* *vim_did_enter-variable* v:vim_did_enter Zero until most of startup is done. It is set to one just before |VimEnter| autocommands are triggered. diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -193,9 +193,10 @@ static struct vimvar {VV_NAME("termrfgresp", VAR_STRING), VV_RO}, {VV_NAME("termrbgresp", VAR_STRING), VV_RO}, {VV_NAME("termu7resp", VAR_STRING), VV_RO}, - {VV_NAME("termstyleresp", VAR_STRING), VV_RO}, - {VV_NAME("termblinkresp", VAR_STRING), VV_RO}, - {VV_NAME("event", VAR_DICT), VV_RO}, + {VV_NAME("termstyleresp", VAR_STRING), VV_RO}, + {VV_NAME("termblinkresp", VAR_STRING), VV_RO}, + {VV_NAME("event", VAR_DICT), VV_RO}, + {VV_NAME("versionlong", VAR_NUMBER), VV_RO}, }; /* shorthand */ @@ -354,6 +355,7 @@ eval_init(void) hash_add(&compat_hashtab, p->vv_di.di_key); } vimvars[VV_VERSION].vv_nr = VIM_VERSION_100; + vimvars[VV_VERSIONLONG].vv_nr = VIM_VERSION_100 * 10000 + highest_patch(); set_vim_var_nr(VV_SEARCHFORWARD, 1L); set_vim_var_nr(VV_HLSEARCH, 1L); diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -171,6 +171,9 @@ func Test_vvar_scriptversion2() echo version call assert_fails('let version = 1', 'E46:') call assert_equal(v:version, version) + + call assert_equal(v:version, v:versionlong / 10000) + call assert_true(v:versionlong > 8011525) endfunc func Test_scriptversion() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -778,6 +778,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1526, +/**/ 1525, /**/ 1524, @@ -3847,13 +3849,8 @@ static char *(extra_patches[]) = int highest_patch(void) { - int i; - int h = 0; - - for (i = 0; included_patches[i] != 0; ++i) - if (included_patches[i] > h) - h = included_patches[i]; - return h; + // this relies on the highest patch number to be the first entry + return included_patches[0]; } #if defined(FEAT_EVAL) || defined(PROTO) diff --git a/src/vim.h b/src/vim.h --- a/src/vim.h +++ b/src/vim.h @@ -1960,7 +1960,8 @@ typedef int sock_T; #define VV_TERMSTYLERESP 85 #define VV_TERMBLINKRESP 86 #define VV_EVENT 87 -#define VV_LEN 88 /* number of v: vars */ +#define VV_VERSIONLONG 88 +#define VV_LEN 89 // number of v: vars /* used for v_number in VAR_SPECIAL */ #define VVAL_FALSE 0L