Editor: Autocomplete all words (not just English words)

Also fix charset conversation for autocompleted text.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-08-13 15:47:11 +03:00
parent d5381e862e
commit a1e3999abf
2 changed files with 36 additions and 2 deletions

View File

@ -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 */

View File

@ -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 */