Merge branch '1486_editor_completion'

* 1486_editor_completion:
  Added description of editor_wordcompletion_collect_entire_file option into man-files
  Editor: Autocomplete all words (not just English words)
  Added option for switch beetween 'collect completions before cursor'
  Ticket #1486: Editor completion is confusing
This commit is contained in:
Slava Zanko 2009-09-23 16:14:03 +03:00
commit 1a4b2af99e
5 changed files with 113 additions and 7 deletions

View File

@ -2590,6 +2590,7 @@ at the
.\"LINK2"
Extension File Edit section
.\"Extension File Edit"
.\"NODE "Internal File Editor"
.SH "Internal File Editor"
The internal file editor is a full\-featured full screen editor. It can
@ -2607,6 +2608,14 @@ commands; regular expression search and replace; shift\-arrow text highlighting
autoindent; tunable tab size; syntax highlighting for various file
types; and an option to pipe text blocks through shell commands like
indent and ispell.
.PP
Sections:
.IP
.\"LINK2"
Options of editor in ini-file
.\"Internal File Editor / options"
.PP
The editor is very easy to use and requires no tutoring. To see what
keys do what, just consult the appropriate pull\-down menu. Other keys
@ -2659,6 +2668,19 @@ The editor also displays non\-us characters (160+). When editing
binary files, you should set
.B display bits
to 7 bits in the options menu to keep the spacing clean.
.\"NODE "Internal File Editor / options"
.SH "Options of editor in ini-file"
In this section described some options in ini-file.
Options placed in '[Midnight Commander]' section
.TP
.I editor_wordcompletion_collect_entire_file
Search autocomplete candidates in entire of file or just from
begin of file to cursor position (0)
.\"NODE "Completion"
.SH "Completion"
Let the Midnight Commander type for you.

View File

@ -484,6 +484,11 @@ save file position on exit.
.TP
.I source_codepage
symbol representation of codepage name for file (i.e. CP1251, ~ \- default).
.TP
.I editor_wordcompletion_collect_entire_file
Search autocomplete candidates in entire of file or just from
begin of file to cursor position (0)
.SH MISCELLANEOUS
You can use scanf search and replace to search and replace a C format
string. First take a look at the

View File

@ -2899,6 +2899,7 @@ shell, возврат в программу просмотра по
.\"LINK2"
файлом расширений\&.
.\"Extension File Edit"
.\"NODE "Internal File Editor"
.SH "Встроенный редактор"
Встроенный редактор обеспечивает выполнение большинства функций
@ -2919,6 +2920,15 @@ shift\-стрелки в стиле MSW\-MAC (только для linux\-кон
переключение между режимами вставки\-замены символа; а
также операция обработки блоков текста командами оболочки (an option to
pipe text blocks through shell commands like indent).
.PP
Разделы:
.IP
.\"LINK2"
Опции в ини-файле для редактора
.\"Internal File Editor / options"
.PP
Редактор очень прост и практически не требует обучения. Для того, чтобы
узнать, какие клавиши вызывают выполнение определенных действий,
@ -2983,6 +2993,20 @@ pipe text blocks through shell commands like indent).
.B man mcedit
или
.B info mcedit
.\"NODE "Internal File Editor / options"
.SH "Опции в ини-файле для редактора"
В данном разделе кратко описаны опции ini\-файла, относящиеся к редактору.
Опции записываются в секцию '[Midnight Commander]'
.TP
.I editor_wordcompletion_collect_entire_file
При автодополнении для сбора похожих слов слов просматривать весь файл(1)
или только от начала до курсора (0)
.\"NODE "Completion"
.SH "Завершение ввода (Completion)"
Заставьте Midnight Commander работать на клавиатуре вместо вас!

View File

@ -59,6 +59,7 @@
#include "../src/charsets.h"
#include "../src/selcodepage.h"
#include "../src/strutil.h" /* utf string functions */
#include "../src/mcconfig/mcconfig.h"
#include "../edit/edit-impl.h"
#include "../edit/edit.h"
@ -2365,19 +2366,27 @@ edit_collect_completions (WEdit *edit, long start, int word_len,
GString *temp;
mc_search_t *srch;
long last_byte;
srch = mc_search_new(match_expr, -1);
if (srch == NULL)
return 0;
if (mc_config_get_bool(mc_main_config, CONFIG_APP_SECTION, "editor_wordcompletion_collect_entire_file", 0)){
last_byte = edit->last_byte;
} else {
last_byte = start;
}
srch->search_type = MC_SEARCH_T_REGEX;
srch->is_case_sentitive = TRUE;
srch->search_fn = edit_search_cmd_callback;
/* collect max MAX_WORD_COMPLETIONS completions */
start--;
while (*num < MAX_WORD_COMPLETIONS) {
start = -1;
while (1) {
/* get next match */
if (mc_search_run (srch, (void *) edit, start+1, edit->last_byte, &len) == FALSE)
if (mc_search_run (srch, (void *) edit, start+1, last_byte, &len) == FALSE)
break;
start = srch->normal_offset;
@ -2399,6 +2408,11 @@ edit_collect_completions (WEdit *edit, long start, int word_len,
(char *) &temp->str[word_len],
max (len, compl[i].len) - (gsize)word_len
) == 0) {
struct selection this = compl[i];
for (++i; i < *num; i++) {
compl[i - 1] = compl[i];
}
compl[*num - 1] = this;
skip = 1;
break; /* skip it, already added */
}
@ -2407,10 +2421,29 @@ edit_collect_completions (WEdit *edit, long start, int word_len,
g_string_free(temp, TRUE);
continue;
}
if (*num == MAX_WORD_COMPLETIONS && MAX_WORD_COMPLETIONS) {
g_free(compl[0].text);
for (i = 1; i < *num; i++) {
compl[i - 1] = compl[i];
}
(*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 */
@ -2443,12 +2476,13 @@ 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 ("(^|\\s)%.*s[^\\s\\.=\\+\\{\\}\\[\\]\\(\\)\\\\\\!\\,<>\\?\\/@#\\$%%\\^&\\*\\~\\|\\\"'\\:\\;]+", 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 */
max_len =
edit_collect_completions (edit, 0, word_len, match_expr,
edit_collect_completions (edit, word_start, word_len, match_expr,
(struct selection *) &compl, &num_compl);
if (num_compl > 0) {

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"
@ -333,15 +334,35 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
add_widget (compl_dlg, compl_list);
/* fill the listbox with the completions */
for (i = 0; i < num_compl; i++)
for (i = num_compl - 1; i >= 0; i--) /* reverse order */
listbox_add_item (compl_list, LISTBOX_APPEND_AT_END, 0, (char *) compl[i].text, NULL);
/* 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 */