mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
version: has("nvim-1.2.3")
Helped-by: Daniel Hahler <git@thequod.de>
This commit is contained in:
parent
f96dfae52f
commit
e7e2844d46
@ -7453,7 +7453,11 @@ There are four types of features:
|
|||||||
Example: >
|
Example: >
|
||||||
:if has("gui_running")
|
:if has("gui_running")
|
||||||
< *has-patch*
|
< *has-patch*
|
||||||
3. Included patches. The "patch123" feature means that patch 123 has been
|
3. {Nvim} version. The "nvim-1.2.3" feature means that the Nvim version is
|
||||||
|
1.2.3 or later. Example: >
|
||||||
|
:if has("nvim-1.2.3")
|
||||||
|
<
|
||||||
|
4. Included patches. The "patch123" feature means that patch 123 has been
|
||||||
included. Note that this form does not check the version of Vim, you need
|
included. Note that this form does not check the version of Vim, you need
|
||||||
to inspect |v:version| for that.
|
to inspect |v:version| for that.
|
||||||
Example (checking version 6.2.148 or later): >
|
Example (checking version 6.2.148 or later): >
|
||||||
@ -7461,7 +7465,7 @@ There are four types of features:
|
|||||||
< Note that it's possible for patch 147 to be omitted even though 148 is
|
< Note that it's possible for patch 147 to be omitted even though 148 is
|
||||||
included.
|
included.
|
||||||
|
|
||||||
4. Beyond a certain version or at a certain version and including a specific
|
5. Beyond a certain version or at a certain version and including a specific
|
||||||
patch. The "patch-7.4.237" feature means that the Vim version is 7.5 or
|
patch. The "patch-7.4.237" feature means that the Vim version is 7.5 or
|
||||||
later, or it is version 7.4 and patch 237 was included.
|
later, or it is version 7.4 and patch 237 was included.
|
||||||
Note that this only works for patch 7.4.237 and later, before that you
|
Note that this only works for patch 7.4.237 and later, before that you
|
||||||
@ -7533,6 +7537,7 @@ multi_byte Compiled with support for 'encoding'
|
|||||||
multi_byte_encoding 'encoding' is set to a multi-byte encoding.
|
multi_byte_encoding 'encoding' is set to a multi-byte encoding.
|
||||||
multi_byte_ime Compiled with support for IME input method.
|
multi_byte_ime Compiled with support for IME input method.
|
||||||
multi_lang Compiled with support for multiple languages.
|
multi_lang Compiled with support for multiple languages.
|
||||||
|
nvim This is Nvim. |has-patch|
|
||||||
ole Compiled with OLE automation support for Win32.
|
ole Compiled with OLE automation support for Win32.
|
||||||
path_extra Compiled with up/downwards search in 'path' and 'tags'
|
path_extra Compiled with up/downwards search in 'path' and 'tags'
|
||||||
persistent_undo Compiled with support for persistent undo history.
|
persistent_undo Compiled with support for persistent undo history.
|
||||||
|
@ -10524,16 +10524,10 @@ static void f_glob2regpat(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
: file_pat_to_reg_pat(pat, NULL, NULL, false);
|
: file_pat_to_reg_pat(pat, NULL, NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// "has()" function
|
||||||
* "has()" function
|
|
||||||
*/
|
|
||||||
static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||||
{
|
{
|
||||||
int i;
|
static char *(has_list[]) = {
|
||||||
char_u *name;
|
|
||||||
int n = FALSE;
|
|
||||||
static char *(has_list[]) =
|
|
||||||
{
|
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
"unix",
|
"unix",
|
||||||
#endif
|
#endif
|
||||||
@ -10646,36 +10640,44 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
name = get_tv_string(&argvars[0]);
|
bool n = false;
|
||||||
for (i = 0; has_list[i] != NULL; ++i)
|
char *name = (char *)get_tv_string(&argvars[0]);
|
||||||
|
|
||||||
|
for (int i = 0; has_list[i] != NULL; i++) {
|
||||||
if (STRICMP(name, has_list[i]) == 0) {
|
if (STRICMP(name, has_list[i]) == 0) {
|
||||||
n = TRUE;
|
n = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (n == FALSE) {
|
if (!n) {
|
||||||
if (STRNICMP(name, "patch", 5) == 0) {
|
if (STRNICMP(name, "patch", 5) == 0) {
|
||||||
if (name[5] == '-'
|
if (name[5] == '-'
|
||||||
&& STRLEN(name) > 11
|
&& strlen(name) > 11
|
||||||
&& ascii_isdigit(name[6])
|
&& ascii_isdigit(name[6])
|
||||||
&& ascii_isdigit(name[8])
|
&& ascii_isdigit(name[8])
|
||||||
&& ascii_isdigit(name[10])) {
|
&& ascii_isdigit(name[10])) {
|
||||||
int major = atoi((char *)name + 6);
|
int major = atoi(name + 6);
|
||||||
int minor = atoi((char *)name + 8);
|
int minor = atoi(name + 8);
|
||||||
|
|
||||||
// Expect "patch-9.9.01234".
|
// Expect "patch-9.9.01234".
|
||||||
n = (major < VIM_VERSION_MAJOR
|
n = (major < VIM_VERSION_MAJOR
|
||||||
|| (major == VIM_VERSION_MAJOR
|
|| (major == VIM_VERSION_MAJOR
|
||||||
&& (minor < VIM_VERSION_MINOR
|
&& (minor < VIM_VERSION_MINOR
|
||||||
|| (minor == VIM_VERSION_MINOR
|
|| (minor == VIM_VERSION_MINOR
|
||||||
&& has_patch(atoi((char *)name + 10))))));
|
&& has_vim_patch(atoi(name + 10))))));
|
||||||
} else {
|
} else {
|
||||||
n = has_patch(atoi((char *)name + 5));
|
n = has_vim_patch(atoi(name + 5));
|
||||||
|
}
|
||||||
|
} else if (STRNICMP(name, "nvim", 4) == 0) {
|
||||||
|
// Expect "nvim-x.y.z"
|
||||||
|
if (name[4] == '-' && strlen(name) >= 10) {
|
||||||
|
n = has_nvim_version(name + 5);
|
||||||
}
|
}
|
||||||
} else if (STRICMP(name, "vim_starting") == 0) {
|
} else if (STRICMP(name, "vim_starting") == 0) {
|
||||||
n = (starting != 0);
|
n = (starting != 0);
|
||||||
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
|
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
|
||||||
n = has_mbyte;
|
n = has_mbyte != 0;
|
||||||
#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
|
#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
|
||||||
} else if (STRICMP(name, "iconv") == 0) {
|
} else if (STRICMP(name, "iconv") == 0) {
|
||||||
n = iconv_enabled(false);
|
n = iconv_enabled(false);
|
||||||
@ -10685,8 +10687,8 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == FALSE && eval_has_provider((char *)name)) {
|
if (!n && eval_has_provider(name)) {
|
||||||
n = TRUE;
|
n = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rettv->vval.v_number = n;
|
rettv->vval.v_number = n;
|
||||||
|
@ -5537,7 +5537,7 @@ void ex_ownsyntax(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int syntax_present(win_T *win)
|
bool syntax_present(win_T *win)
|
||||||
{
|
{
|
||||||
return win->w_s->b_syn_patterns.ga_len != 0
|
return win->w_s->b_syn_patterns.ga_len != 0
|
||||||
|| win->w_s->b_syn_clusters.ga_len != 0
|
|| win->w_s->b_syn_clusters.ga_len != 0
|
||||||
|
@ -2457,20 +2457,61 @@ static char *(extra_patches[]) = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Checks whether patch `n` has been included.
|
/// Compares a version string to the current Nvim version.
|
||||||
///
|
///
|
||||||
/// @param n The patch number.
|
/// @param version Version string like "1.3.42"
|
||||||
///
|
///
|
||||||
/// @return TRUE if patch "n" has been included.
|
/// @return true if Nvim is at or above the version.
|
||||||
int has_patch(int n)
|
bool has_nvim_version(char *version_str)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
int i;
|
char *p = version_str;
|
||||||
for (i = 0; included_patches[i] != 0; ++i) {
|
int major = 0;
|
||||||
if (included_patches[i] == n) {
|
int minor = 0;
|
||||||
return TRUE;
|
int patch = 0;
|
||||||
|
|
||||||
|
if (!ascii_isdigit(*p)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
major = atoi(p);
|
||||||
|
p = strchr(p, '.'); // Find the next dot.
|
||||||
|
|
||||||
|
if (p) {
|
||||||
|
p++; // Advance past the dot.
|
||||||
|
if (!ascii_isdigit(*p)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
minor = atoi(p);
|
||||||
|
p = strchr(p, '.');
|
||||||
|
if (p) {
|
||||||
|
p++;
|
||||||
|
if (!ascii_isdigit(*p)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patch = atoi(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
|
||||||
|
return (major < NVIM_VERSION_MAJOR
|
||||||
|
|| (major == NVIM_VERSION_MAJOR
|
||||||
|
&& (minor < NVIM_VERSION_MINOR
|
||||||
|
|| (minor == NVIM_VERSION_MINOR
|
||||||
|
&& patch <= NVIM_VERSION_PATCH))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks whether a Vim patch has been included.
|
||||||
|
///
|
||||||
|
/// @param n Patch number.
|
||||||
|
///
|
||||||
|
/// @return true if patch `n` has been included.
|
||||||
|
bool has_vim_patch(int n)
|
||||||
|
{
|
||||||
|
for (int i = 0; included_patches[i] != 0; i++) {
|
||||||
|
if (included_patches[i] == n) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ex_version(exarg_T *eap)
|
void ex_version(exarg_T *eap)
|
||||||
|
51
test/functional/eval/has_spec.lua
Normal file
51
test/functional/eval/has_spec.lua
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
local eq = helpers.eq
|
||||||
|
local clear = helpers.clear
|
||||||
|
local funcs = helpers.funcs
|
||||||
|
|
||||||
|
describe('has()', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it('"nvim-x.y.z"', function()
|
||||||
|
eq(0, funcs.has("nvim-"))
|
||||||
|
eq(0, funcs.has("nvim- "))
|
||||||
|
eq(0, funcs.has("nvim- \t "))
|
||||||
|
eq(0, funcs.has("nvim-0. 1. 1"))
|
||||||
|
eq(0, funcs.has("nvim-0. 1.1"))
|
||||||
|
eq(0, funcs.has("nvim-0.1. 1"))
|
||||||
|
eq(0, funcs.has("nvim-a"))
|
||||||
|
eq(0, funcs.has("nvim-a.b.c"))
|
||||||
|
eq(0, funcs.has("nvim-0.b.c"))
|
||||||
|
eq(0, funcs.has("nvim-0.0.c"))
|
||||||
|
eq(0, funcs.has("nvim-0.b.0"))
|
||||||
|
eq(0, funcs.has("nvim-a.b.0"))
|
||||||
|
eq(0, funcs.has("nvim-0.1"))
|
||||||
|
eq(0, funcs.has("nvim-.0.0.0"))
|
||||||
|
eq(0, funcs.has("nvim-.0"))
|
||||||
|
eq(0, funcs.has("nvim-0."))
|
||||||
|
eq(0, funcs.has("nvim-0.."))
|
||||||
|
eq(0, funcs.has("nvim-."))
|
||||||
|
eq(0, funcs.has("nvim-.."))
|
||||||
|
eq(0, funcs.has("nvim-..."))
|
||||||
|
eq(0, funcs.has("nvim-42"))
|
||||||
|
eq(0, funcs.has("nvim-9999"))
|
||||||
|
eq(0, funcs.has("nvim-99.001.05"))
|
||||||
|
|
||||||
|
eq(1, funcs.has("nvim"))
|
||||||
|
eq(1, funcs.has("nvim-0.0.0"))
|
||||||
|
eq(1, funcs.has("nvim-0.1.1."))
|
||||||
|
eq(1, funcs.has("nvim-0.1.1.abc"))
|
||||||
|
eq(1, funcs.has("nvim-0.1.1.."))
|
||||||
|
eq(1, funcs.has("nvim-0.1.1.. .."))
|
||||||
|
eq(1, funcs.has("nvim-0.1.1.... "))
|
||||||
|
eq(1, funcs.has("nvim-0.0.0"))
|
||||||
|
eq(1, funcs.has("nvim-0.0.1"))
|
||||||
|
eq(1, funcs.has("nvim-0.1.0"))
|
||||||
|
eq(1, funcs.has("nvim-0.1.1"))
|
||||||
|
eq(1, funcs.has("nvim-0.1.5"))
|
||||||
|
eq(1, funcs.has("nvim-0000.001.05"))
|
||||||
|
eq(1, funcs.has("nvim-0.01.005"))
|
||||||
|
eq(1, funcs.has("nvim-00.001.05"))
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
Loading…
Reference in New Issue
Block a user