From a1e3999abffc6695ffb387b0ebaec66247747416 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 13 Aug 2009 15:47:11 +0300 Subject: [PATCH] Editor: Autocomplete all words (not just English words) Also fix charset conversation for autocompleted text. Signed-off-by: Slava Zanko --- edit/editcmd.c | 15 ++++++++++++++- edit/editcmd_dialogs.c | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/edit/editcmd.c b/edit/editcmd.c index 94a8b2dfd..53ff14272 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -2428,10 +2428,22 @@ edit_collect_completions (WEdit *edit, long start, int word_len, } (*num)--; } +#ifdef HAVE_CHARSET + { + GString *recoded; + recoded = str_convert_to_display (temp->str); + if (recoded && recoded->len){ + g_string_free(temp,TRUE); + temp = recoded; + } else + g_string_free(recoded , TRUE); + } +#endif compl[*num].text = temp->str; compl[*num].len = temp->len; (*num)++; + start += len; g_string_free(temp, FALSE); /* note the maximal length needed for the completion dialog */ @@ -2464,7 +2476,8 @@ edit_complete_word_cmd (WEdit *edit) bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE] [word_start & M_EDIT_BUF_SIZE]; - match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); + /* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */ + match_expr = g_strdup_printf ("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+", word_len, bufpos); /* collect the possible completions */ /* start search from begin to end of file */ diff --git a/edit/editcmd_dialogs.c b/edit/editcmd_dialogs.c index 3cc7c35c0..22ce0d002 100644 --- a/edit/editcmd_dialogs.c +++ b/edit/editcmd_dialogs.c @@ -40,6 +40,7 @@ #include "../src/dialog.h" /* do_refresh() */ #include "../src/main.h" #include "../src/history.h" +#include "../src/charsets.h" #include "../edit/edit-widget.h" #include "../edit/etags.h" @@ -339,9 +340,29 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len, /* pop up the dialog and apply the choosen completion */ if (run_dlg (compl_dlg) == B_ENTER) { listbox_get_current (compl_list, &curr, NULL); - if (curr) + if (curr) { +#ifdef HAVE_CHARSET + GString *temp, *temp2; + temp = g_string_new(""); + for (curr += word_len; *curr; curr++) + g_string_append_c(temp, *curr); + + temp2 = str_convert_to_input (temp->str); + + if (temp2 && temp2->len){ + g_string_free(temp, TRUE); + temp = temp2; + } + else + g_string_free(temp2, TRUE); + for (curr = temp->str; *curr; curr++) + edit_insert (edit, *curr); + g_string_free(temp, TRUE); +#else for (curr += word_len; *curr; curr++) edit_insert (edit, *curr); +#endif + } } /* destroy dialog before return */