From cee09bb2aaef291f544e07b9db8c9a3827a7aaa1 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri Date: Tue, 19 Jan 2021 17:40:04 +0700 Subject: opt: minimum sign size for auto (#13783) --- src/nvim/option.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index 47b9e9bb07..bf710b5dc6 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -318,6 +318,14 @@ static char *(p_csl_values[]) = { "slash", "backslash", NULL }; static char *(p_icm_values[]) = { "nosplit", "split", NULL }; static char *(p_scl_values[]) = { "yes", "no", "auto", "auto:1", "auto:2", "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", + "auto:1-2", "auto:1-3", "auto:1-4", "auto:1-5", "auto:1-6", "auto:1-7", "auto:1-8", "auto:1-9", + "auto:2-3", "auto:2-4", "auto:2-5", "auto:2-6", "auto:2-7", "auto:2-8", "auto:2-9", + "auto:3-4", "auto:3-5", "auto:3-6", "auto:3-7", "auto:3-8", "auto:3-9", + "auto:4-5", "auto:4-6", "auto:4-7", "auto:4-8", "auto:4-9", + "auto:5-6", "auto:5-7", "auto:5-8", "auto:5-9", + "auto:6-7", "auto:6-8", "auto:6-9", + "auto:7-8", "auto:7-9", + "auto:8-9", "yes:1", "yes:2", "yes:3", "yes:4", "yes:5", "yes:6", "yes:7", "yes:8", "yes:9", "number", NULL }; static char *(p_fdc_values[]) = { "auto", "auto:1", "auto:2", @@ -7095,7 +7103,7 @@ int csh_like_shell(void) /// buffer signs and on user configuration. int win_signcol_count(win_T *wp) { - int maximum = 1, needed_signcols; + int minimum = 0, maximum = 1, needed_signcols; const char *scl = (const char *)wp->w_p_scl; // Note: It checks "no" or "number" in 'signcolumn' option @@ -7119,9 +7127,14 @@ int win_signcol_count(win_T *wp) if (!strncmp(scl, "auto:", 5)) { // Variable depending on a configuration maximum = scl[5] - '0'; + // auto:- + if (strlen(scl) == 8 && *(scl + 6) == '-') { + minimum = maximum; + maximum = scl[7] - '0'; + } } - return MIN(maximum, needed_signcols); + return MAX(minimum, MIN(maximum, needed_signcols)); } /// Get window or buffer local options -- cgit From f1f170a2e7959e06bdb905fa5c0d5972b492be20 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri Date: Tue, 19 Jan 2021 23:22:51 +0700 Subject: opt: reduce hardcoded values (#13783) --- src/nvim/option.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index bf710b5dc6..a3b1e7208d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -318,14 +318,6 @@ static char *(p_csl_values[]) = { "slash", "backslash", NULL }; static char *(p_icm_values[]) = { "nosplit", "split", NULL }; static char *(p_scl_values[]) = { "yes", "no", "auto", "auto:1", "auto:2", "auto:3", "auto:4", "auto:5", "auto:6", "auto:7", "auto:8", "auto:9", - "auto:1-2", "auto:1-3", "auto:1-4", "auto:1-5", "auto:1-6", "auto:1-7", "auto:1-8", "auto:1-9", - "auto:2-3", "auto:2-4", "auto:2-5", "auto:2-6", "auto:2-7", "auto:2-8", "auto:2-9", - "auto:3-4", "auto:3-5", "auto:3-6", "auto:3-7", "auto:3-8", "auto:3-9", - "auto:4-5", "auto:4-6", "auto:4-7", "auto:4-8", "auto:4-9", - "auto:5-6", "auto:5-7", "auto:5-8", "auto:5-9", - "auto:6-7", "auto:6-8", "auto:6-9", - "auto:7-8", "auto:7-9", - "auto:8-9", "yes:1", "yes:2", "yes:3", "yes:4", "yes:5", "yes:6", "yes:7", "yes:8", "yes:9", "number", NULL }; static char *(p_fdc_values[]) = { "auto", "auto:1", "auto:2", @@ -2921,7 +2913,7 @@ ambw_end: #endif } else if (varp == &curwin->w_p_scl) { // 'signcolumn' - if (check_opt_strings(*varp, p_scl_values, false) != OK) { + if (check_signcolumn(*varp) != OK) { errmsg = e_invarg; } // When changing the 'signcolumn' to or from 'number', recompute the @@ -3240,6 +3232,29 @@ static int int_cmp(const void *a, const void *b) return *(const int *)a - *(const int *)b; } +/// Handle setting 'signcolumn' for value 'val' +/// +/// @return OK when the value is valid, FAIL otherwise +int check_signcolumn(char_u *val) +{ + // check for basic match + if (check_opt_strings(val, p_scl_values, false) == OK) { + return OK; + } + + // check for 'auto:-' + if (STRLEN(val) == 8 + && !STRNCMP(val, "auto:", 5) + && ascii_isdigit(*(val + 5)) + && *(val + 6) == '-' + && ascii_isdigit(*(val + 7)) + ) { + return OK; + } + + return FAIL; +} + /// Handle setting 'colorcolumn' or 'textwidth' in window "wp". /// /// @return error message, NULL if it's OK. -- cgit From b7d60c04836255a82656b29deb740df2cd9946a2 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri Date: Tue, 19 Jan 2021 23:37:57 +0700 Subject: opt: better handling number bounds (#13783) --- src/nvim/option.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index a3b1e7208d..febcfd882b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3245,10 +3245,15 @@ int check_signcolumn(char_u *val) // check for 'auto:-' if (STRLEN(val) == 8 && !STRNCMP(val, "auto:", 5) - && ascii_isdigit(*(val + 5)) - && *(val + 6) == '-' - && ascii_isdigit(*(val + 7)) + && ascii_isdigit(val[5]) + && val[6] == '-' + && ascii_isdigit(val[7]) ) { + int min = val[5] - '0'; + int max = val[7] - '0'; + if (min < 1 || max < 2 || min > 8 || max > 9 || min >= max) { + return FAIL; + } return OK; } -- cgit From 52675915a737c22270af23c152bb1f115b157685 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri Date: Wed, 20 Jan 2021 10:39:16 +0700 Subject: opt: address linting issues (#13783) --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/option.c b/src/nvim/option.c index febcfd882b..74bf6f0590 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3238,7 +3238,7 @@ static int int_cmp(const void *a, const void *b) int check_signcolumn(char_u *val) { // check for basic match - if (check_opt_strings(val, p_scl_values, false) == OK) { + if (check_opt_strings(val, p_scl_values, false) == OK) { return OK; } -- cgit