comparison src/evalfunc.c @ 31057:1a32f1a4f823 v9.0.0863

patch 9.0.0863: col() and charcol() only work for the current window Commit: https://github.com/vim/vim/commit/4c8d2f02b3ce037bbe1d5ee12887e343c6bde88f Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Nov 12 16:07:47 2022 +0000 patch 9.0.0863: col() and charcol() only work for the current window Problem: col() and charcol() only work for the current window. Solution: Add an optional winid argument. (Yegappan Lakshmanan, closes #11466, closes #11461)
author Bram Moolenaar <Bram@vim.org>
date Sat, 12 Nov 2022 17:15:03 +0100
parents ed6acfafa17e
children 004aee2845d2
comparison
equal deleted inserted replaced
31056:cb66d96c185f 31057:1a32f1a4f823
1056 static argcheck_T arg2_string_dict[] = {arg_string, arg_dict_any}; 1056 static argcheck_T arg2_string_dict[] = {arg_string, arg_dict_any};
1057 static argcheck_T arg2_string_list_number[] = {arg_string, arg_list_number}; 1057 static argcheck_T arg2_string_list_number[] = {arg_string, arg_list_number};
1058 static argcheck_T arg2_string_number[] = {arg_string, arg_number}; 1058 static argcheck_T arg2_string_number[] = {arg_string, arg_number};
1059 static argcheck_T arg2_string_or_list_dict[] = {arg_string_or_list_any, arg_dict_any}; 1059 static argcheck_T arg2_string_or_list_dict[] = {arg_string_or_list_any, arg_dict_any};
1060 static argcheck_T arg2_string_or_list_bool[] = {arg_string_or_list_any, arg_bool}; 1060 static argcheck_T arg2_string_or_list_bool[] = {arg_string_or_list_any, arg_bool};
1061 static argcheck_T arg2_string_or_list_number[] = {arg_string_or_list_any, arg_number};
1061 static argcheck_T arg2_string_string_or_number[] = {arg_string, arg_string_or_nr}; 1062 static argcheck_T arg2_string_string_or_number[] = {arg_string, arg_string_or_nr};
1062 static argcheck_T arg3_any_list_dict[] = {NULL, arg_list_any, arg_dict_any}; 1063 static argcheck_T arg3_any_list_dict[] = {NULL, arg_list_any, arg_dict_any};
1063 static argcheck_T arg3_buffer_lnum_lnum[] = {arg_buffer, arg_lnum, arg_lnum}; 1064 static argcheck_T arg3_buffer_lnum_lnum[] = {arg_buffer, arg_lnum, arg_lnum};
1064 static argcheck_T arg3_buffer_number_number[] = {arg_buffer, arg_number, arg_number}; 1065 static argcheck_T arg3_buffer_number_number[] = {arg_buffer, arg_number, arg_number};
1065 static argcheck_T arg3_buffer_string_any[] = {arg_buffer, arg_string, NULL}; 1066 static argcheck_T arg3_buffer_string_any[] = {arg_buffer, arg_string, NULL};
1772 ret_number, f_changenr}, 1773 ret_number, f_changenr},
1773 {"char2nr", 1, 2, FEARG_1, arg2_string_bool, 1774 {"char2nr", 1, 2, FEARG_1, arg2_string_bool,
1774 ret_number, f_char2nr}, 1775 ret_number, f_char2nr},
1775 {"charclass", 1, 1, FEARG_1, arg1_string, 1776 {"charclass", 1, 1, FEARG_1, arg1_string,
1776 ret_number, f_charclass}, 1777 ret_number, f_charclass},
1777 {"charcol", 1, 1, FEARG_1, arg1_string_or_list_any, 1778 {"charcol", 1, 2, FEARG_1, arg2_string_or_list_number,
1778 ret_number, f_charcol}, 1779 ret_number, f_charcol},
1779 {"charidx", 2, 3, FEARG_1, arg3_string_number_bool, 1780 {"charidx", 2, 3, FEARG_1, arg3_string_number_bool,
1780 ret_number, f_charidx}, 1781 ret_number, f_charidx},
1781 {"chdir", 1, 1, FEARG_1, arg1_string, 1782 {"chdir", 1, 1, FEARG_1, arg1_string,
1782 ret_string, f_chdir}, 1783 ret_string, f_chdir},
1783 {"cindent", 1, 1, FEARG_1, arg1_lnum, 1784 {"cindent", 1, 1, FEARG_1, arg1_lnum,
1784 ret_number, f_cindent}, 1785 ret_number, f_cindent},
1785 {"clearmatches", 0, 1, FEARG_1, arg1_number, 1786 {"clearmatches", 0, 1, FEARG_1, arg1_number,
1786 ret_void, f_clearmatches}, 1787 ret_void, f_clearmatches},
1787 {"col", 1, 1, FEARG_1, arg1_string_or_list_any, 1788 {"col", 1, 2, FEARG_1, arg2_string_or_list_number,
1788 ret_number, f_col}, 1789 ret_number, f_col},
1789 {"complete", 2, 2, FEARG_2, arg2_number_list, 1790 {"complete", 2, 2, FEARG_2, arg2_number_list,
1790 ret_void, f_complete}, 1791 ret_void, f_complete},
1791 {"complete_add", 1, 1, FEARG_1, arg1_dict_or_string, 1792 {"complete_add", 1, 1, FEARG_1, arg1_dict_or_string,
1792 ret_number, f_complete_add}, 1793 ret_number, f_complete_add},
3387 static void 3388 static void
3388 get_col(typval_T *argvars, typval_T *rettv, int charcol) 3389 get_col(typval_T *argvars, typval_T *rettv, int charcol)
3389 { 3390 {
3390 colnr_T col = 0; 3391 colnr_T col = 0;
3391 pos_T *fp; 3392 pos_T *fp;
3392 int fnum = curbuf->b_fnum; 3393 switchwin_T switchwin;
3393 3394 int winchanged = FALSE;
3394 if (in_vim9script() 3395
3395 && check_for_string_or_list_arg(argvars, 0) == FAIL) 3396 if (check_for_string_or_list_arg(argvars, 0) == FAIL
3396 return; 3397 || check_for_opt_number_arg(argvars, 1) == FAIL)
3397 3398 return;
3399
3400 if (argvars[1].v_type != VAR_UNKNOWN)
3401 {
3402 tabpage_T *tp;
3403 win_T *wp;
3404
3405 // use the window specified in the second argument
3406 wp = win_id2wp_tp((int)tv_get_number(&argvars[1]), &tp);
3407 if (wp == NULL || tp == NULL)
3408 return;
3409
3410 if (switch_win_noblock(&switchwin, wp, tp, TRUE) != OK)
3411 return;
3412
3413 check_cursor();
3414 winchanged = TRUE;
3415 }
3416
3417 int fnum = curbuf->b_fnum;
3398 fp = var2fpos(&argvars[0], FALSE, &fnum, charcol); 3418 fp = var2fpos(&argvars[0], FALSE, &fnum, charcol);
3399 if (fp != NULL && fnum == curbuf->b_fnum) 3419 if (fp != NULL && fnum == curbuf->b_fnum)
3400 { 3420 {
3401 if (fp->col == MAXCOL) 3421 if (fp->col == MAXCOL)
3402 { 3422 {
3425 } 3445 }
3426 } 3446 }
3427 } 3447 }
3428 } 3448 }
3429 rettv->vval.v_number = col; 3449 rettv->vval.v_number = col;
3450
3451 if (winchanged)
3452 restore_win_noblock(&switchwin, TRUE);
3430 } 3453 }
3431 3454
3432 /* 3455 /*
3433 * "charcol()" function 3456 * "charcol()" function
3434 */ 3457 */