Ticket #4160: CompleteAllFiles_v2-1.patch

File CompleteAllFiles_v2-1.patch, 6.6 KB (added by psprint, 3 years ago)

complete from all open buffers by default

  • src/editor/edit.c

    From 300297d8821ce24f562573b35fe09b0e5c93ba98 Mon Sep 17 00:00:00 2001
    From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
    Date: Wed, 20 Jan 2021 19:52:55 -0600
    Subject: Add an option for completing from all buffers.
    
    ---
     src/editor/edit.c            |  1 +
     src/editor/edit.h            |  1 +
     src/editor/editcmd.c         | 46 ++++++++++++++++++++++++++++++++----
     src/editor/editcmd_dialogs.c |  9 +++++++
     src/setup.c                  |  1 +
     5 files changed, 53 insertions(+), 5 deletions(-)
    
    diff --git a/src/editor/edit.c b/src/editor/edit.c
    index edda1f832..bada6619c 100644
    a b gboolean option_line_state = FALSE; 
    9090int option_line_state_width = 0; 
    9191gboolean option_cursor_after_inserted_block = FALSE; 
    9292gboolean option_state_full_filename = FALSE; 
     93gboolean option_completion_collect_other_files = TRUE; 
    9394 
    9495gboolean enable_show_tabs_tws = TRUE; 
    9596gboolean option_check_nl_at_eof = FALSE; 
  • src/editor/edit.h

    diff --git a/src/editor/edit.h b/src/editor/edit.h
    index 6c519e9d3..de5645179 100644
    a b extern int option_save_mode; 
    4747extern gboolean option_save_position; 
    4848extern gboolean option_syntax_highlighting; 
    4949extern gboolean option_group_undo; 
     50extern gboolean option_completion_collect_other_files; 
    5051extern char *option_backup_ext; 
    5152extern char *option_filesize_threshold; 
    5253extern char *option_stop_format_chars; 
  • src/editor/editcmd.c

    diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
    index 0d2caa923..e77b8a07f 100644
    a b gboolean option_drop_selection_on_copy = TRUE; 
    9696 
    9797#define TEMP_BUF_LEN 1024 
    9898 
    99 #define MAX_WORD_COMPLETIONS 100        /* in listbox */ 
     99#define MAX_WORD_COMPLETIONS 150        /* in listbox */ 
    100100 
    101101/*** file scope type declarations ****************************************************************/ 
    102102 
    edit_collect_completions_get_current_word (edit_search_status_msg_t * esm, mc_se 
    12121212 
    12131213static gsize 
    12141214edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, 
    1215                           char *match_expr, GString ** compl, gsize * num) 
     1215                          char *match_expr, GString ** compl, gsize * num, gsize current_limit) 
    12161216{ 
    12171217    gsize len = 0; 
    12181218    gsize max_len = 0; 
    edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, 
    12351235 
    12361236    entire_file = 
    12371237        mc_config_get_bool (mc_global.main_config, CONFIG_APP_SECTION, 
    1238                             "editor_wordcompletion_collect_entire_file", 0); 
     1238                            "editor_wordcompletion_collect_entire_file", 1); 
    12391239 
    12401240    last_byte = entire_file ? edit->buffer.size : word_start; 
    12411241 
    edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, 
    13021302        if (skip != 0) 
    13031303            continue; 
    13041304 
    1305         if (*num == MAX_WORD_COMPLETIONS) 
     1305        if (*num >= current_limit) 
    13061306        { 
    13071307            g_string_free (compl[0], TRUE); 
    13081308            for (i = 1; i < *num; i++) 
    edit_complete_word_cmd (WEdit * edit) 
    33393339    GString *match_expr; 
    33403340    GString *compl[MAX_WORD_COMPLETIONS];       /* completions */ 
    33413341 
     3342    WEdit *edit_wid; 
     3343    const WGroup *gr; 
     3344    GList *w; 
     3345 
    33423346    /* search start of word to be completed */ 
    33433347    if (!edit_find_word_start (&edit->buffer, &word_start, &word_len)) 
    33443348        return; 
    edit_complete_word_cmd (WEdit * edit) 
    33553359    /* start search from begin to end of file */ 
    33563360    max_len = 
    33573361        edit_collect_completions (edit, word_start, word_len, match_expr->str, (GString **) & compl, 
    3358                                   &num_compl); 
     3362                                  &num_compl, MAX_WORD_COMPLETIONS); 
     3363 
     3364    /* 
     3365     * Should search also other open files ? This «if» collects them up to MAX_WORD_COMPLETIONS 
     3366     * limit. 
     3367     */ 
     3368    if (option_completion_collect_other_files && num_compl < MAX_WORD_COMPLETIONS) 
     3369    { 
     3370        /* 
     3371         * Process all the remaining files by listing the editor widgets 
     3372         * grouped in the main editor dialog. 
     3373         */ 
     3374        gr = CONST_GROUP (CONST_WIDGET (edit)->owner); 
     3375        for (w = gr->widgets; w != NULL; w = g_list_next (w)) 
     3376        { 
     3377            if (w->data != edit && edit_widget_is_editor (CONST_WIDGET (w->data))) 
     3378            { 
     3379                gsize max_len_candidate, num_compl_sub = 0; 
     3380                edit_wid = (WEdit *) w->data; 
     3381                max_len_candidate = 
     3382                    edit_collect_completions (edit_wid, word_start, word_len, match_expr->str, 
     3383                                              ((GString **) & compl) + num_compl, &num_compl_sub, 
     3384                                              MAX_WORD_COMPLETIONS - num_compl); 
     3385 
     3386                if (max_len_candidate > max_len) 
     3387                    max_len = max_len_candidate; 
     3388 
     3389                num_compl += num_compl_sub; 
     3390                if (num_compl >= MAX_WORD_COMPLETIONS) 
     3391                    break; 
     3392            } 
     3393        } 
     3394    } 
    33593395 
    33603396    if (num_compl > 0) 
    33613397    { 
  • src/editor/editcmd_dialogs.c

    diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c
    index 8b3634f23..3c65331c2 100644
    a b editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** comp 
    385385 
    386386    /* create the listbox */ 
    387387    compl_list = listbox_new (1, 1, compl_dlg_h - 2, compl_dlg_w - 2, FALSE, NULL); 
     388    compl_list->allow_duplicates = FALSE; 
    388389 
    389390    /* add the dialog */ 
    390391    group_add_widget (GROUP (compl_dlg), compl_list); 
    editcmd_dialog_completion_show (const WEdit * edit, int max_len, GString ** comp 
    394395        listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i]->str, NULL, 
    395396                          FALSE); 
    396397 
     398    /* Set widgets size after possible duplicates removal. */ 
     399    num_compl = listbox_get_length (compl_list); 
     400    if (num_compl < compl_dlg_h - 2) 
     401    { 
     402        WIDGET (compl_list)->lines = num_compl; 
     403        WIDGET (compl_dlg)->lines = num_compl + 2; 
     404    } 
     405 
    397406    /* pop up the dialog and apply the chosen completion */ 
    398407    if (dlg_run (compl_dlg) == B_ENTER) 
    399408    { 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 77c07649d..f2f5eb427 100644
    a b static const struct 
    357357    { "editor_show_right_margin", &show_right_margin }, 
    358358    { "editor_group_undo", &option_group_undo }, 
    359359    { "editor_state_full_filename", &option_state_full_filename }, 
     360    { "editor_wordcompletion_collect_other_files", &option_completion_collect_other_files }, 
    360361#endif /* USE_INTERNAL_EDIT */ 
    361362    { "editor_ask_filename_before_edit", &editor_ask_filename_before_edit }, 
    362363    { "nice_rotating_dash", &nice_rotating_dash },