comparison src/evalfunc.c @ 18104:e59ff7b5d7a7 v8.1.2047

patch 8.1.2047: cannot check the current state Commit: https://github.com/vim/vim/commit/0e57dd859ecb1e8a3b91509d2f4343e839340eb8 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 16 22:56:03 2019 +0200 patch 8.1.2047: cannot check the current state Problem: Cannot check the current state. Solution: Add the state() function.
author Bram Moolenaar <Bram@vim.org>
date Mon, 16 Sep 2019 23:00:04 +0200
parents a1396a35444c
children 4ac8161e92e0
comparison
equal deleted inserted replaced
18103:71bc51a0d8d8 18104:e59ff7b5d7a7
144 static void f_matchlist(typval_T *argvars, typval_T *rettv); 144 static void f_matchlist(typval_T *argvars, typval_T *rettv);
145 static void f_matchstr(typval_T *argvars, typval_T *rettv); 145 static void f_matchstr(typval_T *argvars, typval_T *rettv);
146 static void f_matchstrpos(typval_T *argvars, typval_T *rettv); 146 static void f_matchstrpos(typval_T *argvars, typval_T *rettv);
147 static void f_max(typval_T *argvars, typval_T *rettv); 147 static void f_max(typval_T *argvars, typval_T *rettv);
148 static void f_min(typval_T *argvars, typval_T *rettv); 148 static void f_min(typval_T *argvars, typval_T *rettv);
149 static void f_mode(typval_T *argvars, typval_T *rettv);
150 #ifdef FEAT_MZSCHEME 149 #ifdef FEAT_MZSCHEME
151 static void f_mzeval(typval_T *argvars, typval_T *rettv); 150 static void f_mzeval(typval_T *argvars, typval_T *rettv);
152 #endif 151 #endif
153 static void f_nextnonblank(typval_T *argvars, typval_T *rettv); 152 static void f_nextnonblank(typval_T *argvars, typval_T *rettv);
154 static void f_nr2char(typval_T *argvars, typval_T *rettv); 153 static void f_nr2char(typval_T *argvars, typval_T *rettv);
721 {"spellbadword", 0, 1, FEARG_1, f_spellbadword}, 720 {"spellbadword", 0, 1, FEARG_1, f_spellbadword},
722 {"spellsuggest", 1, 3, FEARG_1, f_spellsuggest}, 721 {"spellsuggest", 1, 3, FEARG_1, f_spellsuggest},
723 {"split", 1, 3, FEARG_1, f_split}, 722 {"split", 1, 3, FEARG_1, f_split},
724 #ifdef FEAT_FLOAT 723 #ifdef FEAT_FLOAT
725 {"sqrt", 1, 1, FEARG_1, f_sqrt}, 724 {"sqrt", 1, 1, FEARG_1, f_sqrt},
725 #endif
726 {"state", 0, 1, FEARG_1, f_state},
727 #ifdef FEAT_FLOAT
726 {"str2float", 1, 1, FEARG_1, f_str2float}, 728 {"str2float", 1, 1, FEARG_1, f_str2float},
727 #endif 729 #endif
728 {"str2list", 1, 2, FEARG_1, f_str2list}, 730 {"str2list", 1, 2, FEARG_1, f_str2list},
729 {"str2nr", 1, 3, FEARG_1, f_str2nr}, 731 {"str2nr", 1, 3, FEARG_1, f_str2nr},
730 {"strcharpart", 2, 3, FEARG_1, f_strcharpart}, 732 {"strcharpart", 2, 3, FEARG_1, f_strcharpart},
1044 } 1046 }
1045 1047
1046 /* 1048 /*
1047 * Return TRUE for a non-zero Number and a non-empty String. 1049 * Return TRUE for a non-zero Number and a non-empty String.
1048 */ 1050 */
1049 static int 1051 int
1050 non_zero_arg(typval_T *argvars) 1052 non_zero_arg(typval_T *argvars)
1051 { 1053 {
1052 return ((argvars[0].v_type == VAR_NUMBER 1054 return ((argvars[0].v_type == VAR_NUMBER
1053 && argvars[0].vval.v_number != 0) 1055 && argvars[0].vval.v_number != 0)
1054 || (argvars[0].v_type == VAR_SPECIAL 1056 || (argvars[0].v_type == VAR_SPECIAL
4909 f_min(typval_T *argvars, typval_T *rettv) 4911 f_min(typval_T *argvars, typval_T *rettv)
4910 { 4912 {
4911 max_min(argvars, rettv, FALSE); 4913 max_min(argvars, rettv, FALSE);
4912 } 4914 }
4913 4915
4914 /*
4915 * "mode()" function
4916 */
4917 static void
4918 f_mode(typval_T *argvars, typval_T *rettv)
4919 {
4920 char_u buf[4];
4921
4922 vim_memset(buf, 0, sizeof(buf));
4923
4924 if (time_for_testing == 93784)
4925 {
4926 /* Testing the two-character code. */
4927 buf[0] = 'x';
4928 buf[1] = '!';
4929 }
4930 #ifdef FEAT_TERMINAL
4931 else if (term_use_loop())
4932 buf[0] = 't';
4933 #endif
4934 else if (VIsual_active)
4935 {
4936 if (VIsual_select)
4937 buf[0] = VIsual_mode + 's' - 'v';
4938 else
4939 buf[0] = VIsual_mode;
4940 }
4941 else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE
4942 || State == CONFIRM)
4943 {
4944 buf[0] = 'r';
4945 if (State == ASKMORE)
4946 buf[1] = 'm';
4947 else if (State == CONFIRM)
4948 buf[1] = '?';
4949 }
4950 else if (State == EXTERNCMD)
4951 buf[0] = '!';
4952 else if (State & INSERT)
4953 {
4954 if (State & VREPLACE_FLAG)
4955 {
4956 buf[0] = 'R';
4957 buf[1] = 'v';
4958 }
4959 else
4960 {
4961 if (State & REPLACE_FLAG)
4962 buf[0] = 'R';
4963 else
4964 buf[0] = 'i';
4965 if (ins_compl_active())
4966 buf[1] = 'c';
4967 else if (ctrl_x_mode_not_defined_yet())
4968 buf[1] = 'x';
4969 }
4970 }
4971 else if ((State & CMDLINE) || exmode_active)
4972 {
4973 buf[0] = 'c';
4974 if (exmode_active == EXMODE_VIM)
4975 buf[1] = 'v';
4976 else if (exmode_active == EXMODE_NORMAL)
4977 buf[1] = 'e';
4978 }
4979 else
4980 {
4981 buf[0] = 'n';
4982 if (finish_op)
4983 {
4984 buf[1] = 'o';
4985 // to be able to detect force-linewise/blockwise/characterwise operations
4986 buf[2] = motion_force;
4987 }
4988 else if (restart_edit == 'I' || restart_edit == 'R'
4989 || restart_edit == 'V')
4990 {
4991 buf[1] = 'i';
4992 buf[2] = restart_edit;
4993 }
4994 }
4995
4996 /* Clear out the minor mode when the argument is not a non-zero number or
4997 * non-empty string. */
4998 if (!non_zero_arg(&argvars[0]))
4999 buf[1] = NUL;
5000
5001 rettv->vval.v_string = vim_strsave(buf);
5002 rettv->v_type = VAR_STRING;
5003 }
5004
5005 #if defined(FEAT_MZSCHEME) || defined(PROTO) 4916 #if defined(FEAT_MZSCHEME) || defined(PROTO)
5006 /* 4917 /*
5007 * "mzeval()" function 4918 * "mzeval()" function
5008 */ 4919 */
5009 static void 4920 static void