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 |
1211 | 1211 | |
1212 | 1212 | static gsize |
1213 | 1213 | edit_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) |
1215 | 1216 | { |
1216 | 1217 | gsize len = 0; |
1217 | 1218 | gsize max_len = 0; |
… |
… |
edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len, |
1301 | 1302 | if (skip != 0) |
1302 | 1303 | continue; |
1303 | 1304 | |
1304 | | if (*num == MAX_WORD_COMPLETIONS) |
| 1305 | if (*num >= current_limit) |
1305 | 1306 | { |
1306 | 1307 | g_string_free (compl[0], TRUE); |
1307 | 1308 | for (i = 1; i < *num; i++) |
… |
… |
edit_complete_word_cmd (WEdit * edit) |
3337 | 3338 | GString *match_expr; |
3338 | 3339 | GString *compl[MAX_WORD_COMPLETIONS]; /* completions */ |
3339 | 3340 | |
| 3341 | gboolean search_all_files; |
| 3342 | WEdit *edit_wid; |
| 3343 | const WGroup *gr; |
| 3344 | GList *w; |
| 3345 | |
3340 | 3346 | /* search start of word to be completed */ |
3341 | 3347 | if (!edit_find_word_start (&edit->buffer, &word_start, &word_len)) |
3342 | 3348 | return; |
… |
… |
edit_complete_word_cmd (WEdit * edit) |
3353 | 3359 | /* start search from begin to end of file */ |
3354 | 3360 | max_len = |
3355 | 3361 | 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 | } |
3357 | 3391 | |
3358 | 3392 | if (num_compl > 0) |
3359 | 3393 | { |