@@ -197,6 +197,8 @@ typedef struct trystate_S
197197#define PFD_PREFIXTREE 0xfe // walking through the prefix tree
198198#define PFD_NOTSPECIAL 0xfd // highest value that's not special
199199
200+ static long spell_suggest_timeout = 5000 ;
201+
200202static void spell_find_suggest (char_u * badptr , int badlen , suginfo_T * su , int maxcount , int banbadword , int need_cap , int interactive );
201203#ifdef FEAT_EVAL
202204static void spell_suggest_expr (suginfo_T * su , char_u * expr );
@@ -429,7 +431,10 @@ spell_check_sps(void)
429431 else if (STRCMP (buf , "double" ) == 0 )
430432 f = SPS_DOUBLE ;
431433 else if (STRNCMP (buf , "expr:" , 5 ) != 0
432- && STRNCMP (buf , "file:" , 5 ) != 0 )
434+ && STRNCMP (buf , "file:" , 5 ) != 0
435+ && (STRNCMP (buf , "timeout:" , 8 ) != 0
436+ || (!VIM_ISDIGIT (buf [8 ])
437+ && !(buf [8 ] == '-' && VIM_ISDIGIT (buf [9 ])))))
433438 f = -1 ;
434439
435440 if (f == -1 || (sps_flags != 0 && f != 0 ))
@@ -842,6 +847,7 @@ spell_find_suggest(
842847 sps_copy = vim_strsave (p_sps );
843848 if (sps_copy == NULL )
844849 return ;
850+ spell_suggest_timeout = 5000 ;
845851
846852 // Loop over the items in 'spellsuggest'.
847853 for (p = sps_copy ; * p != NUL ; )
@@ -864,6 +870,9 @@ spell_find_suggest(
864870 else if (STRNCMP (buf , "file:" , 5 ) == 0 )
865871 // Use list of suggestions in a file.
866872 spell_suggest_file (su , buf + 5 );
873+ else if (STRNCMP (buf , "timeout:" , 8 ) == 0 )
874+ // Limit the time searching for suggestions.
875+ spell_suggest_timeout = atol ((char * )buf + 8 );
867876 else if (!did_intern )
868877 {
869878 // Use internal method once.
@@ -1325,9 +1334,10 @@ suggest_trie_walk(
13251334 }
13261335 }
13271336#ifdef FEAT_RELTIME
1328- // The loop may take an indefinite amount of time. Break out after five
1329- // sectonds. TODO: add an option for the time limit.
1330- profile_setlimit (5000 , & time_limit );
1337+ // The loop may take an indefinite amount of time. Break out after some
1338+ // time.
1339+ if (spell_suggest_timeout > 0 )
1340+ profile_setlimit (spell_suggest_timeout , & time_limit );
13311341#endif
13321342
13331343 // Loop to find all suggestions. At each round we either:
@@ -2659,7 +2669,8 @@ suggest_trie_walk(
26592669 ui_breakcheck ();
26602670 breakcheckcount = 1000 ;
26612671#ifdef FEAT_RELTIME
2662- if (profile_passed_limit (& time_limit ))
2672+ if (spell_suggest_timeout > 0
2673+ && profile_passed_limit (& time_limit ))
26632674 got_int = TRUE;
26642675#endif
26652676 }
0 commit comments