To: vim_dev@googlegroups.com Subject: Patch 8.2.1475 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1475 Problem: Vim9: can't use v:true for option flags. Solution: Add tv_get_bool_chk(). (closes #6725) Files: src/typval.c, src/proto/typval.pro, src/channel.c *** ../vim-8.2.1474/src/typval.c 2020-08-16 14:48:14.377965877 +0200 --- src/typval.c 2020-08-17 21:36:59.741838551 +0200 *************** *** 169,192 **** CLEAR_POINTER(varp); } ! /* ! * Get the number value of a variable. ! * If it is a String variable, uses vim_str2nr(). ! * For incompatible types, return 0. ! * tv_get_number_chk() is similar to tv_get_number(), but informs the ! * caller of incompatible types: it sets *denote to TRUE if "denote" ! * is not NULL or returns -1 otherwise. ! */ ! varnumber_T ! tv_get_number(typval_T *varp) ! { ! int error = FALSE; ! ! return tv_get_number_chk(varp, &error); // return 0L on error ! } ! ! varnumber_T ! tv_get_number_chk(typval_T *varp, int *denote) { varnumber_T n = 0L; --- 169,176 ---- CLEAR_POINTER(varp); } ! static varnumber_T ! tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool) { varnumber_T n = 0L; *************** *** 221,227 **** break; case VAR_BOOL: case VAR_SPECIAL: ! if (in_vim9script()) { emsg(_("E611: Using a Special as a Number")); break; --- 205,211 ---- break; case VAR_BOOL: case VAR_SPECIAL: ! if (!want_bool && in_vim9script()) { emsg(_("E611: Using a Special as a Number")); break; *************** *** 253,258 **** --- 237,275 ---- return n; } + /* + * Get the number value of a variable. + * If it is a String variable, uses vim_str2nr(). + * For incompatible types, return 0. + * tv_get_number_chk() is similar to tv_get_number(), but informs the + * caller of incompatible types: it sets *denote to TRUE if "denote" + * is not NULL or returns -1 otherwise. + */ + varnumber_T + tv_get_number(typval_T *varp) + { + int error = FALSE; + + return tv_get_number_chk(varp, &error); // return 0L on error + } + + varnumber_T + tv_get_number_chk(typval_T *varp, int *denote) + { + return tv_get_bool_or_number_chk(varp, denote, FALSE); + } + + /* + * Get the boolean value of "varp". This is like tv_get_number_chk(), + * but in Vim9 script accepts Number and Bool. + */ + varnumber_T + tv_get_bool(typval_T *varp) + { + return tv_get_bool_or_number_chk(varp, NULL, TRUE); + + } + #ifdef FEAT_FLOAT float_T tv_get_float(typval_T *varp) *** ../vim-8.2.1474/src/proto/typval.pro 2020-07-01 18:29:23.681143435 +0200 --- src/proto/typval.pro 2020-08-17 21:37:04.677806266 +0200 *************** *** 6,11 **** --- 6,12 ---- void init_tv(typval_T *varp); varnumber_T tv_get_number(typval_T *varp); varnumber_T tv_get_number_chk(typval_T *varp, int *denote); + varnumber_T tv_get_bool(typval_T *varp); float_T tv_get_float(typval_T *varp); char_u *tv_get_string(typval_T *varp); char_u *tv_get_string_buf(typval_T *varp, char_u *buf); *** ../vim-8.2.1474/src/channel.c 2020-07-20 21:31:01.268823457 +0200 --- src/channel.c 2020-08-17 21:37:58.185457096 +0200 *************** *** 4922,4928 **** { if (!(supported & JO_MODE)) break; ! opt->jo_noblock = tv_get_number(item); } else if (STRCMP(hi->hi_key, "in_io") == 0 || STRCMP(hi->hi_key, "out_io") == 0 --- 4922,4928 ---- { if (!(supported & JO_MODE)) break; ! opt->jo_noblock = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "in_io") == 0 || STRCMP(hi->hi_key, "out_io") == 0 *************** *** 4949,4955 **** { if (!(supported & JO_MODE)) break; ! opt->jo_pty = tv_get_number(item); } else if (STRCMP(hi->hi_key, "in_buf") == 0 || STRCMP(hi->hi_key, "out_buf") == 0 --- 4949,4955 ---- { if (!(supported & JO_MODE)) break; ! opt->jo_pty = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "in_buf") == 0 || STRCMP(hi->hi_key, "out_buf") == 0 *************** *** 4980,4986 **** if (!(supported & JO_OUT_IO)) break; opt->jo_set |= JO_OUT_MODIFIABLE << (part - PART_OUT); ! opt->jo_modifiable[part] = tv_get_number(item); } else if (STRCMP(hi->hi_key, "out_msg") == 0 || STRCMP(hi->hi_key, "err_msg") == 0) --- 4980,4986 ---- if (!(supported & JO_OUT_IO)) break; opt->jo_set |= JO_OUT_MODIFIABLE << (part - PART_OUT); ! opt->jo_modifiable[part] = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "out_msg") == 0 || STRCMP(hi->hi_key, "err_msg") == 0) *************** *** 4990,4996 **** if (!(supported & JO_OUT_IO)) break; opt->jo_set2 |= JO2_OUT_MSG << (part - PART_OUT); ! opt->jo_message[part] = tv_get_number(item); } else if (STRCMP(hi->hi_key, "in_top") == 0 || STRCMP(hi->hi_key, "in_bot") == 0) --- 4990,4996 ---- if (!(supported & JO_OUT_IO)) break; opt->jo_set2 |= JO2_OUT_MSG << (part - PART_OUT); ! opt->jo_message[part] = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "in_top") == 0 || STRCMP(hi->hi_key, "in_bot") == 0) *************** *** 5184,5190 **** if (!(supported2 & JO2_VERTICAL)) break; opt->jo_set2 |= JO2_VERTICAL; ! opt->jo_vertical = tv_get_number(item); } else if (STRCMP(hi->hi_key, "curwin") == 0) { --- 5184,5190 ---- if (!(supported2 & JO2_VERTICAL)) break; opt->jo_set2 |= JO2_VERTICAL; ! opt->jo_vertical = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "curwin") == 0) { *************** *** 5224,5237 **** if (!(supported2 & JO2_HIDDEN)) break; opt->jo_set2 |= JO2_HIDDEN; ! opt->jo_hidden = tv_get_number(item); } else if (STRCMP(hi->hi_key, "norestore") == 0) { if (!(supported2 & JO2_NORESTORE)) break; opt->jo_set2 |= JO2_NORESTORE; ! opt->jo_term_norestore = tv_get_number(item); } else if (STRCMP(hi->hi_key, "term_kill") == 0) { --- 5224,5237 ---- if (!(supported2 & JO2_HIDDEN)) break; opt->jo_set2 |= JO2_HIDDEN; ! opt->jo_hidden = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "norestore") == 0) { if (!(supported2 & JO2_NORESTORE)) break; opt->jo_set2 |= JO2_NORESTORE; ! opt->jo_term_norestore = tv_get_bool(item); } else if (STRCMP(hi->hi_key, "term_kill") == 0) { *** ../vim-8.2.1474/src/version.c 2020-08-17 21:16:29.261650308 +0200 --- src/version.c 2020-08-17 21:27:26.777615295 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1475, /**/ -- hundred-and-one symptoms of being an internet addict: 227. You sleep next to your monitor. Or on top of it. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///