comparison src/evalfunc.c @ 17218:210c4c5f783d

patch 8.1.1608: the evalfunc.c file is too big commit https://github.com/vim/vim/commit/b60d8514b8813e2f3acefd454efcccbe04ac135a Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 29 07:59:04 2019 +0200 patch 8.1.1608: the evalfunc.c file is too big Problem: The evalfunc.c file is too big. Solution: Move sign functionality to sign.c.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jun 2019 08:00:06 +0200
parents 40c4cb095d53
children a8fc7d97b54d
comparison
equal deleted inserted replaced
17217:256d1e461c89 17218:210c4c5f783d
350 #ifdef FEAT_CRYPT 350 #ifdef FEAT_CRYPT
351 static void f_sha256(typval_T *argvars, typval_T *rettv); 351 static void f_sha256(typval_T *argvars, typval_T *rettv);
352 #endif /* FEAT_CRYPT */ 352 #endif /* FEAT_CRYPT */
353 static void f_shellescape(typval_T *argvars, typval_T *rettv); 353 static void f_shellescape(typval_T *argvars, typval_T *rettv);
354 static void f_shiftwidth(typval_T *argvars, typval_T *rettv); 354 static void f_shiftwidth(typval_T *argvars, typval_T *rettv);
355 #ifdef FEAT_SIGNS
356 static void f_sign_define(typval_T *argvars, typval_T *rettv);
357 static void f_sign_getdefined(typval_T *argvars, typval_T *rettv);
358 static void f_sign_getplaced(typval_T *argvars, typval_T *rettv);
359 static void f_sign_jump(typval_T *argvars, typval_T *rettv);
360 static void f_sign_place(typval_T *argvars, typval_T *rettv);
361 static void f_sign_undefine(typval_T *argvars, typval_T *rettv);
362 static void f_sign_unplace(typval_T *argvars, typval_T *rettv);
363 #endif
364 static void f_simplify(typval_T *argvars, typval_T *rettv); 355 static void f_simplify(typval_T *argvars, typval_T *rettv);
365 #ifdef FEAT_FLOAT 356 #ifdef FEAT_FLOAT
366 static void f_sin(typval_T *argvars, typval_T *rettv); 357 static void f_sin(typval_T *argvars, typval_T *rettv);
367 static void f_sinh(typval_T *argvars, typval_T *rettv); 358 static void f_sinh(typval_T *argvars, typval_T *rettv);
368 #endif 359 #endif
1179 /* 1170 /*
1180 * Get the lnum from the first argument. 1171 * Get the lnum from the first argument.
1181 * Also accepts ".", "$", etc., but that only works for the current buffer. 1172 * Also accepts ".", "$", etc., but that only works for the current buffer.
1182 * Returns -1 on error. 1173 * Returns -1 on error.
1183 */ 1174 */
1184 static linenr_T 1175 linenr_T
1185 tv_get_lnum(typval_T *argvars) 1176 tv_get_lnum(typval_T *argvars)
1186 { 1177 {
1187 typval_T rettv; 1178 typval_T rettv;
1188 linenr_T lnum; 1179 linenr_T lnum;
1189 1180
11607 } 11598 }
11608 11599
11609 rettv->vval.v_number = get_sw_value(curbuf); 11600 rettv->vval.v_number = get_sw_value(curbuf);
11610 } 11601 }
11611 11602
11612 #ifdef FEAT_SIGNS
11613 /*
11614 * "sign_define()" function
11615 */
11616 static void
11617 f_sign_define(typval_T *argvars, typval_T *rettv)
11618 {
11619 char_u *name;
11620 dict_T *dict;
11621 char_u *icon = NULL;
11622 char_u *linehl = NULL;
11623 char_u *text = NULL;
11624 char_u *texthl = NULL;
11625
11626 rettv->vval.v_number = -1;
11627
11628 name = tv_get_string_chk(&argvars[0]);
11629 if (name == NULL)
11630 return;
11631
11632 if (argvars[1].v_type != VAR_UNKNOWN)
11633 {
11634 if (argvars[1].v_type != VAR_DICT)
11635 {
11636 emsg(_(e_dictreq));
11637 return;
11638 }
11639
11640 // sign attributes
11641 dict = argvars[1].vval.v_dict;
11642 if (dict_find(dict, (char_u *)"icon", -1) != NULL)
11643 icon = dict_get_string(dict, (char_u *)"icon", TRUE);
11644 if (dict_find(dict, (char_u *)"linehl", -1) != NULL)
11645 linehl = dict_get_string(dict, (char_u *)"linehl", TRUE);
11646 if (dict_find(dict, (char_u *)"text", -1) != NULL)
11647 text = dict_get_string(dict, (char_u *)"text", TRUE);
11648 if (dict_find(dict, (char_u *)"texthl", -1) != NULL)
11649 texthl = dict_get_string(dict, (char_u *)"texthl", TRUE);
11650 }
11651
11652 if (sign_define_by_name(name, icon, linehl, text, texthl) == OK)
11653 rettv->vval.v_number = 0;
11654
11655 vim_free(icon);
11656 vim_free(linehl);
11657 vim_free(text);
11658 vim_free(texthl);
11659 }
11660
11661 /*
11662 * "sign_getdefined()" function
11663 */
11664 static void
11665 f_sign_getdefined(typval_T *argvars, typval_T *rettv)
11666 {
11667 char_u *name = NULL;
11668
11669 if (rettv_list_alloc_id(rettv, aid_sign_getdefined) != OK)
11670 return;
11671
11672 if (argvars[0].v_type != VAR_UNKNOWN)
11673 name = tv_get_string(&argvars[0]);
11674
11675 sign_getlist(name, rettv->vval.v_list);
11676 }
11677
11678 /*
11679 * "sign_getplaced()" function
11680 */
11681 static void
11682 f_sign_getplaced(typval_T *argvars, typval_T *rettv)
11683 {
11684 buf_T *buf = NULL;
11685 dict_T *dict;
11686 dictitem_T *di;
11687 linenr_T lnum = 0;
11688 int sign_id = 0;
11689 char_u *group = NULL;
11690 int notanum = FALSE;
11691
11692 if (rettv_list_alloc_id(rettv, aid_sign_getplaced) != OK)
11693 return;
11694
11695 if (argvars[0].v_type != VAR_UNKNOWN)
11696 {
11697 // get signs placed in the specified buffer
11698 buf = get_buf_arg(&argvars[0]);
11699 if (buf == NULL)
11700 return;
11701
11702 if (argvars[1].v_type != VAR_UNKNOWN)
11703 {
11704 if (argvars[1].v_type != VAR_DICT ||
11705 ((dict = argvars[1].vval.v_dict) == NULL))
11706 {
11707 emsg(_(e_dictreq));
11708 return;
11709 }
11710 if ((di = dict_find(dict, (char_u *)"lnum", -1)) != NULL)
11711 {
11712 // get signs placed at this line
11713 (void)tv_get_number_chk(&di->di_tv, &notanum);
11714 if (notanum)
11715 return;
11716 lnum = tv_get_lnum(&di->di_tv);
11717 }
11718 if ((di = dict_find(dict, (char_u *)"id", -1)) != NULL)
11719 {
11720 // get sign placed with this identifier
11721 sign_id = (int)tv_get_number_chk(&di->di_tv, &notanum);
11722 if (notanum)
11723 return;
11724 }
11725 if ((di = dict_find(dict, (char_u *)"group", -1)) != NULL)
11726 {
11727 group = tv_get_string_chk(&di->di_tv);
11728 if (group == NULL)
11729 return;
11730 if (*group == '\0') // empty string means global group
11731 group = NULL;
11732 }
11733 }
11734 }
11735
11736 sign_get_placed(buf, lnum, sign_id, group, rettv->vval.v_list);
11737 }
11738
11739 /*
11740 * "sign_jump()" function
11741 */
11742 static void
11743 f_sign_jump(typval_T *argvars, typval_T *rettv)
11744 {
11745 int sign_id;
11746 char_u *sign_group = NULL;
11747 buf_T *buf;
11748 int notanum = FALSE;
11749
11750 rettv->vval.v_number = -1;
11751
11752 // Sign identifier
11753 sign_id = (int)tv_get_number_chk(&argvars[0], &notanum);
11754 if (notanum)
11755 return;
11756 if (sign_id <= 0)
11757 {
11758 emsg(_(e_invarg));
11759 return;
11760 }
11761
11762 // Sign group
11763 sign_group = tv_get_string_chk(&argvars[1]);
11764 if (sign_group == NULL)
11765 return;
11766 if (sign_group[0] == '\0')
11767 sign_group = NULL; // global sign group
11768 else
11769 {
11770 sign_group = vim_strsave(sign_group);
11771 if (sign_group == NULL)
11772 return;
11773 }
11774
11775 // Buffer to place the sign
11776 buf = get_buf_arg(&argvars[2]);
11777 if (buf == NULL)
11778 goto cleanup;
11779
11780 rettv->vval.v_number = sign_jump(sign_id, sign_group, buf);
11781
11782 cleanup:
11783 vim_free(sign_group);
11784 }
11785
11786 /*
11787 * "sign_place()" function
11788 */
11789 static void
11790 f_sign_place(typval_T *argvars, typval_T *rettv)
11791 {
11792 int sign_id;
11793 char_u *group = NULL;
11794 char_u *sign_name;
11795 buf_T *buf;
11796 dict_T *dict;
11797 dictitem_T *di;
11798 linenr_T lnum = 0;
11799 int prio = SIGN_DEF_PRIO;
11800 int notanum = FALSE;
11801
11802 rettv->vval.v_number = -1;
11803
11804 // Sign identifier
11805 sign_id = (int)tv_get_number_chk(&argvars[0], &notanum);
11806 if (notanum)
11807 return;
11808 if (sign_id < 0)
11809 {
11810 emsg(_(e_invarg));
11811 return;
11812 }
11813
11814 // Sign group
11815 group = tv_get_string_chk(&argvars[1]);
11816 if (group == NULL)
11817 return;
11818 if (group[0] == '\0')
11819 group = NULL; // global sign group
11820 else
11821 {
11822 group = vim_strsave(group);
11823 if (group == NULL)
11824 return;
11825 }
11826
11827 // Sign name
11828 sign_name = tv_get_string_chk(&argvars[2]);
11829 if (sign_name == NULL)
11830 goto cleanup;
11831
11832 // Buffer to place the sign
11833 buf = get_buf_arg(&argvars[3]);
11834 if (buf == NULL)
11835 goto cleanup;
11836
11837 if (argvars[4].v_type != VAR_UNKNOWN)
11838 {
11839 if (argvars[4].v_type != VAR_DICT ||
11840 ((dict = argvars[4].vval.v_dict) == NULL))
11841 {
11842 emsg(_(e_dictreq));
11843 goto cleanup;
11844 }
11845
11846 // Line number where the sign is to be placed
11847 if ((di = dict_find(dict, (char_u *)"lnum", -1)) != NULL)
11848 {
11849 (void)tv_get_number_chk(&di->di_tv, &notanum);
11850 if (notanum)
11851 goto cleanup;
11852 lnum = tv_get_lnum(&di->di_tv);
11853 }
11854 if ((di = dict_find(dict, (char_u *)"priority", -1)) != NULL)
11855 {
11856 // Sign priority
11857 prio = (int)tv_get_number_chk(&di->di_tv, &notanum);
11858 if (notanum)
11859 goto cleanup;
11860 }
11861 }
11862
11863 if (sign_place(&sign_id, group, sign_name, buf, lnum, prio) == OK)
11864 rettv->vval.v_number = sign_id;
11865
11866 cleanup:
11867 vim_free(group);
11868 }
11869
11870 /*
11871 * "sign_undefine()" function
11872 */
11873 static void
11874 f_sign_undefine(typval_T *argvars, typval_T *rettv)
11875 {
11876 char_u *name;
11877
11878 rettv->vval.v_number = -1;
11879
11880 if (argvars[0].v_type == VAR_UNKNOWN)
11881 {
11882 // Free all the signs
11883 free_signs();
11884 rettv->vval.v_number = 0;
11885 }
11886 else
11887 {
11888 // Free only the specified sign
11889 name = tv_get_string_chk(&argvars[0]);
11890 if (name == NULL)
11891 return;
11892
11893 if (sign_undefine_by_name(name) == OK)
11894 rettv->vval.v_number = 0;
11895 }
11896 }
11897
11898 /*
11899 * "sign_unplace()" function
11900 */
11901 static void
11902 f_sign_unplace(typval_T *argvars, typval_T *rettv)
11903 {
11904 dict_T *dict;
11905 dictitem_T *di;
11906 int sign_id = 0;
11907 buf_T *buf = NULL;
11908 char_u *group = NULL;
11909
11910 rettv->vval.v_number = -1;
11911
11912 if (argvars[0].v_type != VAR_STRING)
11913 {
11914 emsg(_(e_invarg));
11915 return;
11916 }
11917
11918 group = tv_get_string(&argvars[0]);
11919 if (group[0] == '\0')
11920 group = NULL; // global sign group
11921 else
11922 {
11923 group = vim_strsave(group);
11924 if (group == NULL)
11925 return;
11926 }
11927
11928 if (argvars[1].v_type != VAR_UNKNOWN)
11929 {
11930 if (argvars[1].v_type != VAR_DICT)
11931 {
11932 emsg(_(e_dictreq));
11933 goto cleanup;
11934 }
11935 dict = argvars[1].vval.v_dict;
11936
11937 if ((di = dict_find(dict, (char_u *)"buffer", -1)) != NULL)
11938 {
11939 buf = get_buf_arg(&di->di_tv);
11940 if (buf == NULL)
11941 goto cleanup;
11942 }
11943 if (dict_find(dict, (char_u *)"id", -1) != NULL)
11944 sign_id = dict_get_number(dict, (char_u *)"id");
11945 }
11946
11947 if (buf == NULL)
11948 {
11949 // Delete the sign in all the buffers
11950 FOR_ALL_BUFFERS(buf)
11951 if (sign_unplace(sign_id, group, buf, 0) == OK)
11952 rettv->vval.v_number = 0;
11953 }
11954 else
11955 {
11956 if (sign_unplace(sign_id, group, buf, 0) == OK)
11957 rettv->vval.v_number = 0;
11958 }
11959
11960 cleanup:
11961 vim_free(group);
11962 }
11963 #endif
11964
11965 /* 11603 /*
11966 * "simplify()" function 11604 * "simplify()" function
11967 */ 11605 */
11968 static void 11606 static void
11969 f_simplify(typval_T *argvars, typval_T *rettv) 11607 f_simplify(typval_T *argvars, typval_T *rettv)