comparison src/evalfunc.c @ 14964:2c0bfa167468 v8.1.0493

patch 8.1.0493: argv() and argc() only work on the current argument list commit https://github.com/vim/vim/commit/e6e3989c1b3f18907a0c305712b867e9a3821369 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 25 12:32:11 2018 +0200 patch 8.1.0493: argv() and argc() only work on the current argument list Problem: argv() and argc() only work on the current argument list. Solution: Add a window ID argument. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/832)
author Bram Moolenaar <Bram@vim.org>
date Thu, 25 Oct 2018 12:45:05 +0200
parents 0c845463a0db
children d65790af8514
comparison
equal deleted inserted replaced
14963:81993fcbec84 14964:2c0bfa167468
499 #endif 499 #endif
500 {"add", 2, 2, f_add}, 500 {"add", 2, 2, f_add},
501 {"and", 2, 2, f_and}, 501 {"and", 2, 2, f_and},
502 {"append", 2, 2, f_append}, 502 {"append", 2, 2, f_append},
503 {"appendbufline", 3, 3, f_appendbufline}, 503 {"appendbufline", 3, 3, f_appendbufline},
504 {"argc", 0, 0, f_argc}, 504 {"argc", 0, 1, f_argc},
505 {"argidx", 0, 0, f_argidx}, 505 {"argidx", 0, 0, f_argidx},
506 {"arglistid", 0, 2, f_arglistid}, 506 {"arglistid", 0, 2, f_arglistid},
507 {"argv", 0, 1, f_argv}, 507 {"argv", 0, 2, f_argv},
508 #ifdef FEAT_FLOAT 508 #ifdef FEAT_FLOAT
509 {"asin", 1, 1, f_asin}, /* WJMc */ 509 {"asin", 1, 1, f_asin}, /* WJMc */
510 #endif 510 #endif
511 {"assert_beeps", 1, 2, f_assert_beeps}, 511 {"assert_beeps", 1, 2, f_assert_beeps},
512 {"assert_equal", 2, 3, f_assert_equal}, 512 {"assert_equal", 2, 3, f_assert_equal},
1405 set_buffer_lines(buf, lnum, TRUE, &argvars[2], rettv); 1405 set_buffer_lines(buf, lnum, TRUE, &argvars[2], rettv);
1406 } 1406 }
1407 } 1407 }
1408 1408
1409 /* 1409 /*
1410 * "argc()" function 1410 * "argc([window id])" function
1411 */ 1411 */
1412 static void 1412 static void
1413 f_argc(typval_T *argvars UNUSED, typval_T *rettv) 1413 f_argc(typval_T *argvars, typval_T *rettv)
1414 { 1414 {
1415 rettv->vval.v_number = ARGCOUNT; 1415 win_T *wp;
1416
1417 if (argvars[0].v_type == VAR_UNKNOWN)
1418 // use the current window
1419 rettv->vval.v_number = ARGCOUNT;
1420 else if (argvars[0].v_type == VAR_NUMBER
1421 && get_tv_number(&argvars[0]) == -1)
1422 // use the global argument list
1423 rettv->vval.v_number = GARGCOUNT;
1424 else
1425 {
1426 // use the argument list of the specified window
1427 wp = find_win_by_nr_or_id(&argvars[0]);
1428 if (wp != NULL)
1429 rettv->vval.v_number = WARGCOUNT(wp);
1430 else
1431 rettv->vval.v_number = -1;
1432 }
1416 } 1433 }
1417 1434
1418 /* 1435 /*
1419 * "argidx()" function 1436 * "argidx()" function
1420 */ 1437 */
1437 if (wp != NULL) 1454 if (wp != NULL)
1438 rettv->vval.v_number = wp->w_alist->id; 1455 rettv->vval.v_number = wp->w_alist->id;
1439 } 1456 }
1440 1457
1441 /* 1458 /*
1459 * Get the argument list for a given window
1460 */
1461 static void
1462 get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rettv)
1463 {
1464 int idx;
1465
1466 if (rettv_list_alloc(rettv) == OK && arglist != NULL)
1467 for (idx = 0; idx < argcount; ++idx)
1468 list_append_string(rettv->vval.v_list,
1469 alist_name(&arglist[idx]), -1);
1470 }
1471
1472 /*
1442 * "argv(nr)" function 1473 * "argv(nr)" function
1443 */ 1474 */
1444 static void 1475 static void
1445 f_argv(typval_T *argvars, typval_T *rettv) 1476 f_argv(typval_T *argvars, typval_T *rettv)
1446 { 1477 {
1447 int idx; 1478 int idx;
1479 aentry_T *arglist = NULL;
1480 int argcount = -1;
1448 1481
1449 if (argvars[0].v_type != VAR_UNKNOWN) 1482 if (argvars[0].v_type != VAR_UNKNOWN)
1450 { 1483 {
1451 idx = (int)get_tv_number_chk(&argvars[0], NULL); 1484 if (argvars[1].v_type == VAR_UNKNOWN)
1452 if (idx >= 0 && idx < ARGCOUNT) 1485 {
1453 rettv->vval.v_string = vim_strsave(alist_name(&ARGLIST[idx])); 1486 arglist = ARGLIST;
1487 argcount = ARGCOUNT;
1488 }
1489 else if (argvars[1].v_type == VAR_NUMBER
1490 && get_tv_number(&argvars[1]) == -1)
1491 {
1492 arglist = GARGLIST;
1493 argcount = GARGCOUNT;
1494 }
1454 else 1495 else
1455 rettv->vval.v_string = NULL; 1496 {
1497 win_T *wp = find_win_by_nr_or_id(&argvars[1]);
1498
1499 if (wp != NULL)
1500 {
1501 /* Use the argument list of the specified window */
1502 arglist = WARGLIST(wp);
1503 argcount = WARGCOUNT(wp);
1504 }
1505 }
1506
1456 rettv->v_type = VAR_STRING; 1507 rettv->v_type = VAR_STRING;
1457 } 1508 rettv->vval.v_string = NULL;
1458 else if (rettv_list_alloc(rettv) == OK) 1509 idx = get_tv_number_chk(&argvars[0], NULL);
1459 for (idx = 0; idx < ARGCOUNT; ++idx) 1510 if (arglist != NULL && idx >= 0 && idx < argcount)
1460 list_append_string(rettv->vval.v_list, 1511 rettv->vval.v_string = vim_strsave(alist_name(&arglist[idx]));
1461 alist_name(&ARGLIST[idx]), -1); 1512 else if (idx == -1)
1513 get_arglist_as_rettv(arglist, argcount, rettv);
1514 }
1515 else
1516 get_arglist_as_rettv(ARGLIST, ARGCOUNT, rettv);
1462 } 1517 }
1463 1518
1464 /* 1519 /*
1465 * "assert_beeps(cmd [, error])" function 1520 * "assert_beeps(cmd [, error])" function
1466 */ 1521 */
5356 } 5411 }
5357 else 5412 else
5358 rettv->vval.v_number = FALSE; 5413 rettv->vval.v_number = FALSE;
5359 } 5414 }
5360 5415
5361
5362 /* 5416 /*
5363 * "getcurpos()" function 5417 * "getcurpos()" function
5364 */ 5418 */
5365 static void 5419 static void
5366 f_getcurpos(typval_T *argvars, typval_T *rettv) 5420 f_getcurpos(typval_T *argvars, typval_T *rettv)
6979 if (mouse_used) 7033 if (mouse_used)
6980 selected -= lines_left; 7034 selected -= lines_left;
6981 7035
6982 rettv->vval.v_number = selected; 7036 rettv->vval.v_number = selected;
6983 } 7037 }
6984
6985 7038
6986 static garray_T ga_userinput = {0, 0, sizeof(tasave_T), 4, NULL}; 7039 static garray_T ga_userinput = {0, 0, sizeof(tasave_T), 4, NULL};
6987 7040
6988 /* 7041 /*
6989 * "inputrestore()" function 7042 * "inputrestore()" function
12395 modec = 'c'; 12448 modec = 'c';
12396 else 12449 else
12397 modec = 't'; 12450 modec = 't';
12398 } 12451 }
12399 12452
12400
12401 switch (TOLOWER_ASC(what[0])) 12453 switch (TOLOWER_ASC(what[0]))
12402 { 12454 {
12403 case 'b': 12455 case 'b':
12404 if (TOLOWER_ASC(what[1]) == 'g') /* bg[#] */ 12456 if (TOLOWER_ASC(what[1]) == 'g') /* bg[#] */
12405 p = highlight_color(id, what, modec); 12457 p = highlight_color(id, what, modec);
12806 wp->w_buffer->b_fnum) == FAIL) 12858 wp->w_buffer->b_fnum) == FAIL)
12807 break; 12859 break;
12808 } 12860 }
12809 } 12861 }
12810 12862
12811
12812 /* 12863 /*
12813 * "tabpagenr()" function 12864 * "tabpagenr()" function
12814 */ 12865 */
12815 static void 12866 static void
12816 f_tabpagenr(typval_T *argvars UNUSED, typval_T *rettv) 12867 f_tabpagenr(typval_T *argvars UNUSED, typval_T *rettv)
12897 nr = 0; 12948 nr = 0;
12898 else 12949 else
12899 nr = get_winnr(tp, &argvars[1]); 12950 nr = get_winnr(tp, &argvars[1]);
12900 rettv->vval.v_number = nr; 12951 rettv->vval.v_number = nr;
12901 } 12952 }
12902
12903 12953
12904 /* 12954 /*
12905 * "tagfiles()" function 12955 * "tagfiles()" function
12906 */ 12956 */
12907 static void 12957 static void
14090 { 14140 {
14091 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) 14141 rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
14092 ^ get_tv_number_chk(&argvars[1], NULL); 14142 ^ get_tv_number_chk(&argvars[1], NULL);
14093 } 14143 }
14094 14144
14095
14096 #endif /* FEAT_EVAL */ 14145 #endif /* FEAT_EVAL */