@@ -6923,39 +6923,27 @@ ex_wrongmodifier(exarg_T *eap)
69236923 eap -> errmsg = ex_errmsg (e_invalid_command_str , eap -> cmd );
69246924}
69256925
6926- #ifdef FEAT_EVAL
6926+ #if defined( FEAT_EVAL ) || defined( PROTO )
69276927/*
69286928 * Evaluate the 'findexpr' expression and return the result. When evaluating
69296929 * the expression, v:fname is set to the ":find" command argument.
69306930 */
69316931 static list_T *
6932- eval_findexpr (char_u * ptr , int len )
6932+ eval_findexpr (char_u * ptr )
69336933{
69346934 sctx_T saved_sctx = current_sctx ;
6935- int use_sandbox = FALSE;
69366935 char_u * findexpr ;
69376936 char_u * arg ;
69386937 typval_T tv ;
69396938 list_T * retlist = NULL ;
69406939
6941- if (* curbuf -> b_p_fexpr == NUL )
6942- {
6943- use_sandbox = was_set_insecurely ((char_u * )"findexpr" , OPT_GLOBAL );
6944- findexpr = p_fexpr ;
6945- }
6946- else
6947- {
6948- use_sandbox = was_set_insecurely ((char_u * )"findexpr" , OPT_LOCAL );
6949- findexpr = curbuf -> b_p_fexpr ;
6950- }
6940+ findexpr = get_findexpr ();
69516941
6952- set_vim_var_string (VV_FNAME , ptr , len );
6942+ set_vim_var_string (VV_FNAME , ptr , -1 );
69536943 current_sctx = curbuf -> b_p_script_ctx [BV_FEXPR ];
69546944
69556945 arg = skipwhite (findexpr );
69566946
6957- if (use_sandbox )
6958- ++ sandbox ;
69596947 ++ textlock ;
69606948
69616949 // Evaluate the expression. If the expression is "FuncName()" call the
@@ -6966,10 +6954,10 @@ eval_findexpr(char_u *ptr, int len)
69666954 {
69676955 if (tv .v_type == VAR_LIST )
69686956 retlist = list_copy (tv .vval .v_list , TRUE, TRUE, get_copyID ());
6957+ else
6958+ emsg (_ (e_invalid_return_type_from_findexpr ));
69696959 clear_tv (& tv );
69706960 }
6971- if (use_sandbox )
6972- -- sandbox ;
69736961 -- textlock ;
69746962 clear_evalarg (& EVALARG_EVALUATE , NULL );
69756963
@@ -6979,6 +6967,61 @@ eval_findexpr(char_u *ptr, int len)
69796967 return retlist ;
69806968}
69816969
6970+ /*
6971+ * Find file names matching "pat" using 'findexpr' and return it in "files".
6972+ * Used for expanding the :find, :sfind and :tabfind command argument.
6973+ * Returns OK on success and FAIL otherwise.
6974+ */
6975+ int
6976+ expand_findexpr (char_u * pat , char_u * * * files , int * numMatches )
6977+ {
6978+ list_T * l ;
6979+ int len ;
6980+ char_u * regpat ;
6981+
6982+ * numMatches = 0 ;
6983+ * files = NULL ;
6984+
6985+ // File name expansion uses wildchars. But the 'findexpr' expression
6986+ // expects a regular expression argument. So convert wildchars in the
6987+ // argument to regular expression patterns.
6988+ regpat = file_pat_to_reg_pat (pat , NULL , NULL , FALSE);
6989+ if (regpat == NULL )
6990+ return FAIL ;
6991+
6992+ l = eval_findexpr (regpat );
6993+
6994+ vim_free (regpat );
6995+
6996+ if (l == NULL )
6997+ return FAIL ;
6998+
6999+ len = list_len (l );
7000+ if (len == 0 ) // empty List
7001+ return FAIL ;
7002+
7003+ * files = ALLOC_MULT (char_u * , len );
7004+ if (* files == NULL )
7005+ return FAIL ;
7006+
7007+ // Copy all the List items
7008+ listitem_T * li ;
7009+ int idx = 0 ;
7010+ FOR_ALL_LIST_ITEMS (l , li )
7011+ {
7012+ if (li -> li_tv .v_type == VAR_STRING )
7013+ {
7014+ (* files )[idx ] = vim_strsave (li -> li_tv .vval .v_string );
7015+ idx ++ ;
7016+ }
7017+ }
7018+
7019+ * numMatches = idx ;
7020+ list_free (l );
7021+
7022+ return OK ;
7023+ }
7024+
69827025/*
69837026 * Use 'findexpr' to find file 'findarg'. The 'count' argument is used to find
69847027 * the n'th matching file.
@@ -6994,7 +7037,7 @@ findexpr_find_file(char_u *findarg, int findarg_len, int count)
69947037 cc = findarg [findarg_len ];
69957038 findarg [findarg_len ] = NUL ;
69967039
6997- fname_list = eval_findexpr (findarg , findarg_len );
7040+ fname_list = eval_findexpr (findarg );
69987041 fname_count = list_len (fname_list );
69997042
70007043 if (fname_count == 0 )
0 commit comments