Mercurial > vim
comparison src/evalfunc.c @ 15418:51b3c36b0523 v8.1.0717
patch 8.1.0717: there is no function for the ":sign jump" command
commit https://github.com/vim/vim/commit/6b7b7190aa9e5c4f51bceaebf9275aa5097cfea1
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 11 13:42:41 2019 +0100
patch 8.1.0717: there is no function for the ":sign jump" command
Problem: There is no function for the ":sign jump" command.
Solution: Add the sign_jump() function. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/3780)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 11 Jan 2019 13:45:06 +0100 |
parents | 7444fffa482d |
children | b55b89692fd2 |
comparison
equal
deleted
inserted
replaced
15417:50a5ad000845 | 15418:51b3c36b0523 |
---|---|
369 static void f_shiftwidth(typval_T *argvars, typval_T *rettv); | 369 static void f_shiftwidth(typval_T *argvars, typval_T *rettv); |
370 #ifdef FEAT_SIGNS | 370 #ifdef FEAT_SIGNS |
371 static void f_sign_define(typval_T *argvars, typval_T *rettv); | 371 static void f_sign_define(typval_T *argvars, typval_T *rettv); |
372 static void f_sign_getdefined(typval_T *argvars, typval_T *rettv); | 372 static void f_sign_getdefined(typval_T *argvars, typval_T *rettv); |
373 static void f_sign_getplaced(typval_T *argvars, typval_T *rettv); | 373 static void f_sign_getplaced(typval_T *argvars, typval_T *rettv); |
374 static void f_sign_jump(typval_T *argvars, typval_T *rettv); | |
374 static void f_sign_place(typval_T *argvars, typval_T *rettv); | 375 static void f_sign_place(typval_T *argvars, typval_T *rettv); |
375 static void f_sign_undefine(typval_T *argvars, typval_T *rettv); | 376 static void f_sign_undefine(typval_T *argvars, typval_T *rettv); |
376 static void f_sign_unplace(typval_T *argvars, typval_T *rettv); | 377 static void f_sign_unplace(typval_T *argvars, typval_T *rettv); |
377 #endif | 378 #endif |
378 static void f_simplify(typval_T *argvars, typval_T *rettv); | 379 static void f_simplify(typval_T *argvars, typval_T *rettv); |
856 {"shiftwidth", 0, 1, f_shiftwidth}, | 857 {"shiftwidth", 0, 1, f_shiftwidth}, |
857 #ifdef FEAT_SIGNS | 858 #ifdef FEAT_SIGNS |
858 {"sign_define", 1, 2, f_sign_define}, | 859 {"sign_define", 1, 2, f_sign_define}, |
859 {"sign_getdefined", 0, 1, f_sign_getdefined}, | 860 {"sign_getdefined", 0, 1, f_sign_getdefined}, |
860 {"sign_getplaced", 0, 2, f_sign_getplaced}, | 861 {"sign_getplaced", 0, 2, f_sign_getplaced}, |
862 {"sign_jump", 3, 3, f_sign_jump}, | |
861 {"sign_place", 4, 5, f_sign_place}, | 863 {"sign_place", 4, 5, f_sign_place}, |
862 {"sign_undefine", 0, 1, f_sign_undefine}, | 864 {"sign_undefine", 0, 1, f_sign_undefine}, |
863 {"sign_unplace", 1, 2, f_sign_unplace}, | 865 {"sign_unplace", 1, 2, f_sign_unplace}, |
864 #endif | 866 #endif |
865 {"simplify", 1, 1, f_simplify}, | 867 {"simplify", 1, 1, f_simplify}, |
1912 | 1914 |
1913 /* If not found, try expanding the name, like done for bufexists(). */ | 1915 /* If not found, try expanding the name, like done for bufexists(). */ |
1914 if (buf == NULL) | 1916 if (buf == NULL) |
1915 buf = find_buffer(tv); | 1917 buf = find_buffer(tv); |
1916 | 1918 |
1919 return buf; | |
1920 } | |
1921 | |
1922 /* | |
1923 * Get the buffer from "arg" and give an error and return NULL if it is not | |
1924 * valid. | |
1925 */ | |
1926 static buf_T * | |
1927 get_buf_arg(typval_T *arg) | |
1928 { | |
1929 buf_T *buf; | |
1930 | |
1931 ++emsg_off; | |
1932 buf = tv_get_buf(arg, FALSE); | |
1933 --emsg_off; | |
1934 if (buf == NULL) | |
1935 EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(arg)); | |
1917 return buf; | 1936 return buf; |
1918 } | 1937 } |
1919 | 1938 |
1920 /* | 1939 /* |
1921 * "bufname(expr)" function | 1940 * "bufname(expr)" function |
11364 if (rettv_list_alloc_id(rettv, aid_sign_getplaced) != OK) | 11383 if (rettv_list_alloc_id(rettv, aid_sign_getplaced) != OK) |
11365 return; | 11384 return; |
11366 | 11385 |
11367 if (argvars[0].v_type != VAR_UNKNOWN) | 11386 if (argvars[0].v_type != VAR_UNKNOWN) |
11368 { | 11387 { |
11369 // get signs placed in this buffer | 11388 // get signs placed in the specified buffer |
11370 buf = tv_get_buf(&argvars[0], FALSE); | 11389 buf = get_buf_arg(&argvars[0]); |
11371 if (buf == NULL) | 11390 if (buf == NULL) |
11372 { | |
11373 EMSG2(_("E158: Invalid buffer name: %s"), | |
11374 tv_get_string(&argvars[0])); | |
11375 return; | 11391 return; |
11376 } | |
11377 | 11392 |
11378 if (argvars[1].v_type != VAR_UNKNOWN) | 11393 if (argvars[1].v_type != VAR_UNKNOWN) |
11379 { | 11394 { |
11380 if (argvars[1].v_type != VAR_DICT || | 11395 if (argvars[1].v_type != VAR_DICT || |
11381 ((dict = argvars[1].vval.v_dict) == NULL)) | 11396 ((dict = argvars[1].vval.v_dict) == NULL)) |
11411 | 11426 |
11412 sign_get_placed(buf, lnum, sign_id, group, rettv->vval.v_list); | 11427 sign_get_placed(buf, lnum, sign_id, group, rettv->vval.v_list); |
11413 } | 11428 } |
11414 | 11429 |
11415 /* | 11430 /* |
11431 * "sign_jump()" function | |
11432 */ | |
11433 static void | |
11434 f_sign_jump(typval_T *argvars, typval_T *rettv) | |
11435 { | |
11436 int sign_id; | |
11437 char_u *sign_group = NULL; | |
11438 buf_T *buf; | |
11439 int notanum = FALSE; | |
11440 | |
11441 rettv->vval.v_number = -1; | |
11442 | |
11443 // Sign identifer | |
11444 sign_id = (int)tv_get_number_chk(&argvars[0], ¬anum); | |
11445 if (notanum) | |
11446 return; | |
11447 if (sign_id <= 0) | |
11448 { | |
11449 EMSG(_(e_invarg)); | |
11450 return; | |
11451 } | |
11452 | |
11453 // Sign group | |
11454 sign_group = tv_get_string_chk(&argvars[1]); | |
11455 if (sign_group == NULL) | |
11456 return; | |
11457 if (sign_group[0] == '\0') | |
11458 sign_group = NULL; // global sign group | |
11459 else | |
11460 { | |
11461 sign_group = vim_strsave(sign_group); | |
11462 if (sign_group == NULL) | |
11463 return; | |
11464 } | |
11465 | |
11466 // Buffer to place the sign | |
11467 buf = get_buf_arg(&argvars[2]); | |
11468 if (buf == NULL) | |
11469 goto cleanup; | |
11470 | |
11471 rettv->vval.v_number = sign_jump(sign_id, sign_group, buf); | |
11472 | |
11473 cleanup: | |
11474 vim_free(sign_group); | |
11475 } | |
11476 | |
11477 /* | |
11416 * "sign_place()" function | 11478 * "sign_place()" function |
11417 */ | 11479 */ |
11418 static void | 11480 static void |
11419 f_sign_place(typval_T *argvars, typval_T *rettv) | 11481 f_sign_place(typval_T *argvars, typval_T *rettv) |
11420 { | 11482 { |
11457 sign_name = tv_get_string_chk(&argvars[2]); | 11519 sign_name = tv_get_string_chk(&argvars[2]); |
11458 if (sign_name == NULL) | 11520 if (sign_name == NULL) |
11459 goto cleanup; | 11521 goto cleanup; |
11460 | 11522 |
11461 // Buffer to place the sign | 11523 // Buffer to place the sign |
11462 buf = tv_get_buf(&argvars[3], FALSE); | 11524 buf = get_buf_arg(&argvars[3]); |
11463 if (buf == NULL) | 11525 if (buf == NULL) |
11464 { | |
11465 EMSG2(_("E158: Invalid buffer name: %s"), tv_get_string(&argvars[3])); | |
11466 goto cleanup; | 11526 goto cleanup; |
11467 } | |
11468 | 11527 |
11469 if (argvars[4].v_type != VAR_UNKNOWN) | 11528 if (argvars[4].v_type != VAR_UNKNOWN) |
11470 { | 11529 { |
11471 if (argvars[4].v_type != VAR_DICT || | 11530 if (argvars[4].v_type != VAR_DICT || |
11472 ((dict = argvars[4].vval.v_dict) == NULL)) | 11531 ((dict = argvars[4].vval.v_dict) == NULL)) |
11566 } | 11625 } |
11567 dict = argvars[1].vval.v_dict; | 11626 dict = argvars[1].vval.v_dict; |
11568 | 11627 |
11569 if ((di = dict_find(dict, (char_u *)"buffer", -1)) != NULL) | 11628 if ((di = dict_find(dict, (char_u *)"buffer", -1)) != NULL) |
11570 { | 11629 { |
11571 buf = tv_get_buf(&di->di_tv, FALSE); | 11630 buf = get_buf_arg(&di->di_tv); |
11572 if (buf == NULL) | 11631 if (buf == NULL) |
11573 { | |
11574 EMSG2(_("E158: Invalid buffer name: %s"), | |
11575 tv_get_string(&di->di_tv)); | |
11576 goto cleanup; | 11632 goto cleanup; |
11577 } | |
11578 } | 11633 } |
11579 if (dict_find(dict, (char_u *)"id", -1) != NULL) | 11634 if (dict_find(dict, (char_u *)"id", -1) != NULL) |
11580 sign_id = dict_get_number(dict, (char_u *)"id"); | 11635 sign_id = dict_get_number(dict, (char_u *)"id"); |
11581 } | 11636 } |
11582 | 11637 |