Ticket #4160: 0001-Add-an-option-to-complete-words-from-all-open-files-.patch

File 0001-Add-an-option-to-complete-words-from-all-open-files-.patch, 3.4 KB (added by psprint, 3 years ago)
  • src/editor/editcmd.c

    From 43037f84163c058056a55bc3f7ef002dd90dc814 Mon Sep 17 00:00:00 2001
    From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
    Date: Thu, 17 Dec 2020 18:09:20 -0600
    Subject: [PATCH] =?UTF-8?q?Add=20an=20option=20to=20complete=20words=20fro?=
     =?UTF-8?q?m=20=C2=ABall=C2=BB=20open=20files,=20not=20only=20the=20curren?=
     =?UTF-8?q?t=20one.?=
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    ---
     src/editor/editcmd.c | 40 +++++++++++++++++++++++++++++++++++++---
     1 file changed, 37 insertions(+), 3 deletions(-)
    
    diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
    index f3597fc88..8c73927ea 100644
    a b edit_collect_completions_get_current_word (edit_search_status_msg_t * esm, mc_se 
    12111211 
    12121212static gsize 
    12131213edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, 
    1214                           char *match_expr, GString ** compl, gsize * num) 
     1214                          char *match_expr, GString ** compl, gsize * num, 
     1215                          gsize current_limit) 
    12151216{ 
    12161217    gsize len = 0; 
    12171218    gsize max_len = 0; 
    edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, 
    13011302        if (skip != 0) 
    13021303            continue; 
    13031304 
    1304         if (*num == MAX_WORD_COMPLETIONS) 
     1305        if (*num >= current_limit) 
    13051306        { 
    13061307            g_string_free (compl[0], TRUE); 
    13071308            for (i = 1; i < *num; i++) 
    edit_complete_word_cmd (WEdit * edit) 
    33373338    GString *match_expr; 
    33383339    GString *compl[MAX_WORD_COMPLETIONS];       /* completions */ 
    33393340 
     3341    gboolean search_all_files; 
     3342    WEdit *edit_wid; 
     3343    const WGroup *gr; 
     3344    GList *w; 
     3345 
    33403346    /* search start of word to be completed */ 
    33413347    if (!edit_find_word_start (&edit->buffer, &word_start, &word_len)) 
    33423348        return; 
    edit_complete_word_cmd (WEdit * edit) 
    33533359    /* start search from begin to end of file */ 
    33543360    max_len = 
    33553361        edit_collect_completions (edit, word_start, word_len, match_expr->str, (GString **) & compl, 
    3356                                   &num_compl); 
     3362                                  &num_compl, MAX_WORD_COMPLETIONS); 
     3363 
     3364    // Should search also other open files ? 
     3365    search_all_files = 
     3366        mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, 
     3367                            "editor_wordcompletion_collect_all_files", 1); 
     3368 
     3369    if (search_all_files && num_compl < MAX_WORD_COMPLETIONS) { 
     3370        // Process all the remaining files by listing the editor widgets  
     3371        // grouped in the main editor dialog. 
     3372        gr = CONST_GROUP (CONST_WIDGET(edit)->owner); 
     3373        for (w = gr->widgets; w != NULL; w = g_list_next (w)) { 
     3374            if (w->data != edit && edit_widget_is_editor (CONST_WIDGET (w->data))) { 
     3375                gsize max_len_candidate, num_compl_sub = 0; 
     3376                edit_wid = (WEdit *) w->data; 
     3377                max_len_candidate = 
     3378                    edit_collect_completions (edit_wid, word_start, word_len, match_expr->str, 
     3379                            ((GString **) &compl)+num_compl, &num_compl_sub, 
     3380                             MAX_WORD_COMPLETIONS - num_compl); 
     3381 
     3382                if (max_len_candidate > max_len) 
     3383                    max_len = max_len_candidate; 
     3384 
     3385                num_compl += num_compl_sub; 
     3386                if (num_compl >= MAX_WORD_COMPLETIONS) 
     3387                    break; 
     3388            } 
     3389        } 
     3390    } 
    33573391 
    33583392    if (num_compl > 0) 
    33593393    {